-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_sequence_function_data.py
More file actions
executable file
·58 lines (50 loc) · 1.58 KB
/
get_sequence_function_data.py
File metadata and controls
executable file
·58 lines (50 loc) · 1.58 KB
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
#!/usr/bin/env python
# Filename: get_sequence_function_data.py
import sys
INVALID_ACIDS = set(['U', 'O', 'B', 'Z', 'J', 'X'])
def isOk(seq):
for c in seq:
if c in INVALID_ACIDS:
return False
return True
def main():
positive = dict()
with open('data/uniprot-go-0019825.txt') as f:
for line in f:
line = line.strip().split('\t')
prot_id = line[0]
seq = line[2]
if prot_id not in positive:
positive[prot_id] = seq
negative = dict()
with open('data/uniprot-go-0030246.txt') as f:
for line in f:
line = line.strip().split('\t')
prot_id = line[0]
seq = line[2]
if prot_id not in negative:
negative[prot_id] = seq
data = list()
labels = list()
for gene_id, seq in positive.iteritems():
if gene_id not in negative:
data.append(seq)
labels.append(1)
pos_len = len(labels)
for gene_id, seq in negative.iteritems():
if gene_id not in positive:
data.append(seq)
labels.append(0)
# pos_len -= 1
# if pos_len == 0:
# break
min_len = sys.maxint
with open('data/obtained/go_sequence.txt', 'w') as f:
for i in range(len(labels)):
if len(data[i]) > 24 and isOk(data[i]):
if min_len > len(data[i]):
min_len = len(data[i])
f.write(str(labels[i]) + ' ' + data[i] + '\n')
print 'Minimum length:', min_len
if __name__ == '__main__':
main()