-
Notifications
You must be signed in to change notification settings - Fork 0
/
batcher.py
executable file
·54 lines (36 loc) · 1.7 KB
/
batcher.py
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
#!/usr/bin/python
import glob, fileinput, subprocess, sys, argparse, os.path, datetime
MALIGNER = "/Users/julien/workspaces/xp/hcomp12/pyLatticeAligner/pyLatticeAligner.py"
def main(directory, refFile, opts=None):
begin = datetime.datetime.now()
outFile = os.path.join(directory,refFile[:-4] + ".aligned")
out = open(outFile, "w")
i= 1
for refTrad in fileinput.input(directory+"/"+refFile):
fileName = refFile[:-4] + str(i) + ".txt"
fileTrad = os.path.join(directory, fileName)
print fileTrad
tmpFile = os.path.join('/tmp/', fileName + ".tmp")
tmpF = open(tmpFile, "w")
cmd = [ MALIGNER, fileTrad]
if opts is not None:
cmd.extend(opts)
print cmd
subprocess.call(cmd, stdout=tmpF, stderr=subprocess.STDOUT)
cmd = [ "tail", "-n", "1", tmpFile]
malignedTrad = subprocess.check_output(cmd)
print malignedTrad
out.write(malignedTrad)
cmd = ["rm", tmpFile]
subprocess.call(cmd)
i += 1
out.close()
print "Total time: "+ str(datetime.datetime.now()-begin)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Launch several multialignments in batch')
parser.add_argument("dir", nargs=1, action="store", help="Name of the directory to process")
parser.add_argument("refName", nargs=1, action="store", help="Name of the reference file containing the reference translation, i.e. wiki.ref")
parser.add_argument("-opts", nargs=argparse.REMAINDER, action="store", help="Options to pass to the multialigner")
args = parser.parse_args()
#print args
main(args.dir[0], args.refName[0], args.opts)