File: SpectrumSettings_test.C

package info (click to toggle)
openms 1.11.1-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 436,688 kB
  • ctags: 150,907
  • sloc: cpp: 387,126; xml: 71,547; python: 7,764; ansic: 2,626; php: 2,499; sql: 737; ruby: 342; sh: 325; makefile: 128
file content (511 lines) | stat: -rw-r--r-- 16,347 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
// --------------------------------------------------------------------------
//                   OpenMS -- Open-Source Mass Spectrometry               
// --------------------------------------------------------------------------
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
// ETH Zurich, and Freie Universitaet Berlin 2002-2013.
// 
// This software is released under a three-clause BSD license:
//  * Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//  * Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//  * Neither the name of any author or any participating institution 
//    may be used to endorse or promote products derived from this software 
//    without specific prior written permission.
// For a full list of authors, refer to the file AUTHORS. 
// --------------------------------------------------------------------------
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING 
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// 
// --------------------------------------------------------------------------
// $Maintainer: Andreas Bertsch $
// $Authors: Marc Sturm $
// --------------------------------------------------------------------------

#include <OpenMS/CONCEPT/ClassTest.h>

///////////////////////////
#include <OpenMS/METADATA/SpectrumSettings.h>
#include <OpenMS/METADATA/ProteinIdentification.h>
///////////////////////////

using namespace OpenMS;
using namespace std;

START_TEST(SpectrumSettings, "$Id: SpectrumSettings_test.C 10915 2013-04-04 20:14:57Z aiche $")

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

SpectrumSettings* ptr = 0;
SpectrumSettings* nullPointer = 0;

START_SECTION((SpectrumSettings()))
	ptr = new SpectrumSettings();
	TEST_NOT_EQUAL(ptr, nullPointer)
END_SECTION

START_SECTION((~SpectrumSettings()))
	delete ptr;
END_SECTION

START_SECTION((const String& getNativeID() const))
	SpectrumSettings tmp;
	TEST_STRING_EQUAL(tmp.getNativeID(),"");
END_SECTION

START_SECTION((void setNativeID(const String& native_id)))
	SpectrumSettings tmp;
	tmp.setNativeID("nid");
	TEST_STRING_EQUAL(tmp.getNativeID(),"nid");
END_SECTION

START_SECTION((const std::vector<DataProcessing>& getDataProcessing() const))
  SpectrumSettings tmp;
  TEST_EQUAL(tmp.getDataProcessing().size(),0);
END_SECTION

START_SECTION((void setDataProcessing(const std::vector< DataProcessing > &data_processing)))
  SpectrumSettings tmp;
  std::vector<DataProcessing> dummy;
  dummy.resize(1);
  tmp.setDataProcessing(dummy);
  TEST_EQUAL(tmp.getDataProcessing().size(),1);
END_SECTION

START_SECTION((std::vector<DataProcessing>& getDataProcessing()))
  SpectrumSettings tmp;
  tmp.getDataProcessing().resize(1);
  TEST_EQUAL(tmp.getDataProcessing().size(),1);
END_SECTION

START_SECTION((AcquisitionInfo& getAcquisitionInfo()))
	SpectrumSettings tmp;
	TEST_EQUAL(tmp.getAcquisitionInfo()==AcquisitionInfo(), true);
END_SECTION

START_SECTION((void setAcquisitionInfo(const AcquisitionInfo& acquisition_info)))
	SpectrumSettings tmp;
	AcquisitionInfo ai;
	ai.setMethodOfCombination("test");
	tmp.setAcquisitionInfo(ai);
	TEST_EQUAL(tmp.getAcquisitionInfo()==AcquisitionInfo(), false);
END_SECTION

START_SECTION((const AcquisitionInfo& getAcquisitionInfo() const))
	SpectrumSettings tmp;
	tmp.getAcquisitionInfo().setMethodOfCombination("test");
	TEST_EQUAL(tmp.getAcquisitionInfo()==AcquisitionInfo(), false);
