quantiItemPeptide.cpp 7.23 KB
Newer Older
Edlira Nano's avatar
Edlira Nano committed
1
2
3
4
5
6
7
8
9
/**
 * \file quantiItemPeptide.h
 * \date August 01, 2011
 * \author Edira Nano
 */


#include "quantiItemPeptide.h"
#include "../mcq_error.h"
10
#include "../peptides/isotope_label.h"
11
#include "../quantificator.h"
12
#include "../share/utilities.h"
Olivier Langella's avatar
Olivier Langella committed
13
#include "../xic/xictracepeptide.h"
Olivier Langella's avatar
Olivier Langella committed
14
15
#include <odsstream/tsvdirectorywriter.h>
#include <odsstream/calcwriterinterface.h>
Edlira Nano's avatar
Edlira Nano committed
16
17
18

#include <QStringList>

19
20

QuantiItemPeptide::QuantiItemPeptide(bool trace_peptide_on,
21
22
23
24
                                     const Peptide * p_peptide)
    :
    QuantiItemBase(trace_peptide_on),
    _p_peptide(p_peptide)
25
26
27
{
}

28
29
30
PeptideRtSp QuantiItemPeptide::getPeptideRtSp() const {
    return _p_peptide->getPeptideRtSp();
}
31
QuantiItemPeptide::QuantiItemPeptide(bool trace_peptide_on,
32
                                     const Peptide * p_peptide,
33
                                     unsigned int z)
34
    :
35
    QuantiItemBase(trace_peptide_on),
36
    _p_peptide(p_peptide),
37
    _z(z)
Edlira Nano's avatar
Edlira Nano committed
38
{
39
    _mz = p_peptide->getPappsoPeptideSp().get()->getMz(z);
Edlira Nano's avatar
Edlira Nano committed
40
41
}

Edlira Nano's avatar
Edlira Nano committed
42
43
QuantiItemPeptide::~QuantiItemPeptide()
{
Edlira Nano's avatar
Edlira Nano committed
44
45
46
}


47
const Peptide *
Edlira Nano's avatar
Edlira Nano committed
48
49
QuantiItemPeptide::getPeptide() const
{
50
    return (_p_peptide);
Edlira Nano's avatar
Edlira Nano committed
51
52
}

53
const unsigned int *
Edlira Nano's avatar
Edlira Nano committed
54
55
QuantiItemPeptide::getZ() const
{
56
    return (&_z);
Edlira Nano's avatar
Edlira Nano committed
57
58
59
}


60
void
Olivier Langella's avatar
Olivier Langella committed
61
QuantiItemPeptide::printInfos(QTextStream & out) const
Edlira Nano's avatar
Edlira Nano committed
62
{
63
64
65
    out << "peptide quantification item :" << endl;
    _p_peptide->printInfos(out);
    out << "_z = " << _z << endl;
66
    out << "_mz = " << this->getMz() << endl;
Edlira Nano's avatar
Edlira Nano committed
67
68
}

69
const QString
Edlira Nano's avatar
Edlira Nano committed
70
71
QuantiItemPeptide::getQuantiItemId() const
{
72
73
74
75
    return (_p_peptide->getXmlId());
}


76
77
78
79
const QString QuantiItemPeptide::getMzId() const {
    return (QString("%1+%2").arg(_p_peptide->getXmlId()).arg(_z));
}

80
81
82
83

void QuantiItemPeptide::writeCurrentSearchItem(MCQXmlStreamWriter* _output_stream) const
{

84
    _output_stream->writeAttribute("item_id_ref", _p_peptide->getXmlId());
85
86


87
    _output_stream->writeAttribute("z", QString::number(_z, 'f',0));
88
    const IsotopeLabel * p_isotopeLabel = _p_peptide->getIsotopeLabel();
89
    if (p_isotopeLabel != nullptr) {
90
91
        _output_stream->writeAttribute("isotope", p_isotopeLabel->getXmlId());
    }
Edlira Nano's avatar
Edlira Nano committed
92
}
93

