File: maf_select.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 (37 lines) | stat: -rwxr-xr-x 723 bytes parent folder | download
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
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/python3

"""
Read a feature file containing a 0 or 1 on each line, output
all mafs whose index in maf_file corresponds to a row having a 1

usage: %prog feature_file < maf_file
"""

import sys

import bx.align.maf


def __main__():
    feature_file = sys.argv[1]

    if len(sys.argv) > 2:
        match = int(sys.argv[2])
    else:
        match = 1

    feature_vector = [int(line) for line in open(feature_file)]

    maf_reader = bx.align.maf.Reader(sys.stdin, parse_e_rows=True)
    maf_writer = bx.align.maf.Writer(sys.stdout)

    index = 0

    for m in maf_reader:
        if feature_vector[index] == match:
            maf_writer.write(m)
        index += 1


if __name__ == "__main__":
    __main__()