ProteoWizard
FeatureDetectorSimpleTest.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Kate Hoff <Katherine.Hoff@cshs.org>
6//
7// Copyright 2008 Spielberg Family Center for Applied Proteomics
8// Cedars-Sinai Medical Cnter, 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
28#include "boost/iostreams/positioning.hpp"
29#include "boost/filesystem/path.hpp"
31
32using namespace pwiz::util;
33using namespace pwiz::analysis;
34using namespace pwiz::data;
35using namespace pwiz::data::peakdata;
36using namespace pwiz::msdata;
37
38namespace bfs = boost::filesystem;
39
40ostream* os_ = 0;
41
42double mz_epsilon = .005; // tolerance for mz differences
43double rt_epsilon = 10; // tolerance for rt differences
44
46{
47
49 : a(a_) {}
50
51 bool operator()(FeaturePtr b) const // should be enough info to uniquely identify a feature
52 {
53 return fabs(a->mz-b->mz) < mz_epsilon &&
54 fabs(a->retentionTime - b->retentionTime) < rt_epsilon;
55
56 }
57
59};
60
61void testFeatureDetectorSimple(const bfs::path& datadir)
62{
63
64 if (os_) *os_ << "testFeatureDetectorSimple() ... " << endl;
65
66 // instantiate PeakFamilyDetectorFT
67 // (from PeakFamilyDetectorFTTest.cpp)
68
69 ostream* os_log_ = 0; // don't log peak family detection
70
72 config.log = os_log_;
74 boost::shared_ptr<PeakFamilyDetectorFT> detector(new PeakFamilyDetectorFT(config));
75 FeatureDetectorSimple fds(detector);
76
77 // instantiate MSData from test file
78
79 MSDataFile msd((datadir / "FeatureDetectorTest_Bombesin.mzML").string());
80
81 FeatureField output_features;
82 fds.detect(msd, output_features);
83
84 // instantiate the bombesin +2 feature that we know is correct, with calculated mzMonoisotopic and eyeballed retentionTime
85
86 FeaturePtr bombesin2_truth(new Feature());
87 bombesin2_truth->mz = 810.4148;
88 bombesin2_truth->retentionTime = 1866;
89
90 FeatureField::iterator bombesin2_hopeful = find_if(output_features.begin(), output_features.end(), mzrtEqual(bombesin2_truth));
91
92 // assert that it is found, correctly, in the data
93 unit_assert(bombesin2_hopeful != output_features.end());
94
95
96 if (os_) *os_ << "\n[FeatureDetectorSimple] Bombesin detected at charge state +2 ... " << endl << *bombesin2_hopeful << endl;
97
98
99 // do the same for the +3 feature
100
101 FeaturePtr bombesin3_truth(new Feature());
102 bombesin3_truth->mz = 540.6123;
103 bombesin3_truth->retentionTime = 1866;
104
105 FeatureField::iterator bombesin3_hopeful = find_if(output_features.begin(), output_features.end(), mzrtEqual(bombesin3_truth));
106
107 // assert that it is found, correctly, in the data
108 unit_assert(bombesin3_hopeful != output_features.end());
109
110
111 if (os_) *os_ << "\n[FeatureDetectorSimple] Bombesin detected at charge state +3 ... " << endl << *bombesin3_hopeful << endl;
112
113 return;
114
115}
116
117int main(int argc, char* argv[])
118{
119 TEST_PROLOG(argc, argv)
120
121 try
122 {
123 bfs::path datadir = ".";
124
125 for (int i=1; i<argc; i++)
126 {
127 if (!strcmp(argv[i],"-v"))
128 os_ = &cout;
129 else
130 // hack to allow running unit test from a different directory:
131 // Jamfile passes full path to specified input file.
132 // we want the path, so we can ignore filename
133 datadir = bfs::path(argv[i]).branch_path();
134 }
135
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[])
void testFeatureDetectorSimple(const bfs::path &datadir)
double mz_epsilon
double rt_epsilon
ostream * os_
FeatureDetectorSimple detects 'rectangular' features, ie number of peaks in isotope envelope is the s...
virtual void detect(const MSData &msd, FeatureField &result) const
FT-specific implementation of PeakFamilyDetector.
boost::shared_ptr< Feature > FeaturePtr
Definition PeakData.hpp:292
mzrtEqual(FeaturePtr a_)
bool operator()(FeaturePtr b) const
MZRTField is a std::set of boost::shared_ptrs, stored as a binary tree ordered by LessThan_MZRT.
Definition MZRTField.hpp:95
static CalibrationParameters thermo_FT()
MSData object plus file I/O.
#define unit_assert(x)
Definition unit.hpp:85
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175