libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
psmfeaturesscan.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/processing/cbor/psm/evalscan/psmfeaturesscan.cpp
3 * \date 15/07/2025
4 * \author Olivier Langella
5 * \brief compute features on scan's PSM
6 */
7
8/*******************************************************************************
9 * Copyright (c) 2025 Olivier Langella <Olivier.Langella@universite-paris-saclay.fr>.
10 *
11 * This file is part of PAPPSOms-tools.
12 *
13 * PAPPSOms-tools is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * PAPPSOms-tools is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>.
25 *
26 ******************************************************************************/
27
28#include "psmfeaturesscan.h"
29#include <QCborArray>
30#include <QCborMap>
33
34
35namespace pappso
36{
37namespace cbor
38{
39namespace psm
40{
41
43 pappso::XtandemSpectrumProcess &tandem_spectrum_process,
44 std::list<Enums::PeptideIon> &ion_list,
45 pappso::PsmFeatures &psm_features,
46 pappso::PrecisionPtr fragment_tolerance)
47 : CborScanMapBase(psm_file_scan_process),
48 m_tandemSpectrumProcess(tandem_spectrum_process),
49 m_ionList(ion_list),
50 m_psmFeatures(psm_features)
51{
52 m_fragmentTolerance = fragment_tolerance;
53}
54
58
59double
60PsmFeaturesScan::checkInf(double input) const
61{
62 if(input < 0)
63 return 0;
64 return input;
65}
66
67void
69{
70
71 if(keys().contains("psm_list"))
72 {
74
75 pappso::MassSpectrum spectrum =
76 m_tandemSpectrumProcess.process(*qualified_mass_spectrum.get()->getMassSpectrumSPtr().get(),
77 qualified_mass_spectrum.get()->getPrecursorMz(),
78 qualified_mass_spectrum.get()->getPrecursorCharge());
79
80 // qWarning() << qualified_mass_spectrum.get()->getMassSpectrumId().getSpectrumIndex();
81 QCborArray new_psm_arr;
82 for(QCborValue cbor_psm : value("psm_list").toArray())
83 {
84 QCborMap cbor_psm_map = cbor_psm.toMap();
85 QCborMap cbor_psm_features;
86 pappso::PeptideSp peptide_sp =
87 pappso::PeptideProFormaParser::parseString(cbor_psm_map.value("proforma").toString());
88
89 if(peptide_sp.get()->size() < 2)
90 {
91 throw pappso::PappsoException(QObject::tr("peptide in psm too small %1")
92 .arg(cbor_psm_map.value("proforma").toString()));
93 }
94 // qWarning() << cbor_psm_map.value("proforma").toString() << "end " <<
95 // qualified_mass_spectrum.get()->getMassSpectrumId().getSpectrumIndex();
96
97 std::size_t peptide_size = peptide_sp.get()->size();
98 cbor_psm_features.insert(QString("peptide_size"), (unsigned int)peptide_size);
99
100 pappso::XtandemHyperscore hyperscore(spectrum,
101 peptide_sp,
102 qualified_mass_spectrum.get()->getPrecursorCharge(),
104 m_ionList,
105 true);
106 cbor_psm_features.insert(QString("hyperscore"), QCborValue(hyperscore.getHyperscore()));
107 // qWarning() << cbor_psm_map.value("proforma").toString() << "end2 " <<
108 // qualified_mass_spectrum.get()->getMassSpectrumId().getSpectrumIndex();
109
110 m_psmFeatures.setPeptideSpectrumCharge(
111 peptide_sp,
112 qualified_mass_spectrum.get()->getMassSpectrumSPtr().get(),
113 qualified_mass_spectrum.get()->getPrecursorCharge(),
114 2);
115 // TIC
116 cbor_psm_features.insert(QString("total_intensity"),
117 std::log(m_psmFeatures.getTotalIntensity()));
118 cbor_psm_features.insert(QString("total_matched_intensity"),
119 std::log(m_psmFeatures.getTotalIntensityOfMatchedIons()));
120 // MaxIntALL
121 cbor_psm_features.insert(QString("max_intensity"),
122 checkInf(std::log(qualified_mass_spectrum.get()
123 ->getMassSpectrumSPtr()
124 .get()
125 ->maxIntensityDataPoint()
126 .y)));
127
128 // qWarning() << cbor_psm_map.value("proforma").toString() << "end3 " <<
129 // qualified_mass_spectrum.get()->getMassSpectrumId().getSpectrumIndex();
130 // MaxYionInt
131 cbor_psm_features.insert(
132 QString("MaxYionInt"),
133 checkInf(std::log(m_psmFeatures.getMaxIntensityPeakIonMatch(Enums::PeptideIon::y))));
134
135 // MaxBionInt
136 cbor_psm_features.insert(
137 QString("MaxBionInt"),
138 checkInf(std::log(m_psmFeatures.getMaxIntensityPeakIonMatch(Enums::PeptideIon::b))));
139
140 // SumYmatchInt
141 cbor_psm_features.insert(
142 QString("SumYmatchInt"),
143 checkInf(std::log(m_psmFeatures.getIntensityOfMatchedIon(Enums::PeptideIon::y))));
144
145 // SumBmatchInt
146 cbor_psm_features.insert(
147 QString("SumBmatchInt"),
148 checkInf(std::log(m_psmFeatures.getIntensityOfMatchedIon(Enums::PeptideIon::b))));
149
150 // FracYmatchInt
151 cbor_psm_features.insert(
152 QString("FracYmatchInt"),
153 checkInf(m_psmFeatures.getIntensityOfMatchedIon(Enums::PeptideIon::y) /
154 m_psmFeatures.getTotalIntensity()));
155 // FracBmatchInt
156 cbor_psm_features.insert(
157 QString("FracBmatchInt"),
158 checkInf(m_psmFeatures.getIntensityOfMatchedIon(Enums::PeptideIon::b) /
159 m_psmFeatures.getTotalIntensity()));
160
161 // SeqCoverYion
162 cbor_psm_features.insert(
163 QString("SeqCoverYion"),
164 (double)m_psmFeatures.getAaSequenceCoverage(Enums::PeptideIon::y) /
165 (double)peptide_size);
166 // SeqCoverBion
167 cbor_psm_features.insert(
168 QString("SeqCoverBion"),
169 (double)m_psmFeatures.getAaSequenceCoverage(Enums::PeptideIon::b) /
170 (double)peptide_size);
171
172
173 // ConsecutiveYion
174 cbor_psm_features.insert(
175 QString("ConsecutiveYion"),
176 (qint64)m_psmFeatures.getMaxConsecutiveIon(Enums::PeptideIon::y));
177 // ConsecutiveBion
178 cbor_psm_features.insert(
179 QString("ConsecutiveBion"),
180 (qint64)m_psmFeatures.getMaxConsecutiveIon(Enums::PeptideIon::b));
181
182 // MassErrMean
183 cbor_psm_features.insert(QString("MassErrMean"), m_psmFeatures.getMatchedMzDiffMean());
184
185 // MassErrSD
186 cbor_psm_features.insert(QString("MassErrSD"), m_psmFeatures.getMatchedMzDiffSd());
187
188 // NumofAnnoPeaks
189 cbor_psm_features.insert(QString("NumofAnnoPeaks"),
190 (unsigned int)m_psmFeatures.getNumberOfMatchedIons());
191
192 // qWarning() << cbor_psm_map.value("proforma").toString() << "end2 " <<
193 // qualified_mass_spectrum.get()->getMassSpectrumId().getSpectrumIndex();
194 // NumofComplementPeaks
195 std::size_t num_of_pairs = m_psmFeatures.countMatchedIonComplementPairs();
196 cbor_psm_features.insert(QString("NumofComplementPeaks"), (unsigned int)num_of_pairs);
197 if(num_of_pairs > 0)
198 {
199 // SumComplementPeaksInt
200 cbor_psm_features.insert(
201 QString("SumComplementPeaksInt"),
202 std::log(m_psmFeatures.getTotalIntensityOfMatchedIonComplementPairs()));
203
204 // FracComplementPeaksInt
205 cbor_psm_features.insert(
206 QString("FracComplementPeaksInt"),
207 m_psmFeatures.getTotalIntensityOfMatchedIonComplementPairs() /
208 m_psmFeatures.getTotalIntensity());
209 // SeqCoverComplementPeaks
210 cbor_psm_features.insert(
211 QString("SeqCoverComplementPeaks"),
212 (double)m_psmFeatures.getComplementPairsAaSequenceCoverage() /
213 (double)peptide_size);
214 }
215 pappso::LinearRegression lr = m_psmFeatures.getIonIsotopeLinearRegression();
216 cbor_psm_features.insert(QString("lrSize"), (unsigned int)lr.getSize());
217
218
219 double coeff_of_determination = lr.getCoefficientOfDetermination();
220 if(std::isnan(coeff_of_determination))
221 {
222 }
223 else
224 {
225 cbor_psm_features.insert(QString("lrCoeffDet"), coeff_of_determination);
226 }
227
228
229 QCborMap psm_eval = cbor_psm_map.value("eval").toMap();
230 psm_eval.remove(QString("features"));
231 psm_eval.insert(QString("features"), cbor_psm_features);
232 cbor_psm_map.remove(QString("eval"));
233 cbor_psm_map.insert(QString("eval"), psm_eval);
234
235 new_psm_arr.push_back(cbor_psm_map);
236 }
237
238 insert(QString("psm_list"), new_psm_arr);
239 // qWarning() << "end " <<
240 // qualified_mass_spectrum.get()->getMassSpectrumId().getSpectrumIndex();
241 }
242}
243
244} // namespace psm
245} // namespace cbor
246} // namespace pappso
std::size_t getSize() const
get data size
double getCoefficientOfDetermination() const
get Coefficient of determination (R2)
Class to represent a mass spectrum.
static PeptideSp parseString(const QString &pepstr)
pappso_double getHyperscore() const
CborScanMapBase(const PsmFileScanProcess &psm_file_scan_process)
pappso::QualifiedMassSpectrumSPtr getCurrentQualifiedMassSpectrumSPtr() const
PsmFeaturesScan(const PsmFileScanProcess &psm_file_scan_process, pappso::XtandemSpectrumProcess &tandem_spectrum_process, std::list< pappso::Enums::PeptideIon > &ion_list, pappso::PsmFeatures &psm_features, pappso::PrecisionPtr fragment_tolerance)
pappso::XtandemSpectrumProcess & m_tandemSpectrumProcess
std::list< pappso::Enums::PeptideIon > & m_ionList
double checkInf(double input) const
pappso::PrecisionPtr m_fragmentTolerance
Basic PSM file reader to process scan (parallelized scan processing).
@ y
Cter amino ions.
Definition types.h:281
@ b
Nter acylium ions.
Definition types.h:273
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::shared_ptr< QualifiedMassSpectrum > QualifiedMassSpectrumSPtr
std::shared_ptr< const Peptide > PeptideSp
const PrecisionBase * PrecisionPtr
Definition precision.h:122