masschroqmlParser.cpp 48 KB
Newer Older
1
/**
2
3
4
5
6
7
8
9
 * \file masschroqmlParser.cpp
 * \date September 21, 2009
 * \author Olivier Langella
 */

#include "masschroqmlParser.h"
#include "../lib/msrun/msrun.h"
#include "../lib/alignments/alignment_obiwarp.h"
10
#include "../lib/alignments/monitors/monitor_alignment_time.h"
11
12
13
14
#include "../lib/alignments/alignment_ms2.h"
#include "../lib/xicExtractionMethods/xicExtractionMethodMzRange.h"
#include "../lib/xicExtractionMethods/xicExtractionMethodPpmRange.h"
#include "../lib/monitors/masschroqWriter.h"
15
#include "../lib/monitors/monitorodsoutput.h"
16
#include "../lib/monitors/monitorcomparoutput.h"
Olivier Langella's avatar
Olivier Langella committed
17
#include "../lib/consoleout.h"
18
#include <pappsomspp/pappsoexception.h>
Olivier Langella's avatar
Olivier Langella committed
19
20
21
22
23
#include <pappsomspp/xic/filters/xicfilterspike.h>
#include <pappsomspp/xic/filters/xicfilterbackground.h>
#include <pappsomspp/xic/filters/xicfiltersmoothing.h>
#include <pappsomspp/xic/detection/xicdetectionzivy.h>
#include <pappsomspp/xic/detection/xicdetectionmoulon.h>
24
#include <odsstream/tsvdirectorywriter.h>
25
26
27



Edlira Nano's avatar
Edlira Nano committed
28
29
MasschroqmlParser::MasschroqmlParser(MassChroq * p_my_chroq)
{
30
31
32
33
34
35
36

    _p_my_chroq = p_my_chroq;

    _p_current_alignment_method = 0;
    _p_current_quantification_method = 0;
    _p_current_detection_method = 0;
    _read_time_values = false;
37
38

    _p_current_monitor_speed_list = new MonitorSpeedList();
39
40
}

Edlira Nano's avatar
Edlira Nano committed
41
42
MasschroqmlParser::~MasschroqmlParser()
{
43

44
45
    delete _p_current_monitor_speed_list;

46
47
}

