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 <QDebug>
34
35using namespace pappso;
36
38 : MsRunReader(msrun_id_csp)
39{
40 initialize();
41}
42
44{
45 if(msp_timsData != nullptr)
46 {
47 msp_timsData = nullptr;
48 }
49}
50
51void
53{
54 msp_timsData = std::make_shared<TimsData>(mcsp_msRunId.get()->getFileName());
55
56 if(msp_timsData == nullptr)
57 {
58 throw PappsoException(
59 QObject::tr("ERROR in TimsMsRunReaderMs2::initialize "
60 "msp_timsData is null for MsRunId %1")
61 .arg(mcsp_msRunId.get()->toString()));
62 }
63}
64
65void
67{
68 m_builtinMs2Centroid = centroid;
69 if(msp_timsData != nullptr)
70 {
71 msp_timsData->setMs2BuiltinCentroid(m_builtinMs2Centroid);
72 }
73 else
74 {
75 throw PappsoException(
76 QObject::tr("ERROR in TimsMsRunReaderMs2::setMs2BuiltinCentroid "
77 "msp_timsData is null"));
78 }
79}
80
81void
83{
84 msp_ms2Filter = filter;
85 if(msp_timsData != nullptr)
86 {
87 msp_timsData->setMs2FilterCstSPtr(msp_ms2Filter);
88 }
89 else
90 {
91 throw PappsoException(
92 QObject::tr("ERROR in TimsMsRunReaderMs2::setMs2FilterCstSPtr "
93 "msp_timsData is null"));
94 }
95}
96
97void
99{
100 msp_ms1Filter = filter;
101 if(msp_timsData != nullptr)
102 {
103 msp_timsData->setMs1FilterCstSPtr(filter);
104 }
105 else
106 {
107 throw PappsoException(
108 QObject::tr("ERROR in TimsMsRunReaderMs2::setMs1FilterCstSPtr "
109 "msp_timsData is null"));
110 }
111}
112
113bool
114TimsMsRunReaderMs2::accept(const QString &file_name) const
115{
116 qDebug() << file_name;
117 return true;
118}
119
120
122TimsMsRunReaderMs2::massSpectrumSPtr(std::size_t spectrum_index)
123{
124 QualifiedMassSpectrum mass_spectrum =
125 qualifiedMassSpectrum(spectrum_index, true);
126 return mass_spectrum.getMassSpectrumSPtr();
127}
128
129
132{
133 QualifiedMassSpectrum mass_spectrum =
134 qualifiedMassSpectrum(spectrum_index, true);
135 return mass_spectrum.getMassSpectrumSPtr();
136}
137
138
141 bool want_binary_data) const
142{
143
144 std::size_t precursor_index = (spectrum_index / 2) + 1;
145 TimsData::SpectrumDescr spectrum_descr;
146 try
147 {
148 spectrum_descr =
149 msp_timsData.get()->getSpectrumDescrWithPrecursorId(precursor_index);
150 }
151 catch(ExceptionNotFound &error)
152 {
153 throw ExceptionNotFound(
154 QObject::tr("spectrum_index %1 NOT FOUND in file %2 : %3")
155 .arg(spectrum_index)
156 .arg(getMsRunId().get()->getFileName())
157 .arg(error.qwhat()));
158 }
159
160 if(spectrum_index % 2 == 0)
161 {
162 qDebug() << "MS1 spectrum precursor_index=" << precursor_index;
163 // this is an MS1 spectrum
164 QualifiedMassSpectrum mass_spectrum_ms1;
165 msp_timsData->getQualifiedMs1MassSpectrumByPrecursorId(
166 getMsRunId(), mass_spectrum_ms1, spectrum_descr, want_binary_data);
167 qDebug(); // << mass_spectrum_ms1.toString();
168
169 // qDebug() << mass_spectrum_ms1.getMassSpectrumSPtr().get()->toString();
170 return mass_spectrum_ms1;
171 }
172 else
173 {
174 qDebug() << "MS2 spectrum precursor_index=" << precursor_index;
175 QualifiedMassSpectrum mass_spectrum_ms2;
176 if(spectrum_descr.ms2_index != spectrum_index)
177 {
178 qDebug();
179 throw PappsoException(
180 QObject::tr("ERROR in %1 %2 %3 spectrum_descr.ms2_index(%4) != "
181 "spectrum_index(%5)")
182 .arg(__FILE__)
183 .arg(__FUNCTION__)
184 .arg(__LINE__)
185 .arg(spectrum_descr.ms2_index)
186 .arg(spectrum_index));
187 }
188
189 msp_timsData->getQualifiedMs2MassSpectrumByPrecursorId(
190 getMsRunId(), mass_spectrum_ms2, spectrum_descr, want_binary_data);
191 qDebug(); // << mass_spectrum_ms2.toString();
192
193 // qDebug() << mass_spectrum_ms2.getMassSpectrumSPtr().get()->toString();
194 return mass_spectrum_ms2;
195 }
196}
197
198
199void
205
206void
208 [[maybe_unused]] const MsRunReadConfig &config,
209 [[maybe_unused]] SpectrumCollectionHandlerInterface &handler)
210{
212}
213
214void
216 SpectrumCollectionHandlerInterface &handler, unsigned int ms_level)
217{
218 qDebug() << " ms_level=" << ms_level;
219 // We'll need it to perform the looping in the spectrum list.
220 std::size_t spectrum_list_size = spectrumListSize();
221
222 // qDebug() << "The spectrum list has size:" << spectrum_list_size;
223
224 // Inform the handler of the spectrum list so that it can handle feedback to
225 // the user.
226 handler.spectrumListHasSize(spectrum_list_size);
227
228 msp_timsData.get()->setMonoThread(isMonoThread());
229
230 msp_timsData.get()->ms2ReaderSpectrumCollectionByMsLevel(
231 getMsRunId(), handler, ms_level);
232
233 // Now let the loading handler know that the loading of the data has ended.
234 // The handler might need this "signal" to perform additional tasks or to
235 // cleanup cruft.
236
237 // qDebug() << "Loading ended";
238 handler.loadingEnded();
239}
240
241
242std::size_t
244{
245 return (msp_timsData->getTotalNumberOfPrecursors() * 2);
246}
247
248
249bool
251{
252 return false;
253}
254
255
256bool
258{
259 msp_timsData = nullptr;
260 return true;
261}
262
263bool
265{
266 if(msp_timsData == nullptr)
267 {
268 initialize();
269 msp_timsData->setMs2BuiltinCentroid(m_builtinMs2Centroid);
270 msp_timsData->setMs1FilterCstSPtr(msp_ms1Filter);
271 msp_timsData->setMs2FilterCstSPtr(msp_ms2Filter);
272 }
273 return true;
274}
275
276std::vector<std::size_t>
278 double mz_val,
279 double rt_sec,
280 double k0)
281{
282 return msp_timsData->getPrecursorsFromMzRtCharge(charge, mz_val, rt_sec, k0);
283}
284
287{
288 acquireDevice();
289 return msp_timsData;
290}
291
292
295 std::size_t spectrum_index, pappso::PrecisionPtr precision) const
296{
297 XicCoordTimsSPtr xic_coord = std::make_shared<XicCoordTims>();
298 std::size_t precursor_index = (spectrum_index / 2) + 1;
299 auto xic = this->msp_timsData.get()->getXicCoordTimsFromPrecursorId(
300 precursor_index, precision);
301
302 xic_coord.get()->mzRange = xic.mzRange;
303 xic_coord.get()->rtTarget = xic.rtTarget;
304 xic_coord.get()->scanNumBegin = xic.scanNumBegin;
305 xic_coord.get()->scanNumEnd = xic.scanNumEnd;
306
307
308 return xic_coord;
309}
310
319
320std::vector<double>
322{
323 return msp_timsData.get()->getRetentionTimeLine();
324}
325
326Trace
328{
329 // Use the Sqlite database to fetch the total ion current chromatogram (TIC
330 // chromatogram).
331
333
334 return msp_timsData->getTicChromatogram();
335}
std::size_t getSpectrumIndex() const
base class to read MSrun the only way to build a MsRunReader object is to use the MsRunReaderFactory
Definition msrunreader.h:63
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 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
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:50
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.