END_SECTION

START_SECTION((SourceFile& getSourceFile()))
	SpectrumSettings tmp;
	TEST_EQUAL(tmp.getSourceFile()==SourceFile(), true);
END_SECTION

START_SECTION((void setSourceFile(const SourceFile& source_file)))
	SpectrumSettings tmp;
	SourceFile sf;
	sf.setNameOfFile("test");
	tmp.setSourceFile(sf);
	TEST_EQUAL(tmp.getSourceFile()==SourceFile(), false);
END_SECTION

START_SECTION((const SourceFile& getSourceFile() const))
	SpectrumSettings tmp;
	tmp.getSourceFile().setNameOfFile("test");
	TEST_EQUAL(tmp.getSourceFile()==SourceFile(), false);
END_SECTION

START_SECTION((const InstrumentSettings& getInstrumentSettings() const))
	SpectrumSettings tmp;
	TEST_EQUAL(tmp.getInstrumentSettings()==InstrumentSettings(), true);	  
END_SECTION

START_SECTION((void setInstrumentSettings(const InstrumentSettings& instrument_settings)))
	SpectrumSettings tmp;
	InstrumentSettings is;
	is.getScanWindows().resize(1);
	tmp.setInstrumentSettings(is);
	TEST_EQUAL(tmp.getInstrumentSettings()==InstrumentSettings(), false);
END_SECTION

START_SECTION((InstrumentSettings& getInstrumentSettings()))
	SpectrumSettings tmp;
	tmp.getInstrumentSettings().getScanWindows().resize(1);
	TEST_EQUAL(tmp.getInstrumentSettings()==InstrumentSettings(), false);	
END_SECTION

START_SECTION((const std::vector<Precursor>& getPrecursors() const))
	SpectrumSettings tmp;
	TEST_EQUAL(tmp.getPrecursors().size(),0);	  
END_SECTION

START_SECTION((void setPrecursors(const std::vector<Precursor>& precursors)))
	SpectrumSettings tmp;
	tmp.setPrecursors(vector<Precursor>(2));
	TEST_EQUAL(tmp.getPrecursors().size(), 2);
END_SECTION

START_SECTION((std::vector<Precursor>& getPrecursors()))
	SpectrumSettings tmp;
	tmp.getPrecursors().resize(4);
	TEST_EQUAL(tmp.getPrecursors().size(), 4);	
END_SECTION

START_SECTION((const std::vector<Product>& getProducts() const))
	SpectrumSettings tmp;
	TEST_EQUAL(tmp.getProducts().size(),0);	  
END_SECTION

START_SECTION((void setProducts(const std::vector<Product>& products)))
	SpectrumSettings tmp;
	tmp.setProducts(vector<Product>(2));
	TEST_EQUAL(tmp.getProducts().size(), 2);
END_SECTION

START_SECTION((std::vector<Product>& getProducts()))
	SpectrumSettings tmp;
	tmp.getProducts().resize(4);
	TEST_EQUAL(tmp.getProducts().size(), 4);	
END_SECTION

START_SECTION((SpectrumType getType() const))
	SpectrumSettings tmp;
	TEST_EQUAL(tmp.getType(), SpectrumSettings::UNKNOWN);	  
END_SECTION

START_SECTION((void setType(SpectrumType type)))
	SpectrumSettings tmp;
	tmp.setType(SpectrumSettings::PEAKS);
	TEST_EQUAL(tmp.getType(), SpectrumSettings::PEAKS);
END_SECTION

START_SECTION((const String& getComment() const))
	SpectrumSettings tmp;
	TEST_EQUAL(tmp.getComment(), "");
END_SECTION

START_SECTION((void setComment(const String& comment)))
	SpectrumSettings tmp;
	tmp.setComment("bla");
	TEST_EQUAL(tmp.getComment(), "bla");
END_SECTION