48
bool
Edlira Nano's avatar
Edlira Nano committed
49
MasschroqmlParser::startElement(
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
    const QString &namespaceURI,
    const QString &localName,
    const QString &qName,
    const QXmlAttributes &attributes)
{

    _tag_stack.push_back(qName);
    bool is_ok = true;

    //startElement_rawdata
    if (qName == "rawdata")
    {
        is_ok = startElement_rawdata(attributes);
    }

    //startElement_data_file
    else if (qName == "data_file")
    {
        is_ok = startElement_data_file(attributes);
    }
    //startElement_group
    else if (qName == "group")
    {
        is_ok = startElement_group(attributes);
    }
    //startElement_protein
    else if (qName == "protein")
    {
        is_ok = startElement_protein(attributes);
    }
    //startElement_peptide
    else if (qName == "peptide")
    {
        is_ok = startElement_peptide(attributes);
    }
85
    else if (qName == "psimod")
86
87
88
    {
        is_ok = startElement_psimod(attributes);
    }
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
    //startElement_observed_in
    else if (qName == "observed_in")
    {
        is_ok = startElement_observed_in(attributes);
    }
    //startElement_isotope_label
    else if (qName == "isotope_label")
    {
        is_ok = startElement_isotope_label(attributes);
    }
    // startElement_mod
    else if (qName == "mod")
    {
        is_ok = startElement_mod(attributes);
    }
    // startElement_alignment_method
    else if (qName == "alignment_method")
    {
        is_ok = startElement_alignment_method(attributes);
    }
    // startElement_obiwarp
    else if (qName == "obiwarp")
    {
        is_ok = startElement_obiwarp(attributes);
    }
    // startElement_ms2
    else if (qName == "ms2")
    {
        is_ok = startElement_ms2(attributes);
    }
    // startElement_align
    else if (qName == "align")
    {
        is_ok = startElement_align(attributes);
    }
    // startElement_quantification_method
    else if (qName == "quantification_method")
    {
        is_ok = startElement_quantification_method(attributes);
    }
    // startElement_xic_extraction
    else if (qName == "xic_extraction")
    {
        is_ok = startElement_xic_extraction(attributes);
    }
    // startElement_mz_range
    else if (qName == "mz_range")
    {
        is_ok = startElement_mz_range(attributes);
    }
    // startElement_ppm_range
    else if (qName == "ppm_range")
    {
        is_ok = startElement_ppm_range(attributes);
    }
    // startElement_anti_spike
    else if (qName == "anti_spike")
    {
        is_ok = startElement_anti_spike(attributes);
    }
    // startElement_background
    else if (qName == "background")
    {
        is_ok = startElement_background(attributes);
    }
    // startElement_smoothing
    else if (qName == "smoothing")
    {
        is_ok = startElement_smoothing(attributes);
    }
    // startElement_detection_moulon
    else if (qName == "detection_moulon")
    {
        is_ok = startElement_detection_moulon(attributes);
    }
    // startElement_detection_zivy
    else if (qName == "detection_zivy")
    {
        is_ok = startElement_detection_zivy(attributes);
    }
    // startElement_quantification_results
    else if (qName == "quantification_results")
    {
        is_ok = startElement_quantification_results(attributes);
    }
    // startElement_quantification_result
    else if (qName == "quantification_result")
    {
        is_ok = startElement_quantification_result(attributes);
    }
179
180
181
182
183
    // startElement_compar_result
    else if (qName == "compar_result")
    {
        is_ok = startElement_compar_result(attributes);
    }
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
    // startElement_all_xics_traces
    else if (qName == "all_xics_traces")
    {
        is_ok = startElement_all_xics_traces(attributes);
    }
    // startElement_peptide_traces
    else if (qName == "peptide_traces")
    {
        is_ok = startElement_peptide_traces(attributes);
    }
    // startElement_mz_traces
    else if (qName == "mz_traces")
    {
        is_ok = startElement_mz_traces(attributes);
    }
    // startElement_mzrt_traces
    else if (qName == "mzrt_traces")
    {
        is_ok = startElement_mzrt_traces(attributes);
    }
    // startElement_mzrt_value
    else if (qName == "mzrt_value")
    {
        is_ok = startElement_mzrt_value(attributes);
    }
    // startElement_quantify
    else if (qName == "quantify")
    {
        is_ok = startElement_quantify(attributes);
    }
    // startElement_peptides_in_peptide_list
    else if (qName == "peptides_in_peptide_list")
    {
        is_ok = startElement_peptides_in_peptide_list(attributes);
    }
    // startElement_mzrt
    else if (qName == "mzrt")
    {
        is_ok = startElement_mzrt(attributes);
    }

    _currentText.clear();
    return is_ok;
}


