Add a rank option allowing to add a rank attribute to sequences containing an integer value indicating the position of the sequence in the input file.

This commit is contained in:
2011-02-03 18:48:11 +00:00
parent 41ecd2b5e4
commit 5c54d7a939

View File

@ -18,10 +18,16 @@ from obitools.format._format import printOutput
from array import array
from itertools import chain
import sys
def addInputFormatOption(optionManager):
optionManager.add_option('--rank',
action="store_true", dest='addrank',
default=False,
help="add a rank attribute to the sequence "
"indicating the sequence position in the input data")
optionManager.add_option('--genbank',
action="store_const", dest="seqinformat",
default=None,
@ -127,6 +133,15 @@ def autoEntriesIterator(options):
return iterator
def withRankIterator(formatIterator):
def iterator(lineiterator):
rank=0
for s in formatIterator(lineiterator):
rank+=1
s['rank']=rank
yield s
return iterator
def withQualIterator(qualityfile):
options.outputFormater=formatFastq
options.outputFormat="fastq"
@ -207,6 +222,8 @@ def autoEntriesIterator(options):
options.outputFormater=formatFastq
options.outputFormat="fastq"
if options.addrank:
reader = withRankIterator(reader)
return reader