Olivier Langella's avatar
Olivier Langella committed
94

Olivier Langella's avatar
Olivier Langella committed
95
96
97
98
99
100
101
102
103
104
105
106
void QuantiItemPeptide::writeOdsPeptideLine(CalcWriterInterface & writer) const {

    writer.writeCell(_p_peptide->getXmlId());

    const IsotopeLabel * isotope = _p_peptide->getIsotopeLabel();
    if (isotope != NULL)
    {
        writer.writeCell(isotope->getXmlId());
    }
    else {
        writer.writeEmptyCell();
    }
107
    //writer.writeCell(_p_peptide->getXmlId());
Olivier Langella's avatar
Olivier Langella committed
108
    writer.writeCell(_p_peptide->getSequence());
Olivier Langella's avatar
Olivier Langella committed
109

110
    //writer.writeCell(_p_peptide->getSequence());
Olivier Langella's avatar
Olivier Langella committed
111

Olivier Langella's avatar
Olivier Langella committed
112
    writer.writeCell(_z);
Olivier Langella's avatar
Olivier Langella committed
113

Olivier Langella's avatar
Olivier Langella committed
114
115
    writer.writeCell(_p_peptide->getMods());
}
Olivier Langella's avatar
Olivier Langella committed
116

117
118
119
120



void QuantiItemPeptide::writeOdsComparHeaderLine(CalcWriterInterface & writer) const {
121

122
123
124
125
    //_p_writer->writeCell("peptide");
    writer.writeCell(_p_peptide->getXmlId());
    //_p_writer->writeCell("m/z");
    writer.writeCell(getMz());
126
127
    //_p_writer->writeCell("rt reference");
    writer.writeCell(this->_p_peptide->getPeptideRtSp().get()->getAlignedReferenceRt());
128
129
130
131
132
133
134
135
    //_p_writer->writeCell("z");
    writer.writeCell(_z);
    //_p_writer->writeCell("isotope number");
    writer.writeEmptyCell();
    //_p_writer->writeCell("isotope rank");
    writer.writeEmptyCell();
    writer.writeEmptyCell();
    //_p_writer->writeCell("sequence");
136
    writer.writeCell(_p_peptide->getPappsoPeptideSp().get()->toString());
137
138
139
140
141
142
143
    //_p_writer->writeCell("isotope");
    if (_p_peptide->getIsotopeLabel() == nullptr) {
        writer.writeEmptyCell();
    }
    else {
        writer.writeCell(_p_peptide->getIsotopeLabel()->getXmlId());
    }
144
145
146
147
148
    //_p_writer->writeCell("mods");
    writer.writeCell(_p_peptide->getMods());
    //_p_writer->writeCell("proteins");
    QStringList protein_list;
    for (const Protein * p_protein : _p_peptide->getProteinList()) {
149
        protein_list << p_protein->getXmlId();
150
151
152
153
154
    }
    writer.writeCell(protein_list.join(" "));
}


Olivier Langella's avatar
Olivier Langella committed
155
CalcWriterInterface * QuantiItemPeptide::newCalcWriterInterface(const Quantificator * quantificator, const Msrun* p_msrun, const QString & prefix) const {
Olivier Langella's avatar
Olivier Langella committed
156
157
    QDir trace_dir(QString("%1/%2/%3").arg(quantificator->getTracesDirectory().absolutePath()).arg(this->getPeptide()->getXmlId()).arg(p_msrun->getXmlId()));
    trace_dir.mkpath(trace_dir.absolutePath());
Olivier Langella's avatar
Olivier Langella committed
158
159
    CalcWriterInterface * _p_writer=nullptr;
    if (quantificator->getTracesFormat() == McqTsvFormat::tsv) {
160
        _p_writer = new TsvDirectoryWriter(QString("%1/%2_%3-%4-z%5.d").arg(trace_dir.absolutePath()).arg(prefix).arg(quantificator->getXmlId()).arg(this->getPeptide()->getXmlId()).arg(this->_z));
Olivier Langella's avatar
Olivier Langella committed
161
162
    }
    else {
163
        _p_writer = new OdsDocWriter(QString("%1/%2_%3-%4-z%5.ods").arg(trace_dir.absolutePath()).arg(prefix).arg(quantificator->getXmlId()).arg(this->getPeptide()->getXmlId()).arg(this->_z));
Olivier Langella's avatar
Olivier Langella committed
164
    }
Olivier Langella's avatar
Olivier Langella committed
165
166
167
168
    return _p_writer;

}

