[2] | 1 | #!/usr/bin/env python |
---|
| 2 | """ |
---|
| 3 | Adapted from bx/scripts/axt_to_fasta.py |
---|
| 4 | """ |
---|
| 5 | from galaxy import eggs |
---|
| 6 | import pkg_resources |
---|
| 7 | pkg_resources.require( "bx-python" ) |
---|
| 8 | |
---|
| 9 | import sys |
---|
| 10 | import bx.align.axt |
---|
| 11 | |
---|
| 12 | def usage(s=None): |
---|
| 13 | message = """ |
---|
| 14 | axt_to_fasta species1 species2 < axt_file > fasta_file |
---|
| 15 | """ |
---|
| 16 | if (s == None): sys.exit (message) |
---|
| 17 | else: sys.exit ("%s\n%s" % (s,message)) |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | def main(): |
---|
| 21 | |
---|
| 22 | # check the command line |
---|
| 23 | species1 = sys.argv[1] |
---|
| 24 | species2 = sys.argv[2] |
---|
| 25 | |
---|
| 26 | # convert the alignment blocks |
---|
| 27 | |
---|
| 28 | reader = bx.align.axt.Reader(sys.stdin,support_ids=True,\ |
---|
| 29 | species1=species1,species2=species2) |
---|
| 30 | |
---|
| 31 | for a in reader: |
---|
| 32 | if ("id" in a.attributes): id = a.attributes["id"] |
---|
| 33 | else: id = None |
---|
| 34 | print_component_as_fasta(a.components[0],id) |
---|
| 35 | print_component_as_fasta(a.components[1],id) |
---|
| 36 | print |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | # $$$ this should be moved to a bx.align.fasta module |
---|
| 40 | |
---|
| 41 | def print_component_as_fasta(c,id=None): |
---|
| 42 | header = ">%s_%s_%s" % (c.src,c.start,c.start+c.size) |
---|
| 43 | if (id != None): header += " " + id |
---|
| 44 | print header |
---|
| 45 | print c.text |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | if __name__ == "__main__": main() |
---|
| 49 | |
---|