libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::cbor::psm::CborScanMapBase Class Reference

#include <cborscanmapbase.h>

Inheritance diagram for pappso::cbor::psm::CborScanMapBase:
pappso::cbor::psm::PsmFeaturesScan pappso::cbor::psm::PsmIonSeriesScan pappso::cbor::psm::PsmSpecGlobScan pappso::cbor::psm::PsmSpecPeptidOmsScan

Public Member Functions

 CborScanMapBase (const PsmFileScanProcess &psm_file_scan_process)
virtual ~CborScanMapBase ()
virtual void process ()
virtual void filterAndSortPsmList ()
void filterPsmListUniqueUniqueProforma ()
std::vector< double >::iterator addPsmEvalVectorDouble (const QString &eval_name, const QString &eval_value_key, std::vector< double >::iterator begin, std::vector< double >::const_iterator end)
 add a new eval key and double values (from a vector) to each PSM
QCborMap getCborScanId () const
QCborMap getCborScanPrecursor () const
QCborArray getCborPsmList () const
void populateProteinMapUsingOldProteinMap (const PsmProteinMap &old_protein_map, PsmProteinMap &new_protein_map) const

Protected Member Functions

pappso::QualifiedMassSpectrumSPtr getCurrentQualifiedMassSpectrumSPtr () const

Protected Attributes

const PsmFileScanProcessm_PsmFileScanProcess

Detailed Description

Todo
write docs

Definition at line 47 of file cborscanmapbase.h.

Constructor & Destructor Documentation

◆ CborScanMapBase()

pappso::cbor::psm::CborScanMapBase::CborScanMapBase ( const PsmFileScanProcess & psm_file_scan_process)

◆ ~CborScanMapBase()

pappso::cbor::psm::CborScanMapBase::~CborScanMapBase ( )
virtual

Destructor

Definition at line 45 of file cborscanmapbase.cpp.

46{
47}

Member Function Documentation

◆ addPsmEvalVectorDouble()

std::vector< double >::iterator pappso::cbor::psm::CborScanMapBase::addPsmEvalVectorDouble ( const QString & eval_name,
const QString & eval_value_key,
std::vector< double >::iterator begin,
std::vector< double >::const_iterator end )

add a new eval key and double values (from a vector) to each PSM

Definition at line 86 of file cborscanmapbase.cpp.

90{
91 std::vector<double>::iterator it = itbegin;
92 if(keys().contains("psm_list"))
93 {
94
95
96 QCborArray new_psm_arr;
97 for(QCborValue cbor_psm : value("psm_list").toArray())
98 {
99 QCborMap cbor_psm_map = cbor_psm.toMap();
100
101 if(!cbor_psm_map.keys().contains("proforma"))
102 {
103 throw pappso::PappsoException(
104 QObject::tr("missing proforma in psm %1").arg(cbor_psm_map.keys().size()));
105 }
106 QCborMap cbor_psm_eval_newvalues;
107
108
109 if(it == itend)
110 {
111 throw pappso::PappsoException(
112 QObject::tr("no more values to add in psm %1").arg(cbor_psm_map.keys().size()));
113 }
114 cbor_psm_eval_newvalues.insert(eval_value_key, *it);
115 it++;
116
117
118 QCborMap psm_eval = cbor_psm_map.value("eval").toMap();
119 psm_eval.remove(eval_name);
120 psm_eval.insert(eval_name, cbor_psm_eval_newvalues);
121 cbor_psm_map.remove(QString("eval"));
122 cbor_psm_map.insert(QString("eval"), psm_eval);
123
124 new_psm_arr.push_back(cbor_psm_map);
125 }
126
127 // insert(QString("psm_list"), new_psm_arr);
128 remove(QString("psm_list"));
129 insert(QString("psm_list"), new_psm_arr);
130 }
131 return it;
132}

Referenced by pappso::cbor::psm::PsmNewEval::newCborScanMap().

◆ filterAndSortPsmList()

void pappso::cbor::psm::CborScanMapBase::filterAndSortPsmList ( )
virtual

Reimplemented in pappso::cbor::psm::PsmSpecPeptidOmsScan.

Definition at line 261 of file cborscanmapbase.cpp.

262{
263 // cbor_writer.writeCborMap(*this);
264}

◆ filterPsmListUniqueUniqueProforma()

void pappso::cbor::psm::CborScanMapBase::filterPsmListUniqueUniqueProforma ( )

Definition at line 268 of file cborscanmapbase.cpp.