bool
Edlira Nano's avatar
Edlira Nano committed
231
MasschroqmlParser::endElement(
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
    const QString &namespaceURI,
    const QString &localName,
    const QString &qName)
{
    bool is_ok = true;
    // endElement_peptide_list
    if (qName == "peptide_list")
    {
        is_ok = endElement_peptide_list();
    }
    // endElement_isotope_label
    else if (qName == "isotope_label")
    {
        is_ok = endElement_isotope_label();
    }
    // end of alignment method obiwarp
    else if ((_tag_stack.size() > 1) &&
             (_tag_stack[_tag_stack.size() - 2] == "obiwarp"))
    {
        //startElement_lmat_precision
        if (qName == "lmat_precision")
        {
            is_ok = endElement_lmat_precision();
        }
        //endElement_mz_start
        else if (qName == "mz_start")
        {
            is_ok = endElement_mz_start();
        }//endElement_mz_stop
        else if (qName == "mz_stop")
        {
            is_ok = endElement_mz_stop();
        }
    }
    // end of alignment method ms2
    else if ((_tag_stack.size() > 1) &&
             (_tag_stack[_tag_stack.size() - 2] == "ms2"))
    {
        if (qName == "ms2_tendency_halfwindow")
        {
            is_ok = endElement_ms2_tendency_halfwindow();
        }
        else if (qName == "ms2_smoothing_halfwindow")
        {
            is_ok = endElement_ms2_smoothing_halfwindow();
        }
        else if (qName == "ms1_smoothing_halfwindow")
        {
            is_ok = endElement_ms1_smoothing_halfwindow();
        }
    }
    // endElement_alignment_method
    else if (qName == "alignment_method")
    {
        is_ok = endElement_alignment_method();
    }
    // end of detection_zivy
    else if ((_tag_stack.size() > 1) &&
             (_tag_stack[_tag_stack.size() - 2] == "detection_zivy"))
    {
        if (qName == "minmax_half_edge")
        {
            is_ok = endElement_minmax_half_edge();
        }
        else if (qName == "maxmin_half_edge")
        {
            is_ok = endElement_maxmin_half_edge();
        }
        else if (qName == "detection_threshold_on_max")
        {
            is_ok = endElement_detection_threshold_on_max();
        }
        else if (qName == "detection_threshold_on_min")
        {
            is_ok = endElement_detection_threshold_on_min();
        }
        else if (qName == "mean_filter_half_edge")
        {
            is_ok = endElement_mean_filter_half_edge();
        }

    }
    // end of detection_moulon
    else if ((_tag_stack.size() > 1) &&
             (_tag_stack[_tag_stack.size() - 2] == "detection_moulon"))
    {
        if (qName == "smoothing_point")
        {
            is_ok = endElement_smoothing_point();
        }
        else if (qName == "TIC_start")
        {
            is_ok = endElement_TIC_start();
        }
        else if (qName == "TIC_stop")
        {
            is_ok = endElement_TIC_stop();
        }
    }
    // endElement_peak_detection
    else if (qName == "peak_detection")
    {
        is_ok = endElement_peak_detection();
    }
    // endElement_quantification_method
    else if (qName == "quantification_method")
    {
        is_ok = endElement_quantification_method();
    }
    // endElement_mz_list
    else if (qName == "mz_list")
    {
        is_ok = endElement_mz_list();
    }
    // endElement_mzrt_traces
    else if (qName == "mzrt_traces")
    {
        is_ok = endElement_mzrt_traces();
    }
    // endElement_quantification_traces
    else if (qName == "quantification_traces")
    {
        is_ok = endElement_quantification_traces();
    }
    // endElement_quantify
    else if (qName == "quantify")
    {
        is_ok = endElement_quantify();
    }
    // endElement_quantification
    else if (qName == "quantification")
    {
        is_ok = endElement_quantification();
    }
    // endElement_masschroq
    else if (qName == "masschroq")
    {
        is_ok = endElement_masschroq();
    }
371
372
373
374
    else if (qName == "peptide")
    {
        is_ok = endElement_peptide();
    }
375
376
377
378
379
380
381
382

    _currentText.clear();
    _tag_stack.pop_back();

    return is_ok;
}

bool
Edlira Nano's avatar
Edlira Nano committed
383
384
MasschroqmlParser::startElement_rawdata(const QXmlAttributes &attributes)
{
385
386
387
388
389
390
391
392
393
394
395
396

    QString time_dir = attributes.value("time_values_dir");
    if (!time_dir.isEmpty())
    {
        _read_time_values = true;
        _time_directory = time_dir;
    }
    if (!QDir(time_dir).exists()) {
        _errorStr = QObject::tr("The directory  :\n%1\n from the attribute 'time_values_dir'  in the element 'rawdata' does not exists.").arg(time_dir);
        return false;
    }
    return true;
Edlira Nano's avatar
Edlira Nano committed
397
398
399
}


