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
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
202{
204}
205
206void
208 SpectrumCollectionHandlerInterface &handler, unsigned int ms_level)
209{
210 qDebug() << " ms_level=" << ms_level;
211 // We'll need it to perform the looping in the spectrum list.
212 std::size_t spectrum_list_size = spectrumListSize();
213
214 // qDebug() << "The spectrum list has size:" << spectrum_list_size;
215
216 // Inform the handler of the spectrum list so that it can handle feedback to
217 // the user.
218 handler.spectrumListHasSize(spectrum_list_size);
219
220
221 msp_timsData.get()->setMonoThread(isMonoThread());
222
223 msp_timsData.get()->ms2ReaderSpectrumCollectionByMsLevel(
224 getMsRunId(), handler, ms_level);
225 // Now let the loading handler know that the loading of the data has ended.
226 // The handler might need this "signal" to perform additional tasks or to
227 // cleanup cruft.
228
229 // qDebug() << "Loading ended";
230 handler.loadingEnded();
231}
232
233
234std::size_t
236{
237 return (msp_timsData->getTotalNumberOfPrecursors() * 2);
238}
239
240
241bool
243{
244 return false;
245}
246
247
248bool
250{
251 msp_timsData = nullptr;
252 return true;
253}
254
255bool
257{
258 if(msp_timsData == nullptr)
259 {
260 initialize();
261 msp_timsData->setMs2BuiltinCentroid(m_builtinMs2Centroid);
262 msp_timsData->setMs1FilterCstSPtr(msp_ms1Filter);
263 msp_timsData->setMs2FilterCstSPtr(msp_ms2Filter);
264 }
265 return true;
266}
267
268std::vector<std::size_t>
270 double mz_val,
271 double rt_sec,
272 double k0)
273{
274 return msp_timsData->getPrecursorsFromMzRtCharge(charge, mz_val, rt_sec, k0);
275}
276
279{
280 acquireDevice();
281 return msp_timsData;
282}
283
284
287 std::size_t spectrum_index, pappso::PrecisionPtr precision) const
288{
289 XicCoordTimsSPtr xic_coord = std::make_shared<XicCoordTims>();
290 std::size_t precursor_index = (spectrum_index / 2) + 1;
291 auto xic = this->msp_timsData.get()->getXicCoordTimsFromPrecursorId(
292 precursor_index, precision);
293
294 xic_coord.get()->mzRange = xic.mzRange;
295 xic_coord.get()->rtTarget = xic.rtTarget;
296 xic_coord.get()->scanNumBegin = xic.scanNumBegin;
297 xic_coord.get()->scanNumEnd = xic.scanNumEnd;
298
299
300 return xic_coord;
301}
302
305 const pappso::QualifiedMassSpectrum &mass_spectrum,
306 pappso::PrecisionPtr precision) const
307{
309 mass_spectrum.getMassSpectrumId().getSpectrumIndex(), precision);
310}
311
312std::vector<double>
314{
315 return msp_timsData.get()->getRetentionTimeLine();
316}
317
318Trace
320{
321 // Use the Sqlite database to fetch the total ion current chromatogram (TIC
322 // chromatogram).
323
325
326 return msp_timsData->getTicChromatogram();
327}
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:192
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: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: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.