File: tfloc_summary.py

package info (click to toggle)
python-bx 0.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,000 kB
  • sloc: python: 17,136; ansic: 2,326; makefile: 24; sh: 8
file content (27 lines) | stat: -rwxr-xr-x 636 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/python3

"""
Read TFLOC output from stdin and write out a summary in which the nth line
contains the number of sites found in the nth alignment of the input.

TODO: This is very special case, should it be here?
"""

import sys
from collections import defaultdict

counts = defaultdict(int)

max_index = -1

for line in sys.stdin:
    if line[0].isdigit():
        current_index = int(line)
        max_index = max(current_index, max_index)
    elif line[0] == "'":
        counts[current_index] += 1
    else:
        raise ValueError("Invalid input line " + line)

for i in range(max_index + 1):
    print(counts.get(i, 0))