1 | #!/usr/bin/python2.6 |
---|
2 | |
---|
3 | """ |
---|
4 | Read a maf file from stdin and write out a new maf with only blocks having all of |
---|
5 | the passed in species, after dropping any other species and removing columns |
---|
6 | containing only gaps. By default this will attempt to fuse together any blocks |
---|
7 | which are adjacent after the unwanted species have been dropped. |
---|
8 | |
---|
9 | usage: %prog species1 species2 ... < maf |
---|
10 | -n, --nofuse: Don't attempt to join blocks, just remove rows. |
---|
11 | """ |
---|
12 | |
---|
13 | import psyco_full |
---|
14 | |
---|
15 | import bx.align.maf |
---|
16 | import copy |
---|
17 | import sys |
---|
18 | |
---|
19 | from bx.align.tools.thread import * |
---|
20 | from bx.align.tools.fuse import * |
---|
21 | |
---|
22 | from itertools import * |
---|
23 | |
---|
24 | from bx.cookbook import doc_optparse |
---|
25 | |
---|
26 | def main(): |
---|
27 | |
---|
28 | options, args = doc_optparse.parse( __doc__ ) |
---|
29 | |
---|
30 | try: |
---|
31 | species = args |
---|
32 | # Allow a comma separated list, TODO: allow a newick format tree |
---|
33 | if len( species ) == 1 and ',' in species[0]: species = species[0].split( ',' ) |
---|
34 | fuse = not( bool( options.nofuse ) ) |
---|
35 | except: |
---|
36 | doc_optparse.exit() |
---|
37 | |
---|
38 | maf_reader = bx.align.maf.Reader( sys.stdin ) |
---|
39 | maf_writer = bx.align.maf.Writer( sys.stdout ) |
---|
40 | |
---|
41 | if fuse: |
---|
42 | maf_writer = FusingAlignmentWriter( maf_writer ) |
---|
43 | |
---|
44 | for m in maf_reader: |
---|
45 | new_components = get_components_for_species( m, species ) |
---|
46 | if new_components: |
---|
47 | remove_all_gap_columns( new_components ) |
---|
48 | m.components = new_components |
---|
49 | m.score = 0.0 |
---|
50 | maf_writer.write( m ) |
---|
51 | |
---|
52 | maf_reader.close() |
---|
53 | maf_writer.close() |
---|
54 | |
---|
55 | if __name__ == "__main__": main() |
---|