obigrep.py 1.53 KB
Newer Older
1 2
#!/usr/local/bin/python
'''
Aurélie Bonin committed
3
:py:mod:`obigrep`: filters sequence file 
4
========================================
Eric Coissac committed
5 6 7

.. codeauthor:: Eric Coissac <eric.coissac@metabarcoding.org>

8
The :py:mod:`obigrep` command is in some way analog to the standard Unix `grep`
9
command.
Aurélie Bonin committed
10
It selects a subset of sequence records from a sequence file. 
Eric Coissac committed
11

Aurélie Bonin committed
12
A sequence record is a complex object composed of an identifier, 
13
a set of attributes (``key=value``), a definition, and the sequence itself. 
Eric Coissac committed
14

15 16 17 18
Instead of working text line by text line as the standard Unix tool, selection is 
done sequence record by sequence record. 
A large set of options allows refining selection on any of the sequence record 
elements.
Eric Coissac committed
19

20 21 22
Moreover :py:mod:`obigrep` allows specifying simultaneously several conditions (that 
take the value ``TRUE`` or ``FALSE``) and only the sequence records that fulfill all 
the conditions (all conditions are ``TRUE``) are selected.
Frédéric Boyer committed
23

24
'''
Eric Coissac committed
25

Eric Coissac committed
26

Eric Coissac committed
27
from obitools.format.options import addInOutputOption, sequenceWriterGenerator
28 29 30 31 32 33
from obitools.options import getOptionManager
from obitools.options.bioseqfilter import addSequenceFilteringOptions
from obitools.options.bioseqfilter import sequenceFilterIteratorGenerator

if __name__=='__main__':
    
Eric Coissac committed
34
    optionParser = getOptionManager([addSequenceFilteringOptions,addInOutputOption],progdoc=__doc__)
35 36
    
    (options, entries) = optionParser()
37
    
38
    goodSeq   = sequenceFilterIteratorGenerator(options)
Eric Coissac committed
39 40

    writer = sequenceWriterGenerator(options)
41 42
    
    for seq in goodSeq(entries):
Eric Coissac committed
43
        writer(seq)
44
            
Eric Coissac committed
45