1 | #!/usr/bin/python2.6 |
---|
2 | |
---|
3 | """ |
---|
4 | Pass through blocks from a maf file until a certain number of columns |
---|
5 | have been passed. |
---|
6 | |
---|
7 | usage: %prog -c cols < maf > maf |
---|
8 | """ |
---|
9 | |
---|
10 | import sys |
---|
11 | |
---|
12 | from bx.align import maf |
---|
13 | from optparse import OptionParser |
---|
14 | |
---|
15 | def __main__(): |
---|
16 | |
---|
17 | # Parse command line arguments |
---|
18 | |
---|
19 | parser = OptionParser() |
---|
20 | parser.add_option( "-c", "--cols", action="store" ) |
---|
21 | |
---|
22 | ( options, args ) = parser.parse_args() |
---|
23 | |
---|
24 | maf_reader = maf.Reader( sys.stdin ) |
---|
25 | maf_writer = maf.Writer( sys.stdout ) |
---|
26 | |
---|
27 | if not options.cols: raise "Cols argument is required" |
---|
28 | cols = int( options.cols ) |
---|
29 | |
---|
30 | count = 0 |
---|
31 | |
---|
32 | for m in maf_reader: |
---|
33 | |
---|
34 | maf_writer.write( m ) |
---|
35 | |
---|
36 | count += m.text_size |
---|
37 | |
---|
38 | if count >= cols: return |
---|
39 | |
---|
40 | if __name__ == "__main__": __main__() |
---|