ProteoWizard
PeptideMatcherTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: PeptideMatcherTest.cpp 2051 2010-06-15 18:39:13Z chambm $
3 //
4 //
5 // Original author: Kate Hoff <katherine.hoff@proteowizard.org>
6 //
7 // Copyright 2009 Center for Applied Molecular Medicine
8 // University of Southern California, Los Angeles, CA
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 //
22 
23 #include "PeptideMatcher.hpp"
26 
27 using namespace pwiz::cv;
28 using namespace pwiz::eharmony;
29 using namespace pwiz::util;
30 
31 ostream* os_ = 0;
32 
33 const char* samplePepXML_a =
34  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
35  "<msms_pipeline_analysis>\n"
36  "<msms_run_summary>\n"
37  "<spectrum_query start_scan=\"1\" end_scan=\"2\" precursor_neutral_mass=\"2.0\" assumed_charge=\"1\" retention_time_sec=\"2.0\">\n"
38  "<search_result>\n"
39  "<search_hit peptide=\"BUCKLEMYSHOE\">\n"
40  "<analysis_result analysis=\"peptideprophet\">\n"
41  "<peptideprophet_result probability =\"0.900\" all_ntt_prob=\"(0,0,0.900)\">\n"
42  "<search_score_summary>\n"
43  "</search_score_summary>\n"
44  "</peptideprophet_result>\n"
45  "</analysis_result>\n"
46  "</search_hit>\n"
47  "</search_result>\n"
48  "</spectrum_query>\n"
49  "<spectrum_query start_scan=\"3\" end_scan=\"4\" precursor_neutral_mass=\"3.0\" assumed_charge=\"1\" retention_time_sec=\"4.0\">\n"
50  "<search_result>\n"
51  "<search_hit peptide=\"SHUTTHEDOOR\">\n"
52  "<analysis_result analysis=\"peptideprophet\">\n"
53  "<peptideprophet_result probability =\"0.900\" all_ntt_prob=\"(0,0,0.900)\">\n"
54  "<search_score_summary>\n"
55  "</search_score_summary>\n"
56  "</peptideprophet_result>\n"
57  "</analysis_result>\n"
58  "</search_hit>\n"
59  "</search_result>\n"
60  "</spectrum_query>\n"
61  "<spectrum_query start_scan=\"9\" end_scan=\"10\" precursor_neutral_mass=\"2.0\" assumed_charge=\"1\" retention_time_sec=\"4.0\">\n"
62  "<search_result>\n"
63  "<search_hit peptide=\"ABIGFATHEN\">\n"
64  "<analysis_result analysis=\"peptideprophet\">\n"
65  "<peptideprophet_result probability =\"0.900\" all_ntt_prob=\"(0,0,0.900)\">\n"
66  "<search_score_summary>\n"
67  "</search_score_summary>\n"
68  "</peptideprophet_result>\n"
69  "</analysis_result>\n"
70  "</search_hit>\n"
71  "</search_result>\n"
72  "</spectrum_query>\n"
73  "</msms_run_summary>\n"
74  "</msms_pipeline_analysis>\n";
75 
76 const char* samplePepXML_b =
77  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
78  "<msms_pipeline_analysis>\n"
79  "<msms_run_summary>\n"
80  "<spectrum_query start_scan=\"1\" end_scan=\"2\" precursor_neutral_mass=\"2.1\" assumed_charge=\"1\" retention_time_sec=\"3.0\">\n"
81  "<search_result>\n"
82  "<search_hit peptide=\"BUCKLEMYSHOE\">\n"
83  "<analysis_result analysis=\"peptideprophet\">\n"
84  "<peptideprophet_result probability =\"0.900\" all_ntt_prob=\"(0,0,0.900)\">\n"
85  "<search_score_summary>\n"
86  "</search_score_summary>\n"
87  "</peptideprophet_result>\n"
88  "</analysis_result>\n"
89  "</search_hit>\n"
90  "</search_result>\n"
91  "</spectrum_query>\n"
92  "<spectrum_query start_scan=\"7\" end_scan=\"8\" precursor_neutral_mass=\"3.0\" assumed_charge=\"1\" retention_time_sec=\"4.0\">\n"
93  "<search_result>\n"
94  "<search_hit peptide=\"LAYTHEMSTRAIGHT\">\n"
95  "<analysis_result analysis=\"peptideprophet\">\n"
96  "<peptideprophet_result probability =\"0.900\" all_ntt_prob=\"(0,0,0.900)\">\n"
97  "<search_score_summary>\n"
98  "</search_score_summary>\n"
99  "</peptideprophet_result>\n"
100  "</analysis_result>\n"
101  "</search_hit>\n"
102  "</search_result>\n"
103  "</spectrum_query>\n"
104  "<spectrum_query start_scan=\"9\" end_scan=\"10\" precursor_neutral_mass=\"2.2\" assumed_charge=\"1\" retention_time_sec=\"2.0\">\n"
105  "<search_result>\n"
106  "<search_hit peptide=\"ABIGFATHEN\">\n"
107  "<analysis_result analysis=\"peptideprophet\">\n"
108  "<peptideprophet_result probability =\"0.900\" all_ntt_prob=\"(0,0,0.900)\">\n"
109  "<search_score_summary>\n"
110  "</search_score_summary>\n"
111  "</peptideprophet_result>\n"
112  "</analysis_result>\n"
113  "</search_hit>\n"
114  "</search_result>\n"
115  "</spectrum_query>\n"
116  "</msms_run_summary>\n"
117 "</msms_pipeline_analysis>\n";
118 
119 
121 {
122  istringstream iss(samplePepXML);
123  PidfPtr pidf(new PeptideID_dataFetcher(iss));
124 
125  return pidf;
126 
127 }
128 
129 SpectrumQuery makeSpectrumQuery(double precursorNeutralMass, double rt, int charge, string sequence, double score, int startScan, int endScan)
130 {
131  SpectrumQuery spectrumQuery;
132  spectrumQuery.startScan = startScan;
133  spectrumQuery.endScan = endScan;
134  spectrumQuery.precursorNeutralMass = precursorNeutralMass;
135  spectrumQuery.assumedCharge = charge;
136  spectrumQuery.retentionTimeSec = rt;
137 
138  SearchResult searchResult;
139 
140  SearchHit searchHit;
141  searchHit.peptide = sequence;
142 
143 
144  AnalysisResult analysisResult;
145  analysisResult.analysis = "peptideprophet";
146 
147  PeptideProphetResult peptideProphetResult;
148  peptideProphetResult.probability = score;
149  peptideProphetResult.allNttProb.push_back(0);
150  peptideProphetResult.allNttProb.push_back(0);
151  peptideProphetResult.allNttProb.push_back(score);
152 
153  analysisResult.peptideProphetResult = peptideProphetResult;
154 
155  searchHit.analysisResult = analysisResult;
156  searchResult.searchHit = searchHit;
157 
158  spectrumQuery.searchResult = searchResult;
159 
160  return spectrumQuery;
161 
162 }
163 
164 
165 FeaturePtr makeFeature(double mz, double retentionTime)
166 {
167  FeaturePtr feature(new Feature());
168  feature->mz = mz;
169  feature->retentionTime = retentionTime;
170 
171  return feature;
172 
173 }
174 
175 void test()
176 {
177  // construct test fdfs
178  FeaturePtr a = makeFeature(1,2.1);
179  FeaturePtr b = makeFeature(3,4.2);
180  FeaturePtr c = makeFeature(5,6.4);
181  FeaturePtr d = makeFeature(7,8.8);
182  FeaturePtr e = makeFeature(9,1.9);
183 
184  vector<FeaturePtr> features_a;
185  features_a.push_back(a);
186  features_a.push_back(b);
187  features_a.push_back(e);
188 
189  vector<FeaturePtr> features_b;
190  features_b.push_back(c);
191  features_b.push_back(d);
192  features_b.push_back(e);
193 
194  Feature_dataFetcher fdf_a(features_a);
195  Feature_dataFetcher fdf_b(features_b);
196 
197  // construct pidfs
200 
201  // construct PeptideMatcher
202  // DataFetcherContainer dfc(pidf_a, pidf_b, fdf_a, fdf_b);
203  PeptideMatcher pm(pidf_a, pidf_b);
205 
206  // ensure that _matches attribute is filled in
207  unit_assert(pmc.size() != 0);
208 
209  // and correctly:
210  // construct the objects that should be in matches
211 
212  SpectrumQuery sq_a = makeSpectrumQuery(2.0,2.0,1,"BUCKLEMYSHOE",0.900,1,2);
213  SpectrumQuery sq_b = makeSpectrumQuery(2.1,3.0,1,"BUCKLEMYSHOE",0.900,1,2);
214 
215  SpectrumQuery sq_c = makeSpectrumQuery(2.0,4.0,1,"ABIGFATHEN",0.900,9,10);
216  SpectrumQuery sq_d = makeSpectrumQuery(2.2,2.0,1,"ABIGFATHEN",0.900,9,10);
217 
218  PeptideMatchContainer::iterator it = pmc.begin();
219  if (os_)
220  {
221  *os_ << "\n[PeptideMatcherTest] Matches found:\n " << endl;
222  ostringstream oss;
223  XMLWriter writer(oss);
224  PeptideMatchContainer::iterator it = pmc.begin();
225  for(; it != pmc.end(); ++it)
226  {
227  it->first->write(writer);
228  it->second->write(writer);
229 
230  }
231 
232  oss << "\n[PeptideMatcherTest] Looking for:\n " << endl;
233  sq_a.write(writer);
234  sq_b.write(writer);
235 
236  *os_ << oss.str() << endl;
237  }
238 
239  // assert that known matches are found TODO fix
240  /*
241  unit_assert(find(pmc.begin(), pmc.end(), make_pair(sq_a, sq_b)) != pmc.end());
242  unit_assert(find(pmc.begin(), pmc.end(), make_pair(sq_c, sq_d)) != pmc.end());
243  */
244 
245  // calculate deltaRtDistribution by hand
246  double mean = 0.5;
247  double stdev = 1.5;
248 
249  // and verify that it is correct
251 
254 
255  // calculate deltaMZDistribution by hand
256  double mz_mean = -0.15;
257  double mz_stdev = 0.05;
258 
259  // and verify that it is correct
261 
264 
265 }
266 
267 int main(int argc, char* argv[])
268 {
269  try
270  {
271  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
272  test();
273 
274  }
275 
276  catch (std::exception& e)
277  {
278  cerr << e.what() << endl;
279  return 1;
280 
281  }
282 
283  catch (...)
284  {
285  cerr << "Caught unknown exception.\n";
286  return 1;
287 
288  }
289 
290 }