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
33using namespace pwiz;
34using namespace pwiz::msdata;
35using namespace pwiz::analysis;
36using namespace pwiz::util;
37using boost::logic::tribool;
38
39
40ostream* os_ = 0;
41
42
43void 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);
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";
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 {
126 printChromatogramList(filter, *os_);
127 *os_ << endl;
128 }
129
130 unit_assert_operator_equal(2, filter.size());
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
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 {
168 printChromatogramList(filter, *os_);
169 *os_ << endl;
170 }
171
172 unit_assert_operator_equal(2, filter.size());
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 {
190 printChromatogramList(filter, *os_);
191 *os_ << endl;
192 }
193
194 unit_assert_operator_equal(2, filter.size());
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
200void test()
201{
203 testEven(sl);
205 testIndexSet(sl);
206}
207
208
209int 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
void testIndexSet(ChromatogramListPtr sl)
int main(int argc, char *argv[])
void testSelectedIndices(ChromatogramListPtr sl)
void testEven(ChromatogramListPtr sl)
void printChromatogramList(const ChromatogramList &sl, ostream &os)
ChromatogramListPtr createChromatogramList()
ChromatogramList filter, for creating Chromatogram sub-lists.
Interface for accessing chromatograms, which may be stored in memory or backed by a data file (RAW,...
Definition MSData.hpp:757
virtual size_t size() const =0
returns the number of chromatograms
virtual ChromatogramPtr chromatogram(size_t index, bool getBinaryData=false) const =0
retrieve a chromatogram by index
a virtual container of integers, accessible via an iterator interface, stored as union of intervals
void insert(Interval interval)
insert an interval of integers into the virtual container
MS_TIC_chromatogram
TIC chromatogram (total ion current chromatogram): Chromatogram obtained by plotting the total ion cu...
Definition cv.hpp:1110
MS_CID
CID (collision-induced dissociation): The dissociation of an ion after collisional excitation....
Definition cv.hpp:750
MS_selected_ion_monitoring_chromatogram
selected ion monitoring chromatogram: Chromatogram created by creating an array of the measurements o...
Definition cv.hpp:4812
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
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
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
MS_selected_reaction_monitoring_chromatogram
selected reaction monitoring chromatogram: Chromatogram created by creating an array of the measureme...
Definition cv.hpp:4818
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
boost::shared_ptr< Chromatogram > ChromatogramPtr
Definition MSData.hpp:624
boost::shared_ptr< ChromatogramListSimple > ChromatogramListSimplePtr
Definition MSData.hpp:805
boost::shared_ptr< ChromatogramList > ChromatogramListPtr
Definition MSData.hpp:785
virtual tribool accept(const ChromatogramIdentity &chromatogramIdentity) const
return values: true: accept the Chromatogram false: reject the Chromatogram indeterminate: need to se...
virtual tribool accept(const ChromatogramIdentity &chromatogramIdentity) const
return values: true: accept the Chromatogram false: reject the Chromatogram indeterminate: need to se...
virtual bool done() const
return true iff done accepting chromatograms; this allows early termination of the iteration through ...
client-implemented filter predicate – called during construction of ChromatogramList_Filter to create...
A single chromatogram.
Definition MSData.hpp:578
Identifying information for a chromatogram.
Definition MSData.hpp:490
size_t index
the zero-based, consecutive index of the chromatogram in the ChromatogramList.
Definition MSData.hpp:492
Simple writeable in-memory implementation of ChromatogramList.
Definition MSData.hpp:791
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define unit_assert_operator_equal(expected, actual)
Definition unit.hpp:92
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175