| 1 | #!/usr/bin/python2.6 |
|---|
| 2 | |
|---|
| 3 | """ |
|---|
| 4 | Read a PAIRWISE maf from stdin and print the fraction of columns whose bases |
|---|
| 5 | match for each alignment. |
|---|
| 6 | |
|---|
| 7 | TODO: generalize for more than two speceis. |
|---|
| 8 | |
|---|
| 9 | usage: %prog < maf > out |
|---|
| 10 | """ |
|---|
| 11 | |
|---|
| 12 | from __future__ import division |
|---|
| 13 | |
|---|
| 14 | import sys |
|---|
| 15 | |
|---|
| 16 | import psyco_full |
|---|
| 17 | |
|---|
| 18 | from bx.align import maf |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | def __main__(): |
|---|
| 22 | |
|---|
| 23 | maf_reader = maf.Reader( sys.stdin ) |
|---|
| 24 | |
|---|
| 25 | for m in maf_reader: |
|---|
| 26 | match = 0 |
|---|
| 27 | total = 0 |
|---|
| 28 | for i in range( 0, m.text_size ): |
|---|
| 29 | a = m.components[0].text[i].lower() |
|---|
| 30 | b = m.components[1].text[i].lower() |
|---|
| 31 | if a == b: |
|---|
| 32 | match += 1 |
|---|
| 33 | total += 1 |
|---|
| 34 | |
|---|
| 35 | print match / total |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | if __name__ == "__main__": __main__() |
|---|