ProteoWizard
SpectrumPeakExtractorTest.cpp
Go to the documentation of this file.
1//
2// SpectrumPeakExtractorTest.cpp
3//
4//
5// Original author: Austin Keller <atkeller .@. uw.edu>
6//
7// Licensed under the Apache License, Version 2.0 (the "License");
8// you may not use this file except in compliance with the License.
9// You may obtain a copy of the License at
10//
11// http://www.apache.org/licenses/LICENSE-2.0
12//
13// Unless required by applicable law or agreed to in writing, software
14// distributed under the License is distributed on an "AS IS" BASIS,
15// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16// See the License for the specific language governing permissions and
17// limitations under the License.
18//
19
24#include "DemuxTypes.hpp"
25
26using namespace pwiz::util;
27using namespace pwiz::analysis;
28using namespace pwiz::msdata;
29
31public:
32 void Run()
33 {
34 SetUp();
36 TearDown();
37 }
38
39protected:
40
41 virtual void SetUp()
42 {
43 }
44
45 void TearDown()
46 {
47 }
48
50 {
51 // Generate test data
52 MSData msd;
54
55 // Remember which spectra correspond to what states
56 const int MS2_INDEX_0 = 1;
57 const int MS2_INDEX_1 = 3;
58
59 auto centroidedPtr = msd.run.spectrumListPtr;
60
61 Spectrum_const_ptr s20 = centroidedPtr->spectrum(MS2_INDEX_0, true);
62 SpectrumPtr s21 = centroidedPtr->spectrum(MS2_INDEX_1, true);
63
64 // Build new mz and intensity arrays for the second spectrum
65 s21->binaryDataArrayPtrs.clear();
66 s21->setMZIntensityArrays(vector<double>(), vector<double>(), MS_number_of_detector_counts);
67 BinaryData<double>& newMzs = s21->getMZArray()->data;
68 BinaryData<double>& newIntensities = s21->getIntensityArray()->data;
69
70 newMzs = vector<double>({ 0.0, 2.0, 2.000001, 3.999999, 4.0, 4.000001, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0 });
71 for (size_t mz = 0; mz < newMzs.size(); ++mz)
72 {
73 newIntensities.push_back(1.0);
74 }
75
76 vector<double> s21ExpectedIntensities = { 1.0, 2.0, 3.0 };
77 while (s21ExpectedIntensities.size() < s20->getIntensityArray()->data.size())
78 {
79 s21ExpectedIntensities.push_back(1.0);
80 }
81
82 // Create peak extractor to match mz set of the first spectrum
83 BinaryDataArrayPtr mzsToDemux = s20->getMZArray();
85
86 // Test number of peaks
87 unit_assert_operator_equal(peakExtractor.numPeaks(), mzsToDemux->data.size());
88
89 // Make matrix to extract peak info into
90 MatrixPtr signal;
91 int numSpectra = 2;
92 signal.reset(new MatrixType(numSpectra, mzsToDemux->data.size()));
93
94 // Extract spectra
95 peakExtractor(s20, *signal, 0);
96 peakExtractor(s21, *signal, 1);
97
98 // Check that self extraction returns the original spectrum
99 Spectrum_const_ptr baseSpectrum = centroidedPtr->spectrum(MS2_INDEX_0, true);
100 BinaryDataArrayPtr baseIntensities = baseSpectrum->getIntensityArray();
101 for (size_t i = 0; i < baseIntensities->data.size(); ++i)
102 {
103 unit_assert_equal(signal->row(0)[i], baseIntensities->data.at(i), 0.0001);
104 }
105
106 // Check the second spectrum extraction
107 for (size_t i = 0; i < s21ExpectedIntensities.size(); ++i)
108 {
109 unit_assert_equal(signal->row(1)[i], s21ExpectedIntensities[i], 0.0001);
110 }
111
112 // Now extract from the second spectrum, which has closely spaced peaks to simulate non-centroided data
114 unit_assert_operator_equal(binExamplePeakExtractor.numPeaks(), s21->getMZArray()->data.size());
115
116 // Extract spectra
117 signal.reset(new MatrixType(numSpectra, s21->getMZArray()->data.size()));
118 binExamplePeakExtractor(s21, *signal, 0);
119 binExamplePeakExtractor(s20, *signal, 1);
120
121 // Check the self extraction returns the original spectrum
122 for (size_t i = 0; i < s21->getIntensityArray()->data.size(); ++i)
123 {
124 unit_assert_equal(signal->row(0)[i], s21->getIntensityArray()->data.at(i), 0.0001);
125 }
126 }
127};
128
129int main(int argc, char* argv[])
130{
131 TEST_PROLOG(argc, argv)
132
133 try
134 {
136 tester.Run();
137 }
138 catch (exception& e)
139 {
140 TEST_FAILED(e.what())
141 }
142 catch (...)
143 {
144 TEST_FAILED("Caught unknown exception.")
145 }
146
148}
int main(int argc, char *argv[])
Extracts sets of centroided peaks from spectra using a user-defined list of peaks to extract.
size_t numPeaks() const
Returns the number of peaks extracted.
A custom vector class that can store its contents in either a std::vector or a cli::array (when compi...
void push_back(const T &value)
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
boost::shared_ptr< MatrixType > MatrixPtr
Matrix< DemuxScalar, Dynamic, Dynamic > MatrixType
PWIZ_API_DECL void initializeTiny(MSData &msd)
boost::shared_ptr< const msdata::Spectrum > Spectrum_const_ptr
boost::shared_ptr< BinaryDataArray > BinaryDataArrayPtr
Definition MSData.hpp:417
boost::shared_ptr< Spectrum > SpectrumPtr
Definition MSData.hpp:573
struct for expressing m/z tolerance in either amu or ppm
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition MSData.hpp:850
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument.
Definition MSData.hpp:886
SpectrumListPtr spectrumListPtr
all mass spectra and the acquisitions underlying them are described and attached here....
Definition MSData.hpp:827
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define unit_assert_equal(x, y, epsilon)
Definition unit.hpp:99
#define unit_assert_operator_equal(expected, actual)
Definition unit.hpp:92
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175