| 1 | #!/usr/bin/python2.6 |
|---|
| 2 | |
|---|
| 3 | """ |
|---|
| 4 | Read TFLOC output from stdin and write out a summary in which the nth line |
|---|
| 5 | contains the number of sites found in the nth alignment of the input. |
|---|
| 6 | |
|---|
| 7 | TODO: This is very special case, should it be here? |
|---|
| 8 | """ |
|---|
| 9 | |
|---|
| 10 | import sys |
|---|
| 11 | |
|---|
| 12 | counts = dict() |
|---|
| 13 | |
|---|
| 14 | max_index = -1 |
|---|
| 15 | |
|---|
| 16 | for line in sys.stdin: |
|---|
| 17 | if line[0].isdigit(): |
|---|
| 18 | current_index = int( line ) |
|---|
| 19 | max_index = max( current_index, max_index ) |
|---|
| 20 | elif line[0] == "'": |
|---|
| 21 | try: counts[ current_index ] += 1 |
|---|
| 22 | except: counts[ current_index ] = 1 |
|---|
| 23 | else: |
|---|
| 24 | raise "Invalid input line " + line |
|---|
| 25 | |
|---|
| 26 | for i in range( max_index + 1 ): |
|---|
| 27 | print counts.get( i, 0 ) |
|---|