ProteoWizard
Classes | Functions | Variables
MSDataCacheTest.cpp File Reference
#include "MSDataCache.hpp"
#include "pwiz/data/msdata/MSDataFile.hpp"
#include "pwiz/data/msdata/examples.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"
#include <cstring>

Go to the source code of this file.

Classes

struct  EvenRequester
 

Functions

void testMetadata (MSDataCache &cache)
 
void testDefault ()
 
void printCache (ostream &os, const MSDataCache &cache)
 
void testMRU ()
 
void testUpdateRequest ()
 
void testAutomaticUpdate ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 
const double epsilon_ = 1e-6
 

Function Documentation

§ testMetadata()

void testMetadata ( MSDataCache cache)

Definition at line 41 of file MSDataCacheTest.cpp.

References epsilon_, MS_QIT, pwiz::chemistry::Ion::mz(), os_, unit_assert, and unit_assert_equal.

Referenced by testDefault().

42 {
43  if (os_) *os_ << "testMetadata()\n";
44 
45  if (os_) *os_ << "spectrumCount: " << cache.size() << endl;
46  unit_assert(cache.size() == 5);
47 
48  unit_assert(cache[0].index == 0);
49  unit_assert(cache[0].id == "scan=19");
50  unit_assert(cache[0].scanNumber == 19); // TODO: change to nativeID
51  unit_assert(cache[0].massAnalyzerType == MS_QIT);
52  unit_assert(cache[0].msLevel == 1);
53  unit_assert_equal(cache[0].retentionTime, 353.43, epsilon_);
54  unit_assert_equal(cache[0].mzLow, 400.39, epsilon_);
55  unit_assert_equal(cache[0].mzHigh, 1795.56, epsilon_);
56  unit_assert(cache[0].precursors.empty());
57 
58  unit_assert(cache[1].index == 1);
59  unit_assert(cache[1].id == "scan=20");
60  unit_assert(cache[1].scanNumber == 20); // TODO: change to nativeID
61  unit_assert(cache[1].massAnalyzerType == MS_QIT);
62  unit_assert(cache[1].msLevel == 2);
63  unit_assert_equal(cache[1].retentionTime, 359.43, epsilon_);
64  unit_assert_equal(cache[1].mzLow, 320.39, epsilon_);
65  unit_assert_equal(cache[1].mzHigh, 1003.56, epsilon_);
66  unit_assert(cache[1].precursors.size() == 1);
67  unit_assert(cache[1].precursors[0].index == 0);
68  unit_assert_equal(cache[1].precursors[0].mz, 445.34, epsilon_);
69  unit_assert_equal(cache[1].precursors[0].intensity, 120053, epsilon_);
70  unit_assert(cache[1].precursors[0].charge == 2);
71 
72  if (os_) *os_ << endl;
73 }
#define unit_assert_equal(x, y, epsilon)
Definition: unit.hpp:99
double mz(double neutralMass, int protonDelta, int electronDelta=0, int neutronDelta=0)
Definition: Ion.hpp:78
const double epsilon_
ostream * os_
MS_QIT
QIT (quadrupole ion trap): Quadrupole Ion Trap mass analyzer captures the ions in a three dimensional...
Definition: cv.hpp:391
#define unit_assert(x)
Definition: unit.hpp:85

§ testDefault()

void testDefault ( )

Definition at line 76 of file MSDataCacheTest.cpp.

References pwiz::identdata::examples::initializeTiny(), pwiz::analysis::MSDataCache::open(), pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, testMetadata(), unit_assert, and pwiz::analysis::MSDataCache::update().

Referenced by main().

77 {
78  MSData tiny;
80 
81  MSDataCache cache;
82 
83  cache.open(tiny);
84 
85  cache.update(tiny, *tiny.run.spectrumListPtr->spectrum(0));
86  unit_assert(!cache[0].data.empty());
87  unit_assert(cache[1].data.empty());
88 
89  cache.update(tiny, *tiny.run.spectrumListPtr->spectrum(1));
90  unit_assert(cache[0].data.empty());
91  unit_assert(!cache[1].data.empty());
92 
93  testMetadata(cache);
94 }
simple memory cache for common MSData info
Definition: MSDataCache.hpp:74
void testMetadata(MSDataCache &cache)
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument...
Definition: MSData.hpp:882
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
PWIZ_API_DECL void initializeTiny(IdentData &mzid)
virtual void open(const DataInfo &dataInfo)
start analysis of the data
virtual void update(const DataInfo &dataInfo, const Spectrum &spectrum)
analyze a single spectrum
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

