All commands now handle outputing to another DMS + small fixes
This commit is contained in:
70
python/obitools3/commands/clean.pyx
Normal file → Executable file
70
python/obitools3/commands/clean.pyx
Normal file → Executable file
@ -8,7 +8,7 @@ from obitools3.dms.capi.obiclean cimport obi_clean
|
||||
from obitools3.apps.optiongroups import addMinimalInputOption, addMinimalOutputOption
|
||||
from obitools3.uri.decode import open_uri
|
||||
from obitools3.apps.config import logger
|
||||
from obitools3.utils cimport tobytes
|
||||
from obitools3.utils cimport tobytes, str2bytes
|
||||
from obitools3.dms.view.view cimport View
|
||||
from obitools3.dms.view.typed_view.view_NUC_SEQS cimport View_NUC_SEQS
|
||||
|
||||
@ -66,38 +66,58 @@ def run(config):
|
||||
DMS.obi_atexit()
|
||||
|
||||
logger("info", "obi clean")
|
||||
|
||||
# Open DMS
|
||||
dms_name = config['obi']['inputURI'].split('/')[0]
|
||||
dms = open_uri(dms_name)[0]
|
||||
|
||||
# Read the name of the input view
|
||||
uri_i = config['obi']['inputURI'].split('/')
|
||||
i_view_name = uri_i[1]
|
||||
|
||||
# Read the name of the output view
|
||||
uri_o = config['obi']['outputURI'].split('/')
|
||||
if len(uri_o)==2:
|
||||
# Check that input and output DMS are the same (predicate, to discuss)
|
||||
if dms_name != uri_o[0]:
|
||||
raise Exception("Input and output DMS must be the same")
|
||||
o_view_name = uri_o[1]
|
||||
# Open the input: only the DMS
|
||||
input = open_uri(config['obi']['inputURI'],
|
||||
dms_only=True)
|
||||
if input is None:
|
||||
raise Exception("Could not read input")
|
||||
i_dms = input[0]
|
||||
i_dms_name = input[0].name
|
||||
i_view_name = input[1]
|
||||
|
||||
# Open the output: only the DMS
|
||||
output = open_uri(config['obi']['outputURI'],
|
||||
input=False,
|
||||
dms_only=True)
|
||||
if output is None:
|
||||
raise Exception("Could not create output")
|
||||
o_dms = output[0]
|
||||
final_o_view_name = output[1]
|
||||
|
||||
# If the input and output DMS are not the same, run obiclean creating a temporary view that will be exported to
|
||||
# the right DMS and deleted in the other afterwards.
|
||||
if i_dms != o_dms:
|
||||
temporary_view_name = final_o_view_name
|
||||
i=0
|
||||
while temporary_view_name in i_dms: # Making sure view name is unique in input DMS
|
||||
temporary_view_name = final_o_view_name+b"_"+str2bytes(str(i))
|
||||
i+=1
|
||||
o_view_name = temporary_view_name
|
||||
else:
|
||||
o_view_name = uri_o[0]
|
||||
|
||||
o_view_name = final_o_view_name
|
||||
|
||||
# Save command config in View comments
|
||||
command_line = " ".join(sys.argv[1:])
|
||||
comments = View.print_config(config, "clean", command_line, input_dms_name=[dms_name], input_view_name=[i_view_name])
|
||||
comments = View.print_config(config, "clean", command_line, input_dms_name=[i_dms_name], input_view_name=[i_view_name])
|
||||
|
||||
if obi_clean(tobytes(dms_name), tobytes(i_view_name), tobytes(config['clean']['sample-tag-name']), tobytes(o_view_name), comments, \
|
||||
if obi_clean(tobytes(i_dms_name), tobytes(i_view_name), tobytes(config['clean']['sample-tag-name']), tobytes(o_view_name), comments, \
|
||||
config['clean']['distance'], config['clean']['ratio'], config['clean']['heads-only'], 1) < 0:
|
||||
raise Exception("Error running obiclean")
|
||||
|
||||
|
||||
# If the input and output DMS are not the same, export result view to output DMS
|
||||
if i_dms != o_dms:
|
||||
View.import_view(i_dms.full_path[:-7], o_dms.full_path[:-7], o_view_name, final_o_view_name)
|
||||
|
||||
# Save command config in DMS comments
|
||||
dms.record_command_line(command_line)
|
||||
o_dms.record_command_line(command_line)
|
||||
|
||||
print("\n")
|
||||
print(repr(dms[o_view_name]))
|
||||
|
||||
dms.close()
|
||||
print(repr(o_dms[final_o_view_name]))
|
||||
|
||||
# If the input and the output DMS are different, delete the temporary result view in the input DMS
|
||||
if i_dms != o_dms:
|
||||
View.delete_view(i_dms, o_view_name)
|
||||
o_dms.close()
|
||||
|
||||
i_dms.close()
|
||||
|
Reference in New Issue
Block a user