libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::cbor::mzcbor::MzcborPrecursorFinder Class Reference

base class to transform mzCBOR stream in a new mzCBOR output stream More...

#include <mzcborprecursorfinder.h>

Inheritance diagram for pappso::cbor::mzcbor::MzcborPrecursorFinder:
pappso::cbor::mzcbor::MzcborCopyReplaceBase pappso::cbor::CborStreamReaderInterface

Public Member Functions

 MzcborPrecursorFinder (CborStreamWriter *cbor_output_p, const QJsonObject &json_params)
virtual ~MzcborPrecursorFinder ()
void setRetentionTimeRangeInSeconds (double rt_start, double rt_stop)
Public Member Functions inherited from pappso::cbor::mzcbor::MzcborCopyReplaceBase
 MzcborCopyReplaceBase (CborStreamWriter *cbor_output_p, const QString &operation)
virtual ~MzcborCopyReplaceBase ()
virtual void readCbor (QFile *cborp, pappso::UiMonitorInterface &monitor)
 read mzCBOR file
virtual void readCbor (QIODevice *cborp, pappso::UiMonitorInterface &monitor)
 read mzCBOR from any device (memory buffer or else)
virtual void close ()
 convenient function to clean pointer before leaving
Public Member Functions inherited from pappso::cbor::CborStreamReaderInterface
 CborStreamReaderInterface ()
virtual ~CborStreamReaderInterface ()

Protected Member Functions

virtual void processQcborSpectrum (SpectrumTube &spectrum_tube, QcborSpectrum &cbor_spectrum)
std::vector< QcborSpectrum > findPotentialPrecursorIonData (const QcborSpectrum &ms1_spectrum, const QcborSpectrum &ms2_spectrum, const QcborSpectrumPrecursor &precursor)
Protected Member Functions inherited from pappso::cbor::mzcbor::MzcborCopyReplaceBase
void readRoot (pappso::UiMonitorInterface &monitor)
void readCbor (pappso::UiMonitorInterface &monitor)
void readRun (pappso::UiMonitorInterface &monitor)
void readSpectrumList (pappso::UiMonitorInterface &monitor)
Protected Member Functions inherited from pappso::cbor::CborStreamReaderInterface
bool getExpectedString ()
void initCborReader (QFile *pcborfile)
void initCborReader (QIODevice *pcborfile)

Private Member Functions

QJsonValue getParameterValue (const QString &name) const

Private Attributes

QJsonObject m_parameters
std::vector< std::int8_t > m_potentialPrecursorChargeStateList = {1, 2, 3}
double m_rtStart = 0
double m_rtStop = std::numeric_limits<double>::max()
std::map< QString, QString > m_ms1idOldToNew
std::deque< std::pair< QString, QcborSpectrum > > m_spectrumMs1List
std::size_t m_maxSpectrumMs1ListSize = 100
pappso::PrecisionPtr m_ms2Tolerance
pappso::PrecisionPtr m_ms1Tolerance
double m_intensityRatioThreshold = 0.3
std::size_t m_minimumComplementIon = 1
double m_ms2minimumMz = 150
std::size_t m_ms2nMostIntense = 60
std::deque< std::pair< const QcborSpectrum *, TraceSPtr > > m_cacheMs1Trace

Additional Inherited Members

Protected Attributes inherited from pappso::cbor::mzcbor::MzcborCopyReplaceBase
bool m_stopParsing = false
CborStreamWriter * mp_cborOutput
QString m_operation
Protected Attributes inherited from pappso::cbor::CborStreamReaderInterface
CborStreamReader * mpa_cborReader = nullptr
QString m_expectedString
QByteArray m_data

Detailed Description

base class to transform mzCBOR stream in a new mzCBOR output stream

ensures stream read on regular file or any readable device

Definition at line 51 of file mzcborprecursorfinder.h.

Constructor & Destructor Documentation

◆ MzcborPrecursorFinder()

pappso::cbor::mzcbor::MzcborPrecursorFinder::MzcborPrecursorFinder ( CborStreamWriter * cbor_output_p,
const QJsonObject & json_params )

Default constructor

Definition at line 54 of file mzcborprecursorfinder.cpp.