§ printCache()

void printCache ( ostream &  os,
const MSDataCache cache 
)

Definition at line 97 of file MSDataCacheTest.cpp.

Referenced by testMRU().

98 {
99  os << "cached binary data:\n";
100  for (vector<SpectrumInfo>::const_iterator it=cache.begin(); it!=cache.end(); ++it)
101  {
102  os << it->index << " "
103  << it->data.size() << "/"
104  << it->data.capacity() << endl;
105  }
106  os << endl;
107 }

§ testMRU()

void testMRU ( )

Definition at line 110 of file MSDataCacheTest.cpp.

References pwiz::analysis::MSDataCache::Config::binaryDataCacheSize, boost::lexical_cast(), MS_number_of_detector_counts, pwiz::analysis::MSDataCache::open(), os_, printCache(), pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, unit_assert, and pwiz::analysis::MSDataCache::update().

Referenced by main().

111 {
112  if (os_) *os_ << "testMRU()\n";
113 
114  vector<MZIntensityPair> pairs(100);
115 
117  for (size_t i=0; i<10; i++)
118  {
119  SpectrumPtr spectrum(new Spectrum);
120  spectrum->setMZIntensityPairs(pairs, MS_number_of_detector_counts);
121  spectrum->index = i;
122  spectrum->id = "scan=" + lexical_cast<string>(i);
123  sl->spectra.push_back(spectrum);
124  }
125 
126  MSData msd;
127  msd.run.spectrumListPtr = sl;
128 
129  MSDataCache::Config config;
130  config.binaryDataCacheSize = 3;
131  MSDataCache cache(config);
132 
133  cache.open(msd);
134 
135  if (os_) *os_ << "update: 0 1 2\n";
136  cache.update(msd, *sl->spectrum(0, true));
137  cache.update(msd, *sl->spectrum(1, true));
138  cache.update(msd, *sl->spectrum(2, true));
139  if (os_) printCache(*os_, cache); // mru: 2 1 0
140 
141  unit_assert(cache[0].data.size() == 100);
142  unit_assert(cache[1].data.size() == 100);
143  unit_assert(cache[2].data.size() == 100);
144  unit_assert(cache[3].data.size() == 0);
145 
146  if (os_) *os_ << "update: 3\n";
147  cache.update(msd, *sl->spectrum(3, true));
148  if (os_) printCache(*os_, cache); // mru: 3 2 1
149 
150  unit_assert(cache[0].data.capacity() == 0);
151  unit_assert(cache[1].data.size() == 100);
152  unit_assert(cache[2].data.size() == 100);
153  unit_assert(cache[3].data.size() == 100);
154 
155  if (os_) *os_ << "update: 1\n";
156  cache.update(msd, *sl->spectrum(1, true));
157  if (os_) printCache(*os_, cache); // mru: 1 3 2
158 
159  unit_assert(cache[0].data.capacity() == 0);
160  unit_assert(cache[1].data.size() == 100);
161  unit_assert(cache[2].data.size() == 100);
162  unit_assert(cache[3].data.size() == 100);
163 
164  if (os_) *os_ << "update: 4\n";
165  cache.update(msd, *sl->spectrum(4, true));
166  if (os_) printCache(*os_, cache); // mru: 4 1 3
167 
168  unit_assert(cache[0].data.capacity() == 0);
169  unit_assert(cache[1].data.size() == 100);
170  unit_assert(cache[2].data.capacity() == 0);
171  unit_assert(cache[3].data.size() == 100);
172  unit_assert(cache[3].data.size() == 100);
173 
174  if (os_) *os_ << endl;
175 }
simple memory cache for common MSData info
Definition: MSDataCache.hpp:74
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:569
float lexical_cast(const std::string &str)
void printCache(ostream &os, const MSDataCache &cache)
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument...
Definition: MSData.hpp:882
ostream * os_
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
MS_number_of_detector_counts
number of detector counts: The number of counted events observed in one or a group of elements of a d...
Definition: cv.hpp:580
boost::shared_ptr< SpectrumListSimple > SpectrumListSimplePtr
Definition: MSData.hpp:727
MSDataCache configuration.
Definition: MSDataCache.hpp:81
The structure that captures the generation of a peak list (including the underlying acquisitions) ...
Definition: MSData.hpp:504
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:845
Simple writeable in-memory implementation of SpectrumList.
Definition: MSData.hpp:712
#define unit_assert(x)
Definition: unit.hpp:85

