ProteoWizard
MS2DeisotoperTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: MS2DeisotoperTest.cpp 6389 2014-06-13 19:46:19Z frenchwr $
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  {
108  TestDeisotopeCalculator& t = testDeisotopeCalculators[i];
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  vector<double>& mzs = s->getMZArray()->data;
144  vector<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 }
TestDeisotopeCalculator goldStandard[]
MS_MSn_spectrum
MSn spectrum: MSn refers to multi-stage MS2 experiments designed to record product ion spectra where ...
Definition: cv.hpp:2212
const size_t goldStandardSize
The method of precursor ion selection and activation.
Definition: MSData.hpp:310
const size_t testDeisotopeSize
boost::shared_ptr< SpectrumDataFilter > SpectrumDataFilterPtr
Definition: DataFilter.hpp:42
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:569
SpectrumList implementation that returns spectra with the specified SpectrumDataFilter operation appl...
#define TEST_EPILOG
Definition: unit.hpp:182
#define unit_assert_equal(x, y, epsilon)
Definition: unit.hpp:99
TestDeisotopeCalculator testDeisotopeCalculators[]
MS_ms_level
ms level: Stages of ms achieved in a multi stage mass spectrometry experiment.
Definition: cv.hpp:1987
PrecursorMassFilter&#39;s parameters.
#define unit_assert_operator_equal(expected, actual)
Definition: unit.hpp:92
ostream * os_
int main(int argc, char *argv[])
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition: MSData.hpp:707
std::vector< SpectrumPtr > spectra
Definition: MSData.hpp:714
#define TEST_FAILED(x)
Definition: unit.hpp:176
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
struct for expressing m/z tolerance in either amu or ppm
Definition: MZTolerance.hpp:38
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174
The structure that captures the generation of a peak list (including the underlying acquisitions) ...
Definition: MSData.hpp:504
vector< double > parseDoubleArray(const string &doubleArray)
int test()
Simple writeable in-memory implementation of SpectrumList.
Definition: MSData.hpp:712
#define unit_assert(x)
Definition: unit.hpp:85
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