Repeating a search from a Mascot results file.
1
2
17
18import msparser
19import sys
20import subprocess
21import re
22
23def main() :
24 if len(sys.argv) < 2 :
25 usage()
26 return 1
27
28 return repeatSearch(sys.argv[1])
29
30
31def repeatSearch(filename) :
32 resfile = msparser.ms_mascotresfilebase.createResfile(filename)
33
34 if not resfile.isValid() :
35 print("Cannot open results file %s : %s" % (filename, resfile.getLastErrorString()))
36 return 1
37
38 s = []
39
40 s.append("----12345")
41 s.append('Content-Disposition: form-data; name="QUE"')
42 s.append('')
43
44
45 keys, values = resfile.getSearchParametersKeyValues()
46 for key, val in zip(keys, values):
47
48 if len(val) > 0 and key != "INTERMEDIATE" and key != "RULES" and key != "INTERNALS" and key != "SEARCH" :
49 s.append("%s=%s" % (key, val))
50
51
52
53
54
55 s.append("SEARCH=SQ")
56
57
58 s.append("INTERMEDIATE=" + filename)
59
60
61 for q in range(1, 1 + resfile.getNumQueries()) :
62 s.append(resfile.getRepeatSearchString(q))
63
64
65 s.append("----12345--")
66
67
68 try :
69 tmp = open("tmp.txt", "w")
70
71 except IOError as err:
72 errno, strerror = err.args
73 print("Cannot open tmp.txt for writing: %s" % strerror)
74 return 1
75
76
77 try :
78 proc = subprocess.Popen(
79 ['./nph-mascot.exe', '4', '-commandline'],
80 stdin=subprocess.PIPE,
81 stdout=tmp
82 )
83 except OSError as e :
84 print("Cannot run nph-mascot.exe: %s" % e)
85 return 1
86
87 for line in s :
88 proc.stdin.write(line.encode('utf-8'))
89 proc.stdin.write("\n".encode('utf-8'))
90
91
92 proc.stdin.close()
93 proc.wait()
94
95 tmp.close()
96
97 try :
98 tmp = open("tmp.txt", "r")
99 except IOError as err:
100 errno, strerror = err.args
101 print("Cannot open tmp.txt for reading: %s" % strerror)
102 return 1
103
104 while True :
105 line = tmp.readline()
106
107 if len(line) == 0 : break
108
109 if re.match('.*SUCCESS.*', line) :
110
111 line = tmp.readline()
112
113 compareResults(resfile, line.rstrip('\n'))
114 continue
115
116 if re.match('.*ERROR.*', line) :
117 print("Search failed:", line.rstrip('\n'))
118
119
120 while len(line) != 0 :
121 line = tmp.readline()
122 print(line.rstrip('\n'))
123
124 break
125
126
127def compareResults(originalSearch, repeatedSearchFileName) :
128 repeatedSearch = msparser.ms_mascotresfilebase.createResfile(repeatedSearchFileName)
129 anyReport = 0
130
131 if not repeatedSearch.isValid() :
132 print("Invalid repeat search: %s" % repeatedSearch.getLastErrorString())
133 return
134
135 if originalSearch.anyPMF() :
136
137 originalResults = msparser.ms_proteinsummary(originalSearch)
138 repeatedResults = msparser.ms_proteinsummary(repeatedSearch)
139
140 originalProt = originalResults.getHit(1)
141 repeatedProt = repeatedResults.getHit(1)
142
143 if originalProt and repeatedProt :
144 diff = repeatedProt.getScore() - originalProt.getScore()
145
146 if diff > 10.0 :
147 print("Protein score is %d higher for search" % diff)
148 print("%s than %s " % (originalSearch.getFileName(), repeatedSearchFileName))
149
150
151 anyReport = 1
152 else :
153
154 originalResults = msparser.ms_peptidesummary(originalSearch)
155 repeatedResults = msparser.ms_peptidesummary(repeatedSearch)
156
157
158 for q in range(1, 1 + originalSearch.getNumQueries()) :
159 pepOriginal = originalResults.getPeptide(q, 1)
160 pepRepeated = repeatedResults.getPeptide(q, 1)
161 diff = pepRepeated.getIonsScore() - pepOriginal.getIonsScore()
162
163 if diff > 10.0 :
164 print("Query %d has score %d higher for search %s than %s" % (q, diff, originalSearch.getFileName(), repeatedSearchFileName))
165
166
167 anyReport = 1
168
169 if not anyReport :
170 print("Similar results for %s and %s" % (originalSearch.getFileName(), repeatedSearchFileName))
171
172
173
174def usage() :
175 print("""
176Usage: repeat_search.py <results file>
177
178Given an mascot results file name, repeat the search against the same data.
179
180This program must be run in the Mascot Server cgi directory.
181""")
182
183if __name__ == "__main__" :
184 sys.exit(main())
185