ProteoWizard
MSDataMergerTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: MSDataMergerTest.cpp 4129 2012-11-20 00:05:37Z chambm $
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 
29 using namespace pwiz::msdata;
30 using namespace pwiz::util;
31 
32 
33 ostream* os_ = 0;
34 
35 
36 void 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 
63  unit_assert(tinyMerged.fileDescription.fileContent.hasCVParam(MS_MSn_spectrum));
64  unit_assert(tinyMerged.fileDescription.fileContent.hasCVParam(MS_centroid_spectrum));
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 
104 int 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 }
MS_MSn_spectrum
MSn spectrum: MSn refers to multi-stage MS2 experiments designed to record product ion spectra where ...
Definition: cv.hpp:2212
void test()
std::vector< SourceFilePtr > sourceFilePtrs
list and descriptions of the source files this mzML document was generated or derived from...
Definition: MSData.hpp:89
virtual const SpectrumIdentity & spectrumIdentity(size_t index) const =0
access to a spectrum index
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:569
#define TEST_EPILOG
Definition: unit.hpp:182
virtual SpectrumPtr spectrum(size_t index, bool getBinaryData=false) const =0
retrieve a spectrum by index
PWIZ_API_DECL void initializeTiny(MSData &msd)
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:858
virtual size_t size() const =0
returns the number of spectra
float lexical_cast(const std::string &str)
Interface for accessing spectra, which may be stored in memory or backed by a data file (RAW...
Definition: MSData.hpp:656
std::string id
an optional id for the mzML document. It is recommended to use LSIDs when possible.
Definition: MSData.hpp:851
std::string id
a unique identifier for this run.
Definition: MSData.hpp:808
std::string id
a unique identifier for this spectrum. It should be expected that external files may use this identif...
Definition: MSData.hpp:475
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument...
Definition: MSData.hpp:882
size_t index
the zero-based, consecutive index of the spectrum in the SpectrumList.
Definition: MSData.hpp:472
boost::shared_ptr< MSData > MSDataPtr
Definition: MSData.hpp:909
SpectrumListPtr spectrumListPtr
all mass spectra and the acquisitions underlying them are described and attached here. Subsidiary data arrays are also both described and attached here.
Definition: MSData.hpp:823
Identifying information for a spectrum.
Definition: MSData.hpp:469
ostream * os_
#define TEST_FAILED(x)
Definition: unit.hpp:176
MS_centroid_spectrum
centroid spectrum: Processing of profile data to produce spectra that contains discrete peaks of zero...
Definition: cv.hpp:559
int main(int argc, char *argv[])
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:845
#define unit_assert(x)
Definition: unit.hpp:85