1 | #!/usr/bin/python2.6 |
---|
2 | |
---|
3 | """ |
---|
4 | For each block in a maf file (read from stdin) write a sequence of ints |
---|
5 | corresponding to the columns of the block after applying the provided sequence |
---|
6 | mapping. |
---|
7 | |
---|
8 | The 'correct' number of species is determined by the mapping file, blocks not having |
---|
9 | this number of species will be ignored. |
---|
10 | |
---|
11 | usage: %prog mapping_file |
---|
12 | """ |
---|
13 | |
---|
14 | from __future__ import division |
---|
15 | |
---|
16 | import psyco_full |
---|
17 | |
---|
18 | import bx.align.maf |
---|
19 | from bx import seqmapping |
---|
20 | import string |
---|
21 | import sys |
---|
22 | |
---|
23 | def main(): |
---|
24 | |
---|
25 | if len( sys.argv ) > 1: |
---|
26 | _, alpha_map = seqmapping.alignment_mapping_from_file( file( sys.argv[1] ) ) |
---|
27 | else: |
---|
28 | alpha_map = None |
---|
29 | |
---|
30 | for maf in bx.align.maf.Reader( sys.stdin ): |
---|
31 | # Translate alignment to ints |
---|
32 | int_seq = seqmapping.DNA.translate_list( [ c.text for c in maf.components ] ) |
---|
33 | # Apply mapping |
---|
34 | if alpha_map: |
---|
35 | int_seq = alpha_map.translate( int_seq ) |
---|
36 | # Write ints separated by spaces |
---|
37 | for i in int_seq: print i, |
---|
38 | print |
---|
39 | |
---|
40 | if __name__ == "__main__": main() |
---|