269{
270
271
272 struct uniquePsmResult
273 {
274 QString proforma;
275 QCborMap psm;
276 };
277
278 QCborArray old_psm_arr = value("psm_list").toArray();
279 QCborArray new_psm_arr;
280 // for(QCborValue cbor_psm : old_psm_arr) {
281
282
283 std::vector<uniquePsmResult> all_psm_list;
284 for(auto it_psm : old_psm_arr)
285 {
286 QCborMap psm_map = it_psm.toMap();
287 all_psm_list.push_back({psm_map.value("proforma").toString(), psm_map});
288 }
289 qDebug();
290 std::sort(all_psm_list.begin(), all_psm_list.end(), [](uniquePsmResult &a, uniquePsmResult &b) {
291 return a.proforma > b.proforma;
292 });
293
294 qDebug();
295 std::vector<uniquePsmResult> unique_psm_list;
296
297 for(auto it = all_psm_list.begin(); it != all_psm_list.end(); it++)
298 {
299 qDebug() << it->proforma;
300 if(unique_psm_list.size() > 0)
301 {
302 if(unique_psm_list.back().proforma == it->proforma)
303 {
304 // merge ?
305 PsmCborUtils::mergePsmProteinRefList(unique_psm_list.back().psm, it->psm);
306 }
307 else
308 {
309 unique_psm_list.push_back(*it);
310 }
311 }
312 else
313 {
314 unique_psm_list.push_back(*it);
315 }
316
317 qDebug();
318 }
319
320
321 qDebug() << unique_psm_list.size();
322 for(auto it = unique_psm_list.begin(); it != unique_psm_list.end(); it++)
323 {
324 new_psm_arr.append(it->psm);
325 qDebug();
326 }
327
328 // qWarning() << new_psm_arr.size();
329 remove(QString("psm_list"));
330 insert(QString("psm_list"), new_psm_arr);
331}
static void mergePsmProteinRefList(QCborMap &cbor_psm_destination, const QCborMap &cbor_psm_source)

References pappso::a, pappso::b, and pappso::cbor::psm::PsmCborUtils::mergePsmProteinRefList().

Referenced by pappso::cbor::psm::PsmSpecGlobScan::process(), and pappso::cbor::psm::PsmSpecPeptidOmsScan::process().

◆ getCborPsmList()

QCborArray pappso::cbor::psm::CborScanMapBase::getCborPsmList ( ) const

Definition at line 75 of file cborscanmapbase.cpp.

76{
77 if(!keys().contains("psm_list"))
78 {
79 throw pappso::PappsoException(QObject::tr("missing psm_list in scan"));
80 }
81 return value("psm_list").toArray();
82}

◆ getCborScanId()

QCborMap pappso::cbor::psm::CborScanMapBase::getCborScanId ( ) const

Definition at line 55 of file cborscanmapbase.cpp.

56{
57 if(!keys().contains("id"))
58 {
59 throw pappso::PappsoException(QObject::tr("missing id in scan"));
60 }
61 return value("id").toMap();
62}

◆ getCborScanPrecursor()

QCborMap pappso::cbor::psm::CborScanMapBase::getCborScanPrecursor ( ) const

Definition at line 65 of file cborscanmapbase.cpp.

66{
67 if(!keys().contains("precursor"))
68 {
69 throw pappso::PappsoException(QObject::tr("missing precursor in scan"));
70 }
71 return value("precursor").toMap();
72}

◆ getCurrentQualifiedMassSpectrumSPtr()

pappso::QualifiedMassSpectrumSPtr pappso::cbor::psm::CborScanMapBase::getCurrentQualifiedMassSpectrumSPtr ( ) const
protected

Definition at line 136 of file cborscanmapbase.cpp.

