ProteoWizard
Classes | Functions | Variables
SpectrumList_SorterTest.cpp File Reference
#include "SpectrumList_Sorter.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"
#include <cstring>
#include "pwiz/data/msdata/examples.hpp"
#include "pwiz/data/msdata/TextWriter.hpp"
#include "boost/logic/tribool.hpp"

Go to the source code of this file.

Classes

struct  DefaultArrayLengthSorter
 
struct  MSLevelSorter
 

Functions

void test ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 

Function Documentation

◆ test()

void test ( )

Definition at line 79 of file SpectrumList_SorterTest.cpp.

80{
81 MSData msd;
83
84 SpectrumListPtr originalList = msd.run.spectrumListPtr;
85
86 SpectrumListPtr defaultArrayLengthSortedList(
88
89 SpectrumListPtr msLevelUnstableSortedList(
90 new SpectrumList_Sorter(originalList, MSLevelSorter()));
91
92 SpectrumListPtr msLevelStableSortedList(
93 new SpectrumList_Sorter(originalList, MSLevelSorter(), true));
94
95 SpectrumListPtr sillySortedList(
96 new SpectrumList_Sorter(msLevelStableSortedList, DefaultArrayLengthSorter()));
97
98 if (os_)
99 {
100 *os_ << "Original spectrum list (" << originalList->size() << "):\n";
102 write(*originalList);
103 *os_ << endl;
104 }
105
106 if (os_)
107 {
108 *os_ << "Default array length sorted spectrum list (" << defaultArrayLengthSortedList->size() << "):\n";
110 write(*defaultArrayLengthSortedList);
111 *os_ << endl;
112 }
113
114 if (os_)
115 {
116 *os_ << "MS level unstable sorted spectrum list (" << msLevelUnstableSortedList->size() << "):\n";
118 write(*msLevelUnstableSortedList);
119 *os_ << endl;
120 }
121
122 if (os_)
123 {
124 *os_ << "MS level stable sorted spectrum list (" << msLevelStableSortedList->size() << "):\n";
126 write(*msLevelStableSortedList);
127 *os_ << endl;
128 }
129
130 if (os_)
131 {
132 *os_ << "Silly (nested) sorted spectrum list (" << sillySortedList->size() << "):\n";
134 write(*sillySortedList);
135 *os_ << endl;
136 }
137
138 unit_assert_operator_equal(originalList->size(), defaultArrayLengthSortedList->size());
139 unit_assert_operator_equal(originalList->size(), msLevelUnstableSortedList->size());
140 unit_assert_operator_equal(originalList->size(), msLevelStableSortedList->size());
141 unit_assert_operator_equal(originalList->size(), sillySortedList->size());
142
143 SpectrumPtr s;
144
145 // assert that the original list is unmodified
146 unit_assert_operator_equal("scan=19", originalList->spectrumIdentity(0).id);
147 unit_assert_operator_equal(0, originalList->spectrumIdentity(0).index);
148 unit_assert_operator_equal("scan=20", originalList->spectrumIdentity(1).id);
149 unit_assert_operator_equal(1, originalList->spectrumIdentity(1).index);
150 unit_assert_operator_equal("scan=21", originalList->spectrumIdentity(2).id);
151 unit_assert_operator_equal(2, originalList->spectrumIdentity(2).index);
152 unit_assert_operator_equal("scan=22", originalList->spectrumIdentity(3).id);
153 unit_assert_operator_equal(3, originalList->spectrumIdentity(3).index);
154 s = originalList->spectrum(0);
155 unit_assert_operator_equal("scan=19", s->id);
156 unit_assert_operator_equal(0, s->index);
157
158 // validate the default array length sorted list (ascending order, scan=19 and scan=22 are interchangeable)
159 unit_assert_operator_equal("scan=21", defaultArrayLengthSortedList->spectrumIdentity(0).id);
160 unit_assert_operator_equal(0, defaultArrayLengthSortedList->spectrumIdentity(0).index);
161 unit_assert_operator_equal("scan=20", defaultArrayLengthSortedList->spectrumIdentity(1).id);
162 unit_assert_operator_equal(1, defaultArrayLengthSortedList->spectrumIdentity(1).index);
163 unit_assert_operator_equal(2, defaultArrayLengthSortedList->spectrumIdentity(2).index);
164 unit_assert_operator_equal(3, defaultArrayLengthSortedList->spectrumIdentity(3).index);
165 s = defaultArrayLengthSortedList->spectrum(0);
166 unit_assert_operator_equal("scan=21", s->id);
167 unit_assert_operator_equal(0, s->index);
168 s = defaultArrayLengthSortedList->spectrum(1);
169 unit_assert_operator_equal("scan=20", s->id);
170 unit_assert_operator_equal(1, s->index);
171 s = defaultArrayLengthSortedList->spectrum(2);
172 unit_assert_operator_equal(2, s->index);
173 s = defaultArrayLengthSortedList->spectrum(3);
174 unit_assert_operator_equal(3, s->index);
175 for (size_t i=1, end=defaultArrayLengthSortedList->size(); i < end; ++i)
176 unit_assert(defaultArrayLengthSortedList->spectrum(i)->defaultArrayLength >=
177 defaultArrayLengthSortedList->spectrum(i-1)->defaultArrayLength);
178
179 // validate the MS level unstable sorted list (scan=19, scan=21, and scan=22 are interchangeable)
180 unit_assert_operator_equal(0, msLevelUnstableSortedList->spectrumIdentity(0).index);
181 unit_assert_operator_equal(1, msLevelUnstableSortedList->spectrumIdentity(1).index);
182 unit_assert_operator_equal(2, msLevelUnstableSortedList->spectrumIdentity(2).index);
183 unit_assert_operator_equal("scan=20", msLevelUnstableSortedList->spectrumIdentity(3).id);
184 unit_assert_operator_equal(3, msLevelUnstableSortedList->spectrumIdentity(3).index);
185 s = msLevelUnstableSortedList->spectrum(0);
186 unit_assert_operator_equal(0, s->index);
187 s = msLevelUnstableSortedList->spectrum(1);
188 unit_assert_operator_equal(1, s->index);
189 s = msLevelUnstableSortedList->spectrum(2);
190 unit_assert_operator_equal(2, s->index);
191 s = msLevelUnstableSortedList->spectrum(3);
192 unit_assert_operator_equal("scan=20", s->id);
193 unit_assert_operator_equal(3, s->index);
194
195 // validate the MS level stable sorted list (scan=19, scan=21, and scan=22 should stay in order)
196 unit_assert_operator_equal("scan=19", msLevelStableSortedList->spectrumIdentity(0).id);
197 unit_assert_operator_equal(0, msLevelStableSortedList->spectrumIdentity(0).index);
198 unit_assert_operator_equal("scan=21", msLevelStableSortedList->spectrumIdentity(1).id);
199 unit_assert_operator_equal(1, msLevelStableSortedList->spectrumIdentity(1).index);
200 unit_assert_operator_equal("sample=1 period=1 cycle=23 experiment=1", msLevelStableSortedList->spectrumIdentity(2).id);
201 unit_assert_operator_equal(2, msLevelStableSortedList->spectrumIdentity(2).index);
202 unit_assert_operator_equal("scan=20", msLevelStableSortedList->spectrumIdentity(3).id);
203 unit_assert_operator_equal(3, msLevelStableSortedList->spectrumIdentity(3).index);
204 s = msLevelStableSortedList->spectrum(0);
205 unit_assert_operator_equal("scan=19", s->id);
206 unit_assert_operator_equal(0, s->index);
207 s = msLevelStableSortedList->spectrum(1);
208 unit_assert_operator_equal("scan=21", s->id);
209 unit_assert_operator_equal(1, s->index);
210 s = msLevelStableSortedList->spectrum(2);
211 unit_assert_operator_equal("sample=1 period=1 cycle=23 experiment=1", s->id);
212 unit_assert_operator_equal(2, s->index);
213 s = msLevelStableSortedList->spectrum(3);
214 unit_assert_operator_equal("scan=20", s->id);
215 unit_assert_operator_equal(3, s->index);
216
217 // validate the silly (nested) sorted list
218 unit_assert_operator_equal("scan=21", sillySortedList->spectrumIdentity(0).id);
219 unit_assert_operator_equal(0, sillySortedList->spectrumIdentity(0).index);
220 unit_assert_operator_equal("scan=20", sillySortedList->spectrumIdentity(1).id);
221 unit_assert_operator_equal(1, sillySortedList->spectrumIdentity(1).index);
222 unit_assert_operator_equal(2, sillySortedList->spectrumIdentity(2).index);
223 unit_assert_operator_equal(3, sillySortedList->spectrumIdentity(3).index);
224 s = sillySortedList->spectrum(0);
225 unit_assert_operator_equal("scan=21", s->id);
226 unit_assert_operator_equal(0, s->index);
227 s = sillySortedList->spectrum(1);
228 unit_assert_operator_equal("scan=20", s->id);
229 unit_assert_operator_equal(1, s->index);
230 s = sillySortedList->spectrum(2);
231 unit_assert_operator_equal(2, s->index);
232 s = sillySortedList->spectrum(3);
233 unit_assert_operator_equal(3, s->index);
234 for (size_t i=1, end=sillySortedList->size(); i < end; ++i)
235 unit_assert(sillySortedList->spectrum(i)->defaultArrayLength >=
236 sillySortedList->spectrum(i-1)->defaultArrayLength);
237}
ostream * os_
Provides a custom-sorted spectrum list.
PWIZ_API_DECL void write(minimxml::XMLWriter &writer, const CV &cv)
PWIZ_API_DECL void initializeTiny(MSData &msd)
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition MSData.hpp:711
boost::shared_ptr< Spectrum > SpectrumPtr
Definition MSData.hpp:573
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition MSData.hpp:850
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 unit_assert_operator_equal(expected, actual)
Definition unit.hpp:92

References pwiz::msdata::examples::initializeTiny(), os_, pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, unit_assert, and unit_assert_operator_equal.

Referenced by main().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 240 of file SpectrumList_SorterTest.cpp.

241{
242 TEST_PROLOG(argc, argv)
243
244 try
245 {
246 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
247 test();
248 }
249 catch (exception& e)
250 {
251 TEST_FAILED(e.what())
252 }
253 catch (...)
254 {
255 TEST_FAILED("Caught unknown exception.")
256 }
257
259}
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175

References os_, test(), TEST_EPILOG, TEST_FAILED, and TEST_PROLOG.

Variable Documentation

◆ os_

ostream* os_ = 0

Definition at line 39 of file SpectrumList_SorterTest.cpp.

Referenced by main(), and test().