~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to source/TEST/DBAdapter_test.C

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2012-11-12 15:58:12 UTC
  • Revision ID: package-import@ubuntu.com-20121112155812-vr15wtg9b50cuesg
Tags: upstream-1.9.0
ImportĀ upstreamĀ versionĀ 1.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: C++; tab-width: 2; -*-
 
2
// vi: set ts=2:
 
3
//
 
4
// --------------------------------------------------------------------------
 
5
//                   OpenMS Mass Spectrometry Framework
 
6
// --------------------------------------------------------------------------
 
7
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
 
8
//
 
9
//  This library is free software; you can redistribute it and/or
 
10
//  modify it under the terms of the GNU Lesser General Public
 
11
//  License as published by the Free Software Foundation; either
 
12
//  version 2.1 of the License, or (at your option) any later version.
 
13
//
 
14
//  This library is distributed in the hope that it will be useful,
 
15
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
//  Lesser General Public License for more details.
 
18
//
 
19
//  You should have received a copy of the GNU Lesser General Public
 
20
//  License along with this library; if not, write to the Free Software
 
21
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
22
//
 
23
// --------------------------------------------------------------------------
 
24
// $Maintainer: $
 
25
// $Authors: Marc Sturm $
 
26
// --------------------------------------------------------------------------
 
27
 
 
28
#include <OpenMS/CONCEPT/ClassTest.h>
 
29
 
 
30
///////////////////////////
 
31
#include <OpenMS/FORMAT/TextFile.h>
 
32
#include <OpenMS/FORMAT/DB/DBConnection.h>
 
33
#include <OpenMS/FORMAT/DB/DBAdapter.h>
 
34
#include <OpenMS/FORMAT/FileHandler.h>
 
35
#include <OpenMS/METADATA/Tagging.h>
 
36
#include <OpenMS/METADATA/Modification.h>
 
37
#include <OpenMS/METADATA/Digestion.h>
 
38
#include <OpenMS/KERNEL/StandardTypes.h>
 
39
///////////////////////////
 
40
 
 
41
using namespace OpenMS;
 
42
using namespace std;
 
43
 
 
44
START_TEST(DBAdapter, "$Id: DBAdapter_test.C 8210 2011-03-28 13:19:52Z aiche $")
 
45
 
 
46
/////////////////////////////////////////////////////////////
 
47
/////////////////////////////////////////////////////////////
 
48
 
 
49
/* This check does the following:
 
50
   - store experiment with 2 spectra to DB
 
51
   - load spectrum 1
 
52
   - load full experiment
 
53
   - modify 1st experiment
 
54
   - store 1st experiment (overwrite)
 
55
   - load experiment
 
56
   - store empty experiment
 
57
 
 
58
   So at the end of the test there should be 2 experiments stored in the database:
 
59
   - 1 full one, 2 spectra
 
60
   - 1 empty one.
 
61
*/
 
62
 
 
63
// check for credentials
 
64
// if they are not present, abort the test (successfully)
 
65
bool do_tests=true;
 
66
TextFile credentials;
 
67
try
 
68
{
 
69
        credentials.load(String(OPENMS_BINARY_PATH) + "/source/TEST/DB_credentials.txt",true);
 
70
}
 
71
catch(...)
 
72
{
 
73
        do_tests=false;
 
74
}
 
75
 
 
76
String db,host,user,password,port;
 
77
 
 
78
//read out connection data
 
79
for (TextFile::iterator it = credentials.begin(); it!= credentials.end(); ++it)
 
80
{
 
81
        //comments and empty lines
 
82
        if (it->hasPrefix('#') || *it == "")
 
83
        {
 
84
                continue;
 
85
        }
 
86
 
 
87
        //extract connection info
 
88
        if (it->hasPrefix("Host:")) host = it->suffix(':').trim();
 
89
        if (it->hasPrefix("Port:")) port = it->suffix(':').trim();
 
90
        if (it->hasPrefix("User:")) user = it->suffix(':').trim();
 
91
        if (it->hasPrefix("Password:")) password = it->suffix(':').trim();
 
92
        if (it->hasPrefix("DB:")) db = it->suffix(':').trim();
 
93
}
 
94
 
 
95
if (do_tests)
 
