ProteoWizard
SpectrumList_MZWindowTest.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 <cstring>
28
29
30using namespace pwiz::util;
31using namespace pwiz::msdata;
32using namespace pwiz::analysis;
33
34
35ostream* os_ = 0;
36
37
38void printSpectrumList(const SpectrumList& sl, ostream& os)
39{
40 os << "size: " << sl.size() << endl;
41
42 for (size_t i=0, end=sl.size(); i<end; i++)
43 {
44 SpectrumPtr spectrum = sl.spectrum(i, false);
45 vector<MZIntensityPair> data;
46 spectrum->getMZIntensityPairs(data);
47
48 os << spectrum->index << " "
49 << spectrum->id << ": ";
50
51 copy(data.begin(), data.end(), ostream_iterator<MZIntensityPair>(os, " "));
52
53 os << endl;
54 }
55}
56
57
59{
61
62 for (size_t i=0; i<10; i++)
63 {
64 SpectrumPtr spectrum(new Spectrum);
65 spectrum->index = i;
66 spectrum->id = "scan=" + lexical_cast<string>(100+i);
67
68 // data: (i,1000) (i+1,1001) (i+2,1002) (i+3,1003) (i+4,1004)
69 vector<MZIntensityPair> data(5);
70 for (size_t j=0; j<5; j++) data[j] = MZIntensityPair(i+j, 1000+j);
71 spectrum->setMZIntensityPairs(data, MS_number_of_detector_counts);
72
73 sl->spectra.push_back(spectrum);
74 }
75
76 if (os_)
77 {
78 *os_ << "original spectrum list:\n";
79 printSpectrumList(*sl, *os_);
80 *os_ << endl;
81 }
82
83 return sl;
84}
85
86
87void verifySpectrumSize(const SpectrumList& sl, size_t index, size_t size)
88{
89 SpectrumPtr spectrum = sl.spectrum(index, true);
90 vector<MZIntensityPair> data;
91 spectrum->getMZIntensityPairs(data);
92 unit_assert(data.size() == size);
93}
94
95
96void test()
97{
99 for (size_t i=0; i<sl->size(); i++)
100 verifySpectrumSize(*sl, i, 5);
101
102 SpectrumList_MZWindow window(sl, 4.20, 6.66);
103
104 if (os_)
105 {
106 *os_ << "filtered list:\n";
107 printSpectrumList(window, *os_);
108 *os_ << endl;
109 }
110
111 unit_assert(window.size() == sl->size());
112 verifySpectrumSize(window, 0, 0);
113 verifySpectrumSize(window, 1, 1);
114 verifySpectrumSize(window, 2, 2);
115 verifySpectrumSize(window, 3, 2);
116 verifySpectrumSize(window, 4, 2);
117 verifySpectrumSize(window, 5, 2);
118 verifySpectrumSize(window, 6, 1);
119 verifySpectrumSize(window, 7, 0);
120 verifySpectrumSize(window, 8, 0);
121 verifySpectrumSize(window, 9, 0);
122}
123
124
125int main(int argc, char* argv[])
126{
127 TEST_PROLOG(argc, argv)
128
129 try
130 {
131 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
132 test();
133 }
134 catch (exception& e)
135 {
136 TEST_FAILED(e.what())
137 }
138 catch (...)
139 {
140 TEST_FAILED("Caught unknown exception.")
141 }
142
144}
145
146
int main(int argc, char *argv[])
void verifySpectrumSize(const SpectrumList &sl, size_t index, size_t size)
void printSpectrumList(const SpectrumList &sl, ostream &os)
ostream * os_
SpectrumListPtr createSpectrumList()
SpectrumList filter, for creating Spectrum sub-lists.
Interface for accessing spectra, which may be stored in memory or backed by a data file (RAW,...
Definition MSData.hpp:661
virtual size_t size() const =0
returns the number of spectra
virtual SpectrumPtr spectrum(size_t index, bool getBinaryData=false) const =0
retrieve a spectrum by index
virtual size_t size() const
returns the number of spectra
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
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition MSData.hpp:711
boost::shared_ptr< Spectrum > SpectrumPtr
Definition MSData.hpp:573
boost::shared_ptr< SpectrumListSimple > SpectrumListSimplePtr
Definition MSData.hpp:731
The data point type of a mass spectrum.
Definition MSData.hpp:423
The structure that captures the generation of a peak list (including the underlying acquisitions)
Definition MSData.hpp:506
Simple writeable in-memory implementation of SpectrumList.
Definition MSData.hpp:717
#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