ProteoWizard
LegacyAdapterTest.cpp
Go to the documentation of this file.
1 //
2 // $Id$
3 //
4 //
5 // Original author: Darren Kessner <darren@proteowizard.org>
6 //
7 // Copyright 2007 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 
24 #include "LegacyAdapter.hpp"
26 #include "TextWriter.hpp"
28 #include "boost/lambda/lambda.hpp"
29 #include "boost/lambda/bind.hpp"
31 #include <cstring>
32 
33 
34 using namespace pwiz::util;
35 using namespace pwiz::cv;
36 using namespace pwiz::msdata;
37 using namespace boost::lambda;
38 
39 
40 ostream* os_ = 0;
41 
42 
44 {
45  if (os_) *os_ << "testModelAndManufacturer()\n";
46 
47  InstrumentConfiguration instrumentConfiguration;
48  CVTranslator cvTranslator;
49  LegacyAdapter_Instrument adapter(instrumentConfiguration, cvTranslator);
50 
51  unit_assert(instrumentConfiguration.cvParams.empty() && instrumentConfiguration.userParams.empty());
52 
53  adapter.manufacturerAndModel("dummy", "LTQ-FT");
54  if (os_) *os_ << "manufacturer: " << adapter.manufacturer() << endl
55  << "model: " << adapter.model() << endl;
56  unit_assert(instrumentConfiguration.cvParams.size() == 1);
57  unit_assert(instrumentConfiguration.userParams.empty());
58  unit_assert(adapter.manufacturer() == "Thermo Scientific");
59  unit_assert(adapter.model() == "LTQ FT");
60 
61  adapter.manufacturerAndModel("doobie", "420");
62  if (os_) *os_ << "manufacturer: " << adapter.manufacturer() << endl
63  << "model: " << adapter.model() << endl;
64  unit_assert(instrumentConfiguration.cvParams.empty());
65  unit_assert(instrumentConfiguration.userParams.size() == 2);
66  unit_assert(adapter.manufacturer() == "doobie");
67  unit_assert(adapter.model() == "420");
68 
69  adapter.manufacturerAndModel("dummy", "LTQ-FT");
70  if (os_) *os_ << "manufacturer: " << adapter.manufacturer() << endl
71  << "model: " << adapter.model() << endl;
72  unit_assert(instrumentConfiguration.cvParams.size() == 1);
73  unit_assert(instrumentConfiguration.userParams.empty());
74  unit_assert(adapter.manufacturer() == "Thermo Scientific");
75  unit_assert(adapter.model() == "LTQ FT");
76 }
77 
78 
80 {
81  InstrumentConfiguration instrumentConfiguration;
82  CVTranslator cvTranslator;
83  LegacyAdapter_Instrument adapterEmpty(instrumentConfiguration, cvTranslator);
84  unit_assert(adapterEmpty.ionisation() == "Unknown"); // Empty component list is legal
85  instrumentConfiguration.componentList.push_back(Component(ComponentType_Source, 2));
86  LegacyAdapter_Instrument adapter(instrumentConfiguration, cvTranslator);
87  unit_assert(adapter.ionisation() == "Unknown"); // Empty component list is legal
88 
89  adapter.ionisation(" esi\t");
90  if (os_) *os_ << "ionisation: " << adapter.ionisation() << endl;
91  unit_assert(instrumentConfiguration.componentList.source(0).cvParams.size() == 1);
92  unit_assert(instrumentConfiguration.componentList.source(0).userParams.empty());
93  unit_assert(adapter.ionisation() == "electrospray ionization");
94 
95  adapter.ionisation("goober");
96  if (os_) *os_ << "ionisation: " << adapter.ionisation() << endl;
97  unit_assert(instrumentConfiguration.componentList.source(0).cvParams.empty());
98  unit_assert(instrumentConfiguration.componentList.source(0).userParams.size() == 1);
99  unit_assert(adapter.ionisation() == "goober");
100 
101  adapter.ionisation(" Electrospray-Ionization");
102  if (os_) *os_ << "ionisation: " << adapter.ionisation() << endl;
103  unit_assert(instrumentConfiguration.componentList.source(0).cvParams.size() == 1);
104  unit_assert(instrumentConfiguration.componentList.source(0).userParams.empty());
105  unit_assert(adapter.ionisation() == "electrospray ionization");
106 }
107 
108 
110 {
111  InstrumentConfiguration instrumentConfiguration;
112  CVTranslator cvTranslator;
113  LegacyAdapter_Instrument adapterEmpty(instrumentConfiguration, cvTranslator);
114  unit_assert(adapterEmpty.analyzer() == "Unknown"); // Empty component list is legal
115  instrumentConfiguration.componentList.push_back(Component(ComponentType_Analyzer, 2));
116  LegacyAdapter_Instrument adapter(instrumentConfiguration, cvTranslator);
117  unit_assert(adapter.analyzer() == "Unknown"); // Empty component list is legal
118 
119  adapter.analyzer("IT");
120  if (os_) *os_ << "analyzer: " << adapter.analyzer() << endl;
121  unit_assert(instrumentConfiguration.componentList.analyzer(0).cvParams.size() == 1);
122  unit_assert(instrumentConfiguration.componentList.analyzer(0).userParams.empty());
123  unit_assert(adapter.analyzer() == "ion trap");
124 
125  adapter.analyzer("goober");
126  if (os_) *os_ << "analyzer: " << adapter.analyzer() << endl;
127  unit_assert(instrumentConfiguration.componentList.analyzer(0).cvParams.empty());
128  unit_assert(instrumentConfiguration.componentList.analyzer(0).userParams.size() == 1);
129  unit_assert(adapter.analyzer() == "goober");
130 
131  adapter.analyzer(" qit");
132  if (os_) *os_ << "analyzer: " << adapter.analyzer() << endl;
133  unit_assert(instrumentConfiguration.componentList.analyzer(0).cvParams.size() == 1);
134  unit_assert(instrumentConfiguration.componentList.analyzer(0).userParams.empty());
135  unit_assert(adapter.analyzer() == "quadrupole ion trap");
136 }
137 
138 
140 {
141  InstrumentConfiguration instrumentConfiguration;
142  CVTranslator cvTranslator;
143  LegacyAdapter_Instrument adapterEmpty(instrumentConfiguration, cvTranslator);
144  unit_assert(adapterEmpty.analyzer() == "Unknown"); // Empty component list is legal
145  instrumentConfiguration.componentList.push_back(Component(ComponentType_Detector, 3));
146  LegacyAdapter_Instrument adapter(instrumentConfiguration, cvTranslator);
147  unit_assert(adapter.analyzer() == "Unknown"); // Empty component list is legal
148 
149  adapter.detector("emt");
150  if (os_) *os_ << "detector: " << adapter.detector() << endl;
151  unit_assert(instrumentConfiguration.componentList.detector(0).cvParams.size() == 1);
152  unit_assert(instrumentConfiguration.componentList.detector(0).userParams.empty());
153  unit_assert(adapter.detector() == "electron multiplier tube");
154 
155  adapter.detector("goober");
156  if (os_) *os_ << "detector: " << adapter.detector() << endl;
157  unit_assert(instrumentConfiguration.componentList.detector(0).cvParams.empty());
158  unit_assert(instrumentConfiguration.componentList.detector(0).userParams.size() == 1);
159  unit_assert(adapter.detector() == "goober");
160 
161  adapter.detector(" Electron Multiplier ");
162  if (os_) *os_ << "detector: " << adapter.detector() << endl;
163  unit_assert(instrumentConfiguration.componentList.detector(0).cvParams.size() == 1);
164  unit_assert(instrumentConfiguration.componentList.detector(0).userParams.empty());
165  unit_assert(adapter.detector() == "electron multiplier");
166 }
167 
168 
170 {
172  testIonisation();
173  testAnalyzer();
174  testDetector();
175 }
176 
177 
179 {
180  SoftwarePtr software(new Software("abcd"));
181  MSData msd;
182  CVTranslator cvTranslator;
183  LegacyAdapter_Software adapter(software, msd, cvTranslator);
184 
185  adapter.name(" XcaLibur ");
186  if (os_) *os_ << "software name: " << adapter.name() << endl;
187  CVParam softwareParam = software->cvParamChild(MS_software);
188  unit_assert(softwareParam.cvid == MS_Xcalibur);
189  unit_assert(adapter.name() == "Xcalibur");
190 
191  adapter.name("goober");
192  if (os_) *os_ << "software name: " << adapter.name() << endl;
193  softwareParam = software->cvParamChild(MS_software);
194  unit_assert(softwareParam.cvid == CVID_Unknown);
195  unit_assert(adapter.name() == "goober");
196 
197  adapter.version("4.20");
198  if (os_) *os_ << "software version: " << adapter.version() << endl;
199  unit_assert(adapter.version() == "4.20");
200 
201  //adapter.type("acquisition");
202  //if (os_) *os_ << "software type: " << adapter.type() << endl;
203  //unit_assert(adapter.type() == "acquisition");
204 
205  adapter.type("analysis");
206  if (os_) *os_ << "software type: " << adapter.type() << endl;
207  unit_assert(adapter.type() == "analysis");
208 }
209 
210 
211 void test()
212 {
214  testSoftware();
215 }
216 
217 
218 int main(int argc, char* argv[])
219 {
220  TEST_PROLOG(argc, argv)
221 
222  try
223  {
224  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
225  test();
226  }
227  catch (exception& e)
228  {
229  TEST_FAILED(e.what())
230  }
231  catch (...)
232  {
233  TEST_FAILED("Caught unknown exception.")
234  }
235 
237 }
238 
pwiz::msdata::ComponentList::source
Component & source(size_t index)
returns the source component with ordinal <index+1>
pwiz::msdata::InstrumentConfiguration::componentList
ComponentList componentList
list with the different components used in the mass spectrometer. At least one source,...
Definition: MSData.hpp:235
pwiz::msdata::LegacyAdapter_Instrument::detector
std::string detector() const
CVTranslator.hpp
pwiz::msdata::LegacyAdapter_Instrument::manufacturer
std::string manufacturer() const
pwiz::msdata::Software
A piece of software.
Definition: MSData.hpp:179
pwiz::cv
Definition: cv.hpp:108
pwiz::data::ParamContainer::userParams
std::vector< UserParam > userParams
a collection of uncontrolled user terms
Definition: ParamTypes.hpp:253
MS_software
MS_software
software: Software related to the recording or transformation of spectra.
Definition: cv.hpp:2199
MS_Xcalibur
MS_Xcalibur
Xcalibur: Thermo Finnigan software for data acquisition and analysis.
Definition: cv.hpp:2202
testModelAndManufacturer
void testModelAndManufacturer()
Definition: LegacyAdapterTest.cpp:43
pwiz::msdata
Definition: DemuxTypes.hpp:27
pwiz::msdata::LegacyAdapter_Instrument::ionisation
std::string ionisation() const
testDetector
void testDetector()
Definition: LegacyAdapterTest.cpp:139
pwiz::msdata::LegacyAdapter_Software
interface for legacy access to Software
Definition: LegacyAdapter.hpp:105
testIonisation
void testIonisation()
Definition: LegacyAdapterTest.cpp:79
LegacyAdapter.hpp
testInstrumentConfiguration
void testInstrumentConfiguration()
Definition: LegacyAdapterTest.cpp:169
pwiz::util
Definition: almost_equal.hpp:33
pwiz::msdata::LegacyAdapter_Software::version
std::string version() const
TEST_EPILOG
#define TEST_EPILOG
Definition: unit.hpp:183
pwiz::msdata::ComponentType_Detector
@ ComponentType_Detector
Definition: MSData.hpp:126
CVID_Unknown
CVID_Unknown
Definition: cv.hpp:114
TextWriter.hpp
pwiz::msdata::ComponentType_Source
@ ComponentType_Source
Definition: MSData.hpp:124
pwiz::data::CVTranslator
translates text to CV terms
Definition: CVTranslator.hpp:39
pwiz::msdata::LegacyAdapter_Instrument::analyzer
std::string analyzer() const
pwiz::msdata::LegacyAdapter_Software::name
std::string name() const
Std.hpp
pwiz::msdata::Component
A component of an instrument corresponding to a source (i.e. ion source), an analyzer (i....
Definition: MSData.hpp:131
pwiz::msdata::LegacyAdapter_Instrument::manufacturerAndModel
void manufacturerAndModel(const std::string &valueManufacturer, const std::string &valueModel)
pwiz::msdata::ComponentType_Analyzer
@ ComponentType_Analyzer
Definition: MSData.hpp:125
pwiz::msdata::ComponentList::detector
Component & detector(size_t index)
returns the detector component with ordinal <index+1>
testAnalyzer
void testAnalyzer()
Definition: LegacyAdapterTest.cpp:109
TEST_FAILED
#define TEST_FAILED(x)
Definition: unit.hpp:177
TEST_PROLOG
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:175
main
int main(int argc, char *argv[])
Definition: LegacyAdapterTest.cpp:218
pwiz::msdata::LegacyAdapter_Instrument::model
std::string model() const
os_
ostream * os_
Definition: LegacyAdapterTest.cpp:40
pwiz::msdata::InstrumentConfiguration
Description of a particular hardware configuration of a mass spectrometer. Each configuration MUST ha...
Definition: MSData.hpp:229
pwiz::msdata::MSData
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:849
pwiz::data::CVParam::cvid
CVID cvid
Definition: ParamTypes.hpp:46
testSoftware
void testSoftware()
Definition: LegacyAdapterTest.cpp:178
unit.hpp
unit_assert
#define unit_assert(x)
Definition: unit.hpp:85
pwiz::msdata::LegacyAdapter_Software::type
std::string type() const
pwiz::data::CVParam
represents a tag-value pair, where the tag comes from the controlled vocabulary
Definition: ParamTypes.hpp:44
pwiz::msdata::ComponentList::analyzer
Component & analyzer(size_t index)
returns the analyzer component with ordinal <index+1>
test
void test()
Definition: LegacyAdapterTest.cpp:211
pwiz::msdata::SoftwarePtr
boost::shared_ptr< Software > SoftwarePtr
Definition: MSData.hpp:198
pwiz::msdata::LegacyAdapter_Instrument
interface for legacy access to Instrument
Definition: LegacyAdapter.hpp:61
pwiz::data::ParamContainer::cvParams
std::vector< CVParam > cvParams
a collection of controlled vocabulary terms
Definition: ParamTypes.hpp:250