libpappsomspp
Library for mass spectrometry
timsmsrunreader.cpp
Go to the documentation of this file.
1 /**
2  * \file pappsomspp/msrun/private/timsmsrunreader.h
3  * \date 05/09/2019
4  * \author Olivier Langella
5  * \brief MSrun file reader for native Bruker TimsTOF raw data
6  */
7 
8 /*******************************************************************************
9  * Copyright (c) 2019 Olivier Langella <Olivier.Langella@u-psud.fr>.
10  *
11  * This file is part of the PAPPSOms++ library.
12  *
13  * PAPPSOms++ is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation, either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * PAPPSOms++ is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
25  *
26  ******************************************************************************/
27 
28 #include "timsmsrunreader.h"
29 #include "../../exception/exceptionnotimplemented.h"
30 #include <QDebug>
31 
32 using namespace pappso;
33 
35  : MsRunReader(msrun_id_csp)
36 {
37  initialize();
38 }
39 
41 {
42  if(mpa_timsData != nullptr)
43  {
44  delete mpa_timsData;
45  }
46 }
47 
48 void
50 {
51  mpa_timsData = new TimsData(mcsp_msRunId.get()->getFileName());
52 }
53 
54 
55 bool
56 TimsMsRunReader::accept(const QString &file_name) const
57 {
58  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
59  << file_name;
60  return true;
61 }
62 
63 
65 TimsMsRunReader::massSpectrumSPtr([[maybe_unused]] std::size_t spectrum_index)
66 {
68  QObject::tr("Not yet implemented in TimsMsRunReader %1.\n").arg(__LINE__));
69  return pappso::MassSpectrumSPtr();
70 }
71 
72 
74 TimsMsRunReader::massSpectrumCstSPtr(std::size_t spectrum_index)
75 {
76  return mpa_timsData->getMassSpectrumCstSPtrByRawIndex(spectrum_index);
77 }
78 
79 
81 TimsMsRunReader::qualifiedMassSpectrum(std::size_t spectrum_index,
82  bool want_binary_data) const
83 {
84 
85  QualifiedMassSpectrum mass_spectrum =
87  want_binary_data);
88 
89  MassSpectrumId spectrum_id(mass_spectrum.getMassSpectrumId());
90  spectrum_id.setMsRunId(getMsRunId());
91  mass_spectrum.setMassSpectrumId(spectrum_id);
92  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
93  //<< mass_spectrum.toString();
94 
95  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
96  //<< mass_spectrum.getMassSpectrumSPtr().get()->toString();
97  return mass_spectrum;
98 }
99 
100 
101 void
104 {
105  qDebug();
106 
107  const bool want_binary_data = handler.needPeakList();
108 
109  // We'll need it to perform the looping in the spectrum list.
110  std::size_t spectrum_list_size = spectrumListSize();
111 
112  qDebug() << "The spectrum list has size:" << spectrum_list_size;
113 
114  // Inform the handler of the spectrum list so that it can handle feedback to
115  // the user.
116  handler.spectrumListHasSize(spectrum_list_size);
117 
118  // Iterate in the full list of spectra.
119  // mpa_timsData->iterateOnAllScans(mcsp_msRunId, handler);
120 
121  for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
122  {
123 
124  // If the user of this reader instance wants to stop reading the spectra,
125  // then break this loop.
126  if(handler.shouldStop())
127  {
128  qDebug() << "The operation was cancelled. Breaking the loop.";
129  break;
130  }
131 
132 
133  bool get_data = want_binary_data;
134  if(get_data)
135  {
136  get_data = handler.needMsLevelPeakList(
138  }
139  qDebug();
140 
141  QualifiedMassSpectrum qualified_mass_spectrum =
142  qualifiedMassSpectrum(iter, get_data);
143  qDebug();
144  handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
145  qDebug();
146  }
147  // End of
148  // for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
149 
150  // Now let the loading handler know that the loading of the data has ended.
151  // The handler might need this "signal" to perform additional tasks or to
152  // cleanup cruft.
153 
154  // qDebug() << "Loading ended";
155  handler.loadingEnded();
156 }
157 
158 
159 std::size_t
161 {
163 }
164 
165 
166 bool
168 {
169  return false;
170 }
171 
172 
173 bool
175 {
176  delete mpa_timsData;
177  mpa_timsData = nullptr;
178  return true;
179 }
180 
181 bool
183 {
184  if(mpa_timsData == nullptr)
185  {
186  initialize();
187  }
188  return true;
189 }
pappso::TimsMsRunReader::TimsMsRunReader
TimsMsRunReader(MsRunIdCstSPtr &msrun_id_csp)
Definition: timsmsrunreader.cpp:34
pappso::MassSpectrumCstSPtr
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
Definition: massspectrum.h:55
pappso::MsRunReader
base class to read MSrun the only way to build a MsRunReader object is to use the MsRunReaderFactory
Definition: msrunreader.h:158
pappso::TimsData::getMassSpectrumCstSPtrByRawIndex
pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtrByRawIndex(std::size_t raw_index)
get a mass spectrum given its spectrum index
Definition: timsdata.cpp:305
pappso::SpectrumCollectionHandlerInterface::spectrumListHasSize
virtual void spectrumListHasSize(std::size_t size)
Definition: msrunreader.cpp:55
pappso::TimsMsRunReader::massSpectrumSPtr
virtual MassSpectrumSPtr massSpectrumSPtr(std::size_t spectrum_index) override
get a MassSpectrumSPtr class given its spectrum index
Definition: timsmsrunreader.cpp:65
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
pappso::SpectrumCollectionHandlerInterface::setQualifiedMassSpectrum
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum)=0
pappso::MsRunIdCstSPtr
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
Definition: msrunid.h:44
pappso::TimsMsRunReader::~TimsMsRunReader
virtual ~TimsMsRunReader()
Definition: timsmsrunreader.cpp:40
pappso::TimsMsRunReader::hasScanNumbers
virtual bool hasScanNumbers() const override
tells if spectra can be accessed using scan numbers by default, it returns false. Only overrided func...
Definition: timsmsrunreader.cpp:167
pappso::SpectrumCollectionHandlerInterface::shouldStop
virtual bool shouldStop()
Definition: msrunreader.cpp:46
pappso::TimsData::getMsLevelBySpectrumIndex
unsigned int getMsLevelBySpectrumIndex(std::size_t spectrum_index)
Definition: timsdata.cpp:677
pappso::TimsMsRunReader::acquireDevice
virtual bool acquireDevice() override
acquire data back end device
Definition: timsmsrunreader.cpp:182
pappso::SpectrumCollectionHandlerInterface::loadingEnded
virtual void loadingEnded()
Definition: msrunreader.cpp:51
pappso::TimsMsRunReader::massSpectrumCstSPtr
virtual MassSpectrumCstSPtr massSpectrumCstSPtr(std::size_t spectrum_index) override
Definition: timsmsrunreader.cpp:74
pappso::TimsData
Definition: timsdata.h:70
pappso::MsRunReader::getMsRunId
const MsRunIdCstSPtr & getMsRunId() const
Definition: msrunreader.cpp:232
pappso::TimsMsRunReader::releaseDevice
virtual bool releaseDevice() override
release data back end device if a the data back end is released, the developper has to use acquireDev...
Definition: timsmsrunreader.cpp:174
pappso::TimsMsRunReader::initialize
virtual void initialize() override
Definition: timsmsrunreader.cpp:49
pappso::QualifiedMassSpectrum
Class representing a fully specified mass spectrum.
Definition: qualifiedmassspectrum.h:85
pappso::TimsMsRunReader::readSpectrumCollection
virtual void readSpectrumCollection(SpectrumCollectionHandlerInterface &handler) override
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler
Definition: timsmsrunreader.cpp:102
pappso::TimsData::getQualifiedMassSpectrumByRawIndex
QualifiedMassSpectrum getQualifiedMassSpectrumByRawIndex(std::size_t spectrum_index, bool want_binary_data)
Definition: timsdata.cpp:686
pappso::ExceptionNotImplemented
Definition: exceptionnotimplemented.h:32
timsmsrunreader.h
MSrun file reader for native Bruker TimsTOF raw data.
pappso::SpectrumCollectionHandlerInterface::needPeakList
virtual bool needPeakList() const =0
tells if we need the peak list (if we want the binary data) for each spectrum
pappso::QualifiedMassSpectrum::setMassSpectrumId
void setMassSpectrumId(const MassSpectrumId &iD)
Set the MassSpectrumId.
Definition: qualifiedmassspectrum.cpp:149
pappso::SpectrumCollectionHandlerInterface::needMsLevelPeakList
virtual bool needMsLevelPeakList(unsigned int ms_level) const final
tells if we need the peak list (if we want the binary data) for each spectrum, given an MS level
Definition: msrunreader.cpp:72
pappso::QualifiedMassSpectrum::getMassSpectrumId
const MassSpectrumId & getMassSpectrumId() const
Get the MassSpectrumId.
Definition: qualifiedmassspectrum.cpp:157
pappso::TimsData::getTotalNumberOfScans
std::size_t getTotalNumberOfScans() const
get the total number of scans
Definition: timsdata.cpp:535
pappso::MassSpectrumId
Definition: massspectrumid.h:38
pappso::TimsMsRunReader::accept
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,...
Definition: timsmsrunreader.cpp:56
pappso::MassSpectrumId::setMsRunId
void setMsRunId(MsRunIdCstSPtr other)
Definition: massspectrumid.cpp:74
pappso::TimsMsRunReader::spectrumListSize
virtual std::size_t spectrumListSize() const override
get the totat number of spectrum conained in the MSrun data file
Definition: timsmsrunreader.cpp:160
pappso::TimsMsRunReader::qualifiedMassSpectrum
virtual QualifiedMassSpectrum qualifiedMassSpectrum(std::size_t spectrum_index, bool want_binary_data=true) const override
get a QualifiedMassSpectrum class given its scan number
Definition: timsmsrunreader.cpp:81
pappso::TimsMsRunReader::mpa_timsData
TimsData * mpa_timsData
Definition: timsmsrunreader.h:74
pappso::SpectrumCollectionHandlerInterface
interface to collect spectrums from the MsRunReader class
Definition: msrunreader.h:59
pappso::MassSpectrumSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:54