ProteoWizard
Functions | Variables
obotest.cpp File Reference
#include "obo.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include <boost/filesystem/operations.hpp>
#include "pwiz/utility/misc/Std.hpp"
#include <cstring>

Go to the source code of this file.

Functions

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

Variables

ostream * os_ = 0
 
const char * oboText_
 

Function Documentation

§ test()

void test ( )

Definition at line 133 of file obotest.cpp.

References pwiz::data::OBO::filename, pwiz::data::OBO::header, oboText_, os_, pwiz::data::OBO::prefix, pwiz::data::OBO::terms, and unit_assert.

Referenced by main().

134 {
135  const string& filename = "obotest_temp.txt";
136  ofstream temp(filename.c_str());
137  temp << oboText_ << endl;
138  temp.close();
139 
140  OBO obo(filename);
141 
142  if (os_) *os_ << obo << endl;
143 
144  unit_assert(obo.filename == filename);
145  unit_assert(obo.header.size() == 5);
146  unit_assert(obo.prefix == "MS");
147  unit_assert(obo.terms.size() == 12); // including obsolete terms
148 
149  set<Term>::const_iterator term = obo.terms.begin();
150  unit_assert(term->prefix == "MS");
151  unit_assert(term->id == 0);
152  unit_assert(term->name == "MZ controlled vocabularies");
153  unit_assert(term->def == "MZ controlled vocabularies.");
154  unit_assert(term->parentsPartOf.empty());
155  unit_assert(term->parentsIsA.empty());
156 
157  ++term;
158  unit_assert(term->id == 1);
159  unit_assert(term->name == "sample number");
160  unit_assert(term->parentsPartOf.size() == 1);
161  unit_assert(term->parentsPartOf[0] == 1000548);
162 
163  ++term;
164  unit_assert(term->id == 11);
165  unit_assert(term->name == "mass resolution");
166  unit_assert(term->parentsIsA.size() == 1);
167  unit_assert(term->parentsIsA[0] == 1000503);
168 
169  ++term;
170  unit_assert(term->id == 1000025);
171  unit_assert(term->exactSynonyms.size() == 1);
172  unit_assert(term->exactSynonyms[0] == "B");
173 
174  ++term;
175  unit_assert(term->id == 1000030);
176  unit_assert(term->isObsolete);
177 
178  ++term;
179  unit_assert(term->id == 1000035);
180  unit_assert(term->isObsolete);
181 
182  // test unescaping "\!"
183  ++term;
184  unit_assert(term->id == 1001272);
185  unit_assert(term->name == "(?<=R)(?!P)");
186 
187  // test other relationships
188  ++term;
189  unit_assert(term->id == 1001280);
190  unit_assert(term->relations.size() == 2);
191  unit_assert(term->relations.begin()->first == "has_units");
192  unit_assert(term->relations.begin()->second.first == "MS");
193  unit_assert(term->relations.begin()->second.second == 1000040);
194  unit_assert(term->relations.rbegin()->second.first == "UO");
195  unit_assert(term->relations.rbegin()->second.second == 169);
196 
197  ++term;
198  unit_assert(term->id == 1001303);
199  unit_assert(term->name == "Arg-C");
200  unit_assert(term->relations.size() == 1);
201  unit_assert(term->relations.begin()->first == "has_regexp");
202  unit_assert(term->relations.begin()->second.first == "MS");
203  unit_assert(term->relations.begin()->second.second == 1001272);
204 
205  // test term with OBO 1.2 synonym format
206  ++term;
207  unit_assert(term->id == 2000025);
208  unit_assert(term->exactSynonyms.size() == 1);
209  unit_assert(term->exactSynonyms[0] == "B");
210 
211  // test term with [stuff to ignore]
212  ++term;
213  unit_assert(term->id == 9999999);
214  unit_assert(term->def == "description");
215 
216  ++term;
217  // test property values
218  unit_assert(term->id == 99999999);
219  unit_assert(term->name == "Label:2H(4)+GlyGly");
220  unit_assert(term->def == "Ubiquitination 2H4 lysine");
221  unit_assert(term->propertyValues.size() == 9);
222  unit_assert(term->propertyValues.find("record_id")->second == "853");
223  unit_assert(term->propertyValues.find("delta_mono_mass")->second == "118.068034");
224  unit_assert(term->propertyValues.find("delta_avge_mass")->second == "118.1273");
225  unit_assert(term->propertyValues.find("delta_composition")->second == "H(2) 2H(4) C(4) N(2) O(2)");
226  unit_assert(term->propertyValues.find("spec_classification_1")->second == "Post-translational");
227 
228  boost::filesystem::remove(filename);
229 }
ostream * os_
Definition: obotest.cpp:35
Represents a selectively parsed OBO file.
Definition: obo.hpp:76
const char * oboText_
Definition: obotest.cpp:38
#define unit_assert(x)
Definition: unit.hpp:85

§ main()

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

Definition at line 232 of file obotest.cpp.

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

233 {
234  TEST_PROLOG(argc, argv)
235 
236  try
237  {
238  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
239  test();
240  }
241  catch (exception& e)
242  {
243  TEST_FAILED(e.what())
244  }
245  catch (...)
246  {
247  TEST_FAILED("Caught unknown exception.")
248  }
249 
251 }
ostream * os_
Definition: obotest.cpp:35
#define TEST_EPILOG
Definition: unit.hpp:182
void test()
Definition: obotest.cpp:133
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174

Variable Documentation

§ os_

ostream* os_ = 0

Definition at line 35 of file obotest.cpp.

Referenced by main(), and test().

§ oboText_

const char* oboText_

Definition at line 38 of file obotest.cpp.

Referenced by test().