137{
138 if(isEmpty())
139 {
140 throw pappso::PappsoException(QObject::tr("ERROR: cbor scan map is empty"));
141 }
142 if(!contains(QString("precursor")))
143 {
144 throw pappso::PappsoException(QObject::tr("ERROR: no precursor in scan"));
145 }
146 const QCborMap cbor_precursor(value("precursor").toMap());
147 if(!contains(QString("ms2")))
148 {
149 throw pappso::PappsoException(QObject::tr("ERROR: ms2 is empty in scan"));
150 }
151 const QCborMap cbor_ms2(value("ms2").toMap());
152
153 if(!contains(QString("id")))
154 {
155 throw pappso::PappsoException(QObject::tr("ERROR: id is empty in scan"));
156 }
157 const QCborMap cbor_id(value("id").toMap());
158
159 if(!cbor_id.keys().contains("index"))
160 {
161 throw pappso::PappsoException("There is no scan index");
162 }
163
164 if(!cbor_ms2.keys().contains("spectrum"))
165 {
166 throw pappso::PappsoException("There is no spectrum in ms2");
167 }
168
169 const QCborMap cbor_spectrum(cbor_ms2.value("spectrum").toMap());
170
171 if(!cbor_spectrum.keys().contains("mz"))
172 {
173 throw pappso::PappsoException("There is no cbor_spectrum mz values");
174 }
175 if(!cbor_spectrum.keys().contains("intensity"))
176 {
177 throw pappso::PappsoException("There is no cbor_spectrum intensity values");
178 }
179 pappso::MsRunId msrun_id(m_PsmFileScanProcess.m_currentPeaklistFile.name);
180 msrun_id.setSampleName(m_PsmFileScanProcess.m_currentSampleName);
181 pappso::MsRunIdCstSPtr msrun_id_sp = std::make_shared<const pappso::MsRunId>(msrun_id);
182 pappso::MassSpectrumId ms_id(msrun_id_sp);
183 ms_id.setSpectrumIndex(cbor_id.value("index").toInteger());
184
185 // native_id
186 if(cbor_id.keys().contains("native_id"))
187 {
188 ms_id.setNativeId(cbor_id.value("native_id").toString());
189 }
190
191 std::vector<DataPoint> data_point_vector;
192 std::size_t i = 0;
193 for(auto cbor_mz_value : cbor_spectrum.value("mz").toArray())
194 {
195 data_point_vector.push_back(
196 {cbor_mz_value.toDouble(), cbor_spectrum.value("intensity").toArray().at(i).toDouble()});
197 i++;
198 }
199
200
201 MassSpectrum mass_spectrum(data_point_vector);
202 pappso::PrecursorIonData precursor_ion_data;
203
204 pappso::QualifiedMassSpectrum qualified_mass_spectrum(ms_id);
205 qualified_mass_spectrum.setMassSpectrumSPtr(mass_spectrum.makeMassSpectrumSPtr());
206 qualified_mass_spectrum.setMsLevel(2);
207
208 if(cbor_precursor.keys().contains("z"))
209 {
210 precursor_ion_data.charge = cbor_precursor.value("z").toInteger();
211 }
212 if(cbor_precursor.keys().contains("mz"))
213 {
214 precursor_ion_data.mz = cbor_precursor.value("mz").toDouble();
215 }
216 if(cbor_precursor.keys().contains("intensity"))
217 {
218 precursor_ion_data.intensity = cbor_precursor.value("intensity").toDouble();
219 }
220 qualified_mass_spectrum.appendPrecursorIonData(precursor_ion_data);
221 if(cbor_ms2.keys().contains("rt"))
222 {
223 qualified_mass_spectrum.setRtInSeconds(cbor_ms2.value("rt").toDouble());
224 }
225
226
227 return qualified_mass_spectrum.makeQualifiedMassSpectrumSPtr();
228}
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
Definition msrunid.h:46

References pappso::QualifiedMassSpectrum::appendPrecursorIonData(), pappso::PrecursorIonData::charge, pappso::PrecursorIonData::intensity, m_PsmFileScanProcess, pappso::MassSpectrum::makeMassSpectrumSPtr(), pappso::QualifiedMassSpectrum::makeQualifiedMassSpectrumSPtr(), pappso::PrecursorIonData::mz, pappso::QualifiedMassSpectrum::setMassSpectrumSPtr(), pappso::QualifiedMassSpectrum::setMsLevel(), pappso::MassSpectrumId::setNativeId(), pappso::QualifiedMassSpectrum::setRtInSeconds(), pappso::MsRunId::setSampleName(), and pappso::MassSpectrumId::setSpectrumIndex().

Referenced by pappso::cbor::psm::PsmFeaturesScan::process(), pappso::cbor::psm::PsmIonSeriesScan::process(), pappso::cbor::psm::PsmSpecGlobScan::process(), and pappso::cbor::psm::PsmSpecPeptidOmsScan::process().

◆ populateProteinMapUsingOldProteinMap()

void pappso::cbor::psm::CborScanMapBase::populateProteinMapUsingOldProteinMap ( const PsmProteinMap & old_protein_map,
PsmProteinMap & new_protein_map ) const

Definition at line 230 of file cborscanmapbase.cpp.

232{
233 if(isEmpty())
234 {
235 throw pappso::PappsoException(QObject::tr("ERROR: cbor scan map is empty"));
236 }
237 if(!contains(QString("psm_list")))
238 {
239 throw pappso::PappsoException(QObject::tr("ERROR: no psm_list in scan"));
240 }
241
242 for(auto it_psm : value("psm_list").toArray())
243 {
244 QCborMap psm = it_psm.toMap();
245 if(!psm.contains(QString("protein_list")))
246 {
247 throw pappso::PappsoException(
248 QObject::tr("ERROR: no protein_list in psm, psm_list in scan"));
249 }
250
251 for(auto it_protein : psm.value("protein_list").toArray())
252 {
253 new_protein_map.insert(
254 old_protein_map.getByAccession(it_protein.toMap().value("accession").toString()));
255 }
256 }
257}

References pappso::cbor::psm::PsmProteinMap::getByAccession(), and pappso::cbor::psm::PsmProteinMap::insert().

◆ process()

void pappso::cbor::psm::CborScanMapBase::process ( )
virtual

Member Data Documentation

◆ m_PsmFileScanProcess

const PsmFileScanProcess& pappso::cbor::psm::CborScanMapBase::m_PsmFileScanProcess
protected

Definition at line 85 of file cborscanmapbase.h.

Referenced by CborScanMapBase(), and getCurrentQualifiedMassSpectrumSPtr().


The documentation for this class was generated from the following files: