ProteoWizard
Functions | Variables
MSDataMergerTest.cpp File Reference
#include "pwiz/utility/misc/unit.hpp"
#include "MSDataMerger.hpp"
#include "examples.hpp"
#include "TextWriter.hpp"
#include "pwiz/utility/misc/Std.hpp"

Go to the source code of this file.

Functions

void test ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 

Function Documentation

§ test()

void test ( )

Definition at line 36 of file MSDataMergerTest.cpp.

References pwiz::msdata::MSData::fileDescription, pwiz::msdata::SpectrumIdentity::id, pwiz::msdata::Run::id, pwiz::msdata::MSData::id, pwiz::msdata::SpectrumIdentity::index, pwiz::msdata::examples::initializeTiny(), boost::lexical_cast(), MS_centroid_spectrum, MS_MSn_spectrum, os_, pwiz::msdata::MSData::run, pwiz::msdata::SpectrumList::size(), pwiz::msdata::FileDescription::sourceFilePtrs, pwiz::msdata::SpectrumList::spectrum(), pwiz::msdata::SpectrumList::spectrumIdentity(), pwiz::msdata::Run::spectrumListPtr, and unit_assert.

Referenced by main().

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 }
MS_MSn_spectrum
MSn spectrum: MSn refers to multi-stage MS2 experiments designed to record product ion spectra where ...
Definition: cv.hpp:2212
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
virtual SpectrumPtr spectrum(size_t index, bool getBinaryData=false) const =0
retrieve a spectrum by index
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_
PWIZ_API_DECL void initializeTiny(IdentData &mzid)
MS_centroid_spectrum
centroid spectrum: Processing of profile data to produce spectra that contains discrete peaks of zero...
Definition: cv.hpp:559
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

§ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 104 of file MSDataMergerTest.cpp.

References os_, test(), TEST_EPILOG, TEST_FAILED, and TEST_PROLOG.

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 }
void test()
#define TEST_EPILOG
Definition: unit.hpp:182
ostream * os_
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174

Variable Documentation

§ os_

ostream* os_ = 0

Definition at line 33 of file MSDataMergerTest.cpp.

Referenced by main(), and test().