ProteoWizard
SpectrumList_MetadataFixerTest.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Matt Chambers <matt.chambers <a.t> vanderbilt.edu>
6//
7// Copyright 2009 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
27
28using namespace pwiz::util;
29using namespace pwiz::msdata;
30using namespace pwiz::analysis;
31
32ostream* os_ = 0;
33
34
36{
37 // space-delimited doubles
38 const char* inputMZArray;
40
41 double tic;
42 double bpi;
43 double bpmz;
44};
45
47{
48 { "1 2 3 4 5", "10 20 30 40 50", 150, 50, 5 },
49 { "1 2 3 4 5", "50 40 30 20 10", 150, 50, 1 },
50 { "1 2 3 4 5", "10 20 30 20 10", 90, 30, 3 },
51 { "1", "10", 10, 10, 1 }
52};
53
55
56vector<double> parseDoubleArray(const string& doubleArray)
57{
58 vector<double> doubleVector;
59 vector<string> tokens;
60 bal::split(tokens, doubleArray, bal::is_space());
61 if (!tokens.empty() && !tokens[0].empty())
62 for (size_t i=0; i < tokens.size(); ++i)
63 doubleVector.push_back(lexical_cast<double>(tokens[i]));
64 return doubleVector;
65}
66
67void test()
68{
69 for (size_t i=0; i < testMetadataFixersSize; ++i)
70 {
72 SpectrumListPtr originalList(sl);
73
74 // test once with no metadata
75 SpectrumPtr s0(new Spectrum);
76 sl->spectra.push_back(s0);
77
79
80 // test again with existing metadata to be overwritten
81 SpectrumPtr s1(new Spectrum);
82 s1->set(MS_TIC, t.tic + 1);
83 s1->set(MS_base_peak_intensity, t.bpi + 1);
84 s1->set(MS_base_peak_m_z, t.bpmz + 1);
85 sl->spectra.push_back(s1);
86
87 vector<double> inputMZArray = parseDoubleArray(t.inputMZArray);
88 vector<double> inputIntensityArray = parseDoubleArray(t.inputIntensityArray);
89 s0->setMZIntensityArrays(inputMZArray, inputIntensityArray, MS_number_of_detector_counts);
90 s1->setMZIntensityArrays(inputMZArray, inputIntensityArray, MS_number_of_detector_counts);
91
92 SpectrumListPtr fixer(new SpectrumList_MetadataFixer(originalList));
93
94 SpectrumPtr fixedSpectrum = fixer->spectrum(0, true);
95 unit_assert(fixedSpectrum->cvParam(MS_TIC).valueAs<double>() == t.tic);
96 unit_assert(fixedSpectrum->cvParam(MS_base_peak_intensity).valueAs<double>() == t.bpi);
97 unit_assert(fixedSpectrum->cvParam(MS_base_peak_m_z).valueAs<double>() == t.bpmz);
98
99 fixedSpectrum = fixer->spectrum(1, true);
100 unit_assert(fixedSpectrum->cvParam(MS_TIC).valueAs<double>() == t.tic);
101 unit_assert(fixedSpectrum->cvParam(MS_base_peak_intensity).valueAs<double>() == t.bpi);
102 unit_assert(fixedSpectrum->cvParam(MS_base_peak_m_z).valueAs<double>() == t.bpmz);
103 }
104}
105
106int main(int argc, char* argv[])
107{
108 TEST_PROLOG(argc, argv)
109
110 try
111 {
112 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
113 test();
114 }
115 catch (exception& e)
116 {
117 TEST_FAILED(e.what())
118 }
119 catch (...)
120 {
121 TEST_FAILED("Caught unknown exception.")
122 }
123
125}
int main(int argc, char *argv[])
vector< double > parseDoubleArray(const string &doubleArray)
TestMetadataFixer testMetadataFixers[]
const size_t testMetadataFixersSize
SpectrumList implementation to add (or replace) base peak and total ion metadata with new values calc...
MS_TIC
TIC (total ion current): The sum of all the separate ion currents carried by the ions of different m/...
Definition cv.hpp:1410
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:741
MS_base_peak_intensity
base peak intensity: The intensity of the greatest peak in the mass spectrum.
Definition cv.hpp:2121
MS_base_peak_m_z
base peak m/z: M/z value of the signal of highest intensity in the mass spectrum.
Definition cv.hpp:2118
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition MSData.hpp:711
boost::shared_ptr< Spectrum > SpectrumPtr
Definition MSData.hpp:573
The structure that captures the generation of a peak list (including the underlying acquisitions)
Definition MSData.hpp:506
Simple writeable in-memory implementation of SpectrumList.
Definition MSData.hpp:717
std::vector< SpectrumPtr > spectra
Definition MSData.hpp:718
#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