56 : MzcborCopyReplaceBase(cbor_output_p, "precursor_finder")
57{
58 m_parameters = json_params;
59
60
61 if(getParameterValue("ms1_tolerance_unit").toString() == "dalton")
62 {
65 }
66 else if(getParameterValue("ms1_tolerance_unit").toString() == "ppm")
67 {
70 }
71 else
72 {
73 throw pappso::ExceptionNotFound(QObject::tr("ms1_tolerance_unit %1 not known")
74 .arg(getParameterValue("ms1_tolerance_unit").toString()));
75 }
76
77 if(getParameterValue("ms2_tolerance_unit").toString() == "dalton")
78 {
81 }
82 else if(getParameterValue("ms2_tolerance_unit").toString() == "ppm")
83 {
86 }
87 else
88 {
89 throw pappso::ExceptionNotFound(QObject::tr("ms2_tolerance_unit %1 not known")
90 .arg(getParameterValue("ms2_tolerance_unit").toString()));
91 }
92
93 m_minimumComplementIon = getParameterValue("minimum_complement_ion").toInt();
94 m_intensityRatioThreshold = getParameterValue("intensity_ratio_threshold").toDouble();
95
96 m_ms2nMostIntense = getParameterValue("ms2_max_peaks").toInt();
97
99 QJsonArray charge_arr = getParameterValue("potential_charge_states").toArray();
100 for(auto charge : charge_arr)
101 {
102 m_potentialPrecursorChargeStateList.push_back(charge.toInt());
103 }
104}
static PrecisionPtr getPpmInstance(pappso_double value)
get a ppm precision pointer
static PrecisionPtr getDaltonInstance(pappso_double value)
get a Dalton precision pointer
MzcborCopyReplaceBase(CborStreamWriter *cbor_output_p, const QString &operation)
std::vector< std::int8_t > m_potentialPrecursorChargeStateList
QJsonValue getParameterValue(const QString &name) const

References pappso::cbor::mzcbor::MzcborCopyReplaceBase::MzcborCopyReplaceBase(), pappso::PrecisionFactory::getDaltonInstance(), getParameterValue(), pappso::PrecisionFactory::getPpmInstance(), m_intensityRatioThreshold, m_minimumComplementIon, m_ms1Tolerance, m_ms2nMostIntense, m_ms2Tolerance, m_parameters, and m_potentialPrecursorChargeStateList.

◆ ~MzcborPrecursorFinder()

pappso::cbor::mzcbor::MzcborPrecursorFinder::~MzcborPrecursorFinder ( )
virtual

Destructor

Definition at line 105 of file mzcborprecursorfinder.cpp.

106{
107}

Member Function Documentation

◆ findPotentialPrecursorIonData()

std::vector< QcborSpectrum > pappso::cbor::mzcbor::MzcborPrecursorFinder::findPotentialPrecursorIonData ( const QcborSpectrum & ms1_spectrum,
const QcborSpectrum & ms2_spectrum,
const QcborSpectrumPrecursor & precursor )
protected

Definition at line 251 of file mzcborprecursorfinder.cpp.

254{
255
256 pappso::TraceSPtr ms1_trace_sp;
257
258 auto it_cache_ms1_trace =
259 std::find_if(m_cacheMs1Trace.cbegin(),
260 m_cacheMs1Trace.cend(),
261 [ms1_spectrum](const auto &item) { return item.first == &ms1_spectrum; });
262
263 if(it_cache_ms1_trace == m_cacheMs1Trace.end())
264 {
265 ms1_trace_sp = std::make_shared<Trace>();
266 ms1_spectrum.decodeTrace(*ms1_trace_sp.get());
267 m_cacheMs1Trace.push_back({&ms1_spectrum, ms1_trace_sp});
269 {
270 m_cacheMs1Trace.pop_front();
271 }
272 }
273 else
274 {
275 ms1_trace_sp = it_cache_ms1_trace->second;
276 }
277 pappso::Trace ms1_trace(*ms1_trace_sp.get());
278 pappso::Trace ms2_trace;
279 ms2_spectrum.decodeTrace(ms2_trace);
280
281 // MS2 filters
282 pappso::FilterChargeDeconvolution(m_ms2Tolerance).filter(ms2_trace);
283 pappso::FilterResampleKeepGreater(m_ms2minimumMz).filter(ms2_trace);
284 pappso::FilterGreatestY(m_ms2nMostIntense).filter(ms2_trace);
285 // END MS2 filters
286
287
288 std::vector<QcborSpectrum> potential_precursors;
289 double precursor_intensity = 0;
290 std::vector<SelectedIon> selected_ion_list = precursor.getSelectedIonList();
291 if(selected_ion_list.size() != 1)
292 {
293 throw pappso::PappsoException("ERROR: selected_ion_list.size() != 1");
294 }
295 bool is_ok = false;
296 precursor_intensity = selected_ion_list.at(0).getIntensity(&is_ok);
297 if(!is_ok)
298 {
299 throw pappso::PappsoException(
300 QObject::tr("ERROR: precursor intensity not found in spectrum %1")
301 .arg(ms2_spectrum.getId()));
302 precursor_intensity = 0;
303 }
304
305 qDebug();
306 FilterMs1WindowSelection window(precursor);
307 qDebug();
308 window.filter(ms1_trace);
309 pappso::FilterHighPass(precursor_intensity * m_intensityRatioThreshold).filter(ms1_trace);
310
311 for(const pappso::DataPoint &data_point : ms1_trace)
312 {
314 {
315 double intensity = data_point.y;
316 double mz = data_point.x;
317
318 FilterComplement complement(mz * (double)charge, m_ms2Tolerance);
319 pappso::Trace ms2(ms2_trace);
320 complement.filter(ms2);
321 if(ms2.size() > (std::size_t)m_minimumComplementIon)
322 {
323 QcborSpectrum new_ms2(ms2_spectrum);
324
325 QcborSpectrumPrecursor copy_precursor(precursor);
326 copy_precursor.setSelectedIon(mz, intensity, charge);
327
328 std::vector<QcborSpectrumPrecursor> precursor_list;
329 precursor_list.push_back(copy_precursor);
330
331 qDebug() << copy_precursor;
332 new_ms2.setPrecursorList(precursor_list);
333
334 qDebug() << new_ms2;
335 potential_precursors.push_back(new_ms2);
336 }
337 }
338 }
339
340
341 return potential_precursors;
342}
std::deque< std::pair< const QcborSpectrum *, TraceSPtr > > m_cacheMs1Trace
std::shared_ptr< Trace > TraceSPtr
Definition trace.h:139

