ProteoWizard
obotest.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 "obo.hpp"
26#include <boost/filesystem/operations.hpp>
28#include <cstring>
29
30
31using namespace pwiz::data;
32using namespace pwiz::util;
33
34
35ostream* os_ = 0;
36
37
38const char* oboText_ =
39 "format-version: 1.0\n"
40 "date: 01:10:2007 23:46\n"
41 "saved-by: deutsch\n"
42 "auto-generated-by: OBO-Edit 1.101\n"
43 "default-namespace: PSI-MS\n"
44 "\n"
45 "[Term]\t\n"
46 "id: MS:0000000\t\n"
47 "name: MZ controlled vocabularies\t\n"
48 "def: \"MZ controlled vocabularies.\" [PSI:MS]\t\n"
49 "\n"
50 "[Term]\r\n"
51 "id: MS:0000001\r\n"
52 "name: sample number\r\n"
53 "def: \"A reference number relevant to the sample under study.\" [PSI:MS]\r\n"
54 "relationship: part_of MS:1000548 ! sample attribute\r\n"
55 "\n"
56 "[Term]\n"
57 "id: MS:0000011\n"
58 "name: mass resolution\n"
59 "def: \"The maximum m/z value at which two peaks can be resolved, according to one of the standard measures.\" [PSI:MS]\n"
60 "is_a: MS:1000503 ! scan attribute\n"
61 "\n"
62 "[Term]\n"
63 "id: MS:1000025\n"
64 "name: magnetic field strength\n"
65 "def: \"A property of space that produces a force on a charged particle equal to qv x B where q is the particle charge and v its velocity.\" [PSI:MS]\n"
66 "related_synonym: \"Magnetic Field\" []\n"
67 "exact_synonym: \"B\" []\n"
68 "is_a: MS:1000480 ! mass analyzer attribute\n"
69 "\n"
70 "[Term]\n"
71 "id: MS:1000030\n"
72 "name: vendor\n"
73 "def: \"Name of instrument vendor, replaced by MS:1000031 Model From Vendor.\" [PSI:MS]\n"
74 "is_obsolete: true\n"
75 "\n"
76 "[Term]\n"
77 "id: MS:1000035\n"
78 "name: obsolete by definition\n"
79 "def: \"OBSOLETE description\" [PSI:MS]\n"
80 "\n"
81 "[Term]\n"
82 "id: MS:1001272\n"
83 "name: (?<=R)(?\\!P)\n"
84 "\n"
85 "[Term]\n"
86 "id: MS:1001280\n"
87 "name: accuracy\n"
88 "def: \"Accuracy is the degree of conformity of a measured mass to its actual value.\" [PSI:MS]\n"
89 "xref: value-type:xsd\\:float \"The allowed value-type for this CV term.\"\n"
90 "is_a: MS:1000480 ! mass analyzer attribute\n"
91 "relationship: has_units MS:1000040 ! m/z\n"
92 "relationship: has_units UO:0000169 ! parts per million\n"
93 "\n"
94 "[Term]\n"
95 "id: MS:1001303\n"
96 "name: Arg-C\n"
97 "is_a: MS:1001045 ! cleavage agent name\n"
98 "relationship: has_regexp MS:1001272 ! (?<=R)(?!P)\n"
99 "\n"
100 // OBO format 1.2
101 "[Term]\n"
102 "id: MS:2000025\n"
103 "name: magnetic field strength\n"
104 "def: \"A property of space that produces a force on a charged particle equal to qv x B where q is the particle charge and v its velocity.\" [PSI:MS]\n"
105 "synonym: \"B\" EXACT []\n"
106 "synonym: \"Magnetic Field\" RELATED []\n"
107 "is_a: MS:1000480 ! mass analyzer attribute\n"
108 "\n"
109 "[Term]\n"
110 "id: MS:9999999\n"
111 "name: unit\n"
112 "namespace: unit.ontology\n"
113 "def: \"description\" [ignore this Wikipedia:Wikipedia \"http://www.wikipedia.org/\"]\n"
114 "\n"
115 "[Term]\n"
116 "id: MS:99999999\n"
117 "name: Label:2H(4)+GlyGly\n"
118 "def: \"Ubiquitination 2H4 lysine\" []\n"
119 "property_value: record_id=\"853\"\n"
120 "property_value: delta_mono_mass=\"118.068034\"\n"
121 "property_value: delta_avge_mass=\"118.1273\"\n"
122 "property_value: delta_composition=\"H(2) 2H(4) C(4) N(2) O(2)\"\n"
123 "property_value: spec_group1=\"1\"\n"
124 "property_value: spec_hidden_1=\"1\"\n"
125 "property_value: spec_site_1=\"K\"\n"
126 "property_value: spec_position_1=\"Anywhere\"\n"
127 "property_value: spec_classification_1=\"Post-translational\"\n"
128 "is_a: MS:0 ! unimod root node\n"
129 "\n"
130;
131
132
133void test()
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.prefixes.count("MS") > 0);
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}
230
231
232int main(int argc, char* argv[])
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}
252
253
int main(int argc, char *argv[])
Definition obotest.cpp:232
ostream * os_
Definition obotest.cpp:35
void test()
Definition obotest.cpp:133
const char * oboText_
Definition obotest.cpp:38
Represents a selectively parsed OBO file.
Definition obo.hpp:77
std::vector< std::string > header
Definition obo.hpp:79
std::set< std::string > prefixes
Definition obo.hpp:80
std::string filename
Definition obo.hpp:78
std::set< Term > terms
Definition obo.hpp:81
#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