-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpgx_query.py
More file actions
executable file
·65 lines (52 loc) · 1.67 KB
/
Copy pathpgx_query.py
File metadata and controls
executable file
·65 lines (52 loc) · 1.67 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
59
60
61
62
63
64
65
import re
import sys
def lookup(aPeptide):
global q
global peptides
global proteins
target = aPeptide.replace("L", "I")
output = []
if target[0:q] in peptides:
candidates = peptides[target[0:q]]
for i in range(1, len(target)-q+1):
if target[i:i+q] in peptides:
candidates = candidates.intersection(peptides[target[i:i+q]])
else:
candidates = set()
break
else:
candidates = set()
for code in candidates:
#Obviously, the proteins should be pre-I/L transformed...
transeq = proteins[code][1].replace("L", "I")
for m in re.finditer('(?=%s)' % target, transeq):
output.append((proteins[code][0], m.start()+1))
return output
if __name__ == "__main__":
q = 0
proteins = None
peptides = None
import time
start = time.time()
proteome = sys.argv[1]
if len(sys.argv) == 3:
infile = open(sys.argv[2])
else:
infile = sys.stdin
import pickle
if not proteome.endswith("/"):
proteome += "/"
f = open(proteome + 'proteome.pickle', 'rb')
q = pickle.load(f)
proteins = pickle.load(f)
peptides = pickle.load(f)
f.close()
for l in infile:
pep = l.strip().split()[0]
matches = lookup(pep)
for match in matches:
print("%s\t%s\t%d" % (pep, match[0], match[1]), file=sys.stdout)
# there is no harm in closing stdin... http://effbot.org/pyfaq/why-doesn-t-closing-sys-stdout-stdin-stderr-really-close-it.htm
infile.close()
stop = time.time()
print("query processed in %.3f seconds" % (stop-start), file=sys.stderr)