ProteoWizard
ChromatogramList_FilterTest.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 
30 #include <cstring>
31 
32 
33 using namespace pwiz;
34 using namespace pwiz::msdata;
35 using namespace pwiz::analysis;
36 using namespace pwiz::util;
37 using boost::logic::tribool;
38 
39 
40 ostream* os_ = 0;
41 
42 
43 void printChromatogramList(const ChromatogramList& sl, ostream& os)
44 {
45  os << "size: " << sl.size() << endl;
46 
47  for (size_t i=0, end=sl.size(); i<end; i++)
48  {
49  ChromatogramPtr chromatogram = sl.chromatogram(i, false);
50  os << chromatogram->index << " "
51  << chromatogram->id << " "
52  << endl;
53  }
54 }
55 
56 
58 {
60 
61  {
62  ChromatogramPtr chromatogram(new Chromatogram);
63  chromatogram->index = sl->size();
64 
65  chromatogram->id = "TIC";
66  chromatogram->setTimeIntensityPairs(vector<TimeIntensityPair>(42), UO_second, MS_number_of_detector_counts);
67  chromatogram->set(MS_TIC_chromatogram);
68 
69  sl->chromatograms.push_back(chromatogram);
70  }
71 
72  {
73  ChromatogramPtr chromatogram(new Chromatogram);
74  chromatogram->index = sl->size();
75 
76  chromatogram->id = "SRM SIC Q1=123.45 Q3=234.56";
77  chromatogram->setTimeIntensityPairs(vector<TimeIntensityPair>(42), UO_second, MS_number_of_detector_counts);
79  chromatogram->precursor.isolationWindow.set(MS_isolation_window_target_m_z, 123.45, MS_m_z);
80  chromatogram->precursor.activation.set(MS_CID);
81  chromatogram->product.isolationWindow.set(MS_isolation_window_target_m_z, 234.56, MS_m_z);
82 
83  sl->chromatograms.push_back(chromatogram);
84  }
85 
86  {
87  ChromatogramPtr chromatogram(new Chromatogram);
88  chromatogram->index = sl->size();
89 
90  chromatogram->id = "SIM SIC Q1=123.45";
91  chromatogram->setTimeIntensityPairs(vector<TimeIntensityPair>(42), UO_second, MS_number_of_detector_counts);
92  chromatogram->set(MS_selected_ion_monitoring_chromatogram);
93  chromatogram->precursor.isolationWindow.set(MS_isolation_window_target_m_z, 123.45, MS_m_z);
94 
95  sl->chromatograms.push_back(chromatogram);
96  }
97 
98  if (os_)
99  {
100  *os_ << "original chromatogram list:\n";
101  printChromatogramList(*sl, *os_);
102  *os_ << endl;
103  }
104 
105  return sl;
106 }
107 
108 
110 {
111  virtual tribool accept(const ChromatogramIdentity& chromatogramIdentity) const
112  {
113  return chromatogramIdentity.index%2 == 0;
114  }
115 };
116 
117 
119 {
120  if (os_) *os_ << "testEven:\n";
121 
123 
124  if (os_)
125  {
127  *os_ << endl;
128  }
129 
131  unit_assert_operator_equal(0, filter.chromatogramIdentity(0).index);
132  unit_assert_operator_equal("TIC", filter.chromatogramIdentity(0).id);
133  unit_assert_operator_equal(1, filter.chromatogramIdentity(1).index);
134  unit_assert_operator_equal("SIM SIC Q1=123.45", filter.chromatogramIdentity(1).id);
135 
136 }
137 
138 
140 {
141  mutable bool pastMaxIndex;
142 
143  SelectedIndexPredicate() : pastMaxIndex(false) {}
144 
145  virtual tribool accept(const ChromatogramIdentity& chromatogramIdentity) const
146  {
147  if (chromatogramIdentity.index>2) pastMaxIndex = true;
148 
149  return (chromatogramIdentity.index==1 ||
150  chromatogramIdentity.index==2);
151  }
152 
153  virtual bool done() const
154  {
155  return pastMaxIndex;
156  }
157 };
158 
159 
161 {
162  if (os_) *os_ << "testSelectedIndices:\n";
163 
165 
166  if (os_)
167  {
169  *os_ << endl;
170  }
171 
173  unit_assert_operator_equal("SRM SIC Q1=123.45 Q3=234.56", filter.chromatogramIdentity(0).id);
174  unit_assert_operator_equal("SIM SIC Q1=123.45", filter.chromatogramIdentity(1).id);
175 }
176 
177 
179 {
180  if (os_) *os_ << "testIndexSet:\n";
181 
182  IntegerSet indexSet;
183  indexSet.insert(1);
184  indexSet.insert(2);
185 
187 
188  if (os_)
189  {
191  *os_ << endl;
192  }
193 
195  unit_assert_operator_equal("SRM SIC Q1=123.45 Q3=234.56", filter.chromatogramIdentity(0).id);
196  unit_assert_operator_equal("SIM SIC Q1=123.45", filter.chromatogramIdentity(1).id);
197 }
198 
199 
200 void test()
201 {
203  testEven(sl);
205  testIndexSet(sl);
206 }
207 
208 
209 int main(int argc, char* argv[])
210 {
211  TEST_PROLOG(argc, argv)
212 
213  try
214  {
215  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
216  test();
217  }
218  catch (exception& e)
219  {
220  TEST_FAILED(e.what())
221  }
222  catch (...)
223  {
224  TEST_FAILED("Caught unknown exception.")
225  }
226 
228 }
229 
230 
main
int main(int argc, char *argv[])
Definition: ChromatogramList_FilterTest.cpp:209
EvenPredicate
Definition: ChromatogramList_FilterTest.cpp:110
os_
ostream * os_
Definition: ChromatogramList_FilterTest.cpp:40
EvenPredicate::accept
virtual tribool accept(const ChromatogramIdentity &chromatogramIdentity) const
return values: true: accept the Chromatogram false: reject the Chromatogram indeterminate: need to se...
Definition: ChromatogramList_FilterTest.cpp:111
pwiz::msdata::ChromatogramListSimple
Simple writeable in-memory implementation of ChromatogramList.
Definition: MSData.hpp:791
MS_number_of_detector_counts
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
examples.hpp
pwiz
Definition: ChromatogramList_Filter.hpp:36
ralab::base::filter::filter
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
MS_TIC_chromatogram
MS_TIC_chromatogram
TIC chromatogram (total ion current chromatogram): Chromatogram obtained by plotting the total ion cu...
Definition: cv.hpp:1110
printChromatogramList
void printChromatogramList(const ChromatogramList &sl, ostream &os)
Definition: ChromatogramList_FilterTest.cpp:43
pwiz::analysis
Definition: ChromatogramList_Filter.hpp:37
pwiz::msdata
Definition: DemuxTypes.hpp:27
SelectedIndexPredicate
Definition: ChromatogramList_FilterTest.cpp:140
test
void test()
Definition: ChromatogramList_FilterTest.cpp:200
UO_second
UO_second
second: A time unit which is equal to the duration of 9 192 631 770 periods of the radiation correspo...
Definition: cv.hpp:13833
unit_assert_operator_equal
#define unit_assert_operator_equal(expected, actual)
Definition: unit.hpp:92
SelectedIndexPredicate::accept
virtual tribool accept(const ChromatogramIdentity &chromatogramIdentity) const
return values: true: accept the Chromatogram false: reject the Chromatogram indeterminate: need to se...
Definition: ChromatogramList_FilterTest.cpp:145
pwiz::msdata::ChromatogramIdentity
Identifying information for a chromatogram.
Definition: MSData.hpp:490
SelectedIndexPredicate::done
virtual bool done() const
return true iff done accepting chromatograms; this allows early termination of the iteration through ...
Definition: ChromatogramList_FilterTest.cpp:153
pwiz::msdata::ChromatogramListPtr
boost::shared_ptr< ChromatogramList > ChromatogramListPtr
Definition: MSData.hpp:785
pwiz::msdata::Chromatogram
A single chromatogram.
Definition: MSData.hpp:578
MS_isolation_window_target_m_z
MS_isolation_window_target_m_z
isolation window target m/z: The primary or reference m/z about which the isolation window is defined...
Definition: cv.hpp:3180
pwiz::util
Definition: almost_equal.hpp:33
TEST_EPILOG
#define TEST_EPILOG
Definition: unit.hpp:183
MS_selected_reaction_monitoring_chromatogram
MS_selected_reaction_monitoring_chromatogram
selected reaction monitoring chromatogram: Chromatogram created by creating an array of the measureme...
Definition: cv.hpp:4818
pwiz::util::IntegerSet::insert
void insert(Interval interval)
insert an interval of integers into the virtual container
Std.hpp
pwiz::msdata::ChromatogramList::chromatogram
virtual ChromatogramPtr chromatogram(size_t index, bool getBinaryData=false) const =0
retrieve a chromatogram by index
testIndexSet
void testIndexSet(ChromatogramListPtr sl)
Definition: ChromatogramList_FilterTest.cpp:178
createChromatogramList
ChromatogramListPtr createChromatogramList()
Definition: ChromatogramList_FilterTest.cpp:57
pwiz::msdata::ChromatogramList::size
virtual size_t size() const =0
returns the number of chromatograms
TEST_FAILED
#define TEST_FAILED(x)
Definition: unit.hpp:177
SelectedIndexPredicate::pastMaxIndex
bool pastMaxIndex
Definition: ChromatogramList_FilterTest.cpp:141
TEST_PROLOG
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:175
MS_m_z
MS_m_z
m/z: Three-character symbol m/z is used to denote the quantity formed by dividing the mass of an ion ...
Definition: cv.hpp:384
pwiz::analysis::ChromatogramList_FilterPredicate_IndexSet
Definition: ChromatogramList_Filter.hpp:90
testEven
void testEven(ChromatogramListPtr sl)
Definition: ChromatogramList_FilterTest.cpp:118
pwiz::analysis::ChromatogramList_Filter::Predicate
client-implemented filter predicate – called during construction of ChromatogramList_Filter to create...
Definition: ChromatogramList_Filter.hpp:48
MS_selected_ion_monitoring_chromatogram
MS_selected_ion_monitoring_chromatogram
selected ion monitoring chromatogram: Chromatogram created by creating an array of the measurements o...
Definition: cv.hpp:4812
pwiz::msdata::ChromatogramPtr
boost::shared_ptr< Chromatogram > ChromatogramPtr
Definition: MSData.hpp:624
pwiz::msdata::ChromatogramList
Interface for accessing chromatograms, which may be stored in memory or backed by a data file (RAW,...
Definition: MSData.hpp:757
unit.hpp
IntegerSet.hpp
testSelectedIndices
void testSelectedIndices(ChromatogramListPtr sl)
Definition: ChromatogramList_FilterTest.cpp:160
SelectedIndexPredicate::SelectedIndexPredicate
SelectedIndexPredicate()
Definition: ChromatogramList_FilterTest.cpp:143
ChromatogramList_Filter.hpp
MS_CID
MS_CID
CID (collision-induced dissociation): The dissociation of an ion after collisional excitation....
Definition: cv.hpp:750
pwiz::msdata::ChromatogramIdentity::index
size_t index
the zero-based, consecutive index of the chromatogram in the ChromatogramList.
Definition: MSData.hpp:492
pwiz::util::IntegerSet
a virtual container of integers, accessible via an iterator interface, stored as union of intervals
Definition: IntegerSet.hpp:38
Serializer_mzML.hpp
pwiz::analysis::ChromatogramList_Filter
ChromatogramList filter, for creating Chromatogram sub-lists.
Definition: ChromatogramList_Filter.hpp:42
pwiz::msdata::ChromatogramListSimplePtr
boost::shared_ptr< ChromatogramListSimple > ChromatogramListSimplePtr
Definition: MSData.hpp:805