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 
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 }