quantiitempeptidenaturalisotope.cpp 6.12 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

/*******************************************************************************
 * Copyright (c) 2015 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 "quantiitempeptidenaturalisotope.h"
25
#include "QStringList"
Olivier Langella's avatar
Olivier Langella committed
26
#include "../xic/xictracepeptidenaturalisotope.h"
27
#include "../peptides/isotope_label.h"
Olivier Langella's avatar
Olivier Langella committed
28
29
30
#include <odsstream/tsvdirectorywriter.h>
#include <odsstream/calcwriterinterface.h>

31

32
QuantiItemPeptideNaturalIsotope::QuantiItemPeptideNaturalIsotope(bool trace_peptide_on,
33
        const Peptide * p_peptide,
34
        const pappso::PeptideNaturalIsotopeAverageSp & peptide_natural_isotope_average_sp)
35
    :
36

37
    QuantiItemPeptide(trace_peptide_on, p_peptide)
38
{
39
40
41
    _mz = peptide_natural_isotope_average_sp.get()->getMz();

    _z = peptide_natural_isotope_average_sp.get()->getCharge();
42
43
44
45
46
47
48
49
    _peptide_natural_isotope_average_sp = peptide_natural_isotope_average_sp;
}

QuantiItemPeptideNaturalIsotope::~QuantiItemPeptideNaturalIsotope()
{

}

50
51
const QString QuantiItemPeptideNaturalIsotope::getMzId() const {
    return (QString("%1+%2+%3-%4").arg(_p_peptide->getXmlId()).arg(_z).arg(_peptide_natural_isotope_average_sp.get()->getIsotopeNumber()).arg(_peptide_natural_isotope_average_sp.get()->getIsotopeRank()));
52
}
53
54
55
56
57
58
59
void QuantiItemPeptideNaturalIsotope::writeCurrentSearchItem(MCQXmlStreamWriter* _output_stream) const
{

    QuantiItemPeptide::writeCurrentSearchItem(_output_stream);

    _output_stream->writeAttribute("ninumber", QString::number(_peptide_natural_isotope_average_sp.get()->getIsotopeNumber(), 'f',0));
    _output_stream->writeAttribute("nirank", QString::number(_peptide_natural_isotope_average_sp.get()->getIsotopeRank(), 'f',0));
Olivier Langella's avatar
Olivier Langella committed
60
    _output_stream->writeAttribute("niratio", QString::number(_peptide_natural_isotope_average_sp.get()->getIntensityRatio(), 'f', 5));
61
62
}

Olivier Langella's avatar
Olivier Langella committed
63
64


Olivier Langella's avatar
Olivier Langella committed
65
66
67
68

void QuantiItemPeptideNaturalIsotope::writeOdsPeptideLine(CalcWriterInterface & writer) const {
    QuantiItemPeptide::writeOdsPeptideLine(writer);

69

Olivier Langella's avatar
Olivier Langella committed
70
    writer.writeCell(_peptide_natural_isotope_average_sp.get()->getIsotopeNumber());
71

Olivier Langella's avatar
Olivier Langella committed
72
    writer.writeCell(_peptide_natural_isotope_average_sp.get()->getIsotopeRank());
73

Olivier Langella's avatar
Olivier Langella committed
74
75
    writer.writeCell(_peptide_natural_isotope_average_sp.get()->getIntensityRatio());
}
Olivier Langella's avatar
Olivier Langella committed
76
77


78
79

void QuantiItemPeptideNaturalIsotope::writeOdsComparHeaderLine(CalcWriterInterface & writer) const {
80

81
82
83
84
    //_p_writer->writeCell("peptide");
    writer.writeCell(_p_peptide->getXmlId());
    //_p_writer->writeCell("m/z");
    writer.writeCell(getMz());
85
86
    //_p_writer->writeCell("rt reference");
    writer.writeCell(this->_p_peptide->getPeptideRtSp().get()->getAlignedReferenceRt());
87
88
89
90
91
92
93
94
    //_p_writer->writeCell("z");
    writer.writeCell(_z);
    //_p_writer->writeCell("isotope number");
    writer.writeCell(_peptide_natural_isotope_average_sp.get()->getIsotopeNumber());
    //_p_writer->writeCell("isotope rank");
    writer.writeCell(_peptide_natural_isotope_average_sp.get()->getIsotopeRank());
    writer.writeCell(_peptide_natural_isotope_average_sp.get()->getIntensityRatio());
    //_p_writer->writeCell("sequence");
95
    writer.writeCell(_p_peptide->getPappsoPeptideSp().get()->toString());
96
97
98
99
100
101
102
    //_p_writer->writeCell("isotope");
    if (_p_peptide->getIsotopeLabel() == nullptr) {
        writer.writeEmptyCell();
    }
    else {
        writer.writeCell(_p_peptide->getIsotopeLabel()->getXmlId());
    }
103
104
105
106
107
    //_p_writer->writeCell("mods");
    writer.writeCell(_p_peptide->getMods());
    //_p_writer->writeCell("proteins");
    QStringList protein_list;
    for (const Protein * p_protein : _p_peptide->getProteinList()) {
108
        protein_list << p_protein->getXmlId();
109
110
111
112
113
    }
    writer.writeCell(protein_list.join(" "));
}


Olivier Langella's avatar
Olivier Langella committed
114
pappso::PeptideNaturalIsotopeAverageSp QuantiItemPeptideNaturalIsotope::getPeptideNaturalIsotopeAverageSp () const {
115
    return _peptide_natural_isotope_average_sp;
Olivier Langella's avatar
Olivier Langella committed
116
}
Olivier Langella's avatar
Olivier Langella committed
117
118


Olivier Langella's avatar
Olivier Langella committed
119
CalcWriterInterface * QuantiItemPeptideNaturalIsotope::newCalcWriterInterface(const Quantificator * quantificator, const Msrun* p_msrun, const QString & prefix) const {
Olivier Langella's avatar
Olivier Langella committed
120
121
    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
122
123
    CalcWriterInterface * _p_writer=nullptr;
    if (quantificator->getTracesFormat() == McqTsvFormat::tsv) {
124
        _p_writer = new TsvDirectoryWriter(QString("%1/%2_%3-%4-z%5-%6-%7.d").arg(trace_dir.absolutePath()).arg(prefix).arg(quantificator->getXmlId()).arg(this->getPeptide()->getXmlId()).arg(this->_z).arg(this->getPeptideNaturalIsotopeAverageSp()->getIsotopeNumber()).arg(this->getPeptideNaturalIsotopeAverageSp()->getIsotopeRank()));
Olivier Langella's avatar
Olivier Langella committed
125
126
    }
    else {
127
        _p_writer = new OdsDocWriter(QString("%1/%2_%3-%4-z%5-%6-%7.ods").arg(trace_dir.absolutePath()).arg(prefix).arg(quantificator->getXmlId()).arg(this->getPeptide()->getXmlId()).arg(this->_z).arg(this->getPeptideNaturalIsotopeAverageSp()->getIsotopeNumber()).arg(this->getPeptideNaturalIsotopeAverageSp()->getIsotopeRank()));
Olivier Langella's avatar
Olivier Langella committed
128
129
130
131
132
133
    }
    return _p_writer;

}


Olivier Langella's avatar
Olivier Langella committed
134
XicTraceBase* QuantiItemPeptideNaturalIsotope::newXicTrace(Quantificator * quantificator, Msrun* p_msrun, const QString & prefix) const {
Olivier Langella's avatar
Olivier Langella committed
135
    if (_trace_peptide_on == false) return nullptr;
136

Olivier Langella's avatar
Olivier Langella committed
137
    return new XicTracePeptideNaturalIsotope(newCalcWriterInterface(quantificator, p_msrun, prefix), this, p_msrun);
Olivier Langella's avatar
Olivier Langella committed
138
139
}