-
Notifications
You must be signed in to change notification settings - Fork 2
/
winnow_domains.py
95 lines (85 loc) · 3.14 KB
/
winnow_domains.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
def return_dom_type(dom_name):
if dom_name.startswith("PF"):
return("pfam")
if dom_name.startswith("Coiled"):
return("cc")
if dom_name.startswith("Low"):
return("lc")
if dom_name.startswith("mobidb"):
return("disorder")
def handle_cache(data):
prot_length = 0
accepted_lines = []
for idx, line in enumerate(data):
line = line.rstrip()
accepted = True
entries = line.split(",")
if len(entries) < 8:
continue
len1 = int(entries[7])-int(entries[6])
dom_type = return_dom_type(entries[5])
if len(entries) == 9:
prot_length = entries[8]
for idx2, line2 in enumerate(data):
if idx == idx2:
continue # don't compare like to like
entries2 = line2.split(",")
if len(entries2) < 8:
continue
len2 = int(entries2[7])-int(entries2[6])
dom_type2 = return_dom_type(entries2[5])
if int(entries[6]) in range(int(entries2[6]), int(entries2[7])+1) \
or int(entries[7]) in \
range(int(entries2[6]), int(entries2[7])+1):
# in here we know 1st domain overlaps with this next one
if "pfam" in dom_type:
if "pfam" in dom_type2:
if len1 < len2:
accepted = False
if "disorder" in dom_type:
if "pfam" in dom_type2:
accepted = False
if "disorder" in dom_type2:
if len1 < len2:
accepted = False
if dom_type == "cc":
if "pfam" in dom_type2 or "disorder" in dom_type2:
accepted = False
if "cc" in dom_type2:
if len1 < len2:
accepted = False
if dom_type == "lc":
if "pfam" in dom_type2 or "disorder" in dom_type2 or \
"cc" in dom_type2:
accepted = False
if "lc" in dom_type2:
if len1 < len2:
accepted = False
if accepted:
accepted_lines.append(line)
for line in accepted_lines:
line = line.rstrip()
entries = line.split(",")
if len(entries) == 9:
print(line)
else:
print(line+","+str(prot_length))
previous_uniprot = "XXX"
line_cache = []
# with open("/scratch1/NOT_BACKED_UP/dbuchan/interpro/derived/"
# "combined_domains_E.dat") as pfam:
with open("combined_domains_E.dat") as pfam:
first_line = pfam.readline()
entries = first_line.split(",")
line_cache.append(first_line)
previous_uniprot = entries[0]
for line in pfam:
entries = line.split(",")
if entries[0] not in previous_uniprot:
handle_cache(line_cache)
line_cache = []
line_cache.append(line)
previous_uniprot = entries[0]
else:
line_cache.append(line)
handle_cache(line_cache)