1 | #!/usr/bin/python2.6 |
---|
2 | |
---|
3 | """ |
---|
4 | Read a MAF from standard input and determine the mean length of ungapped pieces |
---|
5 | in each block. |
---|
6 | |
---|
7 | usage: %prog < maf > out |
---|
8 | """ |
---|
9 | |
---|
10 | from __future__ import division |
---|
11 | |
---|
12 | import sys |
---|
13 | import bx.align.maf |
---|
14 | |
---|
15 | def main(): |
---|
16 | |
---|
17 | for m in bx.align.maf.Reader( sys.stdin ): |
---|
18 | |
---|
19 | ungapped_columns = 0 |
---|
20 | ungapped_runs = 0 |
---|
21 | in_ungapped = False |
---|
22 | |
---|
23 | for col in m.column_iter(): |
---|
24 | is_gap = ( '-' in col ) |
---|
25 | if not is_gap: ungapped_columns += 1 |
---|
26 | if in_ungapped and is_gap: |
---|
27 | ungapped_runs += 1 |
---|
28 | in_ungapped = not is_gap |
---|
29 | if in_ungapped: ungapped_runs += 1 |
---|
30 | |
---|
31 | print ungapped_columns / ungapped_runs |
---|
32 | |
---|
33 | |
---|
34 | if __name__ == "__main__": main() |
---|