-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path6.get_depth.py
47 lines (44 loc) · 1.5 KB
/
6.get_depth.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
from sys import argv # [-p prefix], [-d direction], 1_freq, 1_depth, 2_freq, 2_depth, ...
from os.path import isfile
prefix = ""
direction = ""
fns = []
for i in range(1, len(argv)):
if i != len(argv)-1 and argv[i] == "-p":
prefix = argv[i+1]
elif i != len(argv)-1 and argv[i] == "-d":
direction = argv[i+1]
elif i != 0 and argv[i-1] != "-p" and argv[i-1] != "-d":
fns.append(argv[i])
if direction != "":
fns = zip(fns[::2], fns[1::2])
if prefix == "":
fo = open("%s.txt"%direction, "a")
else:
fo = open("%s_%s.txt"%(prefix, direction), "a")
firstline = True
for ffn, fdn in fns:
print ("Processing {0} and {1}...".format(ffn, fdn))
ff = open(ffn)
fd = open(fdn)
for ff_line in ff:
pos = ff_line.split('\t')[0]
while True:
fd_line = fd.readline()
try:
fd_pos = fd_line.split('\t')[0].split(':')[1]
while int(fd_pos) > int(pos):
ff_line = ff.readline()
pos = ff_line.split('\t')[0]
if fd_pos == pos:
if firstline:
firstline = False
else:
fo.write('\n')
fo.write(fd_line.strip())
break
except:
print (ff_line, fd_line)
break
ff.close()
fo.write("\n")