-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6_getSDContinueRegion.py
57 lines (49 loc) · 2 KB
/
6_getSDContinueRegion.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
import argparse
def main():
parser = argparse.ArgumentParser(description="")
parser.add_argument("-n", "--name_list_file")
parser.add_argument("-w", "--work_dir")
args = parser.parse_args()
name_list_file = args.name_list_file
work_dir = args.work_dir
with open(name_list_file,'r') as nlf:
while True:
line = nlf.readline()[:-1]
if not line:
break
name = line.split('\t')[1]
print(name)
sd_file = work_dir + '/' + name + '/final_decomposition.tsv'
out_continue_region_file = work_dir + '/' + name + '/continue_region.txt'
print(sd_file)
continuous_region = []
region = []
with open(sd_file,'r') as sf:
while True:
line = sf.readline()[:-1]
if not line:
break
items = line.split('\t')
start = int(items[2])
end = int(items[3])
identity = float(items[4])
if identity < 80:
continue
region.append([start,end])
if len(region) == 1:
continuous_region.append(region[0])
else:
init_region = region[0]
for i in range(len(region) - 1):
if region[i+1][0] - init_region[1] == 1:
init_region[1] = region[i + 1][1]
else:
continuous_region.append(init_region)
init_region = region[i+1]
continuous_region.append(init_region)
out_continue_region_file = open(out_continue_region_file,'w')
for i in continuous_region:
out_continue_region_file.write(str(i[0])+'\t' + str(i[1])+'\n')
out_continue_region_file.close()
if __name__ == '__main__':
main()