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
30#include "timsmsrunreaderms2.h"
31#include "../../exception/exceptionnotfound.h"
32#include "../../msrun/xiccoord/xiccoordtims.h"
33#include "../../vendors/tims/timsddaprecursors.h"
34#include <QDebug>
35
36using namespace pappso;
37
43
45 : TimsMsRunReaderBase(msrun_reader_base)
46{
47 initialize();
48}
49
51{
52 if(msp_timsData != nullptr)
53 {
54 msp_timsData = nullptr;
55 }
56}
57
58void
60{
61 if(msp_timsData == nullptr)
62 msp_timsData =
63 std::make_shared<TimsData>(mcsp_msRunId.get()->getFileName());
64
65 if(msp_timsData == nullptr)
66 {
67 throw PappsoException(
68 QObject::tr("ERROR in TimsMsRunReaderMs2::initialize "
69 "msp_timsData is null for MsRunId %1")
70 .arg(mcsp_msRunId.get()->toString()));
71 }
72
73 mp_timsDdaPrecursors = msp_timsData.get()->getTimsDdaPrecursorsPtr();
74}
75
76void
78{
79 m_builtinMs2Centroid = centroid;
80 if(mp_timsDdaPrecursors != nullptr)
81 {
83 }
84 else
85 {
86 throw PappsoException(
87 QObject::tr("ERROR in TimsMsRunReaderMs2::setMs2BuiltinCentroid "
88 "mp_timsDdaPrecursors is null"));
89 }
90}
91
92void
94{
95 msp_ms2Filter = filter;
96 if(mp_timsDdaPrecursors != nullptr)
97 {
99 }
100 else
101 {
102 throw PappsoException(
103 QObject::tr("ERROR in TimsMsRunReaderMs2::setMs2FilterCstSPtr "
104 "mp_timsDdaPrecursors is null"));
105 }
106}
107
108void
110{
111 msp_ms1Filter = filter;
112 if(mp_timsDdaPrecursors != nullptr)
113 {
115 }
116 else
117 {
118 throw PappsoException(
119 QObject::tr("ERROR in TimsMsRunReaderMs2::setMs1FilterCstSPtr "
120 "msp_timsData is null"));
121 }
122}
123
124bool
125TimsMsRunReaderMs2::accept(const QString &file_name [[maybe_unused]]) const
126{
127 // qDebug() << file_name;
128 return true;
129}
130
131
133TimsMsRunReaderMs2::massSpectrumSPtr(std::size_t spectrum_index)
134{
135 QualifiedMassSpectrum mass_spectrum =
136 qualifiedMassSpectrum(spectrum_index, true);
137 return mass_spectrum.getMassSpectrumSPtr();
138}
139
140
143{
144 QualifiedMassSpectrum mass_spectrum =
145 qualifiedMassSpectrum(spectrum_index, true);
146 return mass_spectrum.getMassSpectrumSPtr();
147}
148
149
152 bool want_binary_data) const
153{
154
155 std::size_t precursor_index = (spectrum_index / 2) + 1;
157 try
158 {
159 spectrum_descr =
161 }
162 catch(ExceptionNotFound &error)
163 {
164 throw ExceptionNotFound(
165 QObject::tr("spectrum_index %1 NOT FOUND in file %2 : %3")
166 .arg(spectrum_index)
167 .arg(getMsRunId().get()->getFileName())
168 .arg(error.qwhat()));
169 }
170
171 if(spectrum_index % 2 == 0)
172 {
173 // qDebug() << "MS1 spectrum precursor_index=" << precursor_index;
174 // this is an MS1 spectrum
175 QualifiedMassSpectrum mass_spectrum_ms1;
177 getMsRunId(), mass_spectrum_ms1, spectrum_descr, want_binary_data);
178 // qDebug(); // << mass_spectrum_ms1.toString();
179
180 // qDebug() << mass_spectrum_ms1.getMassSpectrumSPtr().get()->toString();
181 return mass_spectrum_ms1;
182 }
183 else
184 {
185 // qDebug() << "MS2 spectrum precursor_index=" << precursor_index;
186 QualifiedMassSpectrum mass_spectrum_ms2;
187 if(spectrum_descr.ms2_index != spectrum_index)
188 {
189 // qDebug();
190 throw PappsoException(
191 QObject::tr("ERROR in %1 %2 %3 spectrum_descr.ms2_index(%4) != "
192 "spectrum_index(%5)")
193 .arg(__FILE__)
194 .arg(__FUNCTION__)
195 .arg(__LINE__)
196 .arg(spectrum_descr.ms2_index)
197 .arg(spectrum_index));
198 }
199
201 getMsRunId(), mass_spectrum_ms2, spectrum_descr, want_binary_data);
202 // qDebug() << mass_spectrum_ms2.toString();
203
204 // qDebug() << mass_spectrum_ms2.getMassSpectrumSPtr().get()->toString();
205 return mass_spectrum_ms2;
206 }
207}
208
209
210void
216
217void
219 [[maybe_unused]] const MsRunReadConfig &config,
220 [[maybe_unused]] SpectrumCollectionHandlerInterface &handler)
221{
223}
224
225void
227 SpectrumCollectionHandlerInterface &handler, unsigned int ms_level)
228{
229 // qDebug() << " ms_level=" << ms_level;
230 // We'll need it to perform the looping in the spectrum list.
231 std::size_t spectrum_list_size = spectrumListSize();
232
233 // qDebug() << "The spectrum list has size:" << spectrum_list_size;
234
235 // Inform the handler of the spectrum list so that it can handle feedback to
236 // the user.
237 handler.spectrumListHasSize(spectrum_list_size);
238
240
242 getMsRunId(), handler, ms_level);
243
244 // Now let the loading handler know that the loading of the data has ended.
245 // The handler might need this "signal" to perform additional tasks or to
246 // cleanup cruft.
247
248 // qDebug() << "Loading ended";
249 handler.loadingEnded();
250}
251
252
253std::size_t
258
259
260bool
262{
263 return false;
264}
265
266
267bool
269{
270 msp_timsData = nullptr;
271 return true;
272}
273
274bool
286
287std::vector<std::size_t>
289 double mz_val,
290 double rt_sec,
291 double k0)
292{
293 return mp_timsDdaPrecursors->getPrecursorsByMzRtCharge(
294 charge, mz_val, rt_sec, k0);
295}
296
299{
300 acquireDevice();
301 return msp_timsData;
302}
303
304
307 std::size_t spectrum_index, pappso::PrecisionPtr precision) const
308{
309 XicCoordTimsSPtr xic_coord = std::make_shared<XicCoordTims>();
310 std::size_t precursor_index = (spectrum_index / 2) + 1;
311 auto xic = this->msp_timsData.get()
312 ->getTimsDdaPrecursorsPtr()
313 ->getXicCoordTimsFromPrecursorId(precursor_index, precision);
314
315 xic_coord.get()->mzRange = xic.mzRange;
316 xic_coord.get()->rtTarget = xic.rtTarget;
317 xic_coord.get()->scanNumBegin = xic.scanNumBegin;
318 xic_coord.get()->scanNumEnd = xic.scanNumEnd;
319
320
321 return xic_coord;
322}
323
332
333std::vector<double>
335{
336 return msp_timsData.get()->getRetentionTimeLineInSeconds();
337}
338
339Trace
341{
342 // Use the Sqlite database to fetch the total ion current chromatogram (TIC
343 // chromatogram).
344
346
347 return msp_timsData->getTicChromatogram();
348}
std::size_t getSpectrumIndex() const
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
void getQualifiedMs1MassSpectrumBySpectrumDescr(const MsRunIdCstSPtr &msrun_id, QualifiedMassSpectrum &mass_spectrum, const SpectrumDescr &spectrum_descr, bool want_binary_data)
void setMs2BuiltinCentroid(bool centroid)
enable or disable simple centroid filter on raw tims data for MS2
void getQualifiedMs2MassSpectrumBySpectrumDescr(const MsRunIdCstSPtr &msrun_id, QualifiedMassSpectrum &mass_spectrum, const SpectrumDescr &spectrum_descr, bool want_binary_data)
void setMs2FilterCstSPtr(pappso::FilterInterfaceCstSPtr &filter)
filter interface to apply just after raw MS2 specturm extraction the filter can be a list of filters ...
void ms2ReaderSpectrumCollectionByMsLevel(const MsRunIdCstSPtr &msrun_id, SpectrumCollectionHandlerInterface &handler, unsigned int ms_level)
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler by Ms Levels
void setMs1FilterCstSPtr(pappso::FilterInterfaceCstSPtr &filter)
filter interface to apply just after raw MS1 specturm extraction the filter can be a list of filters ...
TimsDdaPrecursors::SpectrumDescr getSpectrumDescrWithPrecursorId(std::size_t precursor_id) const
get an intermediate structure describing a spectrum
void setMonoThread(bool is_mono_thread)
set only one is_mono_thread to true
std::size_t getTotalPrecursorCount() const
get the number of precursors analyzed by PASEF
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 std::vector< double > getRetentionTimeLine() override
retention timeline get retention times along the MSrun in seconds
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 TimsDataSp getTimsDataSPtr()
give an access to the underlying raw data pointer
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
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
Definition msrunid.h:46
std::shared_ptr< TimsData > TimsDataSp
shared pointer on a TimsData object
Definition timsdata.h:52
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
std::shared_ptr< const FilterInterface > FilterInterfaceCstSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
std::shared_ptr< XicCoordTims > XicCoordTimsSPtr
std::shared_ptr< XicCoord > XicCoordSPtr
Definition xiccoord.h:43
MSrun file reader for native Bruker TimsTOF specialized for MS2 purpose.