| 1 | #!/usr/bin/python2.6 |
|---|
| 2 | |
|---|
| 3 | """ |
|---|
| 4 | Read a maf and print the text as a fasta file. |
|---|
| 5 | |
|---|
| 6 | usage: %prog < maf > fasta |
|---|
| 7 | """ |
|---|
| 8 | |
|---|
| 9 | from __future__ import division |
|---|
| 10 | |
|---|
| 11 | import textwrap |
|---|
| 12 | import sys |
|---|
| 13 | from bx.align import maf |
|---|
| 14 | |
|---|
| 15 | def __main__(): |
|---|
| 16 | |
|---|
| 17 | maf_reader = maf.Reader( sys.stdin ) |
|---|
| 18 | |
|---|
| 19 | # Confusing since maf_to_concat_fasta takes names. |
|---|
| 20 | |
|---|
| 21 | # if len( sys.argv ) > 1: |
|---|
| 22 | # comps = map( int, sys.argv[1:] ) |
|---|
| 23 | # else: |
|---|
| 24 | # comps = None |
|---|
| 25 | |
|---|
| 26 | comps = None |
|---|
| 27 | |
|---|
| 28 | for i, m in enumerate( maf_reader ): |
|---|
| 29 | if comps: l = [ m.components[i] for i in comps ] |
|---|
| 30 | else: l = m.components |
|---|
| 31 | for c in l: |
|---|
| 32 | print ">%s:%d-%d" % ( c.src, c.start, c.end ) |
|---|
| 33 | print c.text |
|---|
| 34 | #print_n( c.text, 50 ) |
|---|
| 35 | |
|---|
| 36 | def print_n( s, n, f = sys.stdout ): |
|---|
| 37 | p = 0 |
|---|
| 38 | while p < len( s ): |
|---|
| 39 | print >> f, s[p:min(p+n,len(s))] |
|---|
| 40 | p += n |
|---|
| 41 | |
|---|
| 42 | if __name__ == "__main__": __main__() |
|---|