§ testUpdateRequest()

void testUpdateRequest ( )

Definition at line 188 of file MSDataCacheTest.cpp.

References pwiz::analysis::MSDataAnalyzerDriver::analyze(), pwiz::msdata::SpectrumInfo::id, pwiz::msdata::SpectrumInfo::index, boost::lexical_cast(), MS_number_of_detector_counts, os_, pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, and unit_assert.

Referenced by main().

189 {
190  if (os_) *os_ << "testUpdateRequest()\n";
191 
192  vector<MZIntensityPair> pairs(100);
193 
195  for (size_t i=0; i<10; i++)
196  {
197  SpectrumPtr spectrum(new Spectrum);
198  spectrum->setMZIntensityPairs(pairs, MS_number_of_detector_counts);
199  spectrum->index = i;
200  spectrum->id = "scan=" + lexical_cast<string>(i);
201  sl->spectra.push_back(spectrum);
202  }
203 
204  MSData msd;
205  msd.run.spectrumListPtr = sl;
206 
207  MSDataAnalyzerContainer analyzers;
208  shared_ptr<MSDataCache> cache(new MSDataCache);
209  analyzers.push_back(cache);
210  analyzers.push_back(MSDataAnalyzerPtr(new EvenRequester));
211 
212  MSDataAnalyzerDriver driver(analyzers);
213  driver.analyze(msd);
214 
215  for (size_t i=0, end=cache->size(); i<end; i++)
216  {
217  const SpectrumInfo& info = cache->at(i);
218  if (os_) *os_ << info.index << " " << info.id << endl;
219 
220  // cache has only been updated with the spectra requested by EvenRequester
221 
222  unit_assert(i%2==0 && info.index==i && info.id=="scan="+lexical_cast<string>(i) ||
223  i%2==1 && info.index==(size_t)-1&& info.id.empty());
224  }
225 
226  if (os_) *os_ << endl;
227 }
simple memory cache for common MSData info
Definition: MSDataCache.hpp:74
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:569
boost::shared_ptr< MSDataAnalyzer > MSDataAnalyzerPtr
float lexical_cast(const std::string &str)
container of MSDataAnalyzer (composite pattern)
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument...
Definition: MSData.hpp:882
event generator for MSDataAnalyzer
ostream * os_
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
MS_number_of_detector_counts
number of detector counts: The number of counted events observed in one or a group of elements of a d...
Definition: cv.hpp:580
boost::shared_ptr< SpectrumListSimple > SpectrumListSimplePtr
Definition: MSData.hpp:727
The structure that captures the generation of a peak list (including the underlying acquisitions) ...
Definition: MSData.hpp:504
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:845
Simple writeable in-memory implementation of SpectrumList.
Definition: MSData.hpp:712
#define unit_assert(x)
Definition: unit.hpp:85
simple structure for holding Spectrum info

§ testAutomaticUpdate()

void testAutomaticUpdate ( )

Definition at line 230 of file MSDataCacheTest.cpp.

References pwiz::msdata::SpectrumInfo::data, pwiz::msdata::SpectrumInfo::id, pwiz::msdata::SpectrumInfo::index, boost::lexical_cast(), MS_number_of_detector_counts, pwiz::analysis::MSDataCache::open(), os_, pwiz::msdata::MSData::run, pwiz::analysis::MSDataCache::spectrumInfo(), pwiz::msdata::Run::spectrumListPtr, and unit_assert.