Olivier Langella's avatar
Olivier Langella committed
169
XicTraceBase* QuantiItemPeptide::newXicTrace(Quantificator * quantificator, Msrun* p_msrun, const QString & prefix) const {
Olivier Langella's avatar
Olivier Langella committed
170
    if (_trace_peptide_on == false) return nullptr;
171

Olivier Langella's avatar
Olivier Langella committed
172
    return new XicTracePeptide(newCalcWriterInterface(quantificator, p_msrun,prefix), this, p_msrun);
Olivier Langella's avatar
Olivier Langella committed
173
174
}

Olivier Langella's avatar
Olivier Langella committed
175
void QuantiItemPeptide::storeAlignedXicPeakForPostMatching(const Msrun* p_current_msrun,AlignedXicPeakSp & xic_peak_sp) {
176
    qDebug() << "QuantiItemPeptide::storeAlignedXicPeakForPostMatching begin";
177
    std::vector<AlignedXicPeakSp> vec_peak;
178
    vec_peak.push_back(xic_peak_sp);
179
    std::pair<std::map<const Msrun*, std::vector<AlignedXicPeakSp>>::iterator, bool> ret = _map_post_matched_aligned_peaks.insert(std::pair<const Msrun*, std::vector<AlignedXicPeakSp>> (p_current_msrun,vec_peak));
180
181
182
    if (ret.second == false) {
        ret.first->second.push_back(xic_peak_sp);
    }
183
184

    qDebug() << "QuantiItemPeptide::storeAlignedXicPeakForPostMatching end";
185
}
186
void QuantiItemPeptide::clearAlignedXicPeakForPostMatching(const Msrun* p_current_msrun)  {
187
    qDebug() << "QuantiItemPeptide::clearAlignedXicPeakForPostMatching begin";
188
    std::map<const Msrun*, std::vector<AlignedXicPeakSp>>::iterator it = _map_post_matched_aligned_peaks.find(p_current_msrun);
189
190
191
192
    if (it != _map_post_matched_aligned_peaks.end()) {
        _map_post_matched_aligned_peaks.erase (it);
    }

193
    qDebug() << "QuantiItemPeptide::clearAlignedXicPeakForPostMatching end";
194
}
195
196

void QuantiItemPeptide::doPostMatching(MonitorSpeedInterface & monitor_speed) {
197
198

    qDebug() << "QuantiItemPeptide::doPostMatching begin";
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// _p_monitor_speed.writeMatchedPeak();
    pappso::pappso_double rt_target = _p_peptide->getPeptideRtSp().get()->getPostMatchedRtTarget();
    for (std::map<const Msrun*, std::vector<AlignedXicPeakSp>>::iterator it=_map_post_matched_aligned_peaks.begin(); it!=_map_post_matched_aligned_peaks.end(); ++it) {
//   std::cout << it->first << " => " << it->second << '\n';
        const Msrun * p_msrun = it->first;
        bool matched = false;
        std::vector<AlignedXicPeakSp> & _peak_list = it->second;
        for (AlignedXicPeakSp & peak : _peak_list) {
            if (peak.get()->containsRt(rt_target)) {
                matched = true;
                monitor_speed.writeMatchedPeak(p_msrun, this, peak.get());
                break;
            }
        }
        if (matched == false) {
            monitor_speed.writeMatchedPeak(p_msrun, this, nullptr);
        }
    }
217

Olivier Langella's avatar
Olivier Langella committed
218
    _map_post_matched_aligned_peaks.clear();
219

220
    qDebug() << "QuantiItemPeptide::doPostMatching end";
221
}