START_SECTION((const std::vector<PeptideIdentification>& getPeptideIdentifications() const))
	SpectrumSettings tmp;
	vector<PeptideIdentification> vec(tmp.getPeptideIdentifications());
	TEST_EQUAL(vec.size(),0);
END_SECTION

START_SECTION((void setPeptideIdentifications(const std::vector<PeptideIdentification>& identifications)))
	SpectrumSettings tmp;
	vector<PeptideIdentification> vec;
	
	tmp.setPeptideIdentifications(vec);
	TEST_EQUAL(tmp.getPeptideIdentifications().size(),0);
	
	PeptideIdentification dbs;
	vec.push_back(dbs);
	tmp.setPeptideIdentifications(vec);
	TEST_EQUAL(tmp.getPeptideIdentifications().size(),1);
END_SECTION

START_SECTION((std::vector<PeptideIdentification>& getPeptideIdentifications()))
	SpectrumSettings tmp;
	vector<PeptideIdentification> vec;
	
	tmp.getPeptideIdentifications().resize(1);
	TEST_EQUAL(tmp.getPeptideIdentifications().size(),1);
END_SECTION

START_SECTION((SpectrumSettings& operator= (const SpectrumSettings& source)))
  SpectrumSettings tmp;
  tmp.setMetaValue("bla","bluff");
	tmp.getAcquisitionInfo().setMethodOfCombination("test");
	tmp.getInstrumentSettings().getScanWindows().resize(1);
	tmp.getPrecursors().resize(1);
	tmp.getProducts().resize(1);
	tmp.getPeptideIdentifications().resize(1);
	tmp.setType(SpectrumSettings::PEAKS);
	tmp.setComment("bla");
	tmp.setNativeID("nid");
	tmp.getDataProcessing().resize(1);
	
	SpectrumSettings tmp2(tmp);
	TEST_EQUAL(tmp2.getComment(), "bla");
	TEST_EQUAL(tmp2.getType(), SpectrumSettings::PEAKS);
	TEST_EQUAL(tmp2.getPeptideIdentifications().size(), 1);	
	TEST_EQUAL(tmp2.getPrecursors().size(),1);	
	TEST_EQUAL(tmp2.getProducts().size(),1);	
	TEST_EQUAL(tmp2.getInstrumentSettings()==InstrumentSettings(), false);
	TEST_EQUAL(tmp2.getAcquisitionInfo()==AcquisitionInfo(), false);  
	TEST_STRING_EQUAL(tmp2.getNativeID(),"nid");
	TEST_EQUAL(tmp2.getDataProcessing().size(),1);
	TEST_EQUAL(tmp2.getMetaValue("bla")=="bluff",true);
END_SECTION

START_SECTION((SpectrumSettings(const SpectrumSettings& source)))
  SpectrumSettings tmp;
	tmp.getAcquisitionInfo().setMethodOfCombination("test");
	tmp.getInstrumentSettings().getScanWindows().resize(1);
	tmp.getPrecursors().resize(1);
	tmp.getProducts().resize(1);
	tmp.setType(SpectrumSettings::PEAKS);
	tmp.setComment("bla");
	tmp.getPeptideIdentifications().resize(1);
	tmp.setNativeID("nid");
	tmp.getDataProcessing().resize(1);
	tmp.setMetaValue("bla","bluff");
	
	SpectrumSettings tmp2;
	tmp2 = tmp;
	TEST_EQUAL(tmp2.getComment(), "bla");
	TEST_EQUAL(tmp2.getType(), SpectrumSettings::PEAKS);
	TEST_EQUAL(tmp2.getPrecursors().size(), 1);
	TEST_EQUAL(tmp2.getProducts().size(),1);	
	TEST_EQUAL(tmp2.getInstrumentSettings()==InstrumentSettings(), false);	
	TEST_EQUAL(tmp2.getAcquisitionInfo()==AcquisitionInfo(), false);
	TEST_EQUAL(tmp2.getPeptideIdentifications().size(), 1);	
	TEST_STRING_EQUAL(tmp2.getNativeID(),"nid");
	TEST_EQUAL(tmp2.getDataProcessing().size(),1);
	TEST_STRING_EQUAL(tmp2.getMetaValue("bla"),"bluff");


	tmp2 = SpectrumSettings();
	TEST_EQUAL(tmp2.getComment(), "");
	TEST_EQUAL(tmp2.getType(), SpectrumSettings::UNKNOWN);
	TEST_EQUAL(tmp2.getPrecursors().size(),0);	
	TEST_EQUAL(tmp2.getProducts().size(),0);	
	TEST_EQUAL(tmp2.getInstrumentSettings()==InstrumentSettings(), true);	
	TEST_EQUAL(tmp2.getAcquisitionInfo()==AcquisitionInfo(), true);
	TEST_EQUAL(tmp2.getPeptideIdentifications().size(), 0);	
	TEST_STRING_EQUAL(tmp2.getNativeID(),"");
	TEST_EQUAL(tmp2.getDataProcessing().size(),0);
	TEST_EQUAL(tmp2.metaValueExists("bla"),false);

