-
Notifications
You must be signed in to change notification settings - Fork 5
/
toporoot_batch.py
50 lines (47 loc) · 1.73 KB
/
toporoot_batch.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
import os
import sys
import getopt
import csv
def main(argv):
inputfile = ''
outputfile = ''
downsample = 1
multi = False
try:
opts, args = getopt.getopt(argv,"hi:o:v:d:m:",[""])
except getopt.GetoptError:
print('python toporoot_batch.py -i <inputfile> -o <outputfile> -d <downsampling rate:optional> -m (1 or 0)')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('python toporoot_batch.py -i <inputfile> -o <outputfile> -d <downsampling rate:optional> -m (1 or 0)')
sys.exit()
elif opt == '-i':
inputfile = arg
elif opt == '-o':
outputfile = arg
elif opt == '-d':
downsample = float(arg)
elif opt == '-m':
multi = bool(int(arg))
print('Input directory is ', inputfile)
print('Output directory is ', outputfile)
print('Downsampling rate is ', downsample)
for filename in os.listdir(inputfile):
if not filename.endswith(".dat") and not filename.endswith(".raw"):
outputStr = outputfile + filename[0:-4]
print("Processing ", inputfile+filename)
command = "TopoRoot --in " + inputfile+filename + " --out " + outputStr + " --d " + str(downsample)
if multi:
command = command + " --multi"
os.system(command)
if filename.endswith(".raw"):
print("Processing ", inputfile+filename)
datFile = inputfile+filename[0:-3] + "dat"
outputStr = outputfile + filename[0:-4]
command = "TopoRoot --in " + inputfile+filename + " --dat " + datFile + " --out " + outputStr + " --d " + str(downsample)
if multi:
command = command + " --multi"
os.system(command)
if __name__ == "__main__":
main(sys.argv[1:])