ProteoWizard
Main Page
Namespaces
Classes
Files
File List
File Members
pwiz
data
tradata
DiffTest.cpp
Go to the documentation of this file.
1
//
2
// $Id: DiffTest.cpp 4129 2012-11-20 00:05:37Z chambm $
3
//
4
//
5
// Original author: Matt Chambers <matt.chambers .@. vanderbilt.edu>
6
//
7
// Copyright 2009 Vanderbilt University - Nashville, TN 37232
8
//
9
// Licensed under the Apache License, Version 2.0 (the "License");
10
// you may not use this file except in compliance with the License.
11
// You may obtain a copy of the License at
12
//
13
// http://www.apache.org/licenses/LICENSE-2.0
14
//
15
// Unless required by applicable law or agreed to in writing, software
16
// distributed under the License is distributed on an "AS IS" BASIS,
17
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
// See the License for the specific language governing permissions and
19
// limitations under the License.
20
//
21
22
#include "
Diff.hpp
"
23
#include "
pwiz/utility/misc/unit.hpp
"
24
#include "
pwiz/utility/misc/Std.hpp
"
25
#include <cstring>
26
27
28
using namespace
pwiz::util;
29
using namespace
pwiz::cv
;
30
using namespace
pwiz::data;
31
using namespace
pwiz::tradata;
32
33
34
ostream*
os_
= 0;
35
36
37
void
testContact
()
38
{
39
if
(
os_
) *
os_
<<
"testContact()\n"
;
40
41
Contact
a, b;
42
a.
userParams
.push_back(
UserParam
(
"common"
));
43
b.
userParams
.push_back(
UserParam
(
"common"
));
44
a.
cvParams
.push_back(
MS_m_z
);
45
b.
cvParams
.push_back(
MS_m_z
);
46
47
a.
id
= b.
id
=
"foo"
;
48
49
Diff<Contact, DiffConfig>
diff
(a, b);
50
unit_assert
(!diff);
51
52
a.
id
=
"bar"
;
53
54
diff
(a, b);
55
if
(
os_
) *
os_
<< diff << endl;
56
unit_assert
(diff);
57
}
58
59
60
void
testInstrument
()
61
{
62
if
(
os_
) *
os_
<<
"testInstrument()\n"
;
63
64
Instrument
a, b;
65
a.
userParams
.push_back(
UserParam
(
"common"
));
66
b.
userParams
.push_back(
UserParam
(
"common"
));
67
a.
cvParams
.push_back(
MS_m_z
);
68
b.
cvParams
.push_back(
MS_m_z
);
69
70
a.
id
= b.
id
=
"foo"
;
71
72
Diff<Instrument, DiffConfig>
diff
(a, b);
73
unit_assert
(!diff);
74
75
a.
id
=
"bar"
;
76
77
diff
(a, b);
78
if
(
os_
) *
os_
<< diff << endl;
79
unit_assert
(diff);
80
}
81
82
83
void
testConfiguration
()
84
{
85
if
(
os_
) *
os_
<<
"testConfiguration()\n"
;
86
87
Configuration
a, b;
88
a.
userParams
.push_back(
UserParam
(
"common"
));
89
b.
userParams
.push_back(
UserParam
(
"common"
));
90
a.
cvParams
.push_back(
MS_m_z
);
91
b.
cvParams
.push_back(
MS_m_z
);
92
a.
instrumentPtr
=
InstrumentPtr
(
new
Instrument
(
"common"
));
93
b.
instrumentPtr
=
InstrumentPtr
(
new
Instrument
(
"common"
));
94
a.
contactPtr
=
ContactPtr
(
new
Contact
(
"common"
));
95
b.
contactPtr
=
ContactPtr
(
new
Contact
(
"common"
));
96
97
Diff<Configuration, DiffConfig>
diff
(a, b);
98
unit_assert
(!diff);
99
100
a.
instrumentPtr
->id =
"different"
;
101
102
diff
(a, b);
103
if
(
os_
) *
os_
<< diff << endl;
104
unit_assert
(diff);
105
}
106
107
108
void
testPrediction
()
109
{
110
if
(
os_
) *
os_
<<
"testPrediction()\n"
;
111
112
Prediction
a, b;
113
a.
userParams
.push_back(
UserParam
(
"common"
));
114
b.
userParams
.push_back(
UserParam
(
"common"
));
115
a.
cvParams
.push_back(
MS_m_z
);
116
b.
cvParams
.push_back(
MS_m_z
);
117
a.
contactPtr
=
ContactPtr
(
new
Contact
(
"common"
));
118
b.
contactPtr
=
ContactPtr
(
new
Contact
(
"common"
));
119
120
Diff<Prediction, DiffConfig>
diff
(a, b);
121
unit_assert
(!diff);
122
123
a.
softwarePtr
=
SoftwarePtr
(
new
Software
(
"different"
));
124
125
diff
(a, b);
126
if
(
os_
) *
os_
<< diff << endl;
127
unit_assert
(diff);
128
}
129
130
131
void
testValidation
()
132
{
133
if
(
os_
) *
os_
<<
"testValidation()\n"
;
134
135
Validation
a, b;
136
a.
userParams
.push_back(
UserParam
(
"common"
));
137
b.
userParams
.push_back(
UserParam
(
"common"
));
138
a.
cvParams
.push_back(
MS_m_z
);
139
b.
cvParams
.push_back(
MS_m_z
);
140
141
Diff<Validation, DiffConfig>
diff
(a, b);
142
unit_assert
(!diff);
143
144
b.
set
(
MS_peak_intensity
, 42);
145
146
diff
(a, b);
147
if
(
os_
) *
os_
<< diff << endl;
148
unit_assert
(diff);
149
}
150
151
152
void
testEvidence
()
153
{
154
if
(
os_
) *
os_
<<
"testEvidence()\n"
;
155
156
Evidence
a, b;
157
a.
userParams
.push_back(
UserParam
(
"common"
));
158
b.
userParams
.push_back(
UserParam
(
"common"
));
159
a.
cvParams
.push_back(
MS_m_z
);
160
b.
cvParams
.push_back(
MS_m_z
);
161
162
Diff<Evidence, DiffConfig>
diff
(a, b);
163
unit_assert
(!diff);
164
165
a.
set
(
MS_peak_intensity
, 42);
166
167
diff
(a, b);
168
if
(
os_
) *
os_
<< diff << endl;
169
unit_assert
(diff);
170
}
171
172
173
void
testRetentionTime
()
174
{
175
if
(
os_
) *
os_
<<
"testRetentionTime()\n"
;
176
177
RetentionTime
a, b;
178
a.
userParams
.push_back(
UserParam
(
"common"
));
179
b.
userParams
.push_back(
UserParam
(
"common"
));
180
a.
cvParams
.push_back(
MS_m_z
);
181
b.
cvParams
.push_back(
MS_m_z
);
182
183
Diff<RetentionTime, DiffConfig>
diff
(a, b);
184
unit_assert
(!diff);
185
186
a.
set
(
MS_peak_intensity
, 42);
187
188
diff
(a, b);
189
if
(
os_
) *
os_
<< diff << endl;
190
unit_assert
(diff);
191
}
192
193
194
void
testProtein
()
195
{
196
if
(
os_
) *
os_
<<
"testProtein()\n"
;
197
198
Protein
a, b;
199
a.userParams.push_back(
UserParam
(
"common"
));
200
b.userParams.push_back(
UserParam
(
"common"
));
201
a.cvParams.push_back(
MS_m_z
);
202
b.cvParams.push_back(
MS_m_z
);
203
a.
sequence
= b.
sequence
=
"ABCD"
;
204
a.
id
= b.
id
=
"foo"
;
205
206
Diff<Protein, DiffConfig>
diff
(a, b);
207
unit_assert
(!diff);
208
209
a.
sequence
=
"DCBA"
;
210
211
diff
(a, b);
212
if
(
os_
) *
os_
<< diff << endl;
213
unit_assert
(diff);
214
}
215
216
217
void
testModification
()
218
{
219
if
(
os_
) *
os_
<<
"testModification()\n"
;
220
221
Modification
a, b;
222
a.location = b.location = 7;
223
a.monoisotopicMassDelta = b.monoisotopicMassDelta = 42;
224
a.averageMassDelta = b.averageMassDelta = 42;
225
226
Diff<Modification, DiffConfig>
diff
(a, b);
227
unit_assert
(!diff);
228
229
a.monoisotopicMassDelta = 84;
230
231
diff
(a, b);
232
if
(
os_
) *
os_
<< diff << endl;
233
unit_assert
(diff);
234
}
235
236
237
void
testPeptide
()
238
{
239
if
(
os_
) *
os_
<<
"testPeptide()\n"
;
240
241
Peptide
a, b;
242
a.userParams.push_back(
UserParam
(
"common"
));
243
b.userParams.push_back(
UserParam
(
"common"
));
244
a.cvParams.push_back(
MS_m_z
);
245
b.cvParams.push_back(
MS_m_z
);
246
a.evidence.set(
MS_peak_intensity
, 42);
247
b.evidence.set(
MS_peak_intensity
, 42);
248
a.
sequence
= b.
sequence
=
"ABCD"
;
249
a.id = b.id =
"foo"
;
250
251
Diff<Peptide, DiffConfig>
diff
(a, b);
252
unit_assert
(!diff);
253
254
a.
sequence
=
"DCBA"
;
255
256
diff
(a, b);
257
if
(
os_
) *
os_
<< diff << endl;
258
unit_assert
(diff);
259
}
260
261
262
void
testCompound
()
263
{
264
if
(
os_
) *
os_
<<
"testCompound()\n"
;
265
266
Compound
a, b;
267
a.
userParams
.push_back(
UserParam
(
"common"
));
268
b.
userParams
.push_back(
UserParam
(
"common"
));
269
a.
cvParams
.push_back(
MS_m_z
);
270
b.
cvParams
.push_back(
MS_m_z
);
271
a.
id
= b.
id
=
"foo"
;
272
273
Diff<Compound, DiffConfig>
diff
(a, b);
274
unit_assert
(!diff);
275
276
b.
retentionTimes
.push_back(
RetentionTime
());
277
278
diff
(a, b);
279
if
(
os_
) *
os_
<< diff << endl;
280
unit_assert
(diff);
281
}
282
283
284
void
testTransition
()
285
{
286
if
(
os_
) *
os_
<<
"testTransition()\n"
;
287
288
Transition
a, b;
289
a.
id
= b.
id
=
"T1"
;
290
a.
precursor
.
set
(
MS_selected_ion_m_z
, 123.45);
291
b.
precursor
.
set
(
MS_selected_ion_m_z
, 123.45);
292
a.
product
.
set
(
MS_selected_ion_m_z
, 456.78);
293
b.
product
.
set
(
MS_selected_ion_m_z
, 456.78);
294
Validation
v; v.
set
(
MS_peak_intensity
, 42);
295
Configuration
c; c.
validations
.push_back(v);
296
a.
configurationList
.push_back(c);
297
b.
configurationList
.push_back(c);
298
a.
peptidePtr
=
PeptidePtr
(
new
Peptide
(
"common"
));
299
b.
peptidePtr
=
PeptidePtr
(
new
Peptide
(
"common"
));
300
301
Diff<Transition, DiffConfig>
diff
(a, b);
302
unit_assert
(!diff);
303
304
b.
peptidePtr
->sequence =
"different"
;
305
306
diff
(a, b);
307
if
(
os_
) *
os_
<< diff << endl;
308
unit_assert
(diff);
309
}
310
311
void
testTarget
()
312
{
313
if
(
os_
) *
os_
<<
"testTarget()\n"
;
314
315
Target
a, b;
316
a.
id
= b.
id
=
"T1"
;
317
a.
precursor
.
set
(
MS_selected_ion_m_z
, 123.45);
318
b.
precursor
.
set
(
MS_selected_ion_m_z
, 123.45);
319
Validation
v; v.
set
(
MS_peak_intensity
, 42);
320
Configuration
c; c.
validations
.push_back(v);
321
a.
configurationList
.push_back(c);
322
b.
configurationList
.push_back(c);
323
a.
peptidePtr
=
PeptidePtr
(
new
Peptide
(
"common"
));
324
b.
peptidePtr
=
PeptidePtr
(
new
Peptide
(
"common"
));
325
326
Diff<Target, DiffConfig>
diff
(a, b);
327
unit_assert
(!diff);
328
329
b.
peptidePtr
->sequence =
"different"
;
330
331
diff
(a, b);
332
if
(
os_
) *
os_
<< diff << endl;
333
unit_assert
(diff);
334
}
335
336
337
void
testSoftware
()
338
{
339
if
(
os_
) *
os_
<<
"testSoftware()\n"
;
340
341
Software
a, b;
342
343
a.
id
=
"msdata"
;
344
a.
version
=
"4.20"
;
345
a.
set
(
MS_ionization_type
);
346
b = a;
347
348
Diff<Software, DiffConfig>
diff
(a, b);
349
unit_assert
(!diff);
350
351
b.
version
=
"4.21"
;
352
353
diff
(a, b);
354
if
(
os_
) *
os_
<< diff << endl;
355
unit_assert
(diff);
356
}
357
358
359
/*void testPrecursor()
360
{
361
if (os_) *os_ << "testPrecursor()\n";
362
363
Precursor a, b;
364
365
a.mz = 420;
366
a.charge = 2;
367
b = a;
368
369
Diff<Precursor> diff(a, b);
370
unit_assert(!diff);
371
372
b.charge = 3;
373
374
diff(a, b);
375
376
if (os_) *os_ << diff << endl;
377
unit_assert(diff);
378
unit_assert(diff.a_b.mz == 0);
379
unit_assert(diff.a_b.charge == -1);
380
unit_assert(diff.b_a.mz == 0);
381
unit_assert(diff.b_a.charge == 1);
382
}
383
384
385
void testProduct()
386
{
387
if (os_) *os_ << "testProduct()\n";
388
389
Product a, b;
390
391
a.mz = 420;
392
a.charge = 2;
393
b = a;
394
395
Diff<Product> diff(a, b);
396
unit_assert(!diff);
397
398
b.charge = 3;
399
400
diff(a, b);
401
402
if (os_) *os_ << diff << endl;
403
unit_assert(diff);
404
unit_assert(diff.a_b.mz == 0);
405
unit_assert(diff.a_b.charge == -1);
406
unit_assert(diff.b_a.mz == 0);
407
unit_assert(diff.b_a.charge == 1);
408
}*/
409
410
411
void
testTraData
()
412
{
413
if
(
os_
) *
os_
<<
"testTraData()\n"
;
414
415
TraData
a, b;
416
417
Diff<TraData, DiffConfig>
diff
(a, b);
418
unit_assert
(!diff);
419
420
a.
cvs
.push_back(
CV
());
421
b.
softwarePtrs
.push_back(
SoftwarePtr
(
new
Software
(
"software"
)));
422
423
Publication
pub;
424
pub.
id
=
"PUBMED1"
;
425
pub.
set
(
UO_dalton
, 123);
426
a.
publications
.push_back(pub);
427
b.
publications
.push_back(pub);
428
429
diff
(a, b);
430
if
(
os_
) *
os_
<< diff << endl;
431
unit_assert
(diff);
432
433
unit_assert
(diff.
a_b
.
cvs
.size() == 1);
434
unit_assert
(diff.
b_a
.
cvs
.empty());
435
436
unit_assert
(diff.
a_b
.
softwarePtrs
.empty());
437
unit_assert
(!diff.
b_a
.
softwarePtrs
.empty());
438
439
unit_assert
(diff.
a_b
.
publications
.empty());
440
unit_assert
(diff.
b_a
.
publications
.empty());
441
}
442
443
444
void
test
()
445
{
446
testContact
();
447
testInstrument
();
448
testSoftware
();
449
testConfiguration
();
450
testPrediction
();
451
testValidation
();
452
testEvidence
();
453
testRetentionTime
();
454
testProtein
();
455
testModification
();
456
testPeptide
();
457
testCompound
();
458
testTransition
();
459
testTarget
();
460
//testPrecursor();
461
//testProduct();
462
testTraData
();
463
}
464
465
466
int
main
(
int
argc,
char
* argv[])
467
{
468
TEST_PROLOG_EX
(argc, argv,
"_TraData"
)
469
470
try
471
{
472
if
(argc>1 && !strcmp(argv[1],
"-v"
))
os_
= &cout;
473
test
();
474
}
475
catch
(exception&
e
)
476
{
477
TEST_FAILED
(e.what())
478
}
479
catch
(...)
480
{
481
TEST_FAILED
(
"Caught unknown exception."
)
482
}
483
484
TEST_EPILOG
485
}
486
Generated on Mon Nov 26 2012 18:05:48 for ProteoWizard by
1.8.1.1