END_SECTION

START_SECTION((bool operator== (const SpectrumSettings& rhs) const))
  SpectrumSettings edit, empty;
  
  TEST_EQUAL(edit==empty, true);
  
	edit.getAcquisitionInfo().setMethodOfCombination("test");
	TEST_EQUAL(edit==empty, false);
	
	edit = empty;
	edit.setNativeID("nid");
	TEST_EQUAL(edit==empty, false);
	
	edit = empty;
	edit.getInstrumentSettings().getScanWindows().resize(1);
	TEST_EQUAL(edit==empty, false);
	
	edit = empty;
	edit.getPrecursors().resize(1);
	TEST_EQUAL(edit==empty, false);
	
	edit = empty;
	edit.setType(SpectrumSettings::PEAKS);
	TEST_EQUAL(edit==empty, false);
	
	edit = empty;
	edit.setComment("bla");
	TEST_EQUAL(edit==empty, false);

	edit = empty;
	edit.getPrecursors().resize(1);
	TEST_EQUAL(edit==empty, false);

	edit = empty;
	edit.getProducts().resize(1);
	TEST_EQUAL(edit==empty, false);
	
	edit = empty;
	edit.getPeptideIdentifications().resize(1);
	TEST_EQUAL(edit==empty, false);

	edit = empty;
	edit.getDataProcessing().resize(1);
	TEST_EQUAL(edit==empty, false);

	edit = empty;
	edit.setMetaValue("bla","bluff");
	TEST_EQUAL(edit==empty, false);

END_SECTION

START_SECTION((bool operator!= (const SpectrumSettings& rhs) const))
  SpectrumSettings edit, empty;
  
  TEST_EQUAL(edit!=empty, false);
  
	edit.getAcquisitionInfo().setMethodOfCombination("test");
	TEST_EQUAL(edit!=empty, true);
	
	edit = empty;
	edit.setNativeID("nid");
	TEST_EQUAL(edit!=empty, true);
	
	edit = empty;
	edit.getInstrumentSettings().getScanWindows().resize(1);
	TEST_EQUAL(edit!=empty, true);
	
	edit = empty;
	edit.getPrecursors().resize(1);
	TEST_EQUAL(edit!=empty, true);
	
	edit = empty;
	edit.setType(SpectrumSettings::PEAKS);
	TEST_EQUAL(edit!=empty, true);
	
	edit = empty;
	edit.setComment("bla");
	TEST_EQUAL(edit!=empty, true);

	edit = empty;
	edit.getPrecursors().resize(1);
	TEST_EQUAL(edit!=empty, true);

	edit = empty;
	edit.getProducts().resize(1);
	TEST_EQUAL(edit!=empty, true);

	edit = empty;
	edit.getPeptideIdentifications().resize(1);
	TEST_EQUAL(edit!=empty, true);

	edit = empty;
	edit.getDataProcessing().resize(1);
	TEST_EQUAL(edit!=empty, true);

	edit = empty;
	edit.setMetaValue("bla","bluff");
	TEST_EQUAL(edit!=empty, true);


