libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
psmspecglobscan.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/processing/cbor/psm/evalscan/psmspecglobscan.cpp
3 * \date 19/07/2025
4 * \author Olivier Langella
5 * \brief compute specglob alignment 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 "psmspecglobscan.h"
33#include <QCborArray>
34
36 pappso::PrecisionPtr fragment_tolerance)
37 : CborScanMapBase(psm_specgloc)
38{
39 m_fragmentTolerance = fragment_tolerance;
40 mp_psmSpecGlob = &psm_specgloc;
41}
42
46
47void
49{
50 if(!keys().contains("id"))
51 {
52 throw pappso::PappsoException(QObject::tr("missing scan id"));
53 }
54 if(keys().contains("psm_list"))
55 {
57 pappso::specglob::ExperimentalSpectrumCsp experimental_spectrum =
58 std::make_shared<pappso::specglob::ExperimentalSpectrum>(*qualified_mass_spectrum.get(),
60
61
62 mp_psmSpecGlob->filterMassSpectrum(
63 *(qualified_mass_spectrum.get()->getMassSpectrumSPtr().get()));
64
65 QCborArray new_psm_arr;
66 for(QCborValue cbor_psm : value("psm_list").toArray())
67 {
68 QCborMap cbor_psm_map = cbor_psm.toMap();
69
70 if(!cbor_psm_map.keys().contains("proforma"))
71 {
73 QObject::tr("missing proforma in psm %1 spectrum %2")
74 .arg(cbor_psm_map.keys().size())
75 .arg(qualified_mass_spectrum.get()->getMassSpectrumId().getNativeId()));
76 }
77 QString proforma = cbor_psm_map.value("proforma").toString();
78 if(proforma.isEmpty())
79 {
80
82 QObject::tr("proforma is empty in psm %1 spectrum %2")
83 .arg(cbor_psm_map.keys().size())
84 .arg(qualified_mass_spectrum.get()->getMassSpectrumId().getNativeId()));
85 }
86 QCborMap cbor_psm_eval_specglob;
87 qDebug();
89
90 qDebug() << proforma << " " << peptide_sp.get()->toProForma();
92 std::make_shared<pappso::specglob::PeptideSpectrum>(peptide_sp);
93
94 qDebug();
95
96 qDebug();
99
100 spectral_alignment.align(peptide_spectra, experimental_spectrum);
101
102 cbor_psm_eval_specglob.insert(QString("max_score"), spectral_alignment.getMaxScore());
103
104 bool keep = false;
105
106 if(spectral_alignment.getMaxScore() > 0)
107 {
108 pappso::specglob::PeptideModel peptide_model = spectral_alignment.buildPeptideModel();
109
110 // peptide_model.eliminateComplementaryDelta(m_fragmentTolerance);
111 // peptide_model.matchExperimentalPeaks(m_fragmentTolerance);
112
113
114 pappso::specglob::PostTreatment post_treatment(m_fragmentTolerance, peptide_model);
116 post_treatment.findReplaceMutations();
117 peptide_model = post_treatment.getBetterPeptideModel();
118
119 cbor_psm_eval_specglob.insert(QString("count"),
120 (qint64)peptide_model.getCountSharedPeaks());
121
122 cbor_psm_eval_specglob.insert(QString("proforma"), peptide_model.toProForma());
123 cbor_psm_eval_specglob.insert(QString("bracket"), peptide_model.toString());
124
125 // peptide_model.checkForMutations()
126
127 if(mp_psmSpecGlob->m_isProteinMatcherResult)
128 {
129 keep = true;
130 }
131 }
132
133 QCborMap psm_eval = cbor_psm_map.value("eval").toMap();
134 psm_eval.remove(QString("specglob"));
135 psm_eval.insert(QString("specglob"), cbor_psm_eval_specglob);
136 cbor_psm_map.remove(QString("eval"));
137 cbor_psm_map.insert(QString("eval"), psm_eval);
138
139 if(mp_psmSpecGlob->m_isProteinMatcherResult)
140 {
141 if(keep)
142 {
143 QCborMap new_psm;
144 new_psm.insert(QString("proforma"),
145 cbor_psm_eval_specglob.value("proforma").toString());
146 new_psm.insert(QString("protein_list"), cbor_psm_map.value("protein_list"));
147 new_psm.insert(QString("eval"), cbor_psm_map.value("eval"));
148 new_psm_arr.push_back(new_psm);
149 }
150 }
151 else
152 {
153 new_psm_arr.push_back(cbor_psm_map);
154 }
155 }
156
157 // insert(QString("psm_list"), new_psm_arr);
158 remove(QString("psm_list"));
159 insert(QString("psm_list"), new_psm_arr);
160
161
163 }
164}
static PeptideSp parseString(const QString &pepstr)
CborScanMapBase(const PsmFileScanProcess &psm_file_scan_process)
pappso::QualifiedMassSpectrumSPtr getCurrentQualifiedMassSpectrumSPtr() const
pappso::PrecisionPtr m_fragmentTolerance
PsmSpecGlobScan(const PsmSpecGlob &psm_specgloc, pappso::PrecisionPtr fragment_tolerance)
std::size_t getCountSharedPeaks() const
QString toProForma() const
get the peptide model in ProForma notation https://github.com/HUPO-PSI/ProForma/blob/master/README....
const PeptideModel & getBetterPeptideModel() const
void align(PeptideSpectraCsp peptide_spectrum, ExperimentalSpectrumCsp experimental_spectrum)
build the alignment matrix between a peptide sequence and an experimental spectrum
std::shared_ptr< const PeptideSpectrum > PeptideSpectraCsp
std::shared_ptr< const ExperimentalSpectrum > ExperimentalSpectrumCsp
std::shared_ptr< QualifiedMassSpectrum > QualifiedMassSpectrumSPtr
std::shared_ptr< const Peptide > PeptideSp
const PrecisionBase * PrecisionPtr
Definition precision.h:122