ProteoWizard
MinimumPepXMLTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: MinimumPepXMLTest.cpp 4140 2012-11-22 01:07:16Z pcbrefugee $
3 //
4 // Original author: Kate Hoff <katherine.hoff@proteowizard.org>
5 //
6 // Copyright 2009 Spielberg Family Center for Applied Proteomics
7 // Cedars-Sinai Medical Center, Los Angeles, California 90048
8 //
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 //
13 // http://www.apache.org/licenses/LICENSE-2.0
14 //
15 // Unless required by applicable law or agreed to in writing, software
16 // distributed under the License is distributed on an "AS IS" BASIS,
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 // See the License for the specific language governing permissions and
19 // limitations under the License.
20 //
21 
22 
23 #include "MinimumPepXML.hpp"
26 
27 using namespace pwiz::data::pepxml;
28 using namespace pwiz::util;
29 
30 ostream* os_ = 0;
31 
33 {
34  Specificity specificity;
35  specificity.cut = "theCake";
36  specificity.noCut = "notTheCake";
37  specificity.sense = "non";
38  specificity.minSpace = 2;
39 
40  return specificity;
41 
42 }
43 
45 {
46  SampleEnzyme sampleEnzyme;
47  sampleEnzyme.name = "oxiclean";
48  sampleEnzyme.description = "makes your whites whiter.";
49  sampleEnzyme.fidelity = "scoundrel";
50  sampleEnzyme.independent = true;
51 
52  Specificity specificity = makeSpecificity();
53  sampleEnzyme.specificity = specificity;
54 
55  return sampleEnzyme;
56 
57 }
58 
60 {
61  SearchDatabase searchDatabase;
62  searchDatabase.localPath = "http://www.eharmony.com";
63  searchDatabase.databaseName = "yenta";
64  searchDatabase.databaseReleaseIdentifier = "village busy body";
65  searchDatabase.sizeInDbEntries = 2;
66  searchDatabase.sizeOfResidues = 3;
67  searchDatabase.type = "online dating service";
68 
69  return searchDatabase;
70 }
71 
73 {
74  Q3RatioResult q;
75  q.lightFirstScan = 1;
76  q.lightLastScan = 3;
77  q.lightMass = 100;
78  q.heavyFirstScan = 2;
79  q.heavyLastScan = 4;
80  q.heavyMass = 101;
81  q.lightArea = 50;
82  q.heavyArea = 55;
83  q.q2LightArea = 25;
84  q.q2HeavyArea = 30;
85  q.decimalRatio = 0.85;
86 
87  return q;
88 
89 }
90 
92 {
93  PeptideProphetResult peptideProphetResult;
94  peptideProphetResult.probability = 0.98;
95 
96  peptideProphetResult.allNttProb.push_back(0.0000);
97  peptideProphetResult.allNttProb.push_back(0.0000);
98  peptideProphetResult.allNttProb.push_back(0.780);
99 
100  return peptideProphetResult;
101 
102 }
103 
105 {
106  AnalysisResult analysisResult;
107  analysisResult.analysis = "peptideprophet";
108 
110  analysisResult.peptideProphetResult = pp;
111 
112  return analysisResult;
113 
114 }
115 
117 {
118  AlternativeProtein alternativeProtein;
119  alternativeProtein.protein = "Dos Pinos";
120  alternativeProtein.proteinDescr = "leche";
121  alternativeProtein.numTolTerm = "5";
122 
123  return alternativeProtein;
124 
125 }
126 
128 {
129  ModAminoAcidMass modAminoAcidMass;
130  modAminoAcidMass.position = 2;
131  modAminoAcidMass.mass = 12.345;
132 
133  return modAminoAcidMass;
134 
135 }
136 
138 {
139  ModificationInfo modificationInfo;
140  modificationInfo.modifiedPeptide = "GATO";
141  modificationInfo.modAminoAcidMass = makeModAminoAcidMass();
142 
143  return modificationInfo;
144 }
145 
147 {
148  SearchHit searchHit;
149  searchHit.hitRank = 1;
150  searchHit.peptide = "RAGMALLICK";
151  searchHit.peptidePrevAA = "R";
152  searchHit.peptideNextAA = "V";
153  searchHit.protein = "PA";
154  searchHit.proteinDescr = "Bioinfomagicist";
155  searchHit.numTotalProteins = 1;
156  searchHit.numMatchedIons = 9;
157  searchHit.calcNeutralPepMass = 4.21399;
158  searchHit.massDiff = .0004;
159  searchHit.numTolTerm = 2;
160  searchHit.numMissedCleavages = 3;
161  searchHit.isRejected = 0;
162 
163  AnalysisResult analysisResult = makeAnalysisResult();
164  searchHit.analysisResult = analysisResult;
165 
166  AlternativeProtein alternativeProtein = makeAlternativeProtein();
167  searchHit.alternativeProteins.push_back(alternativeProtein);
168 
170 
171  return searchHit;
172 
173 }
174 
176 {
177  EnzymaticSearchConstraint enzymaticSearchConstraint;
178 
179  enzymaticSearchConstraint.enzyme = "emyzne";
180  enzymaticSearchConstraint.maxNumInternalCleavages = 1;
181  enzymaticSearchConstraint.minNumTermini = 1;
182 
183  return enzymaticSearchConstraint;
184 
185 }
186 
188 {
189  AminoAcidModification aminoAcidModification;
190 
191  aminoAcidModification.aminoAcid = "pm";
192  aminoAcidModification.massDiff = 9.63333;
193  aminoAcidModification.mass = 82.65;
194  aminoAcidModification.variable = "c";
195  aminoAcidModification.symbol = "r";
196 
197  return aminoAcidModification;
198 
199 }
200 
202 {
203  SearchSummary searchSummary;
204  searchSummary.baseName = "mseharmony";
205  searchSummary.searchEngine = "yahooooo";
206  searchSummary.precursorMassType = "A";
207  searchSummary.fragmentMassType = "B";
208  searchSummary.searchID = "ego";
209 
210  EnzymaticSearchConstraint enzymaticSearchConstraint = makeEnzymaticSearchConstraint();
211  searchSummary.enzymaticSearchConstraint = enzymaticSearchConstraint;
212 
213  AminoAcidModification aminoAcidModification = makeAminoAcidModification();
214  searchSummary.aminoAcidModifications.push_back(aminoAcidModification);
215  searchSummary.aminoAcidModifications.push_back(aminoAcidModification);
216 
217  SearchDatabase searchDatabase = makeSearchDatabase();
218  searchSummary.searchDatabase = searchDatabase;
219 
220  return searchSummary;
221 
222 }
223 
224 
226 {
227  SearchResult searchResult;
228  SearchHit searchHit = makeSearchHit();
229  searchResult.searchHit.push_back(SearchHitPtr(new SearchHit(searchHit)));
230 
231  return searchResult;
232 
233 }
234 
236 {
237  SpectrumQuery spectrumQuery;
238  spectrumQuery.spectrum = "ultraviolet";
239  spectrumQuery.startScan = 19120414;
240  spectrumQuery.endScan = 19120415;
241  spectrumQuery.precursorNeutralMass = 46328;
242  spectrumQuery.assumedCharge = 1;
243  spectrumQuery.index = 3547;
244  spectrumQuery.retentionTimeSec = 432000;
245 
246  SearchResult searchResult = makeSearchResult();
247  SearchResultPtr srp(new SearchResult(searchResult));
248  spectrumQuery.searchResult.push_back(srp);
249 
250  return spectrumQuery;
251 
252 }
253 
254 
256 {
257  MSMSRunSummary msmsRunSummary;
258 
259  SampleEnzyme sampleEnzyme = makeSampleEnzyme();
260  msmsRunSummary.sampleEnzyme = makeSampleEnzyme();
261 
262  SearchSummary searchSummary = makeSearchSummary();
263  msmsRunSummary.searchSummary.push_back(SearchSummaryPtr(new SearchSummary(searchSummary)));
264 
265  SpectrumQuery spectrumQuery = makeSpectrumQuery();
266  msmsRunSummary.spectrumQueries.push_back(SpectrumQueryPtr(new SpectrumQuery(spectrumQuery)));
267  msmsRunSummary.spectrumQueries.push_back(SpectrumQueryPtr(new SpectrumQuery(spectrumQuery)));
268 
269  return msmsRunSummary;
270 
271 }
272 
274 {
275  MatchPtr match(new Match());
276  match->spectrumQuery = makeSpectrumQuery();
277  match->feature->mz = 1.234;
278  match->feature->retentionTime = 5.678;
279 
280  return match;
281 
282 }
283 
285 {
286  if (os_) *os_ << "\ntestSpecificity() ... \n";
287 
288  Specificity specificity = makeSpecificity();
289 
290  ostringstream oss;
291  XMLWriter writer(oss);
292  specificity.write(writer);
293 
294  Specificity readSpecificity;
295  istringstream iss(oss.str());
296  readSpecificity.read(iss);
297 
298  unit_assert(specificity == readSpecificity);
299 
300  if (os_) *os_ << oss.str() << endl;
301 
302 }
303 
305 {
306  if (os_) *os_ << "\ntestSampleEnzyme() ... \n";
307 
308  SampleEnzyme sampleEnzyme = makeSampleEnzyme();
309 
310  ostringstream oss;
311  XMLWriter writer(oss);
312  sampleEnzyme.write(writer);
313 
314  SampleEnzyme readSampleEnzyme;
315  istringstream iss(oss.str());
316  readSampleEnzyme.read(iss);
317 
318  unit_assert(sampleEnzyme == readSampleEnzyme);
319 
320  if (os_) *os_ << oss.str() << endl;
321 
322 }
323 
325 {
326  if (os_) *os_ << "\ntestSearchDatabase() ... \n";
327 
328  SearchDatabase searchDatabase = makeSearchDatabase();
329 
330  ostringstream oss;
331  XMLWriter writer(oss);
332  searchDatabase.write(writer);
333 
334  SearchDatabase readSearchDatabase;
335  istringstream iss(oss.str());
336  readSearchDatabase.read(iss);
337 
338  unit_assert(searchDatabase == readSearchDatabase);
339 
340  if (os_) *os_ << oss.str() << endl;
341 
342 }
343 
345 {
346  if (os_) *os_ << "\ntestQ3RatioResult() ... \n";
347 
349 
350  ostringstream oss;
351  XMLWriter writer(oss);
352  q.write(writer);
353 
354  Q3RatioResult readQ;
355  istringstream iss(oss.str());
356  readQ.read(iss);
357 
358  unit_assert(q == readQ);
359  if (os_) *os_ << oss.str() << endl;
360 
361 }
362 
364 {
365  if (os_) *os_ << "\ntestPeptideProphetResult() ... \n";
366 
368 
369  ostringstream oss;
370  XMLWriter writer(oss);
371  pp.write(writer);
372 
373  PeptideProphetResult readPeptideProphetResult;
374  istringstream iss(oss.str());
375  readPeptideProphetResult.read(iss);
376 
377  unit_assert(pp == readPeptideProphetResult);
378 
379  if (os_) *os_ << oss.str() << endl;
380 
381 }
382 
384 {
385  if (os_) *os_ << "\ntestAnalysisResult() ...\n";
386 
387  AnalysisResult analysisResult = makeAnalysisResult();
388 
389  ostringstream oss;
390  XMLWriter writer(oss);
391  analysisResult.write(writer);
392 
393  AnalysisResult readAnalysisResult;
394  istringstream iss(oss.str());
395  readAnalysisResult.read(iss);
396 
397  unit_assert(analysisResult == readAnalysisResult);
398 
399  if(os_) *os_ << oss.str() << endl;
400 
401  AnalysisResult analysisResult2;
402  analysisResult2.analysis = "q3";
403  analysisResult2.q3RatioResult = makeQ3RatioResult();
404 
405  ostringstream oss2;
406  XMLWriter writer2(oss2);
407  analysisResult2.write(writer2);
408 
409  AnalysisResult readAnalysisResult2;
410  istringstream iss2(oss2.str());
411  readAnalysisResult2.read(iss2);
412 
413  unit_assert(analysisResult2 == readAnalysisResult2);
414 
415  if(os_) *os_ << oss2.str() << endl;
416 
417 }
418 
420 {
421 
422  if (os_) *os_ << "\ntestAlternativeProtein() ...\n";
423 
424  AlternativeProtein alternativeProtein = makeAlternativeProtein();
425 
426  ostringstream oss;
427  XMLWriter writer(oss);
428  alternativeProtein.write(writer);
429 
430  AlternativeProtein readAlternativeProtein;
431  istringstream iss(oss.str());
432  readAlternativeProtein.read(iss);
433 
434  unit_assert(alternativeProtein == readAlternativeProtein);
435 
436  if(os_) *os_ << oss.str() << endl;
437 
438 }
439 
441 {
442  if (os_) *os_ << "\ntestModAminoAcidMass() ...\n";
443 
444  ModAminoAcidMass modAminoAcidMass = makeModAminoAcidMass();
445 
446  ostringstream oss;
447  XMLWriter writer(oss);
448  modAminoAcidMass.write(writer);
449 
450  ModAminoAcidMass readModAminoAcidMass;
451  istringstream iss(oss.str());
452  readModAminoAcidMass.read(iss);
453 
454  unit_assert(modAminoAcidMass == readModAminoAcidMass);
455 
456  if(os_) *os_ << oss.str() << endl;
457 }
458 
460 {
461  if (os_) *os_ << "\ntestModificationInfo() ...\n";
462 
463  ModificationInfo modificationInfo = makeModificationInfo();
464 
465  ostringstream oss;
466  XMLWriter writer(oss);
467  modificationInfo.write(writer);
468 
469  ModificationInfo readModificationInfo;
470  istringstream iss(oss.str());
471  readModificationInfo.read(iss);
472 
473  unit_assert(modificationInfo == readModificationInfo);
474 
475  if(os_) *os_ << oss.str() << endl;
476 
477 }
478 
480 {
481  if (os_) *os_ << "\ntestSearchHit() ...\n";
482 
483  SearchHit searchHit = makeSearchHit();
484 
485  ostringstream oss;
486  XMLWriter writer(oss);
487  searchHit.write(writer);
488 
489  SearchHit readSearchHit;
490  istringstream iss(oss.str());
491  readSearchHit.read(iss);
492 
493  unit_assert(searchHit == readSearchHit);
494 
495  if(os_) *os_ << oss.str() << endl;
496 }
497 
499 {
500  if(os_) *os_ << "\ntestSearchResult() ... \n";
501 
502  SearchResult searchResult = makeSearchResult();
503 
504  ostringstream oss;
505  XMLWriter writer(oss);
506  searchResult.write(writer);
507 
508  SearchResult readSearchResult;
509  istringstream iss(oss.str());
510  readSearchResult.read(iss);
511 
512  unit_assert(searchResult == readSearchResult);
513 
514  if(os_) *os_ << oss.str() << endl;
515 
516 
517 }
518 
520 {
521  if (os_) *os_ << "\ntestEnzymaticSearchConstraint() ... \n";
522 
523  EnzymaticSearchConstraint enzymaticSearchConstraint = makeEnzymaticSearchConstraint();
524 
525  ostringstream oss;
526  XMLWriter writer(oss);
527  enzymaticSearchConstraint.write(writer);
528 
529  EnzymaticSearchConstraint readEnzymaticSearchConstraint;
530  istringstream iss(oss.str());
531  readEnzymaticSearchConstraint.read(iss);
532 
533  unit_assert(enzymaticSearchConstraint == readEnzymaticSearchConstraint);
534 
535  if(os_) *os_ << oss.str() << endl;
536 
537 }
538 
540 {
541  if (os_) *os_ << "\ntestAminoAcidModification() ... \n";
542 
543  AminoAcidModification aminoAcidModification = makeAminoAcidModification();
544 
545  ostringstream oss;
546  XMLWriter writer(oss);
547  aminoAcidModification.write(writer);
548 
549  AminoAcidModification readAminoAcidModification;
550  istringstream iss(oss.str());
551  readAminoAcidModification.read(iss);
552 
553  unit_assert(aminoAcidModification == readAminoAcidModification);
554 
555  if(os_) *os_ << oss.str() << endl;
556 
557 }
558 
560 {
561  if(os_) *os_ << "\ntestSearchSummary() ... \n";
562 
563  SearchSummary searchSummary = makeSearchSummary();
564 
565  ostringstream oss;
566  XMLWriter writer(oss);
567  searchSummary.write(writer);
568 
569  SearchSummary readSearchSummary;
570  istringstream iss(oss.str());
571  readSearchSummary.read(iss);
572 
573  unit_assert(searchSummary == readSearchSummary);
574 
575  if(os_) *os_ << oss.str() << endl;
576 
577 }
578 
580 {
581  if(os_) *os_ << "\ntestSpectrumQuery() ... \n";
582 
583  SpectrumQuery spectrumQuery = makeSpectrumQuery();
584 
585  ostringstream oss;
586  XMLWriter writer(oss);
587  spectrumQuery.write(writer);
588 
589  if(os_) *os_ << oss.str() << endl;
590 
591  SpectrumQuery readSpectrumQuery;
592  istringstream iss(oss.str());
593  readSpectrumQuery.read(iss);
594 
595  readSpectrumQuery.write(writer);
596  if(os_) *os_ << oss.str() << endl;
597  unit_assert(spectrumQuery == readSpectrumQuery);
598 
599  if(os_) *os_ << oss.str() << endl;
600 
601 }
602 
604 {
605  if(os_) *os_ << "\ntestMSMSRunSummary() ... \n";
606 
607  MSMSRunSummary msmsRunSummary = makeMSMSRunSummary();
608 
609  ostringstream oss;
610  XMLWriter writer(oss);
611  msmsRunSummary.write(writer);
612 
613  MSMSRunSummary readMSMSRunSummary;
614  istringstream iss(oss.str());
615  readMSMSRunSummary.read(iss);
616 
617  unit_assert(msmsRunSummary == readMSMSRunSummary);
618 
619  if(os_) *os_ << oss.str() << endl;
620 
621 }
622 
624 {
625  if(os_) *os_ << "\ntestMSMSPipelineAnalysis() ... \n";
626 
627  MSMSPipelineAnalysis msmsPipelineAnalysis;
628  msmsPipelineAnalysis.date = "20000101";
629  msmsPipelineAnalysis.summaryXML = "/2000/01/20000101/20000101.xml";
630  msmsPipelineAnalysis.xmlns = "http://regis-web.systemsbiology.net/pepXML";
631  msmsPipelineAnalysis.xmlnsXSI = "aruba";
632  msmsPipelineAnalysis.XSISchemaLocation = "jamaica";
633 
635  msmsPipelineAnalysis.msmsRunSummary = msrs;
636 
637  ostringstream oss;
638  XMLWriter writer(oss);
639  msmsPipelineAnalysis.write(writer);
640 
641  MSMSPipelineAnalysis readMSMSPipelineAnalysis;
642  istringstream iss(oss.str());
643  readMSMSPipelineAnalysis.read(iss);
644 
645  unit_assert(msmsPipelineAnalysis == readMSMSPipelineAnalysis);
646 
647  if(os_) *os_ << oss.str() << endl;
648 
649 }
650 
651 void testMatch()
652 {
653  if(os_) *os_ << "\ntestMatch() ... \n";
654 
655  MatchPtr match = makeMatch();
656 
657  ostringstream oss;
658  XMLWriter writer(oss);
659  match->write(writer);
660 
661  Match readMatch;
662  istringstream iss(oss.str());
663  readMatch.read(iss);
664 
665  ostringstream checkstream;
666  XMLWriter check(checkstream);
667  readMatch.write(check);
668  // unit_assert(*match == readMatch);
669 
670  if(os_) *os_ << oss.str() << endl;
671  if(os_) *os_ << checkstream.str() << endl;
672 
673  unit_assert(*match == readMatch);
674 
675 }
676 
678 {
679  if(os_) *os_ << "\ntestMatchData() ... \n";
680 
681  MatchData matchData;
682  matchData.warpFunctionCalculator = "Spock";
683  matchData.searchNbhdCalculator = "Mr. Rogers";
684  matchData.matches.push_back(makeMatch());
685  matchData.matches.push_back(makeMatch());
686 
687  ostringstream oss;
688  XMLWriter writer(oss);
689  matchData.write(writer);
690 
691  MatchData readMatchData;
692  istringstream iss(oss.str());
693  readMatchData.read(iss);
694 
695 
696  ostringstream checkstream;
697  XMLWriter check(checkstream);
698  readMatchData.write(check);
699  // unit_assert(*match == readMatch);
700 
701  if(os_) *os_ << oss.str() << endl;
702  if(os_) *os_ << checkstream.str() << endl;
703 
704 
705 
706  unit_assert(matchData == readMatchData);
707 
708  if(os_) *os_ << oss.str() << endl;
709 
710 }
711 
713 {
714  ifstream ifs("20080619-A-6mixtestRG_Data10_msprefix.pep.xml");
715  if (!(ifs.good()) )
716  {
717  throw runtime_error("bad ifs");
718  return;
719  }
720 
721  MSMSPipelineAnalysis msmsPipelineAnalysis;
722  msmsPipelineAnalysis.read(ifs);
723 
724  ofstream ofs("test.pep.xml", ios::app);
725  XMLWriter writer(ofs);
726  msmsPipelineAnalysis.write(writer);
727 
728 }
729 
730 int main(int argc, char* argv[])
731 {
732  TEST_PROLOG(argc, argv)
733 
734 
735  try
736  {
737  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
738  if (os_) *os_ << "MinimumPepXMLTest ... \n";
739 
740  testSpecificity();
749  testSearchHit();
757  testMatch();
758  testMatchData();
759  //testInvarianceUnderProteinProphet();
760 
761  }
762  catch (exception& e)
763  {
764  TEST_FAILED(e.what())
765  }
766  catch (...)
767  {
768  TEST_FAILED("Caught unknown exception.")
769  }
770 
772 }
773 
774