-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcut_sides.py
59 lines (49 loc) · 1.85 KB
/
cut_sides.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
55
56
57
58
59
import sys
import os
import ntpath
def check_files(file_list):
with open(file_list) as f:
for l in f:
l = l.strip()
if not os.path.exists(l):
print "In", (file_list + ","), l, "does not exists..."
return False
return True
def cut_side(k, fname, kmc_dir):
dir_path, fn = ntpath.split(fname)
begin_fname = os.path.join(kmc_dir, fn + "_k" + str(k - 1) + ".begin")
end_fname = os.path.join(kmc_dir, fn + "_k" + str(k - 1) + ".end")
with open(begin_fname, "w") as begin:
with open(end_fname, "w") as end:
with open(fname, "r") as f:
for l in f:
if l[0] == ">" or l[1] == ">":
begin.write(l)
end.write(l)
else:
begin.write(l[:(k - 1)])
begin.write("\n")
if l[-1] == "\n":
end.write(l[-k:])
else:
end.write(l[-k + 1 :])
def cut_sides(k, file_list, kmc_dir, onefile=False):
if k < 2:
print "k must be >= 2..."
if not os.path.isdir(kmc_dir):
print kmc_dir, "does not exists..."
elif not os.path.exists(file_list):
print file_list, "does not exists..."
elif onefile:
cut_side(k, file_list, kmc_dir)
elif check_files(file_list):
with open(file_list) as f:
for l in f:
l = l.strip()
cut_side(k, l, kmc_dir)
if __name__ == "__main__":
if "-k=" not in sys.argv[1] or len(sys.argv) < 4:
print "Bad argument list..."
print "example usage: ./colorgra_tool -k=32 file_list.txt kmc-files-dir"
else:
cut_sides(int(sys.argv[1][3:]), sys.argv[2], sys.argv[3], ("-m" in sys.argv))