400
/// <data_file id=.../>
401
bool
Edlira Nano's avatar
Edlira Nano committed
402
403
MasschroqmlParser::startElement_data_file(const QXmlAttributes &attributes)
{
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418

    QString filename = attributes.value("path");
    if (filename.isEmpty())
    {
        _errorStr = QObject::tr("The data_file tag must have a path attribute.");
        return false;
    }

    QString idname = attributes.value("id");
    if (idname.isEmpty())
    {
        _errorStr = QObject::tr("The data_file tag must have an id attribute.");
        return false;
    }

Olivier Langella's avatar
Olivier Langella committed
419
    QString format = attributes.value("format");
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
    if (format.isEmpty())
    {
        _errorStr = QObject::tr("The data_file tag must have a mime_type attribute.");
        return false;
    }

    QFileInfo filenameInfo(filename);
    if (! filenameInfo.exists())
    {
        _errorStr =
            QObject::tr("cannot find the '%1' input file : %2 \n").arg(format, filename);
        return false;
    } else if (! filenameInfo.isReadable())
    {
        _errorStr =
            QObject::tr("cannot read the '%1' input file : %2 \n").arg(format, filename);
        return false;
    }

    QString type = attributes.value("type");
    if (!type.isEmpty() && type == "srm")
    {
        _errorStr =
            QObject::tr("The SRM mode is not yet implemented in MassChroQ, but it will: \n%1");
        return false;
    }

447
448
    RawDataFormat raw_data_format;
    if (format == "mzxml")
449
    {
450
451
        raw_data_format = RawDataFormat::mzxml;
    } else if (format == "mzml")
452
    {
453
        raw_data_format = RawDataFormat::mzml;
454
455
456
457
458
459
460
461
462
463
    } else
    {
        _errorStr =
            QObject::tr("the data file format %1 is not supported. Supported formats are 'mzml' and 'mzXml'").arg(format);
        return false;
    }

    try
    {
        /// create the msrun, launch its simple parsing, initialize its slicer if possible
464
        _p_my_chroq->setMsRun(idname, filename, raw_data_format, _read_time_values, _time_directory);
465
466
467
468
469
470
    } catch (mcqError& error)
    {
        _errorStr = QObject::tr("problem creating msrun %1:\n%2").arg(idname, error.what());
        return false;
    }
    return (true);
471
472
473
}

/// <group id="G1" data_ids="delumeau1 delumeau2"></group>
474
bool
Edlira Nano's avatar
Edlira Nano committed
475
476
MasschroqmlParser::startElement_group(const QXmlAttributes &attributes)
{
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
    QString idname = attributes.value("id");
    QString msrun_ids = attributes.value("data_ids");
    if (idname.isEmpty())
    {
        _errorStr = QObject::tr("the group tag must have an id attribute.");
        return false;
    }
    if (msrun_ids.isEmpty())
    {
        _errorStr = QObject::tr("the group tag must have a data_ids attribute.");
        return false;
    }

    QStringList list_msrun_ids = msrun_ids.split(" ", QString::SkipEmptyParts);
    /// add this group of msruns to _groups (: map<group_id, msRunHashGroup *>)
    /// the first msrun in the group will be the reference one
    _p_my_chroq->newMsRunGroup(idname, list_msrun_ids);

    return (true);
496
497
498
}

/// <protein id="P1" desc=""/>
499
bool
Edlira Nano's avatar
Edlira Nano committed
500
501
MasschroqmlParser::startElement_protein(const QXmlAttributes &attributes)
{
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
    QString id = attributes.value("id");
    QString desc = attributes.value("desc");
    if (id.isEmpty())
    {
        _errorStr = QObject::tr("the protein tag must have an id attribute.");
        return false;
    }
    /// create a new Protein object and set its description
    Protein * p_protein;
    try
    {
        p_protein = new Protein(id);
        p_protein->setDescription(desc);
    } catch (mcqError& error)
    {
        _errorStr = QObject::tr("problem creating protein :\n%1").arg(error.what());
        return false;
    }
    /// add this protein to _p_proteins (: map<id, Protein *>)
    _p_my_chroq->addProtein(p_protein);

    return true;
524
525
526
}

/// <peptide id="pep1" seq="" mh="856.23" prot_ids="P1 P2">
527
bool
Edlira Nano's avatar
Edlira Nano committed
528
529
MasschroqmlParser::startElement_peptide(const QXmlAttributes &attributes)
{
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
    QString idname = attributes.value("id");
    QString mh = attributes.value("mh");
    QString seq = attributes.value("seq");
    QString mods = attributes.value("mods");
    QString prot_ids = attributes.value("prot_ids");
    if (idname.isEmpty())
    {
        _errorStr = QObject::tr("the peptide tag must have an id attribute.");
        return false;
    }
    if (mh.isEmpty())
    {
        _errorStr = QObject::tr("the peptide tag must have a mh attribute.");
        return false;
    }
    /// create a new Peptide object and set its members
    _p_current_peptide = new Peptide(idname);

    if (!mods.isEmpty())
    {
        _p_current_peptide->setMods(mods);
    }
    if (!seq.isEmpty())
    {
        try {
            pappso::Peptide peptide(seq);
556
            _current_peptide_sp = peptide.makeNoConstPeptideSp();
557
558
559
560
561
562
563
            _p_current_peptide->setPappsoPeptideSp(_current_peptide_sp);
        }
        catch (const pappso::PappsoException & e) {
            _errorStr = QObject::tr("error building peptide %1\n%2").arg(seq).arg(e.qwhat());
            return false;
        }
    }
564

565
566
    _current_mh = mh.toDouble();
    //_p_current_peptide->setMh(mh.toDouble());
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
    if (!prot_ids.isEmpty())
    {
        QStringList list;
        list = prot_ids.split(" ", QString::SkipEmptyParts);
        for (int i = 0; i < list.size(); ++i)
        {
            const Protein * p_prot = _p_my_chroq->findProtein(list.at(i));
            if (p_prot == NULL)
            {
                _errorStr = QObject::tr("protein id %1 not defined.").arg(list.at(i));
                return false;
            }
            else
            {
                _p_current_peptide->addProtein(p_prot);
            }
        }
    }
    /// add this peptide to _peptide_list (: PeptideList)
    _p_my_chroq->addPeptideInPeptideList(_p_current_peptide);
    return true;
588
}
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
bool
MasschroqmlParser::startElement_psimod(const QXmlAttributes &attributes)
{
    QString at = attributes.value("at");
    QString acc = attributes.value("acc");
    if (at.isEmpty())
    {
        _errorStr = QObject::tr("the psimod tag must have an at attribute.");
        return false;
    }
    if (acc.isEmpty())
    {
        _errorStr = QObject::tr("the psimod tag must have an acc attribute.");
        return false;
    }
    try {
        pappso::AaModificationP modification = pappso::AaModification::getInstance(acc);
        _current_peptide_sp.get()->addAaModification(modification, at.toUInt()-1);
    }
    catch (pappso::PappsoException e) {
        _errorStr = QObject::tr("ERROR setting psimod:\n%1").arg(e.qwhat());
        return false;
    }
    return true;
}
614
/// <observed_in data="delumeau1" scan="33" z="2">
615
bool
Edlira Nano's avatar
Edlira Nano committed
616
617
MasschroqmlParser::startElement_observed_in(const QXmlAttributes &attributes)
{
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648

    QString data = attributes.value("data");
    QString scan = attributes.value("scan");
    QString z = attributes.value("z");

    if (data.isEmpty())
    {
        _errorStr = QObject::tr("the observed_in tag must have a data attribute (reference on a valid msRun id).");
        return false;
    }
    if (scan.isEmpty())
    {
        _errorStr = QObject::tr("the observed_in tag must have a scan attribute.");
        return false;
    }
    if (z.isEmpty())
    {
        _errorStr = QObject::tr("the observed_in tag must have a z attribute.");
        return false;
    }

    Msrun * p_msrun = _p_my_chroq->findMsRun(data);
    if (p_msrun == NULL)
    {
        _errorStr =
            QObject::tr("the observed_in tag contains a data attribute that does not reference any msrun...");
        return false;
    }
    /// add the observed in infos to the current peptide
    _p_current_peptide->observed_in(p_msrun, scan.toInt(),	z.toInt());
    return true;
649
650
651
}

/// </peptide_list>
652
bool
Edlira Nano's avatar
Edlira Nano committed
653
654
MasschroqmlParser::endElement_peptide_list()
{
655
656
    _p_my_chroq->setPeptideListInMsruns();
    return true;
657
658
}

659
660
661
662
663
664
bool
MasschroqmlParser::endElement_peptide()
{
    _p_current_peptide->setMh(_current_mh);
    return true;
}
665

666
bool
Edlira Nano's avatar
Edlira Nano committed
667
668
MasschroqmlParser::startElement_isotope_label(const QXmlAttributes &attributes)
{
669
670
671
672
673
674
675
676
677
678
679
680
    /// create a new IsotopeLabel object and set the current one to it
    _p_isotope_label = new IsotopeLabel();
    QString id = attributes.value("id");
    if (id.isEmpty())
    {
        _errorStr = QObject::tr("the isotope_label tag must have an id attribute.");
        return false;
    } else
    {
        _p_isotope_label->setXmlId(id);
    }
    return true;
681
682
683
}

/// isotope_label modification
684
bool
Edlira Nano's avatar
Edlira Nano committed
685
686
MasschroqmlParser::startElement_mod(const QXmlAttributes &attributes)
{
687
688
    QString value = attributes.value("value");
    QString at = attributes.value("at");
689
    QString acc = attributes.value("acc");
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
    if (value.isEmpty())
    {
        _errorStr =
            QObject::tr("the mod tag must have a value attribute : the mass of this modification");
        return false;
    }

    if (at.isEmpty())
    {
        _errorStr
            = QObject::tr("the mod tag must have an at attribute : the position of the modification given by AA one letter code or Cter or Nter");
        return false;
    }
    /// create a new IsotopeLabelModification and add it to the current isotope
    IsotopeLabelModification * p_mod = new IsotopeLabelModification();
    p_mod->setAA(at);
    p_mod->setMass(value.toDouble());

708
709
710
711
    if (!acc.isEmpty()) {
        pappso::AaModificationP modification = pappso::AaModification::getInstance(acc);
        p_mod->setPappsoModification(modification);
    }
712
713
714
715
716
    _p_isotope_label->addIsotopeLabelModification(p_mod);
    return true;
}

bool
Edlira Nano's avatar
Edlira Nano committed
717
718
MasschroqmlParser::endElement_isotope_label()
{
719
720
721
    _p_my_chroq->addIsotopeLabel(_p_isotope_label);
    //  _p_isotope_label = NULL;
    return true;
722
723
724
}

/// <alignment_method id="obiwarp1">
725
bool
Edlira Nano's avatar
Edlira Nano committed
726
727
MasschroqmlParser::startElement_alignment_method(const QXmlAttributes &attributes)
{
728
729
730
731
732
733
734
735
736
737
738
739

    _current_alignment_method_id = attributes.value("id");
    if (_current_alignment_method_id.isEmpty())
    {
        _errorStr = QObject::tr("the alignment_method tag must have an id attribute.");
        return false;
    }

    /// we will set the current_alignment_method later (in the <obiwarp or
    /// <ms2> tag that follows this one )
    //  _p_current_alignment_method = NULL;
    return true;
740
741
742
}

/// <obiwarp>
743
bool
Edlira Nano's avatar
Edlira Nano committed
744
745
MasschroqmlParser::startElement_obiwarp(const QXmlAttributes &attributes)
{
746
747
748
749
750
751
752
753
754
755
756
757
    QString time_output_dir = attributes.value("write_time_values_output_dir");
    if (!time_output_dir.isEmpty()) {
        //Print time value
        MonitorAlignmentTime * time_monitor = new MonitorAlignmentTime();
        time_monitor->setOutputDirectory(time_output_dir);
        _p_current_alignment_method = new AlignmentObiwarp(time_monitor);
    } else {
        //not print time value
        MonitorAlignmentBase * base_monitor = new MonitorAlignmentBase();
        _p_current_alignment_method = new AlignmentObiwarp(base_monitor);
    }
    return true;
758
759
760
}

/// <lmat_precision>0.5</lmat_precision>
761
bool
Edlira Nano's avatar
Edlira Nano committed
762
763
MasschroqmlParser::endElement_lmat_precision()
{
764
765
766
    AlignmentObiwarp * p_obiwarp_meth((AlignmentObiwarp *) _p_current_alignment_method);
    p_obiwarp_meth->setLmatPrecision(_currentText.toDouble());
    return true;
767
768
769
}

/// <mz_start>300</mz_start>
770
bool
Edlira Nano's avatar
Edlira Nano committed
771
772
MasschroqmlParser::endElement_mz_start()
{
773
774
775
    AlignmentObiwarp * p_obiwarp_meth((AlignmentObiwarp *) _p_current_alignment_method);
    p_obiwarp_meth->setMassStart(_currentText.toDouble());
    return true;
776
777
778
779
}

/// <mz_stop>900</mz_stop>
bool
Edlira Nano's avatar
Edlira Nano committed
780
781
MasschroqmlParser::endElement_mz_stop()
{
782
783
784
    AlignmentObiwarp * p_obiwarp_meth((AlignmentObiwarp *) _p_current_alignment_method);
    p_obiwarp_meth->setMassEnd(_currentText.toDouble());
    return true;
785
786
787
}

/// <ms2>
788
bool
Edlira Nano's avatar
Edlira Nano committed
789
790
MasschroqmlParser::startElement_ms2(const QXmlAttributes &attributes)
{
791
792
793
794
795
796
797
798
799
800
801
802
    QString time_output_dir = attributes.value("write_time_values_output_dir");
    if (!time_output_dir.isEmpty()) {
        //Print time value
        MonitorAlignmentTime * time_monitor = new MonitorAlignmentTime();
        time_monitor->setOutputDirectory(time_output_dir);
        _p_current_alignment_method = new AlignmentMs2(time_monitor);
    } else {
        //not print time value
        MonitorAlignmentBase * base_monitor = new MonitorAlignmentBase();
        _p_current_alignment_method = new AlignmentMs2(base_monitor);
    }
    return true;
803
804
805
}

/// <ms2_tendency_halfwindow>10</ms2_tendency_halfwindow>
806
bool
Edlira Nano's avatar
Edlira Nano committed
807
808
MasschroqmlParser::endElement_ms2_tendency_halfwindow()
{
809
810
811
    AlignmentMs2 * p_ms2_meth((AlignmentMs2 *) _p_current_alignment_method);
    p_ms2_meth->setMs2TendencyWindow(_currentText.toDouble());
    return true;
812
813
814
}

/// <ms2_smoothing_halfwindow>5</ms2_smoothing_halfwindow>
Edlira Nano's avatar
Edlira Nano committed
815
816
bool MasschroqmlParser::endElement_ms2_smoothing_halfwindow()
{
817
818
819
    AlignmentMs2 * p_ms2_meth((AlignmentMs2 *) _p_current_alignment_method);
    p_ms2_meth->setMs2SmoothingWindow(_currentText.toDouble());
    return true;
820
821
822
}

/// <ms1_smoothing_halfwindow>15</ms1_smoothing_halfwindow>
823
bool
Edlira Nano's avatar
Edlira Nano committed
824
825
MasschroqmlParser::endElement_ms1_smoothing_halfwindow()
{
826
827
828
829
    AlignmentMs2 *
    p_ms2_meth((AlignmentMs2 *) _p_current_alignment_method);
    p_ms2_meth->setMs1SmoothingWindow(_currentText.toDouble());
    return true;
830
831
}

832
bool
Edlira Nano's avatar
Edlira Nano committed
833
834
MasschroqmlParser::endElement_alignment_method()
{
835
836
837
838
839
    _p_my_chroq->addAlignmentMethod(_current_alignment_method_id,
                                    _p_current_alignment_method);
    _current_alignment_method_id.clear();
    //  _p_current_alignment_method = NULL;
    return true;
840
841
842
}

/// <align group_id="G1" method_id="obiwarp1">
843
bool
Edlira Nano's avatar
Edlira Nano committed
844
845
MasschroqmlParser::startElement_align(const QXmlAttributes &attributes)
{
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871

    QString group_id = attributes.value("group_id");
    QString align_method_id = attributes.value("method_id");
    QString ref_msrun_id = attributes.value("reference_data_id");

    if (group_id.isEmpty())
    {
        _errorStr =
            QObject::tr("the align tag must have a group_id attribute.");
        return false;
    }
    if (align_method_id.isEmpty())
    {
        _errorStr =
            QObject::tr("the align tag must have a method_id attribute.");
        return false;
    }
    if (ref_msrun_id.isEmpty())
    {
        _errorStr =
            QObject::tr("the align tag must have a ref_msrun_id attribute.");
        return false;
    }
    /// launch alignment
    _p_my_chroq->alignGroup(group_id, align_method_id, ref_msrun_id);
    return true;
872
873
874
}

/// <quantification_method id="q1">
875
bool
Edlira Nano's avatar
Edlira Nano committed
876
877
MasschroqmlParser::startElement_quantification_method(const QXmlAttributes &attributes)
{
878
879
880
881
882
883
884
885
886
887
888

    const QString quantification_id = attributes.value("id");

    if (quantification_id.isEmpty())
    {
        _errorStr = QObject::tr("the quantification_method tag must have an id attribute.");
        return false;
    }

    _p_current_quantification_method = new QuantificationMethod(quantification_id);
    return true;
889
890
891
892
}


/// <xic_extraction xic_type="sum">
893
bool
Edlira Nano's avatar
Edlira Nano committed
894
895
MasschroqmlParser::startElement_xic_extraction(const QXmlAttributes &attributes)
{
896
    QString xic_type = attributes.value("xic_type");
Olivier Langella's avatar
Olivier Langella committed
897
898
899
900
    if (xic_type == "sum") {
        _p_current_quantification_method->setXicType(McqXicType::sum);
        return true;
    } else if (xic_type == "max")
901
    {
Olivier Langella's avatar
Olivier Langella committed
902
        _p_current_quantification_method->setXicType(McqXicType::max);
903
904
905
906
907
908
909
910
        return true;
    }
    else
    {
        _errorStr =
            QObject::tr("the xic_extraction tag must have a xic_type attribute whose value is 'sum' or 'max'.");
        return false;
    }
911
912
913
914
}

/// <xic_extraction>
/// <mz_range min="0.5" max="1.5"/>
915
bool
Edlira Nano's avatar
Edlira Nano committed
916
917
MasschroqmlParser::startElement_mz_range(const QXmlAttributes &attributes)
{
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
    QString min = attributes.value("min");
    QString max = attributes.value("max");
    if (min.isEmpty())
    {
        _errorStr = QObject::tr("the mz_range tag must have a min attribute.");
        return false;
    }
    if (max.isEmpty())
    {
        _errorStr = QObject::tr("the mz_range tag must have a max attribute.");
        return false;
    }

    XicExtractionMethodMzRange * extraction_method =
        new XicExtractionMethodMzRange();
    extraction_method->set_min_range(min.toDouble());
    extraction_method->set_max_range(max.toDouble());
    _p_current_quantification_method->setXicExtractionMethod(extraction_method);

    return true;
938
939
940
941
}

/// <xic_extraction>
/// <ppm_range min="" max=""/>
942
bool
Edlira Nano's avatar
Edlira Nano committed
943
944
MasschroqmlParser::startElement_ppm_range(const QXmlAttributes &attributes)
{
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964

    QString min = attributes.value("min");
    QString max = attributes.value("max");
    if (min.isEmpty())
    {
        _errorStr = QObject::tr("the ppm_range tag must have a min attribute.");
        return false;
    }
    if (max.isEmpty())
    {
        _errorStr = QObject::tr("the ppm_range tag must have a max attribute.");
        return false;
    }

    XicExtractionMethodPpmRange * extraction_method = new XicExtractionMethodPpmRange();
    extraction_method->set_min_range(min.toDouble());
    extraction_method->set_max_range(max.toDouble());
    _p_current_quantification_method->setXicExtractionMethod(extraction_method);

    return true;
965
966
967
}

/// <anti_spike half="8">
968
bool
Edlira Nano's avatar
Edlira Nano committed
969
970
MasschroqmlParser::startElement_anti_spike(const QXmlAttributes &attributes)
{
971

972
973
974
975
976
977
978
    QString half = attributes.value("half");
    if (half.isEmpty())
    {
        _errorStr = QObject::tr("the anti_spike tag must have a half attribute.");
        return false;
    }

Olivier Langella's avatar
Olivier Langella committed
979
980
    pappso::XicFilterSpike * f_spike = new pappso::XicFilterSpike();
    f_spike->setHalfEdgeWindows(half.toDouble());
981
982
    _p_current_quantification_method->addFilter(f_spike);
    return true;
983
984
985
}

//<background half_mediane="5" half_min_max="20">
986
bool
Edlira Nano's avatar
Edlira Nano committed
987
988
MasschroqmlParser::startElement_background(const QXmlAttributes &attributes)
{
989
990
991
992
993
994
995
996
997
998
999
1000
    QString half_mediane = attributes.value("half_mediane");
    QString half_min_max = attributes.value("half_min_max");

    if (half_mediane.isEmpty())
    {
        _errorStr = QObject::tr("the background tag must have a half_mediane attribute.");
        return false;
    }
    if (half_min_max.isEmpty())
    {
        _errorStr = QObject::tr("the background tag must have a half_min_max attribute.");
        return false;
For faster browsing, not all history is shown. View entire blame