References pappso::cbor::mzcbor::QcborSpectrum::decodeTrace(), FilterComplement::filter(), FilterMs1WindowSelection::filter(), pappso::FilterChargeDeconvolution::filter(), pappso::FilterGreatestY::filter(), pappso::FilterHighPass::filter(), pappso::FilterResampleKeepGreater::filter(), pappso::cbor::mzcbor::QcborSpectrum::getId(), pappso::cbor::mzcbor::QcborSpectrumPrecursor::getSelectedIonList(), m_cacheMs1Trace, m_intensityRatioThreshold, m_maxSpectrumMs1ListSize, m_minimumComplementIon, m_ms2minimumMz, m_ms2nMostIntense, m_ms2Tolerance, m_potentialPrecursorChargeStateList, pappso::cbor::mzcbor::QcborSpectrum::setPrecursorList(), and pappso::cbor::mzcbor::QcborSpectrumPrecursor::setSelectedIon().

Referenced by processQcborSpectrum().

◆ getParameterValue()

QJsonValue pappso::cbor::mzcbor::MzcborPrecursorFinder::getParameterValue ( const QString & name) const
private

Definition at line 111 of file mzcborprecursorfinder.cpp.

112{
113 QJsonValue value;
114 if(m_parameters.contains(name))
115 {
116 return m_parameters.value(name);
117 }
118 else
119 {
120 throw pappso::ExceptionNotFound(QObject::tr("parameter %1 not defined precursor finder JSON "
121 "parameters")
122 .arg(name));
123 }
124 return value;
125}

References m_parameters.

Referenced by MzcborPrecursorFinder().

◆ processQcborSpectrum()

void pappso::cbor::mzcbor::MzcborPrecursorFinder::processQcborSpectrum ( SpectrumTube & spectrum_tube,
QcborSpectrum & cbor_spectrum )
protectedvirtual

Reimplemented from pappso::cbor::mzcbor::MzcborCopyReplaceBase.

Definition at line 134 of file mzcborprecursorfinder.cpp.

