ProteoWizard
SpectrumList_PrecursorRecalculatorTest.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Darren Kessner <darren@proteowizard.org>
6//
7// Copyright 2008 Spielberg Family Center for Applied Proteomics
8// Cedars-Sinai Medical Center, Los Angeles, California 90048
9//
10// Licensed under the Apache License, Version 2.0 (the "License");
11// you may not use this file except in compliance with the License.
12// You may obtain a copy of the License at
13//
14// http://www.apache.org/licenses/LICENSE-2.0
15//
16// Unless required by applicable law or agreed to in writing, software
17// distributed under the License is distributed on an "AS IS" BASIS,
18// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19// See the License for the specific language governing permissions and
20// limitations under the License.
21//
22
23
27#include "boost/filesystem/path.hpp"
29#include <cstring>
30
31
32using namespace pwiz::cv;
33using namespace pwiz::msdata;
34using namespace pwiz::util;
35using namespace pwiz::analysis;
36namespace bfs = boost::filesystem;
37
38
39ostream* os_ = 0;
40
41
42void verifyPrecursorInfo(const Spectrum& spectrum, double precursorMZ, int precursorCharge)
43{
44 unit_assert(!spectrum.precursors.empty());
45 const Precursor& precursor = spectrum.precursors[0];
46 unit_assert(!precursor.selectedIons.empty());
47 const SelectedIon& selectedIon = precursor.selectedIons[0];
48
49 const double epsilon = 1e-2;
50 if (os_)
51 {
52 *os_ << "[verifyPrecursorInfo] " << spectrum.index << " " << spectrum.id << " "
53 << precursorMZ << " " << precursorCharge << ": "
54 << selectedIon.cvParam(MS_selected_ion_m_z).value << " " << selectedIon.cvParam(MS_charge_state).value << endl;
55 }
56
57 unit_assert_equal(selectedIon.cvParam(MS_selected_ion_m_z).valueAs<double>(), precursorMZ, epsilon);
58
59 if (precursorCharge != 0)
60 unit_assert(selectedIon.cvParam(MS_charge_state).valueAs<int>() == precursorCharge);
61}
62
63
64void test5peptideFT(const bfs::path& datadir)
65{
66 MSDataFile msd((datadir / "5peptideFT.mzML").string());
67
68 unit_assert(msd.run.spectrumListPtr.get() && msd.run.spectrumListPtr->size()==7);
69 if (os_) *os_ << "original spectra:\n";
70 verifyPrecursorInfo(*msd.run.spectrumListPtr->spectrum(2), 810.79, 0);
71 verifyPrecursorInfo(*msd.run.spectrumListPtr->spectrum(3), 837.34, 0);
72 verifyPrecursorInfo(*msd.run.spectrumListPtr->spectrum(4), 725.36, 0);
73 verifyPrecursorInfo(*msd.run.spectrumListPtr->spectrum(5), 558.87, 0);
74 verifyPrecursorInfo(*msd.run.spectrumListPtr->spectrum(6), 812.33, 0);
75
76 shared_ptr<SpectrumList_PrecursorRecalculator> spectrumListRecalculated(
78
79 unit_assert(spectrumListRecalculated->size() == 7);
80 if (os_) *os_ << "recalculated spectra:\n";
81 verifyPrecursorInfo(*spectrumListRecalculated->spectrum(2), 810.42, 2);
82 verifyPrecursorInfo(*spectrumListRecalculated->spectrum(3), 836.96, 2);
83 verifyPrecursorInfo(*spectrumListRecalculated->spectrum(4), 724.91, 2);
84 verifyPrecursorInfo(*spectrumListRecalculated->spectrum(5), 558.31, 3);
85 verifyPrecursorInfo(*spectrumListRecalculated->spectrum(6), 810.42, 2);
86}
87
88
89void test(const bfs::path& datadir)
90{
91 test5peptideFT(datadir);
92}
93
94
95int main(int argc, char* argv[])
96{
97 TEST_PROLOG(argc, argv)
98
99 try
100 {
101 bfs::path datadir = ".";
102
103 for (int i=1; i<argc; i++)
104 {
105 if (!strcmp(argv[i],"-v"))
106 os_ = &cout;
107 else
108 // hack to allow running unit test from a different directory:
109 // Jamfile passes full path to specified input file.
110 // we want the path, so we can ignore filename
111 datadir = bfs::path(argv[i]).branch_path();
112 }
113
114 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
115 test(datadir);
116 }
117 catch (exception& e)
118 {
119 TEST_FAILED(e.what())
120 }
121 catch (...)
122 {
123 TEST_FAILED("Caught unknown exception.")
124 }
125
127}
128
129
int main(int argc, char *argv[])
void verifyPrecursorInfo(const Spectrum &spectrum, double precursorMZ, int precursorCharge)
void test5peptideFT(const bfs::path &datadir)
SpectrumList wrapper that recalculates precursor info on spectrum() requests.
MS_charge_state
charge state: The charge state of the ion, single or multiple and positive or negatively charged.
Definition cv.hpp:396
MS_selected_ion_m_z
selected ion m/z: Mass-to-charge ratio of an selected ion.
Definition cv.hpp:2901
const double epsilon
Definition DiffTest.cpp:41
value_type valueAs() const
templated value access with type conversion
CVParam cvParam(CVID cvid) const
finds cvid in the container:
MSData object plus file I/O.
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument.
Definition MSData.hpp:886
The method of precursor ion selection and activation.
Definition MSData.hpp:312
std::vector< SelectedIon > selectedIons
this list of precursor ions that were selected.
Definition MSData.hpp:329
SpectrumListPtr spectrumListPtr
all mass spectra and the acquisitions underlying them are described and attached here....
Definition MSData.hpp:827
The structure that captures the generation of a peak list (including the underlying acquisitions)
Definition MSData.hpp:506
std::vector< Precursor > precursors
list and descriptions of precursors to the spectrum currently being described.
Definition MSData.hpp:520
std::string id
a unique identifier for this spectrum. It should be expected that external files may use this identif...
Definition MSData.hpp:476
size_t index
the zero-based, consecutive index of the spectrum in the SpectrumList.
Definition MSData.hpp:473
#define unit_assert(x)
Definition unit.hpp:85
#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 TEST_PROLOG(argc, argv)
Definition unit.hpp:175