File: lav_to_maf.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 (55 lines) | stat: -rwxr-xr-x 1,203 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python3
"""
Application to convert LAV file to MAF file. Reads a LAV file from standard
input and writes a MAF file to standard out; some statistics are written to
standard error.

usage: lav_to_maf [--silent] [path=replacement] < lav_file > maf_file
"""

import sys

import bx.align.lav
import bx.align.maf


def usage(s=None):
    message = __doc__
    if s is None:
        sys.exit(message)
    else:
        sys.exit(f"{s}\n{message}")


def main():
    # parse the command line

    silent = False
    pathSubs = []

    for arg in sys.argv[1:]:
        if "=" in arg:
            ix = arg.find("=")
            pathSubs.append((arg[:ix], arg[ix + 1 :]))
        elif arg == "--silent":
            silent = True
        else:
            usage("unrecognized argument: " + arg)

    # read the alignments and other info

    out = bx.align.maf.Writer(sys.stdout)

    lavsRead = mafsWritten = 0
    for lavBlock in bx.align.lav.Reader(sys.stdin, path_subs=pathSubs):
        lavsRead += 1

        out.write(lavBlock)
        mafsWritten += 1

    if not silent:
        sys.stderr.write("%d blocks read, %d written\n" % (lavsRead, mafsWritten))


if __name__ == "__main__":
    main()