obi import: importing a view to a DMS now uses the C API (more efficient

and imports all metadata)
This commit is contained in:
Celine Mercier
2019-09-21 12:49:29 +02:00
parent f0f7edf152
commit 06f9d6da60
2 changed files with 26 additions and 12 deletions

View File

@ -14,6 +14,7 @@ from obitools3.dms.taxo.taxo cimport Taxonomy
from obitools3.utils cimport tobytes, \ from obitools3.utils cimport tobytes, \
tostr, \
get_obitype, \ get_obitype, \
update_obitype update_obitype
@ -25,6 +26,8 @@ from obitools3.dms.capi.obiview cimport VIEW_TYPE_NUC_SEQS, \
COUNT_COLUMN, \ COUNT_COLUMN, \
TAXID_COLUMN TAXID_COLUMN
from obitools3.dms.capi.obidms cimport obi_import_view
from obitools3.dms.capi.obitypes cimport obitype_t, \ from obitools3.dms.capi.obitypes cimport obitype_t, \
OBI_VOID, \ OBI_VOID, \
OBI_QUAL OBI_QUAL
@ -124,7 +127,7 @@ def run(config):
else: else:
v = None v = None
if config['obi']['taxdump']: if config['obi']['taxdump'] or isinstance(input[1], View):
dms_only=True dms_only=True
else: else:
dms_only=False dms_only=False
@ -134,20 +137,31 @@ def run(config):
newviewtype=v, newviewtype=v,
dms_only=dms_only) dms_only=dms_only)
if output is None: if output is None:
raise Exception("Could not create output view") raise Exception("Could not open output")
o_dms = output[0]
# If importing a view between two DMS, use C API
if isinstance(input[1], View):
if obi_import_view(input[0].name_with_full_path, o_dms.name_with_full_path, input[1].name, tobytes((config['obi']['outputURI'].split('/'))[-1])) < 0 :
raise Exception("Error importing a view in a DMS")
o_dms.record_command_line(" ".join(sys.argv[1:]))
o_dms.close()
logger("info", "Done.")
return
# Read taxdump # Read taxdump
if config['obi']['taxdump']: # The input is a taxdump to import in a DMS if config['obi']['taxdump']: # The input is a taxdump to import in a DMS
# Check if taxonomy name isn't already taken # Check if taxonomy name isn't already taken
dms = output[0]
taxo_name = output[1] taxo_name = output[1]
if Taxonomy.exists(dms, taxo_name.split(b'/')[1]): if Taxonomy.exists(o_dms, taxo_name.split(b'/')[1]):
raise Exception("Taxonomy name already exists in this DMS") raise Exception("Taxonomy name already exists in this DMS")
taxo = Taxonomy.open_taxdump(dms, config['obi']['inputURI']) taxo = Taxonomy.open_taxdump(o_dms, config['obi']['inputURI'])
taxo.write(taxo_name) taxo.write(taxo_name)
taxo.close() taxo.close()
dms.record_command_line(" ".join(sys.argv[1:])) o_dms.record_command_line(" ".join(sys.argv[1:]))
dms.close() o_dms.close()
logger("info", "Done.") logger("info", "Done.")
return return

View File

@ -5,7 +5,7 @@ from obitools3.apps.config import logger
from obitools3.dms import DMS from obitools3.dms import DMS
from obitools3.dms.taxo.taxo cimport Taxonomy from obitools3.dms.taxo.taxo cimport Taxonomy
from obitools3.apps.optiongroups import addMinimalInputOption from obitools3.apps.optiongroups import addMinimalInputOption
from obitools3.utils cimport tostr from obitools3.utils cimport tostr, bytes2str_object
__title__="Print a preview of a DMS, view, column...." __title__="Print a preview of a DMS, view, column...."
@ -35,7 +35,7 @@ def run(config):
dms = input[0] dms = input[0]
l = [] l = []
for view in input[0]: for view in input[0]:
l.append(tostr(view) + "\t(Date created: " + tostr(dms[view].comments["Date created"])+")") l.append(tostr(view) + "\t(Date created: " + str(bytes2str_object(dms[view].comments["Date created"]))+")")
l.sort() l.sort()
for v in l: for v in l:
print(v) print(v)