Referenced by main().

231 {
232  if (os_) *os_ << "testAutomaticUpdate()\n";
233 
234  vector<MZIntensityPair> pairs(100);
235 
237  for (size_t i=0; i<10; i++)
238  {
239  SpectrumPtr spectrum(new Spectrum);
240  spectrum->setMZIntensityPairs(pairs, MS_number_of_detector_counts);
241  spectrum->index = i;
242  spectrum->id = "scan=" + lexical_cast<string>(i);
243  sl->spectra.push_back(spectrum);
244  }
245 
246  MSData msd;
247  msd.run.spectrumListPtr = sl;
248 
249  MSDataCache cache;
250  cache.open(msd);
251 
252  unit_assert(cache.size() == sl->size());
253  for (size_t i=0; i<cache.size(); i++)
254  unit_assert(cache[i].index == (size_t)-1);
255 
256  const SpectrumInfo& info5 = cache.spectrumInfo(5, true);
257  unit_assert(cache[5].data.size() == 100);
258 
259  cache.spectrumInfo(7); // getBinaryData==false -> doesn't change cached binary data
260  unit_assert(cache[5].data.size() == 100);
261  unit_assert(cache[7].data.size() == 0);
262 
263  const SpectrumInfo& info7 = cache.spectrumInfo(7, true);
264 
265  if (os_)
266  {
267  for (size_t i=0; i<cache.size(); i++)
268  *os_ << i << " " << cache[i].index << " " << cache[i].id << " "
269  << cache[i].data.size() << endl;
270  }
271 
272  unit_assert(info7.data.size() == 100);
273  unit_assert(info5.data.size() == 0);
274 
275  unit_assert(info5.index==5 && info5.id=="scan=5");
276  unit_assert(cache[5].index==5 && cache[5].id=="scan=5");
277  unit_assert(info7.index==7 && info7.id=="scan=7");
278  unit_assert(cache[7].index==7 && cache[7].id=="scan=7");
279 
280  for (size_t i=0; i<cache.size(); i++)
281  if (i!=5 && i!=7)
282  unit_assert(cache[i].index == (size_t)-1);
283 }
simple memory cache for common MSData info
Definition: MSDataCache.hpp:74
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:569
float lexical_cast(const std::string &str)
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument...
Definition: MSData.hpp:882
ostream * os_
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
MS_number_of_detector_counts
number of detector counts: The number of counted events observed in one or a group of elements of a d...
Definition: cv.hpp:580
virtual void open(const DataInfo &dataInfo)
start analysis of the data
boost::shared_ptr< SpectrumListSimple > SpectrumListSimplePtr
Definition: MSData.hpp:727
The structure that captures the generation of a peak list (including the underlying acquisitions) ...
Definition: MSData.hpp:504
std::vector< MZIntensityPair > data
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:845
Simple writeable in-memory implementation of SpectrumList.
Definition: MSData.hpp:712
#define unit_assert(x)
Definition: unit.hpp:85
const SpectrumInfo & spectrumInfo(size_t index, bool getBinaryData=false)
access to SpectrumInfo with automatic update (open() must be called first)
simple structure for holding Spectrum info

§ main()

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

Definition at line 286 of file MSDataCacheTest.cpp.

References os_, TEST_EPILOG, TEST_FAILED, TEST_PROLOG, testAutomaticUpdate(), testDefault(), testMRU(), and testUpdateRequest().

287 {
288  TEST_PROLOG(argc, argv)
289 
290  try
291  {
292  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
293  testDefault();
294  testMRU();
297  }
298  catch (exception& e)
299  {
300  TEST_FAILED(e.what())
301  }
302  catch (...)
303  {
304  TEST_FAILED("Caught unknown exception.")
305  }
306 
308 }
void testMRU()
#define TEST_EPILOG
Definition: unit.hpp:182
void testAutomaticUpdate()
ostream * os_
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174
void testDefault()
void testUpdateRequest()

Variable Documentation

§ os_

ostream* os_ = 0

§ epsilon_

const double epsilon_ = 1e-6

Definition at line 38 of file MSDataCacheTest.cpp.

Referenced by testMetadata().