96
{
 
97
 
 
98
        //DB connection for DBAdapter
 
99
        DBConnection con;
 
100
        con.connect(db, user, password, host, port.toInt());
 
101
        DBConnection con2;
 
102
        con2.connect(db, user, password, host, port.toInt(), DB_PLUGIN, "alternateConnection");
 
103
 
 
104
        DBAdapter* ptr = 0;
 
105
        DBAdapter* nullPointer = 0;
 
106
 
 
107
        START_SECTION((DBAdapter(DBConnection& db_con)))
 
108
                ptr = new DBAdapter(con);
 
109
        TEST_NOT_EQUAL(ptr, nullPointer)
 
110
END_SECTION
 
111
 
 
112
        START_SECTION((~DBAdapter()))
 
113
                delete ptr;
 
114
END_SECTION
 
115
 
 
116
        START_SECTION((void createDB()))
 
117
        DBAdapter a(con);
 
118
                a.createDB();
 
119
 
 
120
                QSqlQuery result = con.executeQuery("SELECT id FROM META_MSExperiment");
 
121
          TEST_EQUAL(result.size(),0)
 
122
END_SECTION
 
123
 
 
124
        //check if the DB is up-to-date
 
125
        bool db_up_to_date;
 
126
        START_SECTION((bool checkDBVersion(bool warning)))
 
127
                DBAdapter a(con);
 
128
                db_up_to_date = a.checkDBVersion(true);
 
129
                TEST_EQUAL(db_up_to_date,true)
 
130
END_SECTION
 
131
 
 
132
        if (db_up_to_date)
 
133
        {
 
134
 
 
135
                // create test data - one experiment containing 2 spectra.
 
136
                RichPeakMap exp_original;
 
137
                exp_original.setComment("bla");
 
138
 
 
139
                exp_original.getSample().setName("fruity loops");
 
140
                exp_original.getSample().setNumber("007");
 
141
                exp_original.getSample().setMass(30.1);
 
142
                vector<Sample> subsamples;
 
143
                Sample subsample;
 
144
                subsample.setVolume(60.1);
 
145
                subsample.setConcentration(101.1);
 
146
                Digestion digestion;
 
147
                digestion.setEnzyme("dhdh");
 
148
                digestion.setDigestionTime(36.6);
 
149
                digestion.setPh(7.2);
 
150
                digestion.setTemperature(37.7);
 
151
                subsample.addTreatment(digestion);
 
152
                subsamples.push_back(subsample);
 
153
                subsample = Sample();
 
154
                subsample.setState(Sample::GAS);
 
155
                subsample.setOrganism("isistius brasiliensis (cookiecutter shark, see www.isistius.de)");
 
156
                Modification modification;
 
157
                modification.setReagentName("reagent");
 
158
                modification.setAffectedAminoAcids("123");
 
159
                modification.setSpecificityType(Modification::CTERM);
 
160
                modification.setMass(12.3);
 
161
                subsample.addTreatment(modification);
 
162
                Tagging tagging;
 
163
                tagging.setReagentName("tagging");
 
164
                tagging.setMassShift(0.123);
 
165
                tagging.setVariant(Tagging::HEAVY);
 
166
                subsample.addTreatment(tagging);
 
167
                subsamples.push_back(subsample);
 
168
                subsample = Sample();
 
169
                subsample.setComment("nice");
 
170
                subsample.setMetaValue("label", String("pink"));
 
171
                subsamples.push_back(subsample);
 
172
                exp_original.getSample().setSubsamples(subsamples);
 
173
 
 
174
                // setting experiment's first protein identification (+ 2 proteine hits)
 
175
                ProteinIdentification pi;
 
176
                ProteinHit ph;
 
177
                pi.setSearchEngine("google");
 
178
                pi.setSearchEngineVersion("beta");
 
179
                DateTime datetime;
 
180
                // does not save time yet, DB schema must be changed from Date to DateTime
 
181
                datetime.set("2006-12-12 00:00:00");
 
182
                pi.setDateTime(datetime);
 
183
                pi.setScoreType("Type");
 
184
                pi.setHigherScoreBetter(true);
 
185
                pi.setSignificanceThreshold(3.456);
 
186
                ph.setAccession("0110110");
 
187
                std::vector<ProteinHit> vector_ph;
 
188
                vector_ph.push_back(ph);
 
189
                ph = ProteinHit();
 
190
                ph.setScore(4.567);
 
191
                ph.setAccession("1001001");
 
192
                ph.setSequence("ZXY");
 
193
                ph.setRank(4u);
 
194
                vector_ph.push_back(ph);
 
195
                pi.setHits(vector_ph);
 
196
                pi.setMetaValue("label", String("proteinidentificationmetainfo"));
 
197
 
 
198
                ProteinIdentification::SearchParameters sp;
 
199
                sp.db = "register";
 
200
                sp.db_version = "0.0";
 
201
                sp.taxonomy = "bundesadler";
 
202
                sp.charges = "high";
 
203
                sp.mass_type = ProteinIdentification::AVERAGE;
 
204
                sp.enzyme = ProteinIdentification::TRYPSIN;
 
205
                sp.missed_cleavages = 6;
 
206
                sp.peak_mass_tolerance = 0.44;
 
207
                sp.precursor_tolerance = 0.55;
 
208
                sp.setMetaValue("label", String("searchparametersmetainfo"));
 
209
 
 
210
                std::vector<String> fm (3,"a");
 
211
                for(Size i = 0; i < fm.size(); ++i)
 
212
                {
 
213
                        fm[i]+=i;
 
214
                }
 
215
                std::vector<String> vm (fm);
 
216
                for(Size i = 0; i < vm.size(); ++i)
 
217
                {
 
218
                        vm[i]+=i;
 
219
                }
 
220
 
 
221
                sp.fixed_modifications = fm;
 
222
                sp.variable_modifications = vm;
 
223
                pi.setSearchParameters(sp);
 
224
 
 
225
                exp_original.getProteinIdentifications().push_back(pi);
 
226
 
 
227
                // setting experiment's second protein identification (+ no proteine hits)
 
228
                pi = ProteinIdentification();
 
229
                pi.setHigherScoreBetter(false);
 
230
                exp_original.getProteinIdentifications().push_back(pi);
 
231
 
 
232
                ContactPerson contact;
 
233
                contact.setFirstName("Ferdinand");
 
234
                contact.setLastName("Piech");
 
235
                contact.setInstitution("aff");
 
236
                exp_original.getContacts().push_back(contact);
 
237
                contact = ContactPerson();
 
238
                contact.setEmail("ferdi@porsche.de");
 
239
                contact.setContactInfo("ttss");
 
240
                contact.setMetaValue("label", String("polka-dotted"));
 
241
                exp_original.getContacts().push_back(contact);
 
242
 
 
243
                exp_original.getHPLC().setInstrument("guitar");
 
244
                exp_original.getHPLC().setColumn("bigone");
 
245
                exp_original.getHPLC().setComment("fhth");
 
246
                exp_original.getHPLC().setFlux(1);
 
247
                exp_original.getHPLC().setPressure(2);
 
248
                exp_original.getHPLC().setTemperature(3);
 
249
 
 
250
                exp_original.getHPLC().getGradient().addEluent("C2H5OH");
 
251
                exp_original.getHPLC().getGradient().addEluent("H2O");
 
252
                exp_original.getHPLC().getGradient().addTimepoint(1);
 
253
                exp_original.getHPLC().getGradient().addTimepoint(5);
 
254
                exp_original.getHPLC().getGradient().addTimepoint(7);
 
255
                exp_original.getHPLC().getGradient().setPercentage("C2H5OH", 1, 20);
 
256
                exp_original.getHPLC().getGradient().setPercentage("C2H5OH", 5, 40);
 
257
                exp_original.getHPLC().getGradient().setPercentage("C2H5OH", 7, 60);
 
258
                exp_original.getHPLC().getGradient().setPercentage("H2O", 1, 80);
 
259
                exp_original.getHPLC().getGradient().setPercentage("H2O", 5, 60);
 
260
                exp_original.getHPLC().getGradient().setPercentage("H2O", 7, 40);
 
261
 
 
262
                Software sw;
 
263
                sw.setName("tolle instrument-software");
 
264
                sw.setVersion("alpha");
 
265
                sw.setMetaValue("label", String("neu fuer msinstrument"));
 
266
                exp_original.getInstrument().setSoftware(sw);
 
267
                exp_original.getInstrument().setModel("Porsche 911");
 
268
                exp_original.getInstrument().setVendor("Porsche K.G. Zuffenhausen");
 
269
                exp_original.getInstrument().setCustomizations("340 PS");
 
270
                exp_original.getInstrument().setMetaValue("label", String("red"));
 
271
                exp_original.getInstrument().getIonDetectors().resize(1);
 
272
                exp_original.getInstrument().getIonDetectors()[0].setAcquisitionMode(IonDetector::PULSECOUNTING);
 
273
                exp_original.getInstrument().getIonDetectors()[0].setType(IonDetector::PHOTOMULTIPLIER);
 
274
                exp_original.getInstrument().getIonDetectors()[0].setResolution(6.7677);
 
275
                exp_original.getInstrument().getIonDetectors()[0].setADCSamplingFrequency(7.6766);
 
276
                exp_original.getInstrument().getIonDetectors()[0].setOrder(3);
 
277
                exp_original.getInstrument().getIonDetectors()[0].setMetaValue("label", String("black"));
 
278
                exp_original.getInstrument().getIonSources().resize(1);
 
279
                exp_original.getInstrument().getIonSources()[0].setInletType(IonSource::DIRECT);
 
280
                exp_original.getInstrument().getIonSources()[0].setIonizationMethod(IonSource::ESI);
 
281
                exp_original.getInstrument().getIonSources()[0].setPolarity(IonSource::POSITIVE);
 
282
                exp_original.getInstrument().getIonSources()[0].setMetaValue("label", String("blue"));
 
283
                exp_original.getInstrument().getIonSources()[0].setOrder(0);
 
284
                exp_original.getInstrument().setIonOptics(Instrument::FRINGING_FIELD);
 
285
 
 
286
                MassAnalyzer analyzer;
 
287
                analyzer.setAccuracy(1.2687);
 
288
                analyzer.setFinalMSExponent(8);
 
289
                analyzer.setIsolationWidth(8.456);
 
290
                analyzer.setMagneticFieldStrength(9.999);
 
291
                analyzer.setReflectronState(MassAnalyzer::NONE);
 
292
                analyzer.setResolution(7.444);
 
293
                analyzer.setResolutionMethod(MassAnalyzer::FWHM);
 
294
                analyzer.setResolutionType(MassAnalyzer::CONSTANT);
 
295
                analyzer.setOrder(1);
 
296
                exp_original.getInstrument().getMassAnalyzers().push_back(analyzer);
 
297
                analyzer = MassAnalyzer();
 
298
                analyzer.setScanDirection(MassAnalyzer::UP);
 
299
                analyzer.setScanLaw(MassAnalyzer::LINEAR);
 
300
                analyzer.setScanRate(5.555);
 
301
                analyzer.setScanTime(6.666);
 
302
                analyzer.setTOFTotalPathLength(7.777);
 
303
                analyzer.setType(MassAnalyzer::TOF);
 
304
                analyzer.setMetaValue("label", String("pink"));
 
305
                analyzer.setOrder(2);
 
306
                exp_original.getInstrument().getMassAnalyzers().push_back(analyzer);
 
307
 
 
308
                // MS spectrum
 
309
                RichPeakMap::SpectrumType spec;
 
310
                RichPeakMap::SpectrumType::PeakType p;
 
311
                p.setIntensity(565.0f);
 
312
                p.getPosition()[0] = 600.1;
 
313
                p.setMetaValue("label", String("peaklabel"));
 
314
                spec.push_back(p);
 
315
                p.setIntensity(620.0f);
 
316
                p.getPosition()[0] = 700.1;
 
317
                p.removeMetaValue("label");
 
318
                spec.push_back(p);
 
319
                p.setIntensity(701.0f);
 
320
                p.getPosition()[0] = 800.1;
 
321
                spec.push_back(p);
 
322
                spec.setRT(1.98);
 
323
                spec.setMSLevel(1);
 
324
 
 
325
                std::vector<Product> eier;
 
326
                Product ei;
 
327
                ei.setMZ(1.0);
 
328
                ei.setIsolationWindowLowerOffset(2.0);
 
329
                ei.setIsolationWindowUpperOffset(3.0);
 
330
                ei.setMetaValue("farbe", String("lilablassblau"));
 
331
                eier.push_back(ei);
 
332
                spec.setProducts(eier);
 
333
                ei.setMZ(4.0);
 
334
                ei.setIsolationWindowLowerOffset(5.0);
 
335
                ei.setIsolationWindowUpperOffset(6.0);
 
336
                ei.removeMetaValue("farbe");
 
337
                eier.push_back(ei);
 
338
                spec.setProducts(eier);
 
339
 
 
340
                InstrumentSettings settings;
 
341
                settings.getScanWindows().resize(1);
 
342
                settings.getScanWindows()[0].begin = 3.456;
 
343
                settings.getScanWindows()[0].end = 7.89;
 
344
                settings.getScanWindows()[0].setMetaValue("metavalue", String("info"));
 
345
                settings.setPolarity(IonSource::NEGATIVE);
 
346
                settings.setScanMode(InstrumentSettings::SIM);
 
347
                settings.setZoomScan(true);
 
348
                spec.setInstrumentSettings (settings);
 
349
 
 
350
                // set a spectrum source file
 
351
                SourceFile source_file;
 
352
                source_file.setNameOfFile("westberlin");
 
353
                source_file.setPathToFile("/osten/");
 
354
                source_file.setNativeIDType("Waters nativeID format");
 
355
                spec.setSourceFile(source_file);
 
356
 
 
357
                RichPeakSpectrum::FloatDataArray meta_data_array;
 
358
                meta_data_array.setName("icon");
 
359
                meta_data_array.setMetaValue ("icon", String("an icon is an icon is an icon"));
 
360
                meta_data_array.push_back(3.14f);
 
361
                meta_data_array.push_back(3.1f);
 
362
                meta_data_array.push_back(3.0f);
 
363
                spec.getFloatDataArrays().push_back(meta_data_array);
 
364
 
 
365
                // set acquisition info with 1 acquisition
 
366
                AcquisitionInfo info;
 
367
                info.setMethodOfCombination("combo");
 
368
                Acquisition acquisition;
 
369
                acquisition.setIdentifier("1");
 
370
                acquisition.setMetaValue ("icon", String("yet another icon"));
 
371
                info.push_back(acquisition);
 
372
 
 
373
                spec.setAcquisitionInfo(info);
 
374
 
 
375
                PeptideIdentification pei;
 
376
                PeptideHit peh;
 
377
                // first PeptideIdentification (+ 2 PeptideHits) for 1st Spectrum
 
378
                std::vector<PeptideIdentification> vec_pei;
 
379
                pei.setSignificanceThreshold(1.235);
 
380
                pei.setScoreType("ScoreType");
 
381
                pei.setHigherScoreBetter(true);
 
382
                std::vector<PeptideHit> vec_peh;
 
383
                peh.setScore(2.345);
 
384
                peh.setSequence("AACD");
 
385
                peh.setCharge(7);
 
386
                peh.setAABefore('b');
 
387
                peh.setAAAfter('c');
 
388
                vec_peh.push_back(peh);
 
389
                peh = PeptideHit();
 
390
                peh.setAABefore('d');
 
391
                peh.setAAAfter('e');
 
392
                vec_peh.push_back(peh);
 
393
                pei.setHits(vec_peh);
 
394
                vec_pei.push_back(pei);
 
395
 
 
396
                // second PeptideIdentification (+ no PeptideHits) for 1st Spectrum
 
397
                pei = PeptideIdentification();
 
398
                pei.setHigherScoreBetter(false);
 
399
                vec_pei.push_back(pei);
 
400
                spec.setPeptideIdentifications(vec_pei);
 
401
 
 
402
                exp_original.push_back(spec);
 
403
 
 
404
                //MSMS spectrum
 
405
                spec.clear(false);
 
406
                p.setIntensity(210.0f);
 
407
                p.getPosition()[0] = 100.155;
 
408
                spec.push_back(p);
 
409
                p.setIntensity(101.0f);
 
410
                p.getPosition()[0] = 150.25;
 
411
                spec.push_back(p);
 
412
                p.setIntensity(90.0f);
 
413
                p.getPosition()[0] = 300.5;
 
414
                spec.push_back(p);
 
415
                spec.setRT(3.96);
 
416
                spec.setMSLevel(2);
 
417
 
 
418
                DataProcessing dp;
 
419
                DateTime d;
 
420
                d.set("2006-12-12 00:00:00");
 
421
                dp.setCompletionTime(d);
 
422
                sw.setName("tolle software");
 
423
                sw.setVersion("alpha");
 
424
                sw.setMetaValue("label", String("echt"));
 
425
                dp.setSoftware(sw);
 
426
                spec.getDataProcessing().push_back(dp);
 
427
                dp.setCompletionTime(d);
 
428
                dp.getSoftware().setName("nicht so tolle software");
 
429
                dp.getSoftware().setVersion("alpha");
 
430
                dp.setMetaValue("label", String("prozessiert"));
 
431
                dp.getProcessingActions().insert(DataProcessing::ALIGNMENT);
 
432
                dp.getProcessingActions().insert(DataProcessing::SMOOTHING);
 
433
                spec.getDataProcessing().push_back(dp);
 
434
 
 
435
                //spectrum 2 gets 2 precursors
 
436
                spec.getPrecursors().resize(2);
 
437
                //1st precursor for spectrum 2
 
438
                spec.getPrecursors()[0].setMZ(600.1);
 
439
                spec.getPrecursors()[0].setIntensity(4711.0f);
 
440
                spec.getPrecursors()[0].setCharge(2);
 
441
                spec.getPrecursors()[0].setActivationEnergy(9.99);
 
442
                spec.getPrecursors()[0].setMetaValue("icon",String("Precursor1"));
 
443
                std::vector<Int> pcs;
 
444
                pcs.push_back(1);
 
445
                pcs.push_back(2);
 
446
                pcs.push_back(3);
 
447
                spec.getPrecursors()[0].setPossibleChargeStates(pcs);
 
448
                std::set<Precursor::ActivationMethod> am;
 
449
                am.insert(Precursor::LCID);
 
450
                am.insert(Precursor::CID);
 
451
                am.insert(Precursor::HCID);
 
452
                spec.getPrecursors()[0].setActivationMethods(am);
 
453
                spec.getFloatDataArrays().clear();
 
454
                //2nd precursor for spectrum 2
 
455
                spec.getPrecursors()[1].setMZ(600.1);
 
456
                spec.getPrecursors()[1].setIntensity(4711.0f);
 
457
                spec.getPrecursors()[1].setCharge(2);
 
458
                spec.getPrecursors()[1].setActivationEnergy(9.99);
 
459
                spec.getPrecursors()[1].setMetaValue("icon",String("Precursor2"));
 
460
                pcs[0]=(4);
 
461
                pcs[1]=(5);
 
462
                pcs[2]=(6);
 
463
                spec.getPrecursors()[1].setPossibleChargeStates(pcs);
 
464
                am.erase(Precursor::CID);
 
465
                spec.getPrecursors()[1].setActivationMethods(am);
 
466
                spec.setComment("bla");
 
467
                spec.getFloatDataArrays().clear();
 
468
 
 
469
                // set empty AcquisitionInfo for spectrum 2
 
470
                spec.setAcquisitionInfo(AcquisitionInfo());
 
471
 
 
472
                exp_original.push_back(spec);
 
473
 
 
474
                //meta info
 
475
                exp_original.setMetaValue("label",5.55);
 
476
                exp_original.setMetaValue("icon",String("MSExperiment"));
 
477
                exp_original.setMetaValue("color",5);
 
478
                exp_original[0].setMetaValue("icon",String("Spectrum1"));
 
479
                exp_original[1].setMetaValue("icon",String("Spectrum2"));
 
480
 
 
481
                // to store the id of reading and writing
 
482
                UID tmp_id,spec_tmp_id,tmp_id2,spec_tmp_id2;
 
483
 
 
484
                // create a Peak1D experiment (raw data)
 
485
                // Peak1Ds are no MetaInfoInterfaces --> peak meta data should not be
 
486
                // tried to be stored in DB
 
487
                MSExperiment<Peak1D> exp_peak1d;
 
488
                MSSpectrum<Peak1D> spec_peak1d;
 
489
                Peak1D peak1d;
 
490
 
 
491
                peak1d.setIntensity(565.0f);
 
492
                peak1d.getPosition()[0] = 600.1;
 
493
                spec_peak1d.push_back(peak1d);
 
494
                peak1d.setIntensity(620.0f);
 
495
                peak1d.getPosition()[0] = 700.1;
 
496
                spec_peak1d.push_back(peak1d);
 
497
                peak1d.setIntensity(701.0f);
 
498
                peak1d.getPosition()[0] = 800.1;
 
499
                spec_peak1d.push_back(peak1d);
 
500
                spec_peak1d.setRT(1.98);
 
501
                spec_peak1d.setMSLevel(1);
 
502
 
 
503
                exp_peak1d.push_back(spec_peak1d);
 
504
 
 
505
                // save newly created experiments - should be added to database.
 
506
                // success is implicitly checked later when loading from database.
 
507
        START_SECTION((template<class ExperimentType> void storeExperiment(ExperimentType& exp)))
 
508
          DBAdapter a(con);
 
509
          a.storeExperiment(exp_original);
 
510
          a.storeExperiment(exp_peak1d);
 
511
                tmp_id = exp_original.getPersistenceId();
 
512
                tmp_id2 = exp_peak1d.getPersistenceId();
 
513
                spec_tmp_id = exp_original[0].getPersistenceId();
 
514
                spec_tmp_id2 = exp_peak1d[0].getPersistenceId();
 
515
                QSqlQuery result = con.executeQuery("SELECT id FROM META_MSExperiment");
 
516
          TEST_EQUAL(result.size(),2)
 
517
END_SECTION
 
518
 
 
519
        // add another experiment to the database (for TOPPView tests etc.)
 
520
        DBAdapter a(con);
 
521
        RichPeakMap exp_2;
 
522
        FileHandler fh;
 
523
        fh.loadExperiment(OPENMS_GET_TEST_DATA_PATH("SimpleExtender_test.mzData"), exp_2);
 
524
        a.storeExperiment(exp_2);
 
525
 
 
526
 
 
527
        // check if first spectrum of the first saved experiment can be loaded correctly
 
528
        START_SECTION((template <class SpectrumType> void loadSpectrum(UID id, SpectrumType &spec)))
 
529
                DBAdapter a(con);
 
530
                DBAdapter a2(con2);
 
531
 
 
532
                        RichPeakSpectrum spec;
 
533
                        a.loadSpectrum(spec_tmp_id, spec);
 
534
 
 
535
                  TEST_EQUAL( spec.getRT() , exp_original.begin()->getRT() )
 
536
                        TEST_EQUAL( spec.getMSLevel() , exp_original.begin()->getMSLevel() )
 
537
                        TEST_EQUAL( spec.size() , exp_original.begin()->size() )
 
538
                        TEST_EQUAL( spec.getInstrumentSettings().getScanWindows().size(),1)
 
539
                        TEST_REAL_SIMILAR( spec.getInstrumentSettings().getScanWindows()[0].begin , exp_original.begin()->getInstrumentSettings().getScanWindows()[0].begin )
 
540
                        TEST_REAL_SIMILAR( spec.getInstrumentSettings().getScanWindows()[0].end , exp_original.begin()->getInstrumentSettings().getScanWindows()[0].end )
 
541
                        TEST_EQUAL( spec.getInstrumentSettings().getPolarity() , exp_original.begin()->getInstrumentSettings().getPolarity() )
 
542
                        TEST_EQUAL( spec.getInstrumentSettings().getScanMode() , exp_original.begin()->getInstrumentSettings().getScanMode() )
 
543
                        TEST_EQUAL( spec.getInstrumentSettings().getZoomScan() , exp_original.begin()->getInstrumentSettings().getZoomScan() )
 
544
                        TEST_EQUAL( spec.getInstrumentSettings().getScanWindows()[0].getMetaValue("metavalue") , exp_original.begin()->getInstrumentSettings().getScanWindows()[0].getMetaValue("metavalue"))
 
545
                        for(Size ps = 0; ps < spec.getProducts().size(); ++ps)
 
546
                        {
 
547
                                TEST_EQUAL( spec.getProducts()[ps].getMZ() , exp_original.begin()->getProducts()[ps].getMZ() )
 
548
                                TEST_EQUAL( spec.getProducts()[ps].getIsolationWindowLowerOffset() , exp_original.begin()->getProducts()[ps].getIsolationWindowLowerOffset() )
 
549
                                TEST_EQUAL( spec.getProducts()[ps].getIsolationWindowUpperOffset() , exp_original.begin()->getProducts()[ps].getIsolationWindowUpperOffset() )
 
550
                                TEST_EQUAL( spec.getProducts()[ps].getMetaValue("farbe") , exp_original.begin()->getProducts()[ps].getMetaValue("farbe"))
 
551
                        }
 
552
                        TEST_EQUAL( spec.getAcquisitionInfo().getMethodOfCombination(), "combo");
 
553
                        // and how do we check  info.setSpectrumType("type"); ?
 
554
                        TEST_EQUAL( spec.getAcquisitionInfo()[0].getIdentifier(), "1");
 
555
                        TEST_EQUAL( spec.getAcquisitionInfo()[0].getMetaValue("icon"), "yet another icon");
 
556
 
 
557
                        TEST_EQUAL( spec.getSourceFile().getNameOfFile() , exp_original.begin()->getSourceFile().getNameOfFile() )
 
558
                        TEST_EQUAL( spec.getSourceFile().getPathToFile() , exp_original.begin()->getSourceFile().getPathToFile() )
 
559
                        TEST_EQUAL( spec.getSourceFile().getNativeIDType() , exp_original.begin()->getSourceFile().getNativeIDType())
 
560
                        TEST_EQUAL( spec.getSourceFile().getChecksum() , exp_original.begin()->getSourceFile().getChecksum() )
 
561
 
 
562
                        // make sure storing/loading of meta data works for RichPeaks
 
563
                        TEST_EQUAL( spec[0].getMetaValue("label"), "peaklabel");
 
564
 
 
565
                        RichPeakSpectrum::FloatDataArrays& meta_data_arrays = spec.getFloatDataArrays();
 
566
                        TEST_STRING_EQUAL( meta_data_arrays[0].getName(),"icon")
 
567
                        TEST_EQUAL( meta_data_arrays[0].getMetaValue("icon"), "an icon is an icon is an icon" )
 
568
                        TEST_REAL_SIMILAR( meta_data_arrays[0][0], 3.14 )
 
569
                        TEST_REAL_SIMILAR( meta_data_arrays[0][1], 3.1 )
 
570
                        TEST_REAL_SIMILAR( meta_data_arrays[0][2], 3 )
 
571
 
 
572
 
 
573
                        TEST_EQUAL( spec.getSourceFile().getNameOfFile(), "westberlin" )
 
574
                        TEST_EQUAL( spec.getSourceFile().getPathToFile(), "/osten/" )
 
575
 
 
576
                        for (Size i=0; i<3; ++i)
 
577
                        {
 
578
                                TEST_REAL_SIMILAR( spec[i].getIntensity() , exp_original.begin()->operator[](i).getIntensity() )
 
579
                                TEST_REAL_SIMILAR( spec[i].getPosition()[0] , exp_original.begin()->operator[](i).getPosition()[0] )
 
580
                        }
 
581
 
 
582
                        PeakFileOptions options;
 
583
                        options.setIntensityRange(DRange<1> (600, 1000));
 
584
                        a.getOptions() = options;
 
585
                        a.loadSpectrum(spec_tmp_id, spec);
 
586
 
 
587
                        // check if the Intensity restriction worked - first peak (565) should have been skipped
 
588
                        TEST_REAL_SIMILAR( spec[0].getIntensity() , 620 )
 
589
                        TEST_REAL_SIMILAR( spec[1].getIntensity() , 701 )
 
590
 
 
591
                        options = PeakFileOptions();
 
592
                        options.setMZRange(DRange<1> (650, 1000));
 
593
                        a.getOptions() = options;
 
594
                        a.loadSpectrum(spec_tmp_id, spec);
 
595
 
 
596
                        // check if the MZ restriction worked - first peak (600.1) should have been skipped
 
597
                        TEST_REAL_SIMILAR( spec[0].getPosition()[0] , 700.1 )
 
598
                        TEST_REAL_SIMILAR( spec[1].getPosition()[0] , 800.1 )
 
599
 
 
600
                        // testing concurrent DB connections
 
601
                        a2.loadSpectrum(spec_tmp_id, spec);
 
602
                        TEST_REAL_SIMILAR( spec[0].getIntensity() , 565 )
 
603
END_SECTION
 
604
 
 
605
        // load first two experiments from database
 
606
        // (this implicitly checks if the new experiments were stored correctly)
 
607
        START_SECTION((template <class ExperimentType> void loadExperiment(UID id, ExperimentType &exp)))
 
608
                  DBAdapter a(con);
 
609
                  RichPeakMap exp_new;
 
610
                  std::map<String, MetaInfoDescription> descriptions;
 
611
 
 
612
                        a.loadExperiment(tmp_id, exp_new);
 
613
                        TEST_EQUAL(exp_new.getPersistenceId(), tmp_id)
 
614
                        TEST_EQUAL(exp_new.getComment() , "bla" )
 
615
 
 
616
                        TEST_EQUAL(exp_new.getSample().getName(), "fruity loops" )
 
617
                        TEST_EQUAL(exp_new.getSample().getNumber(), "007" )
 
618
                        TEST_REAL_SIMILAR(exp_new.getSample().getMass(), 30.1 )
 
619
                        TEST_REAL_SIMILAR(exp_new.getSample().getSubsamples()[0].getVolume(), 60.1 )
 
620
                        TEST_REAL_SIMILAR(exp_new.getSample().getSubsamples()[0].getConcentration(), 101.1 )
 
621
                        const Digestion* digestion = dynamic_cast<const Digestion*>(&exp_new.getSample().getSubsamples()[0].getTreatment(0));
 
622
                        TEST_EQUAL(digestion->getEnzyme(), "dhdh" )
 
623
                        TEST_REAL_SIMILAR(digestion->getDigestionTime(), 36.6 )
 
624
                        TEST_REAL_SIMILAR(digestion->getPh(), 7.2 )
 
625
                        TEST_REAL_SIMILAR(digestion->getTemperature(), 37.7 )
 
626
 
 
627
                        //test for products
 
628
 
 
629
                        TEST_EQUAL(exp_new.getProteinIdentifications()[0].getSearchEngine(), "google" )
 
630
                        TEST_EQUAL(exp_new.getProteinIdentifications()[0].getSearchEngineVersion(), "beta" )
 
631
                        TEST_EQUAL(exp_new.getProteinIdentifications()[0].getDateTime().get(), "2006-12-12 00:00:00" )
 
632
                        TEST_EQUAL(exp_new.getProteinIdentifications()[0].getScoreType(), "Type" )
 
633
                        TEST_EQUAL(exp_new.getProteinIdentifications()[0].isHigherScoreBetter(), true )
 
634
                        TEST_REAL_SIMILAR(exp_new.getProteinIdentifications()[0].getSignificanceThreshold(), 3.456 )
 
635
                        TEST_EQUAL(exp_new.getProteinIdentifications()[0].getHits()[0].getAccession(), "0110110" )
 
636
                        TEST_REAL_SIMILAR(exp_new.getProteinIdentifications()[0].getHits()[1].getScore(), 4.567 )
 
637
                        TEST_EQUAL(exp_new.getProteinIdentifications()[0].getHits()[1].getAccession(), "1001001" )
 
638
                        TEST_EQUAL(exp_new.getProteinIdentifications()[0].getHits()[1].getSequence(), "ZXY" )
 
639
 
 
640
                        TEST_REAL_SIMILAR(exp_new[0].getPeptideIdentifications()[0].getSignificanceThreshold(), 1.235 )
 
641
                        TEST_EQUAL(exp_new[0].getPeptideIdentifications()[0].getScoreType(), "ScoreType" )
 
642
                        TEST_EQUAL(exp_new[0].getPeptideIdentifications()[0].isHigherScoreBetter(), true )
 
643
// needs getter and setter methods first
 
644
//                      TEST_EQUAL(exp_new[0].getPeptideIdentifications()[0].getSourceFile().getNameOfFile(), "testberlin" )
 
645
//                      TEST_EQUAL(exp_new[0].getPeptideIdentifications()[0].getSourceFile().getPathToFile(), "/testen/" )
 
646
                        TEST_EQUAL(exp_new[0].getPeptideIdentifications()[1].isHigherScoreBetter(), false )
 
647
 
 
648
                        TEST_REAL_SIMILAR(exp_new[0].getPeptideIdentifications()[0].getHits()[0].getScore(), 2.345 )
 
649
                        TEST_EQUAL(exp_new[0].getPeptideIdentifications()[0].getHits()[0].getSequence(), "AACD" )
 
650
                        TEST_EQUAL(exp_new[0].getPeptideIdentifications()[0].getHits()[0].getCharge(), 7 )
 
651
                        TEST_EQUAL(exp_new[0].getPeptideIdentifications()[0].getHits()[0].getAABefore(), 'b' )
 
652
                        TEST_EQUAL(exp_new[0].getPeptideIdentifications()[0].getHits()[0].getAAAfter(), 'c' )
 
653
                        TEST_EQUAL(exp_new[0].getPeptideIdentifications()[0].getHits()[1].getAABefore(), 'd' )
 
654
                        TEST_EQUAL(exp_new[0].getPeptideIdentifications()[0].getHits()[1].getAAAfter(), 'e' )
 
655
 
 
656
 
 
657
                        TEST_EQUAL(exp_new.getProteinIdentifications()[0].getMetaValue("label"), exp_original.getProteinIdentifications()[0].getMetaValue("label"))
 
658
 
 
659
                TEST_EQUAL(exp_new.getProteinIdentifications()[0].getSearchParameters().db, exp_original.getProteinIdentifications()[0].getSearchParameters().db)
 
660
                TEST_EQUAL(exp_new.getProteinIdentifications()[0].getSearchParameters().db_version, exp_original.getProteinIdentifications()[0].getSearchParameters().db_version)
 
661
                TEST_EQUAL(exp_new.getProteinIdentifications()[0].getSearchParameters().taxonomy, exp_original.getProteinIdentifications()[0].getSearchParameters().taxonomy)
 
662
                TEST_EQUAL(exp_new.getProteinIdentifications()[0].getSearchParameters().charges, exp_original.getProteinIdentifications()[0].getSearchParameters().charges)
 
663
                TEST_EQUAL(exp_new.getProteinIdentifications()[0].getSearchParameters().mass_type, exp_original.getProteinIdentifications()[0].getSearchParameters().mass_type)
 
664
                TEST_EQUAL(exp_new.getProteinIdentifications()[0].getSearchParameters().enzyme, exp_original.getProteinIdentifications()[0].getSearchParameters().enzyme)
 
665
                TEST_EQUAL(exp_new.getProteinIdentifications()[0].getSearchParameters().missed_cleavages, exp_original.getProteinIdentifications()[0].getSearchParameters().missed_cleavages)
 
666
                TEST_EQUAL(exp_new.getProteinIdentifications()[0].getSearchParameters().peak_mass_tolerance, exp_original.getProteinIdentifications()[0].getSearchParameters().peak_mass_tolerance)
 
667
                TEST_EQUAL(exp_new.getProteinIdentifications()[0].getSearchParameters().precursor_tolerance, exp_original.getProteinIdentifications()[0].getSearchParameters().precursor_tolerance)
 
668
                TEST_EQUAL(exp_new.getProteinIdentifications()[0].getSearchParameters().getMetaValue("label"), exp_original.getProteinIdentifications()[0].getSearchParameters().getMetaValue("label"))
 
669
 
 
670
                TEST_EQUAL(exp_new.getProteinIdentifications()[0].getSearchParameters().fixed_modifications.size(), exp_original.getProteinIdentifications()[0].getSearchParameters().fixed_modifications.size())
 
671
                for(Size i = 0; i < exp_original.getProteinIdentifications()[0].getSearchParameters().fixed_modifications.size(); ++i)
 
672
                {
 
673
                        TEST_EQUAL(exp_new.getProteinIdentifications()[0].getSearchParameters().fixed_modifications[i], exp_original.getProteinIdentifications()[0].getSearchParameters().fixed_modifications[i])
 
674
                }
 
675
                TEST_EQUAL(exp_new.getProteinIdentifications()[0].getSearchParameters().variable_modifications.size(), exp_original.getProteinIdentifications()[0].getSearchParameters().variable_modifications.size())
 
676
                for(Size i = 0; i < exp_original.getProteinIdentifications()[0].getSearchParameters().variable_modifications.size(); ++i)
 
677
                {
 
678
                        TEST_EQUAL(exp_new.getProteinIdentifications()[0].getSearchParameters().variable_modifications[i], exp_original.getProteinIdentifications()[0].getSearchParameters().variable_modifications[i])
 
679
                }
 
680
 
 
681
 
 
682
                        TEST_EQUAL(exp_new.getSample().getSubsamples()[1].getState(), Sample::GAS )
 
683
                        TEST_EQUAL(exp_new.getSample().getSubsamples()[1].getOrganism(), "isistius brasiliensis (cookiecutter shar" )
 
684
                        const Modification* modification = dynamic_cast<const Modification*>(&exp_new.getSample().getSubsamples()[1].getTreatment(0));
 
685
                        TEST_EQUAL(modification->getReagentName(), "reagent" )
 
686
                        TEST_EQUAL(modification->getAffectedAminoAcids(), "123" )
 
687
                        TEST_EQUAL(modification->getSpecificityType(), Modification::CTERM )
 
688
                        TEST_REAL_SIMILAR(modification->getMass(), 12.3 )
 
689
                        const Tagging* tagging = dynamic_cast<const Tagging*>(&exp_new.getSample().getSubsamples()[1].getTreatment(1));
 
690
                        TEST_EQUAL(tagging->getReagentName(), "tagging" )
 
691
                        TEST_REAL_SIMILAR(tagging->getMassShift(), 0.123 )
 
692
                        TEST_EQUAL(tagging->getVariant(), Tagging::HEAVY )
 
693
 
 
694
                        TEST_EQUAL(exp_new.getSample().getSubsamples()[2].getComment(), "nice" )
 
695
                        TEST_EQUAL(exp_new.getSample().getSubsamples()[2].getMetaValue("label"), "pink" )
 
696
 
 
697
                        TEST_EQUAL(exp_new.getContacts()[0].getFirstName() , "Ferdinand" )
 
698
                        TEST_EQUAL(exp_new.getContacts()[0].getLastName() , "Piech" )
 
699
                        TEST_EQUAL(exp_new.getContacts()[0].getInstitution() , "aff" )
 
700
                        TEST_EQUAL(exp_new.getContacts()[1].getEmail() , "ferdi@porsche.de" )
 
701
                        TEST_EQUAL(exp_new.getContacts()[1].getContactInfo() , "ttss" )
 
702
                        TEST_EQUAL(exp_new.getContacts()[1].getMetaValue("label") , "polka-dotted" )
 
703
 
 
704
                        TEST_EQUAL(exp_new.getHPLC().getInstrument() , "guitar" )
 
705
                        TEST_EQUAL(exp_new.getHPLC().getColumn() , "bigone" )
 
706
                        TEST_EQUAL(exp_new.getHPLC().getComment() , "fhth" )
 
707
                        TEST_EQUAL(exp_new.getHPLC().getFlux() , 1 )
 
708
                        TEST_EQUAL(exp_new.getHPLC().getPressure() , 2 )
 
709
                        TEST_EQUAL(exp_new.getHPLC().getTemperature() , 3 )
 
710
 
 
711
                        TEST_EQUAL(exp_new.getHPLC().getGradient().getPercentages()[0][0] , 20 )
 
712
                        TEST_EQUAL(exp_new.getHPLC().getGradient().getPercentages()[0][1] , 40 )
 
713
                        TEST_EQUAL(exp_new.getHPLC().getGradient().getPercentages()[0][2] , 60 )
 
714
                        TEST_EQUAL(exp_new.getHPLC().getGradient().getPercentages()[1][0] , 80 )
 
715
                        TEST_EQUAL(exp_new.getHPLC().getGradient().getPercentages()[1][1] , 60 )
 
716
                        TEST_EQUAL(exp_new.getHPLC().getGradient().getPercentages()[1][2] , 40 )
 
717
                        TEST_EQUAL(exp_new.getHPLC().getGradient().getEluents()[0] , "C2H5OH" )
 
718
                        TEST_EQUAL(exp_new.getHPLC().getGradient().getEluents()[1] , "H2O" )
 
719
                        TEST_EQUAL(exp_new.getHPLC().getGradient().getTimepoints()[0] , 1 )
 
720
                        TEST_EQUAL(exp_new.getHPLC().getGradient().getTimepoints()[1] , 5 )
 
721
                        TEST_EQUAL(exp_new.getHPLC().getGradient().getTimepoints()[2] , 7 )
 
722
 
 
723
                        TEST_EQUAL(exp_new.getInstrument().getSoftware().getName() , exp_original.getInstrument().getSoftware().getName() )
 
724
                        TEST_EQUAL(exp_new.getInstrument().getSoftware().getVersion() , exp_original.getInstrument().getSoftware().getVersion() )
 
725
                        TEST_EQUAL(exp_new.getInstrument().getSoftware().getMetaValue("label") , exp_original.getInstrument().getSoftware().getMetaValue("label") )
 
726
 
 
727
                        TEST_EQUAL(exp_new.getInstrument().getModel() , "Porsche 911" )
 
728
                        TEST_EQUAL(exp_new.getInstrument().getVendor() , "Porsche K.G. Zuffenhausen" )
 
729
                        TEST_EQUAL(exp_new.getInstrument().getCustomizations() , "340 PS" )
 
730
                        TEST_EQUAL(exp_new.getInstrument().getMetaValue("label") , "red" )
 
731
                        TEST_EQUAL(exp_new.getInstrument().getIonDetectors().size(),1)
 
732
                        TEST_EQUAL(exp_new.getInstrument().getIonDetectors()[0].getType() , IonDetector::PHOTOMULTIPLIER )
 
733
                        TEST_EQUAL(exp_new.getInstrument().getIonDetectors()[0].getAcquisitionMode() , IonDetector::PULSECOUNTING )
 
734
                        TEST_REAL_SIMILAR(exp_new.getInstrument().getIonDetectors()[0].getResolution() , 6.7677 )
 
735
                        TEST_REAL_SIMILAR(exp_new.getInstrument().getIonDetectors()[0].getADCSamplingFrequency() , 7.6766 )
 
736
                        TEST_EQUAL(exp_new.getInstrument().getIonDetectors()[0].getMetaValue("label") , "black" )
 
737
                        TEST_EQUAL(exp_new.getInstrument().getIonDetectors()[0].getOrder(), 3)
 
738
                        TEST_EQUAL(exp_new.getInstrument().getIonSources()[0].getOrder(), 0)
 
739
                        TEST_EQUAL(exp_new.getInstrument().getIonSources().size(),1)
 
740
                        TEST_EQUAL(exp_new.getInstrument().getIonSources()[0].getInletType() , IonSource::DIRECT )
 
741
                        TEST_EQUAL(exp_new.getInstrument().getIonSources()[0].getIonizationMethod() , IonSource::ESI )
 
742
                        TEST_EQUAL(exp_new.getInstrument().getIonSources()[0].getPolarity() , IonSource::POSITIVE )
 
743
                        TEST_EQUAL(exp_new.getInstrument().getIonSources()[0].getMetaValue("label") , "blue" )
 
744
 
 
745
                        TEST_REAL_SIMILAR(exp_new.getInstrument().getMassAnalyzers()[0].getAccuracy() , 1.2687 )
 
746
                        TEST_EQUAL(exp_new.getInstrument().getMassAnalyzers()[0].getFinalMSExponent() , 8 )
 
747
                        TEST_REAL_SIMILAR(exp_new.getInstrument().getMassAnalyzers()[0].getIsolationWidth() , 8.456 )
 
748
                        TEST_REAL_SIMILAR(exp_new.getInstrument().getMassAnalyzers()[0].getMagneticFieldStrength() , 9.999 )
 
749
                        TEST_EQUAL(exp_new.getInstrument().getMassAnalyzers()[0].getReflectronState() , MassAnalyzer::NONE )
 
750
                        TEST_REAL_SIMILAR(exp_new.getInstrument().getMassAnalyzers()[0].getResolution() , 7.444 )
 
751
                        TEST_EQUAL(exp_new.getInstrument().getMassAnalyzers()[0].getResolutionMethod() , MassAnalyzer::FWHM )
 
752
                        TEST_EQUAL(exp_new.getInstrument().getMassAnalyzers()[0].getResolutionType() , MassAnalyzer::CONSTANT )
 
753
                        TEST_EQUAL(exp_new.getInstrument().getMassAnalyzers()[0].getOrder() , 1 )
 
754
                        TEST_EQUAL(exp_new.getInstrument().getMassAnalyzers()[1].getScanDirection() , MassAnalyzer::UP )
 
755
                        TEST_EQUAL(exp_new.getInstrument().getMassAnalyzers()[1].getScanLaw() , MassAnalyzer::LINEAR )
 
756
                        TEST_REAL_SIMILAR(exp_new.getInstrument().getMassAnalyzers()[1].getScanRate() , 5.555 )
 
757
                        TEST_REAL_SIMILAR(exp_new.getInstrument().getMassAnalyzers()[1].getScanTime() , 6.666 )
 
758
                        TEST_REAL_SIMILAR(exp_new.getInstrument().getMassAnalyzers()[1].getTOFTotalPathLength() , 7.777 )
 
759
                        TEST_EQUAL(exp_new.getInstrument().getMassAnalyzers()[1].getType() , MassAnalyzer::TOF )
 
760
                        TEST_EQUAL(exp_new.getInstrument().getMassAnalyzers()[1].getMetaValue("label") , "pink" )
 
761
                        TEST_EQUAL(exp_new.getInstrument().getMassAnalyzers()[1].getOrder() , 2 )
 
762
 
 
763
                        TEST_EQUAL(exp_new.getInstrument().getIonOptics() , Instrument::FRINGING_FIELD )
 
764
 
 
765
                        //------ test if values are correct ------
 
766
 
 
767
                        //SPECTRUM 1
 
768
                        RichPeakMap::const_iterator itn(exp_new.begin());
 
769
                        RichPeakMap::const_iterator ito(exp_original.begin());
 
770
 
 
771
                  TEST_EQUAL( itn->getRT() , ito->getRT() )
 
772
                        TEST_EQUAL( itn->getMSLevel() , ito->getMSLevel() )
 
773
                        TEST_EQUAL( itn->size() , ito->size() )
 
774
                        for (Size i=0; i<3; ++i)
 
775
                        {
 
776
                                TEST_REAL_SIMILAR( itn->operator[](i).getIntensity() , ito->operator[](i).getIntensity() )
 
777
                                TEST_REAL_SIMILAR( itn->operator[](i).getPosition()[0] , ito->operator[](i).getPosition()[0] )
 
778
                        }
 
779
                        //~ TEST_EQUAL( itn->getPrecursors()[0].getMetaValue("icon") , "Precursor" )
 
780
 
 
781
 
 
782
 
 
783
                        TEST_EQUAL(itn->getDataProcessing().size(), ito->getDataProcessing().size())
 
784
                        for (Size i=0; i<itn->getDataProcessing().size(); ++i)
 
785
                        {
 
786
                                TEST_EQUAL(itn->getDataProcessing()[i].getSoftware().getName(), ito->getDataProcessing()[i].getSoftware().getName())
 
787
                                TEST_EQUAL(itn->getDataProcessing()[i].getSoftware().getVersion(), ito->getDataProcessing()[i].getSoftware().getVersion())
 
788
                                TEST_EQUAL(itn->getDataProcessing()[i].getCompletionTime().get(), ito->getDataProcessing()[i].getCompletionTime().get())
 
789
                                TEST_EQUAL(itn->getDataProcessing()[i].getMetaValue("label"), ito->getDataProcessing()[i].getMetaValue("label"))
 
790
                                TEST_EQUAL(itn->getDataProcessing()[i].getProcessingActions().size(), ito->getDataProcessing()[i].getProcessingActions().size())
 
791
                                std::set< DataProcessing::ProcessingAction >::const_iterator set_it_original, set_it_new;
 
792
                                set_it_new = (itn->getDataProcessing()[i].getProcessingActions()).begin();
 
793
                                set_it_original = ito->getDataProcessing()[i].getProcessingActions().begin();
 
794
                                for (set_it_new=set_it_new; set_it_new!=itn->getDataProcessing()[i].getProcessingActions().end() && set_it_original!=ito->getDataProcessing()[i].getProcessingActions().end() ; (++set_it_new), (++set_it_original))
 
795
                                {
 
796
                                        TEST_EQUAL(*set_it_new, *set_it_original)
 
797
                                }
 
798
                        }
 
799
 
 
800
                        //SPECTRUM 2
 
801
                        ++itn;
 
802
                        ++ito;
 
803
 
 
804
                  TEST_EQUAL( itn->getRT() , ito->getRT() )
 
805
                        TEST_EQUAL( itn->getMSLevel() , ito->getMSLevel() )
 
806
 
 
807
                        TEST_EQUAL( itn->getPrecursors().size() , ito->getPrecursors().size() )
 
808
                        for(Size i = 0; i < itn->getPrecursors().size(); ++i)
 
809
                        {
 
810
                                TEST_EQUAL( itn->getPrecursors()[i].getMZ() , ito->getPrecursors()[i].getMZ() )
 
811
                                TEST_EQUAL( itn->getPrecursors()[i].getIntensity() , ito->getPrecursors()[i].getIntensity() )
 
812
                                TEST_EQUAL( itn->getPrecursors()[i].getCharge() , ito->getPrecursors()[i].getCharge() )
 
813
                                TEST_EQUAL( itn->getPrecursors()[i].getActivationEnergy() , ito->getPrecursors()[i].getActivationEnergy() )
 
814
                                TEST_EQUAL( itn->getPrecursors()[i].getMetaValue("icon") , ito->getPrecursors()[i].getMetaValue("icon") )
 
815
                                TEST_EQUAL( itn->getPrecursors()[i].getPossibleChargeStates().size() , ito->getPrecursors()[i].getPossibleChargeStates().size() )
 
816
                                for (Size j=0; j<itn->getPrecursors()[i].getPossibleChargeStates().size(); ++j)
 
817
                                {
 
818
                                        TEST_EQUAL( itn->getPrecursors()[i].getPossibleChargeStates()[j] , ito->getPrecursors()[i].getPossibleChargeStates()[j] )
 
819
                                }
 
820
                                TEST_EQUAL( itn->getPrecursors()[i].getActivationMethods().size() , ito->getPrecursors()[i].getActivationMethods().size() )
 
821
                                for ( std::set<Precursor::ActivationMethod>::const_iterator amn_it(itn->getPrecursors()[i].getActivationMethods().begin()), amo_it(ito->getPrecursors()[i].getActivationMethods().begin()); amn_it != itn->getPrecursors()[i].getActivationMethods().end(); ++amn_it,++amo_it)
 
822
                                {
 
823
                                        TEST_EQUAL( *amn_it , *amo_it )
 
824
                                }
 
825
                        }
 
826
 
 
827
                        TEST_EQUAL( itn->getComment() , "bla" )
 
828
                        TEST_EQUAL( itn->size() , ito->size() )
 
829
                        for (Size i=0; i<3; ++i)
 
830
                        {
 
831
                                TEST_REAL_SIMILAR( itn->operator[](i).getIntensity() , ito->operator[](i).getIntensity() )
 
832
                                TEST_REAL_SIMILAR( itn->operator[](i).getPosition()[0] , ito->operator[](i).getPosition()[0] )
 
833
                        }
 
834
 
 
835
                        //META INFO
 
836
                        TEST_REAL_SIMILAR((double)exp_new.getMetaValue("label"),5.55)
 
837
                        TEST_EQUAL((string)exp_new.getMetaValue("icon"),"MSExperiment")
 
838
                        TEST_EQUAL((int)exp_new.getMetaValue("color"),5)
 
839
                        TEST_EQUAL((string)exp_new[0].getMetaValue("icon"),"Spectrum1")
 
840
                        TEST_EQUAL((string)exp_new[1].getMetaValue("icon"),"Spectrum2")
 
841
 
 
842
                        exp_new = RichPeakMap();
 
843
                        PeakFileOptions options;
 
844
                        options = PeakFileOptions();
 
845
                        options.setRTRange(DRange<1> (2.5, 4.5));
 
846
                        a.getOptions() = options;
 
847
                        a.loadExperiment(tmp_id, exp_new);
 
848
 
 
849
                        // check if the RT restriction worked - first spectrum should have been skipped
 
850
                        TEST_REAL_SIMILAR( exp_new[0][0].getPosition()[0] , 100.155 )
 
851
 
 
852
                        exp_new = RichPeakMap();
 
853
                        options = PeakFileOptions();
 
854
                        std::vector<int> levels;
 
855
                        levels.push_back(2);
 
856
                        options.setMSLevels(levels);
 
857
                        a.getOptions() = options;
 
858
                        a.loadExperiment(tmp_id, exp_new);
 
859
 
 
860
                        // check if the MSLevel restriction worked - first spectrum should have been skipped
 
861
                        TEST_REAL_SIMILAR( exp_new[0][0].getPosition()[0] , 100.155 )
 
862
END_SECTION
 
863
 
 
864
                // save modified version of already existing experiment - old records should be updated.
 
865
                // no checks are run, results are implicitly checked later when loading
 
866
                START_SECTION([EXTRA] updating of an existing dataset)
 
867
                        exp_original.setComment("blubb");
 
868
 
 
869
                        // modify first spectrum
 
870
                        RichPeakMap::SpectrumType & modified_spec = exp_original[0];
 
871
                        modified_spec[0].setIntensity(566.0f);
 
872
                        modified_spec[0].getPosition()[0] = 612.1;
 
873
                        modified_spec[1].setIntensity(620.0f);
 
874
                        modified_spec[1].getPosition()[0] = 712.1;
 
875
                        modified_spec[2].setIntensity(701.0f);
 
876
                        modified_spec[2].getPosition()[0] = 812.1;
 
877
                        modified_spec.setRT(1.88);
 
878
                        modified_spec.setMSLevel(1);
 
879
                        modified_spec.getInstrumentSettings().getScanWindows()[0].begin = 3.567;
 
880
                        modified_spec.getInstrumentSettings().getScanWindows()[0].end = 7.91;
 
881
                        modified_spec.getInstrumentSettings().setPolarity(IonSource::POSITIVE);
 
882
                        modified_spec.getInstrumentSettings().setScanMode(InstrumentSettings::SIM);
 
883
                        modified_spec.getInstrumentSettings().setZoomScan(false);
 
884
                        modified_spec.getInstrumentSettings().setMetaValue("label", String("please bite here"));
 
885
 
 
886
                        modified_spec.getProducts()[1].setMZ(5);
 
887
                        modified_spec.getProducts()[1].setIsolationWindowLowerOffset(6);
 
888
                        modified_spec.getProducts()[1].setIsolationWindowUpperOffset(7);
 
889
                        modified_spec.getProducts()[1].setMetaValue("farbe", String("erbrochengruengelb"));
 
890
 
 
891
                        info.clear();
 
892
                        acquisition.setIdentifier("1");
 
893
                        acquisition.setMetaValue ("icon", String("one more icon"));
 
894
                        info.push_back(acquisition);
 
895
                        acquisition.setIdentifier("2");
 
896
                        acquisition.setMetaValue ("label", String("yet another label"));
 
897
                        info.push_back(acquisition);
 
898
 
 
899
                        modified_spec.setAcquisitionInfo(info);
 
900
                        // adding a meta data array
 
901
                        modified_spec.getFloatDataArrays().clear();
 
902
                        RichPeakSpectrum::FloatDataArray meta_data_array;
 
903
                        meta_data_array.setName("icon");
 
904
                        meta_data_array.push_back(23.0f);
 
905
                        meta_data_array.push_back(42.0f);
 
906
                        meta_data_array.push_back(100.001f);
 
907
 
 
908
                        modified_spec.getFloatDataArrays().push_back(meta_data_array);
 
909
 
 
910
 
 
911
                        // modify 2nd spectrum
 
912
                        exp_original[1].getPrecursors()[0].setMetaValue("icon", String("NewPrecursor"));
 
913
 
 
914
                        // update others
 
915
                        exp_original.getProteinIdentifications()[0].getHits()[1].setRank( 5u );
 
916
                        exp_original.getInstrument().getMassAnalyzers()[0].setOrder(2);
 
917
                        exp_original.getInstrument().getMassAnalyzers()[1].setOrder(3);
 
918
                        exp_original.getInstrument().getIonDetectors()[0].setOrder(4);
 
919
                        exp_original.getInstrument().getIonSources()[0].setOrder(1);
 
920
                        exp_original.getInstrument().setIonOptics(Instrument::EINZEL_LENS);
 
921
                        ProteinIdentification::SearchParameters s = exp_original.getProteinIdentifications()[0].getSearchParameters();
 
922
                        s.missed_cleavages = 66;
 
923
                        exp_original.getProteinIdentifications()[0].setSearchParameters(s);
 
924
 
 
925
                  DBAdapter a(con);
 
926
                  a.storeExperiment(exp_original);
 
927
 
 
928
                        ////////////PART 2 => LOADING
 
929
 
 
930
                  RichPeakMap exp_new;
 
931
 
 
932
                        a.loadExperiment(tmp_id, exp_new);
 
933
                        TEST_EQUAL(exp_new.getPersistenceId(), tmp_id)
 
934
                        TEST_EQUAL(exp_new.getComment() , "blubb" )
 
935
 
 
936
                        //------ test if values are correct ------
 
937
 
 
938
                        //SPECTRUM 1
 
939
                        RichPeakMap::const_iterator itn(exp_new.begin());
 
940
                        RichPeakMap::const_iterator ito(exp_original.begin());
 
941
 
 
942
                  TEST_EQUAL( itn->getRT() , ito->getRT() )
 
943
                        TEST_EQUAL( itn->getMSLevel() , ito->getMSLevel() )
 
944
                        TEST_EQUAL( itn->size() , ito->size() )
 
945
                        TEST_EQUAL( itn->getInstrumentSettings().getMetaValue("label") , "please bite here" )
 
946
                        TEST_EQUAL( itn->getAcquisitionInfo()[0].getIdentifier(), "1");
 
947
                        TEST_EQUAL( itn->getAcquisitionInfo()[0].getMetaValue("icon"), "one more icon");
 
948
                        TEST_EQUAL( itn->getAcquisitionInfo()[1].getIdentifier(), "2");
 
949
                        TEST_EQUAL( itn->getAcquisitionInfo()[1].getMetaValue("label"), "yet another label");
 
950
                        for (Size i=0; i<3; ++i)
 
951
                        {
 
952
                                TEST_REAL_SIMILAR( itn->operator[](i).getIntensity() , ito->operator[](i).getIntensity() )
 
953
                                TEST_REAL_SIMILAR( itn->operator[](i).getPosition()[0] , ito->operator[](i).getPosition()[0] )
 
954
                        }
 
955
                        TEST_EQUAL( itn->getInstrumentSettings().getZoomScan() , ito->getInstrumentSettings().getZoomScan() )
 
956
                        for(Size ps = 0; ps < itn->getProducts().size(); ++ps)
 
957
                        {
 
958
                                TEST_EQUAL( itn->getProducts()[ps].getMZ() , ito->getProducts()[ps].getMZ() )
 
959
                                TEST_EQUAL( itn->getProducts()[ps].getIsolationWindowLowerOffset() , ito->getProducts()[ps].getIsolationWindowLowerOffset() )
 
960
                                TEST_EQUAL( itn->getProducts()[ps].getIsolationWindowUpperOffset() , ito->getProducts()[ps].getIsolationWindowUpperOffset() )
 
961
                                TEST_EQUAL( itn->getProducts()[ps].getMetaValue("farbe") , ito->getProducts()[ps].getMetaValue("farbe"))
 
962
                        }
 
963
 
 
964
 
 
965
                        //SPECTRUM 2
 
966
                        ++itn;
 
967
                        ++ito;
 
968
 
 
969
                  TEST_EQUAL( itn->getRT() , ito->getRT() )
 
970
                        TEST_EQUAL( itn->getMSLevel() , ito->getMSLevel() )
 
971
                        TEST_EQUAL( itn->getPrecursors().size() , ito->getPrecursors().size() )
 
972
                        TEST_EQUAL( itn->getPrecursors()[0].getMZ() , ito->getPrecursors()[0].getMZ() )
 
973
                        TEST_EQUAL( itn->getPrecursors()[0].getIntensity() , ito->getPrecursors()[0].getIntensity() )
 
974
                        TEST_EQUAL( itn->getPrecursors()[0].getCharge() , ito->getPrecursors()[0].getCharge() )
 
975
                        TEST_EQUAL( itn->getPrecursors()[0].getMetaValue("icon") , "NewPrecursor" )
 
976
                        TEST_EQUAL( itn->getComment() , "bla" )
 
977
                        TEST_EQUAL( itn->size() , ito->size() )
 
978
                        for (Size i=0; i<3; ++i)
 
979
                        {
 
980
                                TEST_REAL_SIMILAR( itn->operator[](i).getIntensity() , ito->operator[](i).getIntensity() )
 
981
                                TEST_REAL_SIMILAR( itn->operator[](i).getPosition()[0] , ito->operator[](i).getPosition()[0] )
 
982
                        }
 
983
 
 
984
                        //META INFO
 
985
                        TEST_REAL_SIMILAR((double)exp_new.getMetaValue("label"),5.55)
 
986
                        TEST_EQUAL((string)exp_new.getMetaValue("icon"),"MSExperiment")
 
987
                        TEST_EQUAL((int)exp_new.getMetaValue("color"),5)
 
988
                        TEST_EQUAL((string)exp_new[0].getMetaValue("icon"),"Spectrum1")
 
989
                        TEST_EQUAL((string)exp_new[1].getMetaValue("icon"),"Spectrum2")
 
990
 
 
991
                        //load the Peak1D experiment
 
992
                        //(peak meta data should not be tried to be loaded, because
 
993
                        //Peak1D is no MetaInfoInterface)
 
994
                        MSExperiment<Peak1D> exp2;
 
995
                        a.loadExperiment(tmp_id2, exp2);
 
996
                        TEST_EQUAL( exp2.size(), 1 );
 
997
                        MSSpectrum<Peak1D>& spec2 = *exp2.begin();
 
998
                        MSSpectrum<Peak1D>& spec2_original = *exp_peak1d.begin();
 
999
                        TEST_EQUAL ( spec2.size(), 3 )
 
1000
                        //test if values are correct
 
1001
                        for(int i = 0; i < 3; i++)
 
1002
                        {
 
1003
                                TEST_REAL_SIMILAR( spec2[i].getIntensity(), spec2_original[i].getIntensity() )
 
1004
                                TEST_REAL_SIMILAR( spec2[i].getPosition()[0], spec2_original[i].getPosition()[0] )
 
1005
                        }
 
1006
 
 
1007
                        //test update of others
 
1008
                        TEST_EQUAL(exp_new.getProteinIdentifications()[0].getHits()[1].getRank(), 5u )
 
1009
                        TEST_EQUAL(exp_new[0].getSourceFile().getChecksumType(), SourceFile::UNKNOWN_CHECKSUM )
 
1010
                        TEST_STRING_EQUAL(exp_new[0].getSourceFile().getNativeIDType(), "Waters nativeID format" )
 
1011
                        TEST_EQUAL(exp_new.getInstrument().getMassAnalyzers()[0].getOrder() , 2 )
 
1012
                        TEST_EQUAL(exp_new.getInstrument().getMassAnalyzers()[1].getOrder() , 3 )
 
1013
                        TEST_EQUAL(exp_new.getInstrument().getIonDetectors()[0].getOrder(), 4)
 
1014
                        TEST_EQUAL(exp_new.getInstrument().getIonSources()[0].getOrder(), 1)
 
1015
                        TEST_EQUAL(exp_new.getInstrument().getIonOptics() , Instrument::EINZEL_LENS )
 
1016
 
 
1017
                        TEST_EQUAL(exp_new.getProteinIdentifications()[0].getSearchParameters().missed_cleavages, 66)
 
1018
                        TEST_EQUAL(exp_new.getProteinIdentifications()[0].getSearchParameters().peak_mass_tolerance, exp_original.getProteinIdentifications()[0].getSearchParameters().peak_mass_tolerance)
 
1019
 
 
1020
 
 
1021
END_SECTION
 
1022
 
 
1023
                START_SECTION(([EXTRA] load and store of empty map))
 
1024
                        DBAdapter a(con);
 
1025
                  RichPeakMap in, out;
 
1026
                  a.storeExperiment(in);
 
1027
                        a.loadExperiment(in.getPersistenceId(),out);
 
1028
                        TEST_EQUAL(in==out, true)
 
1029
END_SECTION
 
1030
 
 
1031
        START_SECTION((const PeakFileOptions& getOptions() const))
 
1032
                        DBAdapter a(con);
 
1033
                        TEST_EQUAL(a.getOptions().hasMSLevels(),false)
 
1034
END_SECTION
 
1035
 
 
1036
        START_SECTION((PeakFileOptions& getOptions()))
 
1037
                        DBAdapter a(con);
 
1038
                        a.getOptions().addMSLevel(1);
 
1039
                        TEST_EQUAL(a.getOptions().hasMSLevels(),true);
 
1040
END_SECTION
 
1041
 
 
1042
        //extra test with an empty spectrum
 
1043
        START_SECTION(([EXTRA] template<class ExperimentType> void storeExperiment(ExperimentType& exp)))
 
1044
                  RichPeakMap exp_tmp;
 
1045
                  exp_tmp.resize(1);
 
1046
                  DBAdapter a(con);
 
1047
                  a.storeExperiment(exp_tmp);
 
1048
                  TEST_NOT_EQUAL(exp_tmp[0].getPersistenceId(),0);
 
1049
END_SECTION
 
1050
 
 
1051
        } // DB up-to-date
 
1052
 
 
1053
}
 
1054
else
 
1055
{
 
1056
        ADD_MESSAGE("skipped")
 
1057
}
 
1058
/////////////////////////////////////////////////////////////
 
1059
/////////////////////////////////////////////////////////////
 
1060
END_TEST
 
1061
 
 
1062
 
 
1063