[2] | 1 | #!/usr/bin/env python |
---|
| 2 | """ |
---|
| 3 | Adapted from bx/scripts/axt_to_concat_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 | sp1text = list() |
---|
| 31 | sp2text = list() |
---|
| 32 | for a in reader: |
---|
| 33 | sp1text.append(a.components[0].text) |
---|
| 34 | sp2text.append(a.components[1].text) |
---|
| 35 | sp1seq = "".join(sp1text) |
---|
| 36 | sp2seq = "".join(sp2text) |
---|
| 37 | print_component_as_fasta(sp1seq,species1) |
---|
| 38 | print_component_as_fasta(sp2seq,species2) |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | # $$$ this should be moved to a bx.align.fasta module |
---|
| 43 | |
---|
| 44 | def print_component_as_fasta(text,src): |
---|
| 45 | header = ">" + src |
---|
| 46 | print header |
---|
| 47 | print text |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | if __name__ == "__main__": main() |
---|
| 51 | |
---|