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.apps.optiongroups import addMinimalInputOption, \
addExportOutputOption
addExportOutputOption, \
addNoProgressBarOption
import sys
import io
__title__="Export a view to a different file format"
@ -18,6 +20,7 @@ def addOptions(parser):
addMinimalInputOption(parser)
addExportOutputOption(parser)
addNoProgressBarOption(parser)
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")
# Initialize the progress bar
if config['obi']['noprogressbar']:
pb = None
else:
pb = ProgressBar(len(iview), config, seconde=5)
i=0
for seq in iview :
if pb is not None:
pb(i)
try:
writer(seq)
except StopIteration:
except (StopIteration, BrokenPipeError, IOError):
break
i+=1
if pb is not None:
pb(i, force=True)
print("", file=sys.stderr)
# TODO save command in input dms?
if not BrokenPipeError and not IOError:
output_object.close()
iview.close()
input[0].close()
logger("info", "Done.")
if BrokenPipeError or IOError:
sys.stderr.close()