ProteoWizard
FeatureDetectorPeakelTest.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Darren Kessner <darren@proteowizard.org>
6//
7// Copyright 2009 Center for Applied Molecular Medicine
8// University of Southern California, Los Angeles, CA
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
30
31using namespace pwiz::util;
32using namespace pwiz::analysis;
33using namespace pwiz::data;
34using namespace pwiz::data::peakdata;
35using namespace pwiz::msdata;
36namespace bfs = boost::filesystem;
37
38
39ostream* os_ = 0;
40
41
42void verifyBombesinFeatures(const FeatureField& featureField)
43{
44 const double epsilon = .01;
45
46 const double mz_bomb2 = 810.415;
47 vector<FeaturePtr> bombesin_2_found = featureField.find(mz_bomb2, epsilon,
49 unit_assert(bombesin_2_found.size() == 1);
50 const Feature& bombesin_2 = *bombesin_2_found[0];
51 unit_assert(bombesin_2.charge == 2);
52 unit_assert(bombesin_2.peakels.size() == 5);
53 unit_assert_equal(bombesin_2.peakels[0]->mz, mz_bomb2, epsilon);
54 unit_assert_equal(bombesin_2.peakels[1]->mz, mz_bomb2+.5, epsilon);
55 unit_assert_equal(bombesin_2.peakels[2]->mz, mz_bomb2+1, epsilon);
56 unit_assert_equal(bombesin_2.peakels[3]->mz, mz_bomb2+1.5, epsilon);
57 unit_assert_equal(bombesin_2.peakels[4]->mz, mz_bomb2+2, epsilon);
58 //TODO: verify feature metadata
59
60 const double mz_bomb3 = 540.612;
61 vector<FeaturePtr> bombesin_3_found = featureField.find(mz_bomb3, epsilon,
63 unit_assert(bombesin_3_found.size() == 1);
64 const Feature& bombesin_3 = *bombesin_3_found[0];
65 unit_assert(bombesin_3.charge == 3);
66 unit_assert(bombesin_3.peakels.size() == 3);
67 unit_assert_equal(bombesin_3.peakels[0]->mz, mz_bomb3, epsilon);
68 unit_assert_equal(bombesin_3.peakels[1]->mz, mz_bomb3+1./3, epsilon);
69 unit_assert_equal(bombesin_3.peakels[2]->mz, mz_bomb3+2./3, epsilon);
70 //TODO: verify feature metadata
71}
72
73
74shared_ptr<FeatureDetectorPeakel> createFeatureDetectorPeakel()
75{
77
78 // these are just the defaults, to demonstrate usage
79
81
85
87
90
91 config.peakelPicker_Basic.log = 0; // ostream*
98
99 return FeatureDetectorPeakel::create(config);
100}
101
102
103void testBombesin(const string& filename)
104{
105 if (os_) *os_ << "testBombesin()" << endl;
106
107 // open data file and check sanity
108
109 MSDataFile msd(filename);
111 unit_assert(msd.run.spectrumListPtr->size() == 8);
112
113 // instantiate FeatureDetector
114
115 shared_ptr<FeatureDetectorPeakel> featureDetectorPeakel = createFeatureDetectorPeakel();
116
117 FeatureField featureField;
118 featureDetectorPeakel->detect(msd, featureField);
119
120 if (os_) *os_ << "featureField:\n" << featureField << endl;
121 verifyBombesinFeatures(featureField);
122}
123
124
125void test(const bfs::path& datadir)
126{
127 testBombesin((datadir / "FeatureDetectorTest_Bombesin.mzML").string());
128}
129
130
131int main(int argc, char* argv[])
132{
133 TEST_PROLOG(argc, argv)
134
135 try
136 {
137 bfs::path datadir = ".";
138
139 for (int i=1; i<argc; i++)
140 {
141 if (!strcmp(argv[i],"-v"))
142 os_ = &cout;
143 else
144 // hack to allow running unit test from a different directory:
145 // Jamfile passes full path to specified input file.
146 // we want the path, so we can ignore filename
147 datadir = bfs::path(argv[i]).branch_path();
148 }
149
150 test(datadir);
151 }
152 catch (exception& e)
153 {
154 TEST_FAILED(e.what())
155 }
156 catch (...)
157 {
158 TEST_FAILED("Caught unknown exception.")
159 }
160
162}
163
void testBombesin(const string &filename)
int main(int argc, char *argv[])
shared_ptr< FeatureDetectorPeakel > createFeatureDetectorPeakel()
void verifyBombesinFeatures(const FeatureField &featureField)
ostream * os_
static boost::shared_ptr< FeatureDetectorPeakel > create(Config config)
const double epsilon
Definition DiffTest.cpp:41
MZRTField is a std::set of boost::shared_ptrs, stored as a binary tree ordered by LessThan_MZRT.
Definition MZRTField.hpp:95
std::vector< TPtr > find(double mz, MZTolerance mzTolerance, RTMatches matches) const
find all objects with a given m/z, within a given m/z tolerance, satisfying the 'matches' predicate
predicate returns true iff the object's retention time range contains the specified retention time
struct for expressing m/z tolerance in either amu or ppm
std::vector< PeakelPtr > peakels
Definition PeakData.hpp:274
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
SpectrumListPtr spectrumListPtr
all mass spectra and the acquisitions underlying them are described and attached here....
Definition MSData.hpp:827
#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