136{
137 if(cbor_spectrum.getMsLevel() == 1)
138 {
139 QString old_ms1_id = cbor_spectrum.getId();
140 m_spectrumMs1List.push_back({old_ms1_id, cbor_spectrum});
142 {
143 m_spectrumMs1List.pop_front();
144 }
145 QString new_ms1_id = spectrum_tube.push_back(cbor_spectrum);
146
147 m_ms1idOldToNew.insert({old_ms1_id, new_ms1_id});
148 }
149 else
150 {
151 double rt = cbor_spectrum.getRetentionTimeInSeconds();
152 if((rt > m_rtStart) && (rt < m_rtStop))
153 {
154
155 std::vector<QcborSpectrumPrecursor> precursor_list = cbor_spectrum.getPrecursorList();
156 if(precursor_list.size() == 1)
157 {
158 //"spectrumRef":"controllerType=0 controllerNumber=1 scan=2711",
159 QString spectrum_ref = precursor_list.at(0).getSpectrumRef();
160
161 auto it_ms1 =
162 std::find_if(m_spectrumMs1List.begin(),
163 m_spectrumMs1List.end(),
164 [spectrum_ref](const std::pair<QString, QcborSpectrum> &pair) {
165 return pair.first == spectrum_ref;
166 });
167 if(it_ms1 != m_spectrumMs1List.end())
168 {
169
170 // replace with new spectrum_ref
171 QString new_spectrum_ref = m_ms1idOldToNew.at(spectrum_ref);
172
173
174 QcborSpectrumPrecursor precursor = precursor_list.at(0);
175
176 pappso::MzRange original_ms1_peak_range(
177 precursor.getSelectedIonList().at(0).getMz(), m_ms1Tolerance);
178 // qWarning() << "original precursor charge="
179 // << precursor.getSelectedIonList().at(0).getChargeState();
180 precursor.setSpectrumRef(new_spectrum_ref);
181 std::vector<QcborSpectrumPrecursor> new_precursor_list;
182 new_precursor_list.push_back(precursor);
183 cbor_spectrum.setPrecursorList(new_precursor_list);
184
185
186 std::vector<QcborSpectrum> spectrum_list =
187 findPotentialPrecursorIonData(it_ms1->second, cbor_spectrum, precursor);
188
189 int i = 0;
190 bool report_original_spectrum = true;
191 for(QcborSpectrum &spectrum : spectrum_list)
192 {
193 QcborSpectrumPrecursor candidate_precursor =
194 spectrum.getPrecursorList().at(0);
195
196 // qWarning() << "candidate_precursor charge="
197 // <<
198 // candidate_precursor.getSelectedIonList().at(0).getChargeState();
199 if(candidate_precursor.getSelectedIonList().at(0).getChargeState() ==
200 precursor.getSelectedIonList().at(0).getChargeState())
201 {
202 if(original_ms1_peak_range.contains(
203 candidate_precursor.getSelectedIonList().at(0).getMz()))
204 {
205 report_original_spectrum = false;
206 }
207 }
208
209 QString new_id = spectrum_tube.push_back(spectrum);
210 // qWarning() << " id=" << new_id << " candidate_precursor charge="
211 // << spectrum.getPrecursorList()
212 // .at(0)
213 // .getSelectedIonList()
214 // .at(0)
215 // .getChargeState();
216 i++;
217 }
218 if(report_original_spectrum)
219 {
220 QString new_id = spectrum_tube.push_back(cbor_spectrum);
221 // qWarning() << "orig id=" << new_id
222 // << " spectrum_list.size()=" << spectrum_list.size()
223 // << " candidate_precursor charge="
224 // << cbor_spectrum.getPrecursorList()
225 // .at(0)
226 // .getSelectedIonList()
227 // .at(0)
228 // .getChargeState();
229 }
230 }
231 else
232 {
233 throw pappso::ExceptionNotFound(
234 QObject::tr("ERROR: precursor ref %1 not found for current spectrum %2")
235 .arg(spectrum_ref)
236 .arg(cbor_spectrum.getId()));
237 }
238 }
239 else
240 {
241 qDebug() << cbor_spectrum.getId();
242 throw pappso::PappsoException(
243 QObject::tr("ERROR: precursor_list.size() != 1 (%1)").arg(precursor_list.size()));
244 }
245 }
246 }
247}
std::vector< QcborSpectrum > findPotentialPrecursorIonData(const QcborSpectrum &ms1_spectrum, const QcborSpectrum &ms2_spectrum, const QcborSpectrumPrecursor &precursor)
std::deque< std::pair< QString, QcborSpectrum > > m_spectrumMs1List
@ rt
Retention time.
Definition types.h:240

References pappso::MzRange::contains(), findPotentialPrecursorIonData(), pappso::cbor::mzcbor::QcborSpectrum::getId(), pappso::cbor::mzcbor::QcborSpectrum::getMsLevel(), pappso::cbor::mzcbor::QcborSpectrum::getPrecursorList(), pappso::cbor::mzcbor::QcborSpectrum::getRetentionTimeInSeconds(), pappso::cbor::mzcbor::QcborSpectrumPrecursor::getSelectedIonList(), m_maxSpectrumMs1ListSize, m_ms1idOldToNew, m_ms1Tolerance, m_rtStart, m_rtStop, m_spectrumMs1List, pappso::cbor::mzcbor::SpectrumTube::push_back(), pappso::cbor::mzcbor::QcborSpectrum::setPrecursorList(), and pappso::cbor::mzcbor::QcborSpectrumPrecursor::setSpectrumRef().

◆ setRetentionTimeRangeInSeconds()

