ProteoWizard
MS2DeisotoperTest.cpp
Go to the documentation of this file.
1 //
2 // $Id$
3 //
4 //
5 // Original author: William French <william.r.french <a.t> vanderbilt.edu>
6 //
7 // Copyright 2008 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 
23 #include "MS2Deisotoper.hpp"
30 
31 using namespace pwiz::util;
32 using namespace pwiz::msdata;
33 using namespace pwiz::analysis;
34 
35 ostream* os_ = 0;
36 
37 ostream& operator<< (ostream& os, const vector<double>& v)
38 {
39  os << "(";
40  for (size_t i=0; i < v.size(); ++i)
41  os << " " << v[i];
42  os << " )";
43  return os;
44 }
45 
47 {
48  // space-delimited doubles
49  const char* inputMZArray;
50  const char* inputIntensityArray;
51 
52 };
53 
55 {
56 
57  { "300.0 302.1 303.11 304.12 305.20",
58  "1.0 85.0 15.0 3.0 3.0"},
59 
60  { "299.5 300.01 300.52 301.03",
61  "10.0 75.0 25.0 40.0"},
62 
63  { "302.1 302.435 302.77 302.94 303.11",
64  "61.0 31.0 8.0 45.0 40.0"},
65 
66 };
67 
69 {
70 
71  { "300.0 302.1 305.20",
72  "1.0 85.0 3.0"},
73 
74  { "299.5 300.01 301.03",
75  "10.0 75.0 40.0"},
76 
77  { "302.1 302.94 303.11",
78  "61.0 45.0 40.0"},
79 
80 
81 };
82 
84 const size_t goldStandardSize = sizeof(goldStandard) / sizeof(TestDeisotopeCalculator);
85 
86 vector<double> parseDoubleArray(const string& doubleArray)
87 {
88  vector<double> doubleVector;
89  vector<string> tokens;
90  bal::split(tokens, doubleArray, bal::is_space(), bal::token_compress_on);
91  if (!tokens.empty())
92  for (size_t i=0; i < tokens.size(); ++i)
93  if (!tokens[i].empty())
94  doubleVector.push_back(lexical_cast<double>(tokens[i]));
95  return doubleVector;
96 }
97 
98 int test()
99 {
100  int failedTests = 0;
101 
102  // create the spectrum list
104  SpectrumListPtr originalList(sl);
105 
106  for (size_t i=0; i < testDeisotopeSize; ++i)
107  {
109  // attach all the data to the spectrum list
110  SpectrumPtr s(new Spectrum);
111  s->set(MS_MSn_spectrum);
112  s->set(MS_ms_level,2);
113  s->precursors.push_back(Precursor(100.0)); // dummy precursor m/z
114 
115  vector<double> inputMZArray = parseDoubleArray(t.inputMZArray);
116  vector<double> inputIntensityArray = parseDoubleArray(t.inputIntensityArray);
117  s->setMZIntensityArrays(inputMZArray, inputIntensityArray, MS_number_of_detector_counts);
118  s->defaultArrayLength = inputMZArray.size();
119 
120  sl->spectra.push_back(s);
121 
122  }
123 
124  vector<double> goldMZArray = parseDoubleArray(goldStandard[0].inputMZArray);
125  vector<double> goldIntensityArray = parseDoubleArray(goldStandard[0].inputIntensityArray);
126 
127  // construct the filter
128  bool hires = false;
129  MZTolerance mzt(hires? 0.01 : 0.5);
130  bool poisson = true;
131  int maxCharge = 3, minCharge = 1;
132  SpectrumDataFilterPtr filter = SpectrumDataFilterPtr(new MS2Deisotoper(MS2Deisotoper::Config(mzt, hires, poisson, maxCharge, minCharge)));
133 
134  // run spectral summation
135  try
136  {
137 
138  SpectrumListPtr calculator(new SpectrumList_PeakFilter(originalList,filter));
139 
140  for (size_t i=0; i < calculator->size(); ++i)
141  {
142  SpectrumPtr s = calculator->spectrum(i,true);
143  BinaryData<double>& mzs = s->getMZArray()->data;
144  BinaryData<double>& intensities = s->getIntensityArray()->data;
145 
146  vector<double> goldMZArray = parseDoubleArray(goldStandard[i].inputMZArray);
147  vector<double> goldIntensityArray = parseDoubleArray(goldStandard[i].inputIntensityArray);
148 
149  unit_assert(mzs.size() == goldMZArray.size());
150  unit_assert(intensities.size() == goldIntensityArray.size());
151 
152  for (size_t j=0; j < mzs.size(); ++j)
153  {
154  unit_assert_equal(mzs[j], goldMZArray[j], 1e-5);
155  unit_assert_equal(intensities[j], goldIntensityArray[j], 1e-5);
156  }
157 
158  }
159 
160 
161 
162 
163  }
164  catch (exception& e)
165  {
166  cerr << "Test failed:\n" << e.what() << endl;
167  ++failedTests;
168  }
169  return failedTests;
170 }
171 
172 
173 int main(int argc, char* argv[])
174 {
175  TEST_PROLOG(argc, argv)
176 
177  try
178  {
179  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
180  int failedTests = test();
181  unit_assert_operator_equal(0, failedTests);
182  }
183  catch (exception& e)
184  {
185  TEST_FAILED(e.what())
186  }
187  catch (...)
188  {
189  TEST_FAILED("Caught unknown exception.")
190  }
191 
193 }
SpectrumList_PeakFilter.hpp
pwiz::msdata::SpectrumListPtr
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition: MSData.hpp:711
main
int main(int argc, char *argv[])
Definition: MS2DeisotoperTest.cpp:173
MS_number_of_detector_counts
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
examples.hpp
pwiz::msdata::Spectrum
The structure that captures the generation of a peak list (including the underlying acquisitions)
Definition: MSData.hpp:506
CVTranslator.hpp
unit_assert_equal
#define unit_assert_equal(x, y, epsilon)
Definition: unit.hpp:99
ralab::base::filter::filter
void filter(const TContainer &data, const TContainer &filter, TContainer &result, bool circular=false, uint32_t sides=2)
Applies linear convolution (filtering) to a univariate time series.
Definition: filter.hpp:112
pwiz::util::BinaryData::size
size_t size() const
Definition: BinaryData.hpp:145
goldStandardSize
const size_t goldStandardSize
Definition: MS2DeisotoperTest.cpp:84
testDeisotopeSize
const size_t testDeisotopeSize
Definition: MS2DeisotoperTest.cpp:83
pwiz::analysis
Definition: ChromatogramList_Filter.hpp:37
MS_MSn_spectrum
MS_MSn_spectrum
MSn spectrum: MSn refers to multi-stage MS2 experiments designed to record product ion spectra where ...
Definition: cv.hpp:2364
pwiz::chemistry::MZTolerance
struct for expressing m/z tolerance in either amu or ppm
Definition: MZTolerance.hpp:39
test
int test()
Definition: MS2DeisotoperTest.cpp:98
TestDeisotopeCalculator::inputIntensityArray
const char * inputIntensityArray
Definition: MS2DeisotoperTest.cpp:50
pwiz::msdata
Definition: DemuxTypes.hpp:27
unit_assert_operator_equal
#define unit_assert_operator_equal(expected, actual)
Definition: unit.hpp:92
MS2Deisotoper.hpp
operator<<
ostream & operator<<(ostream &os, const vector< double > &v)
Definition: MS2DeisotoperTest.cpp:37
pwiz::util
Definition: almost_equal.hpp:33
os_
ostream * os_
Definition: MS2DeisotoperTest.cpp:35
TEST_EPILOG
#define TEST_EPILOG
Definition: unit.hpp:183
TextWriter.hpp
pwiz::analysis::MS2Deisotoper::Config
PrecursorMassFilter's parameters.
Definition: MS2Deisotoper.hpp:48
Std.hpp
pwiz::msdata::SpectrumPtr
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:573
pwiz::util::BinaryData< double >
pwiz::msdata::SpectrumListSimple
Simple writeable in-memory implementation of SpectrumList.
Definition: MSData.hpp:717
parseDoubleArray
vector< double > parseDoubleArray(const string &doubleArray)
Definition: MS2DeisotoperTest.cpp:86
TEST_FAILED
#define TEST_FAILED(x)
Definition: unit.hpp:177
TEST_PROLOG
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:175
MS_ms_level
MS_ms_level
ms level: Stages of ms achieved in a multi stage mass spectrometry experiment.
Definition: cv.hpp:2139
goldStandard
TestDeisotopeCalculator goldStandard[]
Definition: MS2DeisotoperTest.cpp:68
TestDeisotopeCalculator::inputMZArray
const char * inputMZArray
Definition: MS2DeisotoperTest.cpp:49
pwiz::analysis::SpectrumDataFilterPtr
boost::shared_ptr< SpectrumDataFilter > SpectrumDataFilterPtr
Definition: DataFilter.hpp:42
pwiz::analysis::MS2Deisotoper
Definition: MS2Deisotoper.hpp:45
unit.hpp
unit_assert
#define unit_assert(x)
Definition: unit.hpp:85
pwiz::msdata::Precursor
The method of precursor ion selection and activation.
Definition: MSData.hpp:312
pwiz::msdata::SpectrumListSimple::spectra
std::vector< SpectrumPtr > spectra
Definition: MSData.hpp:718
pwiz::analysis::SpectrumList_PeakFilter
SpectrumList implementation that returns spectra with the specified SpectrumDataFilter operation appl...
Definition: SpectrumList_PeakFilter.hpp:37
testDeisotopeCalculators
TestDeisotopeCalculator testDeisotopeCalculators[]
Definition: MS2DeisotoperTest.cpp:54
TestDeisotopeCalculator
Definition: MS2DeisotoperTest.cpp:47