1 | #!/usr/bin/python2.6 |
---|
2 | """ |
---|
3 | Application to convert LAV file to AXT file. Reads a LAV file from standard |
---|
4 | input and writes a AXT file to standard out; some statistics are written |
---|
5 | to standard error. |
---|
6 | |
---|
7 | usage: lav_to_axt [--silent] [path=replacement] < lav_file > axt_file |
---|
8 | """ |
---|
9 | |
---|
10 | __author__ = "Bob Harris (rsharris@bx.psu.edu)" |
---|
11 | |
---|
12 | import sys |
---|
13 | import copy |
---|
14 | import bx.align.lav |
---|
15 | import bx.align.axt |
---|
16 | |
---|
17 | def usage(s=None): |
---|
18 | message = __doc__ |
---|
19 | if (s == None): sys.exit (message) |
---|
20 | else: sys.exit ("%s\n%s" % (s,message)) |
---|
21 | |
---|
22 | |
---|
23 | def main(): |
---|
24 | |
---|
25 | # parse the command line |
---|
26 | |
---|
27 | silent = False |
---|
28 | pathSubs = [] |
---|
29 | |
---|
30 | for arg in sys.argv[1:]: |
---|
31 | if ("=" in arg): |
---|
32 | ix = arg.find("=") |
---|
33 | pathSubs.append((arg[:ix],arg[ix+1:])) |
---|
34 | elif (arg == "--silent"): |
---|
35 | silent = True |
---|
36 | else: |
---|
37 | usage("unrecognized argument: " + arg) |
---|
38 | |
---|
39 | # read the alignments and other info |
---|
40 | |
---|
41 | out = bx.align.axt.Writer(sys.stdout) |
---|
42 | |
---|
43 | lavsRead = axtsWritten = 0 |
---|
44 | for lavBlock in bx.align.lav.Reader(sys.stdin,path_subs=pathSubs): |
---|
45 | lavsRead += 1 |
---|
46 | |
---|
47 | out.write (lavBlock) |
---|
48 | axtsWritten += 1 |
---|
49 | |
---|
50 | if (not silent): |
---|
51 | sys.stderr.write ("%d blocks read, %d written\n" % (lavsRead,axtsWritten)) |
---|
52 | |
---|
53 | |
---|
54 | if __name__ == "__main__": main() |
---|
55 | |
---|