libpappsomspp
Library for mass spectrometry
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
37TimsMsRunReaderMs2::TimsMsRunReaderMs2(MsRunIdCstSPtr &msrun_id_csp)
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 if(msp_timsData == nullptr)
56 {
57 throw PappsoException(
58 QObject::tr("ERROR in TimsMsRunReaderMs2::initialize "
59 "msp_timsData is null for MsRunId %1")
60 .arg(mcsp_msRunId.get()->toString()));
61 }
62}
63
64void
66{
67 m_builtinMs2Centroid = centroid;
68 if(msp_timsData != nullptr)
69 {
70 msp_timsData->setMs2BuiltinCentroid(m_builtinMs2Centroid);
71 }
72 else
73 {
74 throw PappsoException(
75 QObject::tr("ERROR in TimsMsRunReaderMs2::setMs2BuiltinCentroid "
76 "msp_timsData is null"));
77 }
78}
79
80void
82{
83 msp_ms2Filter = filter;
84 if(msp_timsData != nullptr)
85 {
86 msp_timsData->setMs2FilterCstSPtr(msp_ms2Filter);
87 }
88 else
89 {
90 throw PappsoException(
91 QObject::tr("ERROR in TimsMsRunReaderMs2::setMs2FilterCstSPtr "
92 "msp_timsData is null"));
93 }
94}
95
96void
98{
99 msp_ms1Filter = filter;
100 if(msp_timsData != nullptr)
101 {
102 msp_timsData->setMs1FilterCstSPtr(filter);
103 }
104 else
105 {
106 throw PappsoException(
107 QObject::tr("ERROR in TimsMsRunReaderMs2::setMs1FilterCstSPtr "
108 "msp_timsData is null"));
109 }
110}
111
112bool
113TimsMsRunReaderMs2::accept(const QString &file_name) const
114{
115 qDebug() << file_name;
116 return true;
117}
118
119
121TimsMsRunReaderMs2::massSpectrumSPtr(std::size_t spectrum_index)
122{
123 QualifiedMassSpectrum mass_spectrum =
124 qualifiedMassSpectrum(spectrum_index, true);
125 return mass_spectrum.getMassSpectrumSPtr();
126}
127
128
131{
132 QualifiedMassSpectrum mass_spectrum =
133 qualifiedMassSpectrum(spectrum_index, true);
134 return mass_spectrum.getMassSpectrumSPtr();
135}
136
137
140 bool want_binary_data) const
141{
142
143 std::size_t precursor_index = (spectrum_index / 2) + 1;
144 TimsData::SpectrumDescr spectrum_descr;
145 try
146 {
147 spectrum_descr =
148 msp_timsData.get()->getSpectrumDescrWithPrecursorId(precursor_index);
149 }
150 catch(ExceptionNotFound &error)
151 {
152 throw ExceptionNotFound(
153 QObject::tr("spectrum_index %1 NOT FOUND in file %2 : %3")
154 .arg(spectrum_index)
155 .arg(getMsRunId().get()->getFileName())
156 .arg(error.qwhat()));
157 }
158
159 if(spectrum_index % 2 == 0)
160 {
161 qDebug() << "MS1 spectrum precursor_index=" << precursor_index;
162 // this is an MS1 spectrum
163 QualifiedMassSpectrum mass_spectrum_ms1;
164 msp_timsData->getQualifiedMs1MassSpectrumByPrecursorId(
165 getMsRunId(), mass_spectrum_ms1, spectrum_descr, want_binary_data);
166 qDebug(); // << mass_spectrum_ms1.toString();
167
168 // qDebug() << mass_spectrum_ms1.getMassSpectrumSPtr().get()->toString();
169 return mass_spectrum_ms1;
170 }
171 else
172 {
173 qDebug() << "MS2 spectrum precursor_index=" << precursor_index;
174 QualifiedMassSpectrum mass_spectrum_ms2;
175 if(spectrum_descr.ms2_index != spectrum_index)
176 {
177 qDebug();
178 throw PappsoException(
179 QObject::tr("ERROR in %1 %2 %3 spectrum_descr.ms2_index(%4) != "
180 "spectrum_index(%5)")
181 .arg(__FILE__)
182 .arg(__FUNCTION__)
183 .arg(__LINE__)
184 .arg(spectrum_descr.ms2_index)
185 .arg(spectrum_index));
186 }
187
188 msp_timsData->getQualifiedMs2MassSpectrumByPrecursorId(
189 getMsRunId(), mass_spectrum_ms2, spectrum_descr, want_binary_data);
190 qDebug(); // << mass_spectrum_ms2.toString();
191
192 // qDebug() << mass_spectrum_ms2.getMassSpectrumSPtr().get()->toString();
193 return mass_spectrum_ms2;
194 }
195}
196
197
198void
201{
203}
204
205void
207 SpectrumCollectionHandlerInterface &handler, unsigned int ms_level)
208{
209 qDebug() << " ms_level=" << ms_level;
210 // We'll need it to perform the looping in the spectrum list.
211 std::size_t spectrum_list_size = spectrumListSize();
212
213 // qDebug() << "The spectrum list has size:" << spectrum_list_size;
214
215 // Inform the handler of the spectrum list so that it can handle feedback to
216 // the user.
217 handler.spectrumListHasSize(spectrum_list_size);
218
219
220 msp_timsData.get()->setMonoThread(isMonoThread());
221
222 msp_timsData.get()->ms2ReaderSpectrumCollectionByMsLevel(
223 getMsRunId(), handler, ms_level);
224 // Now let the loading handler know that the loading of the data has ended.
225 // The handler might need this "signal" to perform additional tasks or to
226 // cleanup cruft.
227
228 // qDebug() << "Loading ended";
229 handler.loadingEnded();
230}
231
232
233std::size_t
235{
236 return (msp_timsData->getTotalNumberOfPrecursors() * 2);
237}
238
239
240bool
242{
243 return false;
244}
245
246
247bool
249{
250 msp_timsData = nullptr;
251 return true;
252}
253
254bool
256{
257 if(msp_timsData == nullptr)
258 {
259 initialize();
260 msp_timsData->setMs2BuiltinCentroid(m_builtinMs2Centroid);
261 msp_timsData->setMs1FilterCstSPtr(msp_ms1Filter);
262 msp_timsData->setMs2FilterCstSPtr(msp_ms2Filter);
263 }
264 return true;
265}
266
267std::vector<std::size_t>
269 double mz_val,
270 double rt_sec,
271 double k0)
272{
273 return msp_timsData->getPrecursorsFromMzRtCharge(charge, mz_val, rt_sec, k0);
274}
275
278{
279 acquireDevice();
280 return msp_timsData;
281}
282
283
286 std::size_t spectrum_index, pappso::PrecisionPtr precision) const
287{
288 XicCoordTimsSPtr xic_coord = std::make_shared<XicCoordTims>();
289 std::size_t precursor_index = (spectrum_index / 2) + 1;
290 auto xic = this->msp_timsData.get()->getXicCoordTimsFromPrecursorId(
291 precursor_index, precision);
292
293 xic_coord.get()->mzRange = xic.mzRange;
294 xic_coord.get()->rtTarget = xic.rtTarget;
295 xic_coord.get()->scanNumBegin = xic.scanNumBegin;
296 xic_coord.get()->scanNumEnd = xic.scanNumEnd;
297
298
299 return xic_coord;
300}
301
304 const pappso::QualifiedMassSpectrum &mass_spectrum,
305 pappso::PrecisionPtr precision) const
306{
308 mass_spectrum.getMassSpectrumId().getSpectrumIndex(), precision);
309}
310
311std::vector<double>
313{
314 return msp_timsData.get()->getRetentionTimeLine();
315}
316
317Trace
319{
320 // Use the Sqlite database to fetch the total ion current chromatogram (TIC
321 // chromatogram).
322
324
325 return msp_timsData->getTicChromatogram();
326}
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:191
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
Definition: msrunreader.h:56
virtual void spectrumListHasSize(std::size_t size)
Definition: msrunreader.cpp:53
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
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 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:38
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:45
std::shared_ptr< TimsData > TimsDataSp
shared pointer on a TimsData object
Definition: timsdata.h:50
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
Definition: massspectrum.h:55
std::shared_ptr< const FilterInterface > FilterInterfaceCstSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:54
std::shared_ptr< XicCoordTims > XicCoordTimsSPtr
Definition: xiccoordtims.h:40
std::shared_ptr< XicCoord > XicCoordSPtr
Definition: xiccoord.h:43
MSrun file reader for native Bruker TimsTOF specialized for MS2 purpose.