ProteoWizard
SpectrumListWrapperTest.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
27
28using namespace pwiz::cv;
29using namespace pwiz::msdata;
30using namespace pwiz::util;
31
32
33class MyWrapper : public SpectrumListWrapper
34{
35 public:
36
38 : SpectrumListWrapper(inner)
39 {}
40
41 void verifySize(size_t size)
42 {
43 // verify that we can see inner_
44 unit_assert(size == inner_->size());
45 }
46
47 virtual SpectrumPtr spectrum(size_t index, bool getBinaryData = false) const {return inner_->spectrum(index, getBinaryData);}
48};
49
50
52{
53 // a simple filter that returns only even indices
54
55 public:
56
58 : SpectrumListWrapper(inner)
59 {}
60
61 virtual size_t size() const {return inner_->size()/2;}
62 virtual const SpectrumIdentity& spectrumIdentity(size_t index) const {return inner_->spectrumIdentity(index*2);}
63 virtual SpectrumPtr spectrum(size_t index, bool getBinaryData = false) const {return inner_->spectrum(index*2, getBinaryData);}
64};
65
66
67void test()
68{
70
71 const size_t spectrumCount = 10;
72 for (size_t i=0; i<spectrumCount; i++)
73 {
74 simple->spectra.push_back(SpectrumPtr(new Spectrum));
75 Spectrum& s = *simple->spectra.back();
76 s.index = i;
77 s.id = "scan=" + lexical_cast<string>(i);
78 }
79
80 // check MyWrapper
81
82 shared_ptr<MyWrapper> wrapper(new MyWrapper(simple));
83
84 wrapper->verifySize(10);
85 unit_assert(wrapper->size() == 10);
86 for (size_t i=0; i<spectrumCount; i++)
87 {
88 string id = "scan=" + lexical_cast<string>(i);
89
90 unit_assert(wrapper->find(id) == i);
91 IndexList indexList = wrapper->findNameValue("scan", lexical_cast<string>(i));
92 unit_assert(indexList.size()==1 && indexList[0]==i);
93
94 const SpectrumIdentity& identity = wrapper->spectrumIdentity(i);
95 unit_assert(identity.id == id);
96
97 SpectrumPtr s = wrapper->spectrum(i);
98 unit_assert(s->id == id);
99 }
100
101 // check FilterWrapper
102
103 shared_ptr<FilterWrapper> filterWrapper(new FilterWrapper(simple));
104
105 unit_assert(filterWrapper->size() == 5);
106
107 for (size_t i=0; i<filterWrapper->size(); i++)
108 {
109 string id = "scan=" + lexical_cast<string>(i*2);
110 string scanNumber = lexical_cast<string>(i*2);
111
112 unit_assert(filterWrapper->find(id) == i);
113 IndexList indexList = filterWrapper->findNameValue("scan", scanNumber);
114 unit_assert(indexList.size()==1 && indexList[0]==i);
115
116 const SpectrumIdentity& identity = filterWrapper->spectrumIdentity(i);
117 unit_assert(identity.id == id);
118
119 SpectrumPtr s = filterWrapper->spectrum(i);
120 unit_assert(s->id == id);
121 }
122}
123
124
125int main(int argc, char* argv[])
126{
127 TEST_PROLOG(argc, argv)
128
129 try
130 {
131 test();
132 }
133 catch (exception& e)
134 {
135 TEST_FAILED(e.what())
136 }
137 catch (...)
138 {
139 TEST_FAILED("Caught unknown exception.")
140 }
141
143}
144
145
int main(int argc, char *argv[])
virtual const SpectrumIdentity & spectrumIdentity(size_t index) const
virtual size_t size() const
virtual SpectrumPtr spectrum(size_t index, bool getBinaryData=false) const
FilterWrapper(const SpectrumListPtr &inner)
virtual SpectrumPtr spectrum(size_t index, bool getBinaryData=false) const
void verifySize(size_t size)
MyWrapper(const SpectrumListPtr &inner)
Inheritable pass-through implementation for wrapping a SpectrumList.
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 structure that captures the generation of a peak list (including the underlying acquisitions)
Definition MSData.hpp:506
Identifying information for a spectrum.
Definition MSData.hpp:471
std::string id
a unique identifier for this spectrum. It should be expected that external files may use this identif...
Definition MSData.hpp:476
size_t index
the zero-based, consecutive index of the spectrum in the SpectrumList.
Definition MSData.hpp:473
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