| 1 | #!/usr/bin/python2.6 |
|---|
| 2 | |
|---|
| 3 | """ |
|---|
| 4 | Read a MAF from standard input and print average GC content of each alignment |
|---|
| 5 | |
|---|
| 6 | usage: %prog < maf > out |
|---|
| 7 | """ |
|---|
| 8 | |
|---|
| 9 | from __future__ import division |
|---|
| 10 | |
|---|
| 11 | import sys |
|---|
| 12 | |
|---|
| 13 | from bx.align import maf |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | def __main__(): |
|---|
| 17 | |
|---|
| 18 | maf_reader = maf.Reader( sys.stdin ) |
|---|
| 19 | |
|---|
| 20 | for m in maf_reader: |
|---|
| 21 | gc = 0 |
|---|
| 22 | bases = 0 |
|---|
| 23 | for c in m.components: |
|---|
| 24 | gc += c.text.count( 'G' ) |
|---|
| 25 | gc += c.text.count( 'C' ) |
|---|
| 26 | gc += c.text.count( 'g' ) |
|---|
| 27 | gc += c.text.count( 'c' ) |
|---|
| 28 | bases += ( len( c.text ) - c.text.count( '-' ) ) |
|---|
| 29 | |
|---|
| 30 | print gc / bases |
|---|
| 31 | |
|---|
| 32 | if __name__ == "__main__": __main__() |
|---|