1 | #!/usr/bin/python2.6 |
---|
2 | |
---|
3 | """ |
---|
4 | Application to convert AXT file to FASTA file. Reads an AXT file from standard |
---|
5 | input and writes a FASTA file to standard out. |
---|
6 | |
---|
7 | usage: %prog < axt_file > fasta_file |
---|
8 | """ |
---|
9 | |
---|
10 | __author__ = "Bob Harris (rsharris@bx.psu.edu)" |
---|
11 | |
---|
12 | import sys |
---|
13 | import bx.align.axt |
---|
14 | |
---|
15 | def usage(s=None): |
---|
16 | message = """ |
---|
17 | axt_to_fasta < axt_file > fasta_file |
---|
18 | """ |
---|
19 | if (s == None): sys.exit (message) |
---|
20 | else: sys.exit ("%s\n%s" % (s,message)) |
---|
21 | |
---|
22 | |
---|
23 | def main(): |
---|
24 | |
---|
25 | # check the command line |
---|
26 | |
---|
27 | if (len(sys.argv) > 1): |
---|
28 | usage("give me no arguments") |
---|
29 | |
---|
30 | # convert the alignment blocks |
---|
31 | |
---|
32 | reader = bx.align.axt.Reader(sys.stdin,support_ids=True,\ |
---|
33 | species1="",species2="") |
---|
34 | |
---|
35 | for a in reader: |
---|
36 | if ("id" in a.attributes): id = a.attributes["id"] |
---|
37 | else: id = None |
---|
38 | print_component_as_fasta(a.components[0],id) |
---|
39 | print_component_as_fasta(a.components[1],id) |
---|
40 | print |
---|
41 | |
---|
42 | |
---|
43 | # $$$ this should be moved to a bx.align.fasta module |
---|
44 | |
---|
45 | def print_component_as_fasta(c,id=None): |
---|
46 | header = ">%s_%s_%s" % (c.src,c.start,c.start+c.size) |
---|
47 | if (id != None): header += " " + id |
---|
48 | print header |
---|
49 | print c.text |
---|
50 | |
---|
51 | |
---|
52 | if __name__ == "__main__": main() |
---|
53 | |
---|