obi export: made output to stdout and pipe in less possible

This commit is contained in:
Celine Mercier
2019-09-17 12:31:03 +02:00
parent f566618be6
commit a0c8deb806

View File

@ -7,9 +7,11 @@ from obitools3.dms import DMS
from obitools3.dms.obiseq import Nuc_Seq from obitools3.dms.obiseq import Nuc_Seq
from obitools3.apps.optiongroups import addMinimalInputOption, \ from obitools3.apps.optiongroups import addMinimalInputOption, \
addExportOutputOption addExportOutputOption, \
addNoProgressBarOption
import sys import sys
import io
__title__="Export a view to a different file format" __title__="Export a view to a different file format"
@ -18,6 +20,7 @@ def addOptions(parser):
addMinimalInputOption(parser) addMinimalInputOption(parser)
addExportOutputOption(parser) addExportOutputOption(parser)
addNoProgressBarOption(parser)
def run(config): def run(config):
@ -46,24 +49,33 @@ def run(config):
raise Exception("Error: the view to export in fasta or fastq format is not a NUC_SEQS view") raise Exception("Error: the view to export in fasta or fastq format is not a NUC_SEQS view")
# Initialize the progress bar # Initialize the progress bar
pb = ProgressBar(len(iview), config, seconde=5) if config['obi']['noprogressbar']:
pb = None
else:
pb = ProgressBar(len(iview), config, seconde=5)
i=0 i=0
for seq in iview : for seq in iview :
pb(i) if pb is not None:
pb(i)
try: try:
writer(seq) writer(seq)
except StopIteration: except (StopIteration, BrokenPipeError, IOError):
break break
i+=1 i+=1
pb(i, force=True) if pb is not None:
pb(i, force=True)
print("", file=sys.stderr) print("", file=sys.stderr)
# TODO save command in input dms? # TODO save command in input dms?
output_object.close() if not BrokenPipeError and not IOError:
output_object.close()
iview.close() iview.close()
input[0].close() input[0].close()
logger("info", "Done.") logger("info", "Done.")
if BrokenPipeError or IOError:
sys.stderr.close()