1 | #!/usr/bin/python2.6 |
---|
2 | |
---|
3 | """ |
---|
4 | Filter each block in a maf file. Can filter blocks for a minimum number of |
---|
5 | components (rows), a minimum length in columns, or an arbitrary python |
---|
6 | expression (which will be evaluated for each block with the variable 'm' |
---|
7 | containing that block). |
---|
8 | |
---|
9 | usage: %prog [options] < maf > maf |
---|
10 | --component_count=N: Minimum number of components (rows) |
---|
11 | --min_cols=N: Minimum number of columns |
---|
12 | -e, --expr=EXPR: Python expression that must evaulate to true |
---|
13 | """ |
---|
14 | |
---|
15 | import psyco_full |
---|
16 | |
---|
17 | import sys |
---|
18 | |
---|
19 | import sys |
---|
20 | from bx.align import maf |
---|
21 | from optparse import OptionParser |
---|
22 | |
---|
23 | def __main__(): |
---|
24 | |
---|
25 | # Parse command line arguments |
---|
26 | |
---|
27 | parser = OptionParser() |
---|
28 | parser.add_option( "--component_count", action="store", default=None, type="int", help="" ) |
---|
29 | parser.add_option( "--min_cols", action="store", default=None, type="int", help="" ) |
---|
30 | parser.add_option( "-e", "--expr", action="store", default=None ) |
---|
31 | |
---|
32 | ( options, args ) = parser.parse_args() |
---|
33 | |
---|
34 | component_count = options.component_count |
---|
35 | min_cols = options.min_cols |
---|
36 | expr = options.expr |
---|
37 | |
---|
38 | # Compile expression for SPEED |
---|
39 | if expr: expr = compile( expr, '<expr arg>', 'eval' ) |
---|
40 | |
---|
41 | maf_reader = maf.Reader( sys.stdin ) |
---|
42 | maf_writer = maf.Writer( sys.stdout ) |
---|
43 | |
---|
44 | for m in maf_reader: |
---|
45 | |
---|
46 | if component_count and len( m.components ) != component_count: continue |
---|
47 | if min_cols and m.text_size < min_cols: continue |
---|
48 | if expr and not bool( eval( expr, { "m": m, "maf": m } ) ): continue |
---|
49 | |
---|
50 | maf_writer.write( m ) |
---|
51 | |
---|
52 | if __name__ == "__main__": __main__() |
---|