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