ProteoWizard
MSDataMergerTest.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Matt Chambers <matt.chambers .@. vanderbilt.edu>
6//
7// Copyright 2010 Vanderbilt University - Nashville, TN 37232
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
24#include "MSDataMerger.hpp"
25#include "examples.hpp"
26#include "TextWriter.hpp"
28
29using namespace pwiz::msdata;
30using namespace pwiz::util;
31
32
33ostream* os_ = 0;
34
35
36void test()
37{
38 MSData tinyReference;
39 examples::initializeTiny(tinyReference);
40
41 const size_t tinyCopyCount = 3;
42
43 vector<MSDataPtr> tinyExamples;
44 for (size_t i=0; i < tinyCopyCount; ++i)
45 {
46 tinyExamples.push_back(MSDataPtr(new MSData));
47 MSData& msd = *tinyExamples.back();
49 msd.id = msd.run.id = "tiny" + lexical_cast<string>(i);
50 }
51
52 MSDataMerger tinyMerged(tinyExamples);
53
54 if (os_)
55 {
56 TextWriter writer(*os_);
57 writer(tinyMerged);
58 }
59
60 unit_assert(tinyMerged.id == "tiny"); // longest common prefix of tiny[012]
61 unit_assert(tinyMerged.run.id == "tiny"); // longest common prefix of tiny[012]
62
65
66 unit_assert(tinyMerged.fileDescription.sourceFilePtrs.size() == tinyReference.fileDescription.sourceFilePtrs.size() * tinyCopyCount);
67 for (size_t i=0; i < tinyCopyCount; ++i)
68 for (size_t j=0; j < tinyReference.fileDescription.sourceFilePtrs.size(); ++j)
69 {
70 string expectedPrefix = "tiny" + lexical_cast<string>(i) + "_";
71 size_t expectedIndex = j + (i * tinyReference.fileDescription.sourceFilePtrs.size());
72 unit_assert(tinyMerged.fileDescription.sourceFilePtrs[expectedIndex]->id == expectedPrefix + tinyReference.fileDescription.sourceFilePtrs[j]->id);
73 }
74
75
76 //unit_assert(tinyMerged.fileDescription.contacts.size() == tinyReference.fileDescription.contacts.size());
77 SpectrumList& sl = *tinyMerged.run.spectrumListPtr;
78 unit_assert(sl.size() == 3 * tinyReference.run.spectrumListPtr->size());
79 for (size_t index=0; index < sl.size(); ++index)
80 {
81 size_t referenceIndex = index % tinyReference.run.spectrumListPtr->size();
82
83 const SpectrumIdentity& identity = sl.spectrumIdentity(index);
84 const SpectrumIdentity& referenceIdentity = tinyReference.run.spectrumListPtr->spectrumIdentity(referenceIndex);
85
86 unit_assert(identity.index == index);
87 unit_assert(identity.id == referenceIdentity.id);
88
89 SpectrumPtr spectrum = sl.spectrum(index);
90 SpectrumPtr referenceSpectrum = tinyReference.run.spectrumListPtr->spectrum(referenceIndex);
91
92 unit_assert(spectrum->index == index);
93 unit_assert(spectrum->id == referenceSpectrum->id);
94
95 vector<SourceFilePtr>::const_iterator foundSourceFile = find(tinyMerged.fileDescription.sourceFilePtrs.begin(),
96 tinyMerged.fileDescription.sourceFilePtrs.end(),
97 spectrum->sourceFilePtr);
98
99 unit_assert(foundSourceFile != tinyMerged.fileDescription.sourceFilePtrs.end());
100 }
101}
102
103
104int main(int argc, char* argv[])
105{
106 TEST_PROLOG(argc, argv)
107
108 try
109 {
110 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
111 test();
112 }
113 catch (exception& e)
114 {
115 TEST_FAILED(e.what())
116 }
117 catch (...)
118 {
119 TEST_FAILED("Caught unknown exception.")
120 }
121
123}
int main(int argc, char *argv[])
ostream * os_
void test()
Interface for accessing spectra, which may be stored in memory or backed by a data file (RAW,...
Definition MSData.hpp:661
virtual size_t size() const =0
returns the number of spectra
virtual SpectrumPtr spectrum(size_t index, bool getBinaryData=false) const =0
retrieve a spectrum by index
virtual const SpectrumIdentity & spectrumIdentity(size_t index) const =0
access to a spectrum index
MS_centroid_spectrum
centroid spectrum: Processing of profile data to produce spectra that contains discrete peaks of zero...
Definition cv.hpp:720
MS_MSn_spectrum
MSn spectrum: MSn refers to multi-stage MS2 experiments designed to record product ion spectra where ...
Definition cv.hpp:2364
PWIZ_API_DECL void initializeTiny(MSData &msd)
boost::shared_ptr< MSData > MSDataPtr
Definition MSData.hpp:913
boost::shared_ptr< Spectrum > SpectrumPtr
Definition MSData.hpp:573
bool hasCVParam(CVID cvid) const
returns true iff cvParams contains exact cvid (recursive)
FileContent fileContent
this summarizes the different types of spectra that can be expected in the file. This is expected to ...
Definition MSData.hpp:87
std::vector< SourceFilePtr > sourceFilePtrs
list and descriptions of the source files this mzML document was generated or derived from.
Definition MSData.hpp:90
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition MSData.hpp:850
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument.
Definition MSData.hpp:886
std::string id
an optional id for the mzML document. It is recommended to use LSIDs when possible.
Definition MSData.hpp:855
FileDescription fileDescription
information pertaining to the entire mzML file (i.e. not specific to any part of the data set) is sto...
Definition MSData.hpp:862
std::string id
a unique identifier for this run.
Definition MSData.hpp:812
SpectrumListPtr spectrumListPtr
all mass spectra and the acquisitions underlying them are described and attached here....
Definition MSData.hpp:827
Identifying information for a spectrum.
Definition MSData.hpp:471
std::string id
a unique identifier for this spectrum. It should be expected that external files may use this identif...
Definition MSData.hpp:476
size_t index
the zero-based, consecutive index of the spectrum in the SpectrumList.
Definition MSData.hpp:473
#define unit_assert(x)
Definition unit.hpp:85
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175