1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#!/usr/bin/python3
'''
:py:mod:`obihead`: extracts the first sequence records
======================================================
.. codeauthor:: Eric Coissac <eric.coissac@metabarcoding.org>
:py:mod:`obihead` command is in some way analog to the standard Unix `head` command.
It selects the head of a sequence file.
But instead of working text line by text line as the standard Unix tool,
selection is done at the sequence record level. You can specify the number of sequence records
to select.
*Example:*
.. code-block:: bash
> obihead -n 150 seq1.fasta > seq2.fasta
Selects the 150 first sequence records from the ``seq1.fasta`` file and stores
them into the ``seq2.fasta`` file.
'''
import sys
from obitools.format.options import addInOutputOption, sequenceWriterGenerator
from obitools.options import getOptionManager
def addHeadOptions(optionManager):
optionManager.add_option('-n','--sequence-count',
action="store", dest="count",
metavar="###",
type="int",
default=10,
help="Count of first sequences to print")
if __name__ == '__main__':
optionParser = getOptionManager([addHeadOptions,addInOutputOption])
(options, entries) = optionParser()
i=0
writer = sequenceWriterGenerator(options)
for s in entries:
if i < options.count:
writer(s)
i+=1
else:
print("", file=sys.stderr)
sys.exit(0)
|