END_SECTION

START_SECTION((void unify(const SpectrumSettings &rhs)))
{
  SpectrumSettings org, appended;

  // MetaValues
  org.setMetaValue(1, "will be gone");
  org.setMetaValue(2, "will be still present");
  appended.setMetaValue(1, "will overwrite org comment");

  // Comments
  org.setComment("Original Comment");
  appended.setComment("Appended to org Commment");

  // Precursors
  Precursor org_precursor;
  org_precursor.setMZ(1.0);
  org.getPrecursors().push_back(org_precursor);

  Precursor appended_precursor;
  appended_precursor.setMZ(2.0);
  appended.getPrecursors().push_back(appended_precursor);

  // type
  org.setType(SpectrumSettings::RAWDATA);
  appended.setType(SpectrumSettings::RAWDATA);

  // Products
  Product org_product;
  org_product.setMZ(1.0);
  org.getProducts().push_back(org_product);

  Product appended_product;
  appended_product.setMZ(2.0);
  appended.getProducts().push_back(appended_product);

  // Identifications
  PeptideIdentification org_ident;
  org_ident.setIdentifier("org_ident");
  org.getPeptideIdentifications().push_back(org_ident);

  PeptideIdentification appended_ident;
  appended_ident.setIdentifier("appended_ident");
  appended.getPeptideIdentifications().push_back(appended_ident);

  // DataProcessings
  DataProcessing org_processing;
  Software org_software;
  org_software.setName("org_software");
  org_processing.setSoftware(org_software);
  org.getDataProcessing().push_back(org_processing);

  DataProcessing appended_processing;
  Software appended_software;
  appended_software.setName("appended_software");
  appended_processing.setSoftware(appended_software);
  appended.getDataProcessing().push_back(appended_processing);

  org.unify(appended);

  // MetaValues
  TEST_EQUAL(org.getMetaValue(1), "will overwrite org comment")
  TEST_EQUAL(org.getMetaValue(2), "will be still present")

  // Comments
  TEST_EQUAL(org.getComment(), "Original CommentAppended to org Commment")

  // Precursors
  TEST_EQUAL(org.getPrecursors().size(), 2)
  ABORT_IF(org.getPrecursors().size()!=2)

  TEST_EQUAL(org.getPrecursors()[0].getMZ(), 1.0)
  TEST_EQUAL(org.getPrecursors()[1].getMZ(), 2.0)

  // type
  TEST_EQUAL(org.getType(), SpectrumSettings::RAWDATA)

  // Products
  TEST_EQUAL(org.getProducts().size(), 2)
  ABORT_IF(org.getProducts().size()!=2)

  TEST_EQUAL(org.getProducts()[0].getMZ(), 1.0)
  TEST_EQUAL(org.getProducts()[1].getMZ(), 2.0)

  // Identifications
  TEST_EQUAL(org.getPeptideIdentifications().size(), 2)
  ABORT_IF(org.getPeptideIdentifications().size()!=2)

  TEST_EQUAL(org.getPeptideIdentifications()[0].getIdentifier(), "org_ident")
  TEST_EQUAL(org.getPeptideIdentifications()[1].getIdentifier(), "appended_ident")

  // Identifications
  TEST_EQUAL(org.getDataProcessing().size(), 2)
  ABORT_IF(org.getDataProcessing().size()!=2)

  TEST_EQUAL(org.getDataProcessing()[0].getSoftware().getName(), "org_software")
  TEST_EQUAL(org.getDataProcessing()[1].getSoftware().getName(), "appended_software")

  // unify should set Type to unknown in case of type mismatch
  SpectrumSettings empty;
  empty.setType(SpectrumSettings::PEAKS);
  org.unify(empty);

  TEST_EQUAL(org.getType(), SpectrumSettings::UNKNOWN)
}
END_SECTION

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST