mapquanti.cpp 4.72 KB
Newer Older
Olivier Langella's avatar
Olivier Langella committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

/*******************************************************************************
 * Copyright (c) 2016 Olivier Langella <Olivier.Langella@moulon.inra.fr>.
 *
 * This file is part of the MassChroQ software.
 *
 *     MassChroQ is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     MassChroQ is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with MassChroQ.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Contributors:
 *     Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and implementation
 ******************************************************************************/
#include "mapquanti.h"
#include "../quanti_items/quantiItemBase.h"
#include "../xic/xicfilterdetectmatch.h"
26
#include "../xic/xicfilterdetectmatchrealrt.h"
Olivier Langella's avatar
Olivier Langella committed
27
#include "../xic/xic_base.h"
Olivier Langella's avatar
Olivier Langella committed
28
#include "../xic/xictracebase.h"
Olivier Langella's avatar
Olivier Langella committed
29
#include "../consoleout.h"
30
#include <cmath>
Olivier Langella's avatar
Olivier Langella committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

MapQuanti::MapQuanti(MonitorSpeedInterface & monitor, Msrun * current_msrun, McqXicType xic_type, Quantificator * quantificator,
                     const pappso::XicFilterInterface * p_xic_filter,const pappso::XicDetectionInterface * p_detection)
    :_monitor(monitor), _xic_type(xic_type) {
    _p_msrun = current_msrun;
    _p_xic_filter = p_xic_filter;
    _p_detection = p_detection;
    _matching_mode = quantificator->getMatchingMode();
    _quantificator = quantificator;
}

void MapQuanti::operator()(QuantiItemBase * p_currentSearchItem)
{
    qDebug() << " MapQuanti::operator begin";
    try {
        pappso::pappso_double rt_target = -1;
47
        //std::vector<MsMsRtIntensity> rt_list;
Olivier Langella's avatar
Olivier Langella committed
48

Olivier Langella's avatar
Olivier Langella committed
49
50
51
        PeptideRt * p_peptide_rt = p_currentSearchItem->getPeptideRtSp().get();

        if (p_peptide_rt != nullptr) {
Olivier Langella's avatar
Olivier Langella committed
52
            rt_target = p_peptide_rt->getRtTarget(_p_msrun, _matching_mode);
53

Olivier Langella's avatar
Olivier Langella committed
54
55
56
57
58
59
            if (std::isnan(rt_target)) {
                qDebug() << " MapQuanti::operator() isnan(rt_target) " << p_currentSearchItem->getQuantiItemId() << " " << rt_target;
                throw mcqError(QObject::tr("Error in MapQuanti::operator() isnan(rt_target) %1")
                               .arg(p_currentSearchItem->getQuantiItemId()));
            }
        }
Olivier Langella's avatar
Olivier Langella committed
60
61

        if (rt_target == -1) {
62
            if (_matching_mode == McqMatchingMode::post_matching) {
63
                //it's Ok, just detect and keep peaks
64
            } else if (_matching_mode == McqMatchingMode::no_matching) {
Olivier Langella's avatar
Olivier Langella committed
65
66
67
68
69
70
71
                rt_target = p_currentSearchItem->getRt();
            } else {
                qDebug() << " MapQuanti::operator rt_target == -1 exit";
                return;
            }
        }
        qDebug() << " MapQuanti::operator _p_msrun->extractXic";
72
        McqXicNoConstSp _p_xic = _p_msrun->extractXic(_xic_type, _quantificator->getXicExtractionMethod()->getPappsoMassRange( p_currentSearchItem->getMz()));
Olivier Langella's avatar
Olivier Langella committed
73
74
75
76
77
78
79
80

        if (_p_xic == nullptr) {
            qDebug() << "detectAndQuantify null xic ";

            qDebug() << " MapQuanti::operator begin 2";
        }
        else {
            qDebug() << " MapQuanti::operator begin 3 rt_target=" << rt_target;
81
82
            XicTraceBase * p_xic_trace = nullptr;

83
84
            //only take an rt reference to match peak
            p_xic_trace = p_currentSearchItem->newXicTrace(_quantificator, _p_msrun, "target");
Olivier Langella's avatar
Olivier Langella committed
85

Olivier Langella's avatar
Olivier Langella committed
86

87
88
            XicFilterDetectMatch filter_detect_match(p_xic_trace, _monitor, _p_xic_filter, _p_detection, _matching_mode) ;
            filter_detect_match.filterDetectQuantify(*(_p_xic.get()), rt_target, p_currentSearchItem, _p_msrun);
89

Olivier Langella's avatar
Olivier Langella committed
90
91

            if (p_xic_trace != nullptr) {
92
                p_xic_trace->setAlignedRtTarget(_p_msrun->getAlignedRtByOriginalRt(rt_target));
Olivier Langella's avatar
Olivier Langella committed
93
94
                p_xic_trace->setRtTarget(rt_target);
                p_xic_trace->setXic(_p_xic);
Olivier Langella's avatar
Olivier Langella committed
95
                p_xic_trace->close();
Olivier Langella's avatar
Olivier Langella committed
96
97
                delete p_xic_trace;
            }
Olivier Langella's avatar
Olivier Langella committed
98
99
100
101
102
103
104
105
106
        }
        qDebug() << " MapQuanti::operator end";
    }
    catch (mcqError& errorException)
    {
        // QObject::tr("%1 CPUs used").arg(cpu_number)
        // mcqerr() << "Oops! an error occurred in MassChroQ. Dont Panic :" << endl;
        // mcqerr() << error.qwhat() << endl;
        qDebug() << " MapQuanti::operator " << errorException.qwhat();
Olivier Langella's avatar
Olivier Langella committed
107
108
        throw mcqError(QObject::tr("Error in MapQuanti::operator() :\n %1")
                       .arg(errorException.qwhat()));
Olivier Langella's avatar
Olivier Langella committed
109
110
111
112
        // windaube_exit();
        // return 1;
    }
}