libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
timsmsrunreaderms2.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/msrun/private/timsmsrunreaderms2.cpp
3 * \date 10/09/2019
4 * \author Olivier Langella
5 * \brief MSrun file reader for native Bruker TimsTOF specialized for MS2
6 * purpose
7 */
8
9
10/*******************************************************************************
11 * Copyright (c) 2019 Olivier Langella <Olivier.Langella@u-psud.fr>.
12 *
13 * This file is part of the PAPPSOms++ library.
14 *
15 * PAPPSOms++ is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * PAPPSOms++ is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
27 *
28 ******************************************************************************/
29
35#include <QDebug>
36
37using namespace pappso;
38
44
46 : TimsMsRunReaderBase(msrun_reader_base)
47{
48 initialize();
49}
50
52{
53 if(msp_timsData != nullptr)
54 {
55 msp_timsData = nullptr;
56 }
57}
58
59void
61{
62 if(msp_timsData == nullptr)
63 msp_timsData = std::make_shared<TimsData>(mcsp_msRunId.get()->getFileName());
64
65 if(msp_timsData == nullptr)
66 {
67 throw PappsoException(QObject::tr("ERROR in TimsMsRunReaderMs2::initialize "
68 "msp_timsData is null for MsRunId %1")
69 .arg(mcsp_msRunId.get()->toString()));
70 }
71
72 mp_timsDdaPrecursors = msp_timsData.get()->getTimsDdaPrecursorsPtr();
73}
74
75void
77{
78 m_builtinMs2Centroid = centroid;
79 if(mp_timsDdaPrecursors != nullptr)
80 {
81 mp_timsDdaPrecursors->setMs2BuiltinCentroid(m_builtinMs2Centroid);
82 }
83 else
84 {
85 throw PappsoException(
86 QObject::tr("ERROR in TimsMsRunReaderMs2::setMs2BuiltinCentroid "
87 "mp_timsDdaPrecursors is null"));
88 }
89}
90
91void
93{
95 if(mp_timsDdaPrecursors != nullptr)
96 {
97 mp_timsDdaPrecursors->setMs2FilterCstSPtr(msp_ms2Filter);
98 }
99 else
100 {
101 throw PappsoException(
102 QObject::tr("ERROR in TimsMsRunReaderMs2::setMs2FilterCstSPtr "
103 "mp_timsDdaPrecursors is null"));
104 }
105}
106
107void
109{
111 if(mp_timsDdaPrecursors != nullptr)
112 {
113 mp_timsDdaPrecursors->setMs1FilterCstSPtr(filter);
114 }
115 else
116 {
117 throw PappsoException(
118 QObject::tr("ERROR in TimsMsRunReaderMs2::setMs1FilterCstSPtr "
119 "msp_timsData is null"));
120 }
121}
122
123bool
124TimsMsRunReaderMs2::accept(const QString &file_name [[maybe_unused]]) const
125{
126 // qDebug() << file_name;
127 return true;
128}
129
130
132TimsMsRunReaderMs2::massSpectrumSPtr(std::size_t spectrum_index)
133{
134 QualifiedMassSpectrum mass_spectrum = qualifiedMassSpectrum(spectrum_index, true);
135 return mass_spectrum.getMassSpectrumSPtr();
136}
137
138
141{
142 QualifiedMassSpectrum mass_spectrum = qualifiedMassSpectrum(spectrum_index, true);
143 return mass_spectrum.getMassSpectrumSPtr();
144}
145
146
148TimsMsRunReaderMs2::qualifiedMassSpectrum(std::size_t spectrum_index, bool want_binary_data) const
149{
150
151 std::size_t precursor_index = (spectrum_index / 2) + 1;
153 try
154 {
155 spectrum_descr = mp_timsDdaPrecursors->getSpectrumDescrWithPrecursorId(precursor_index);
156 }
157 catch(ExceptionNotFound &error)
158 {
159 throw ExceptionNotFound(QObject::tr("spectrum_index %1 NOT FOUND in file %2 : %3")
160 .arg(spectrum_index)
161 .arg(getMsRunId().get()->getFileName())
162 .arg(error.qwhat()));
163 }
164
165 if(spectrum_index % 2 == 0)
166 {
167 // qDebug() << "MS1 spectrum precursor_index=" << precursor_index;
168 // this is an MS1 spectrum
169 QualifiedMassSpectrum mass_spectrum_ms1;
170 mp_timsDdaPrecursors->getQualifiedMs1MassSpectrumBySpectrumDescr(
171 getMsRunId(), mass_spectrum_ms1, spectrum_descr, want_binary_data);
172 // qDebug(); // << mass_spectrum_ms1.toString();
173
174 // qDebug() << mass_spectrum_ms1.getMassSpectrumSPtr().get()->toString();
175 return mass_spectrum_ms1;
176 }
177 else
178 {
179 // qDebug() << "MS2 spectrum precursor_index=" << precursor_index;
180 QualifiedMassSpectrum mass_spectrum_ms2;
181 if(spectrum_descr.ms2_index != spectrum_index)
182 {
183 // qDebug();
184 throw PappsoException(QObject::tr("ERROR in %1 %2 %3 spectrum_descr.ms2_index(%4) != "
185 "spectrum_index(%5)")
186 .arg(__FILE__)
187 .arg(__FUNCTION__)
188 .arg(__LINE__)
189 .arg(spectrum_descr.ms2_index)
190 .arg(spectrum_index));
191 }
192
193 mp_timsDdaPrecursors->getQualifiedMs2MassSpectrumBySpectrumDescr(
194 getMsRunId(), mass_spectrum_ms2, spectrum_descr, want_binary_data);
195 // qDebug() << mass_spectrum_ms2.toString();
196
197 // qDebug() << mass_spectrum_ms2.getMassSpectrumSPtr().get()->toString();
198 return mass_spectrum_ms2;
199 }
200}
201
202
203void
208
209void
211 [[maybe_unused]] const MsRunReadConfig &config,
212 [[maybe_unused]] SpectrumCollectionHandlerInterface &handler)
213{
215}
216
217void
219 unsigned int ms_level)
220{
221 // qDebug() << " ms_level=" << ms_level;
222 // We'll need it to perform the looping in the spectrum list.
223 std::size_t spectrum_list_size = spectrumListSize();
224
225 // qDebug() << "The spectrum list has size:" << spectrum_list_size;
226
227 // Inform the handler of the spectrum list so that it can handle feedback to
228 // the user.
229 handler.spectrumListHasSize(spectrum_list_size);
230
231 mp_timsDdaPrecursors->setMonoThread(isMonoThread());
232
233 mp_timsDdaPrecursors->ms2ReaderSpectrumCollectionByMsLevel(getMsRunId(), handler, ms_level);
234
235 // Now let the loading handler know that the loading of the data has ended.
236 // The handler might need this "signal" to perform additional tasks or to
237 // cleanup cruft.
238
239 // qDebug() << "Loading ended";
240 handler.loadingEnded();
241}
242
243
244std::size_t
246{
247 return (mp_timsDdaPrecursors->getTotalPrecursorCount() * 2);
248}
249
250
251bool
253{
254 return false;
255}
256
257
258bool
260{
261 msp_timsData = nullptr;
262 return true;
263}
264
265bool
267{
268 if(msp_timsData == nullptr)
269 {
270 initialize();
271 mp_timsDdaPrecursors->setMs2BuiltinCentroid(m_builtinMs2Centroid);
272 mp_timsDdaPrecursors->setMs1FilterCstSPtr(msp_ms1Filter);
273 mp_timsDdaPrecursors->setMs2FilterCstSPtr(msp_ms2Filter);
274 }
275 return true;
276}
277
278std::vector<std::size_t>
280 double mz_val,
281 double rt_sec,
282 double k0)
283{
284 return mp_timsDdaPrecursors->getPrecursorsByMzRtCharge(charge, mz_val, rt_sec, k0);
285}
286
293
294
297 pappso::PrecisionPtr precision) const
298{
299 XicCoordTimsSPtr xic_coord = std::make_shared<XicCoordTims>();
300 std::size_t precursor_index = (spectrum_index / 2) + 1;
301 auto xic = this->msp_timsData.get()->getTimsDdaPrecursorsPtr()->getXicCoordTimsFromPrecursorId(
302 precursor_index, precision);
303
304 xic_coord.get()->mzRange = xic.mzRange;
305 xic_coord.get()->rtTarget = xic.rtTarget;
306 xic_coord.get()->scanNumBegin = xic.scanNumBegin;
307 xic_coord.get()->scanNumEnd = xic.scanNumEnd;
308
309
310 return xic_coord;
311}
312
320
321std::vector<double>
323{
324 return msp_timsData.get()->getRetentionTimeLineInSeconds();
325}
326
327Trace
329{
330 // Use the Sqlite database to fetch the total ion current chromatogram (TIC
331 // chromatogram).
332
334
335 return msp_timsData->getTicChromatogram();
336}
337
338
339std::size_t
341 [[maybe_unused]])
342{
344 QObject::tr("%1 %2 %3 not implemented").arg(__FILE__).arg(__FUNCTION__).arg(__LINE__));
345}
std::size_t getSpectrumIndex() const
MsRunIdCstSPtr mcsp_msRunId
bool isMonoThread() const
const MsRunIdCstSPtr & getMsRunId() const
virtual const QString & qwhat() const
Class representing a fully specified mass spectrum.
const MassSpectrumId & getMassSpectrumId() const
Get the MassSpectrumId.
MassSpectrumSPtr getMassSpectrumSPtr() const
Get the MassSpectrumSPtr.
interface to collect spectrums from the MsRunReader class
TimsMsRunReaderBase(MsRunIdCstSPtr &msrun_id_csp)
void setMs2FilterCstSPtr(pappso::FilterInterfaceCstSPtr filter)
void setMs1FilterCstSPtr(pappso::FilterInterfaceCstSPtr filter)
virtual QualifiedMassSpectrum qualifiedMassSpectrum(std::size_t spectrum_index, bool want_binary_data=true) const override
get a QualifiedMassSpectrum class given its scan number
TimsMsRunReaderMs2(MsRunIdCstSPtr &msrun_id_csp)
virtual pappso::XicCoordSPtr newXicCoordSPtrFromSpectrumIndex(std::size_t spectrum_index, pappso::PrecisionPtr precision) const override
get a xic coordinate object from a given spectrum index
virtual MassSpectrumSPtr massSpectrumSPtr(std::size_t spectrum_index) override
get a MassSpectrumSPtr class given its spectrum index
pappso::FilterInterfaceCstSPtr msp_ms2Filter
TimsDdaPrecursors * mp_timsDdaPrecursors
virtual std::size_t spectrumListSize() const override
get the totat number of spectrum conained in the MSrun data file
virtual bool releaseDevice() override
release data back end device if a the data back end is released, the developper has to use acquireDev...
pappso::FilterInterfaceCstSPtr msp_ms1Filter
virtual void readSpectrumCollection(SpectrumCollectionHandlerInterface &handler) override
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler
virtual std::vector< std::size_t > getPrecursorsIDFromMzRt(int charge, double mz_val, double rt_sec, double k0)
Get all the precursors id which match the values.
virtual void initialize() override
virtual TimsDataSp getTimsDataSPtr() override
give an access to the underlying raw data pointer
virtual std::vector< double > getRetentionTimeLine() override
retention timeline get retention times along the MSrun in seconds
virtual std::size_t spectrumStringIdentifier2SpectrumIndex(const QString &spectrum_identifier) override
if possible, get the spectrum index given a string identifier throw a not found exception if spectrum...
bool m_builtinMs2Centroid
enable builtin centroid on raw tims integers by default
virtual Trace getTicChromatogram() override
get a TIC chromatogram
void setMs2BuiltinCentroid(bool centroid)
enable or disable simple centroid filter on raw tims data for MS2
virtual void readSpectrumCollection2(const MsRunReadConfig &config, SpectrumCollectionHandlerInterface &handler) override
virtual void readSpectrumCollectionByMsLevel(SpectrumCollectionHandlerInterface &handler, unsigned int ms_level) override
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler by Ms Levels
virtual bool acquireDevice() override
acquire data back end device
virtual bool hasScanNumbers() const override
tells if spectra can be accessed using scan numbers by default, it returns false. Only overrided func...
virtual MassSpectrumCstSPtr massSpectrumCstSPtr(std::size_t spectrum_index) override
virtual bool accept(const QString &file_name) const override
tells if the reader is able to handle this file must be implemented by private MS run reader,...
virtual pappso::XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum(const pappso::QualifiedMassSpectrum &mass_spectrum, pappso::PrecisionPtr precision) const override
get a xic coordinate object from a given spectrum
A simple container of DataPoint instances.
Definition trace.h:148
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
@ filter
concerning filters (psm, peptide, protein validation)
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
Definition msrunid.h:46
std::shared_ptr< TimsData > TimsDataSp
shared pointer on a TimsData object
Definition timsdata.h:54
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
std::shared_ptr< const FilterInterface > FilterInterfaceCstSPtr
const PrecisionBase * PrecisionPtr
Definition precision.h:122
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
std::shared_ptr< XicCoordTims > XicCoordTimsSPtr
std::shared_ptr< XicCoord > XicCoordSPtr
Definition xiccoord.h:44
std::size_t scanNumEnd
mobility index end
std::size_t scanNumBegin
mobility index begin
double rtTarget
the targeted retention time to extract around intended in seconds, and related to one msrun....
Definition xiccoord.h:131
MzRange mzRange
the mass to extract
Definition xiccoord.h:125