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 
void testInstrumentConfiguration()
ComponentList componentList
list with the different components used in the mass spectrometer. At least one source, one mass analyzer and one detector need to be specified.
Definition: MSData.hpp:235
boost::shared_ptr< Software > SoftwarePtr
Definition: MSData.hpp:198
void testDetector()
void test()
A component of an instrument corresponding to a source (i.e. ion source), an analyzer (i...
Definition: MSData.hpp:131
translates text to CV terms
interface for legacy access to Instrument
interface for legacy access to Software
#define TEST_EPILOG
Definition: unit.hpp:183
MS_software
software: Software related to the recording or transformation of spectra.
Definition: cv.hpp:2199
Component & source(size_t index)
returns the source component with ordinal <index+1>
void testModelAndManufacturer()
std::vector< UserParam > userParams
a collection of uncontrolled user terms
Definition: ParamTypes.hpp:253
void testAnalyzer()
std::vector< CVParam > cvParams
a collection of controlled vocabulary terms
Definition: ParamTypes.hpp:250
void testIonisation()
A piece of software.
Definition: MSData.hpp:179
Component & analyzer(size_t index)
returns the analyzer component with ordinal <index+1>
Description of a particular hardware configuration of a mass spectrometer. Each configuration MUST ha...
Definition: MSData.hpp:229
#define TEST_FAILED(x)
Definition: unit.hpp:177
CVID_Unknown
Definition: cv.hpp:114
void testSoftware()
int main(int argc, char *argv[])
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:175
ostream * os_
MS_Xcalibur
Xcalibur: Thermo Finnigan software for data acquisition and analysis.
Definition: cv.hpp:2202
Component & detector(size_t index)
returns the detector component with ordinal <index+1>
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:849
void manufacturerAndModel(const std::string &valueManufacturer, const std::string &valueModel)
#define unit_assert(x)
Definition: unit.hpp:85
Definition: cv.hpp:108
represents a tag-value pair, where the tag comes from the controlled vocabulary
Definition: ParamTypes.hpp:44