void pappso::cbor::mzcbor::MzcborPrecursorFinder::setRetentionTimeRangeInSeconds ( double rt_start,
double rt_stop )

Definition at line 128 of file mzcborprecursorfinder.cpp.

129{
130 m_rtStart = rt_start;
131 m_rtStop = rt_stop;
132}

References m_rtStart, and m_rtStop.

Member Data Documentation

◆ m_cacheMs1Trace

std::deque<std::pair<const QcborSpectrum *, TraceSPtr> > pappso::cbor::mzcbor::MzcborPrecursorFinder::m_cacheMs1Trace
private

Definition at line 92 of file mzcborprecursorfinder.h.

Referenced by findPotentialPrecursorIonData().

◆ m_intensityRatioThreshold

double pappso::cbor::mzcbor::MzcborPrecursorFinder::m_intensityRatioThreshold = 0.3
private

Definition at line 87 of file mzcborprecursorfinder.h.

Referenced by MzcborPrecursorFinder(), and findPotentialPrecursorIonData().

◆ m_maxSpectrumMs1ListSize

std::size_t pappso::cbor::mzcbor::MzcborPrecursorFinder::m_maxSpectrumMs1ListSize = 100
private

Definition at line 84 of file mzcborprecursorfinder.h.

Referenced by findPotentialPrecursorIonData(), and processQcborSpectrum().

◆ m_minimumComplementIon

std::size_t pappso::cbor::mzcbor::MzcborPrecursorFinder::m_minimumComplementIon = 1
private

Definition at line 88 of file mzcborprecursorfinder.h.

Referenced by MzcborPrecursorFinder(), and findPotentialPrecursorIonData().

◆ m_ms1idOldToNew

std::map<QString, QString> pappso::cbor::mzcbor::MzcborPrecursorFinder::m_ms1idOldToNew
private

Definition at line 82 of file mzcborprecursorfinder.h.

Referenced by processQcborSpectrum().

◆ m_ms1Tolerance

pappso::PrecisionPtr pappso::cbor::mzcbor::MzcborPrecursorFinder::m_ms1Tolerance
private

Definition at line 86 of file mzcborprecursorfinder.h.

Referenced by MzcborPrecursorFinder(), and processQcborSpectrum().

◆ m_ms2minimumMz

double pappso::cbor::mzcbor::MzcborPrecursorFinder::m_ms2minimumMz = 150
private

Definition at line 89 of file mzcborprecursorfinder.h.

Referenced by findPotentialPrecursorIonData().

◆ m_ms2nMostIntense

std::size_t pappso::cbor::mzcbor::MzcborPrecursorFinder::m_ms2nMostIntense = 60
private

Definition at line 90 of file mzcborprecursorfinder.h.

Referenced by MzcborPrecursorFinder(), and findPotentialPrecursorIonData().

◆ m_ms2Tolerance

pappso::PrecisionPtr pappso::cbor::mzcbor::MzcborPrecursorFinder::m_ms2Tolerance
private

Definition at line 85 of file mzcborprecursorfinder.h.

Referenced by MzcborPrecursorFinder(), and findPotentialPrecursorIonData().

◆ m_parameters

QJsonObject pappso::cbor::mzcbor::MzcborPrecursorFinder::m_parameters
private

Definition at line 77 of file mzcborprecursorfinder.h.

Referenced by MzcborPrecursorFinder(), and getParameterValue().

◆ m_potentialPrecursorChargeStateList

std::vector<std::int8_t> pappso::cbor::mzcbor::MzcborPrecursorFinder::m_potentialPrecursorChargeStateList = {1, 2, 3}
private

Definition at line 78 of file mzcborprecursorfinder.h.

78{1, 2, 3};

Referenced by MzcborPrecursorFinder(), and findPotentialPrecursorIonData().

◆ m_rtStart

double pappso::cbor::mzcbor::MzcborPrecursorFinder::m_rtStart = 0
private

Definition at line 79 of file mzcborprecursorfinder.h.

Referenced by processQcborSpectrum(), and setRetentionTimeRangeInSeconds().

◆ m_rtStop

double pappso::cbor::mzcbor::MzcborPrecursorFinder::m_rtStop = std::numeric_limits<double>::max()
private

Definition at line 80 of file mzcborprecursorfinder.h.

Referenced by processQcborSpectrum(), and setRetentionTimeRangeInSeconds().

◆ m_spectrumMs1List

std::deque<std::pair<QString, QcborSpectrum> > pappso::cbor::mzcbor::MzcborPrecursorFinder::m_spectrumMs1List
private

Definition at line 83 of file mzcborprecursorfinder.h.

Referenced by processQcborSpectrum().


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