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 {
106 }
107 
108 
109 void
111  SpectrumCollectionHandlerInterface &handler, unsigned int ms_level)
112 {
113 
114  qDebug();
115 
116  const bool want_binary_data = handler.needPeakList();
117 
118  // We'll need it to perform the looping in the spectrum list.
119  std::size_t spectrum_list_size = spectrumListSize();
120 
121  qDebug() << "The spectrum list has size:" << spectrum_list_size;
122 
123  // Inform the handler of the spectrum list so that it can handle feedback to
124  // the user.
125  handler.spectrumListHasSize(spectrum_list_size);
126 
127  // Iterate in the full list of spectra.
128  // mpa_timsData->iterateOnAllScans(mcsp_msRunId, handler);
129 
130  for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
131  {
132  unsigned int current_ms_level =
134 
135  // If the user of this reader instance wants to stop reading the spectra,
136  // then break this loop.
137  if(handler.shouldStop())
138  {
139  qDebug() << "The operation was cancelled. Breaking the loop.";
140  break;
141  }
142 
143  if(ms_level > 0)
144  {
145  if(ms_level != current_ms_level)
146  {
147  continue;
148  }
149  }
150  bool get_data = want_binary_data;
151  if(get_data)
152  {
153  get_data = handler.needMsLevelPeakList(ms_level);
154  }
155  qDebug();
156 
157  QualifiedMassSpectrum qualified_mass_spectrum =
158  qualifiedMassSpectrum(iter, get_data);
159  qDebug();
160  handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
161  qDebug();
162  }
163  // End of
164  // for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
165 
166  // Now let the loading handler know that the loading of the data has ended.
167  // The handler might need this "signal" to perform additional tasks or to
168  // cleanup cruft.
169 
170  // qDebug() << "Loading ended";
171  handler.loadingEnded();
172 }
173 
174 
175 std::size_t
177 {
179 }
180 
181 
182 bool
184 {
185  return false;
186 }
187 
188 
189 bool
191 {
192  delete mpa_timsData;
193  mpa_timsData = nullptr;
194  return true;
195 }
196 
197 bool
199 {
200  if(mpa_timsData == nullptr)
201  {
202  initialize();
203  }
204  return true;
205 }
void setMsRunId(MsRunIdCstSPtr other)
base class to read MSrun the only way to build a MsRunReader object is to use the MsRunReaderFactory
Definition: msrunreader.h:158
const MsRunIdCstSPtr & getMsRunId() const
Class representing a fully specified mass spectrum.
const MassSpectrumId & getMassSpectrumId() const
Get the MassSpectrumId.
void setMassSpectrumId(const MassSpectrumId &iD)
Set the MassSpectrumId.
interface to collect spectrums from the MsRunReader class
Definition: msrunreader.h:59
virtual bool needPeakList() const =0
tells if we need the peak list (if we want the binary data) for each spectrum
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
virtual void spectrumListHasSize(std::size_t size)
Definition: msrunreader.cpp:55
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum)=0
QualifiedMassSpectrum getQualifiedMassSpectrumByRawIndex(std::size_t spectrum_index, bool want_binary_data)
Definition: timsdata.cpp:743
unsigned int getMsLevelBySpectrumIndex(std::size_t spectrum_index)
Definition: timsdata.cpp:734
std::size_t getTotalNumberOfScans() const
get the total number of scans
Definition: timsdata.cpp:592
pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtrByRawIndex(std::size_t raw_index)
get a mass spectrum given its spectrum index
Definition: timsdata.cpp:376
virtual void initialize() override
TimsMsRunReader(MsRunIdCstSPtr &msrun_id_csp)
virtual void readSpectrumCollection(SpectrumCollectionHandlerInterface &handler) override
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler
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 MassSpectrumCstSPtr massSpectrumCstSPtr(std::size_t spectrum_index) override
virtual MassSpectrumSPtr massSpectrumSPtr(std::size_t spectrum_index) override
get a MassSpectrumSPtr class given its spectrum index
virtual bool hasScanNumbers() const override
tells if spectra can be accessed using scan numbers by default, it returns false. Only overrided func...
virtual QualifiedMassSpectrum qualifiedMassSpectrum(std::size_t spectrum_index, bool want_binary_data=true) const override
get a QualifiedMassSpectrum class given its scan number
virtual bool releaseDevice() override
release data back end device if a the data back end is released, the developper has to use acquireDev...
virtual bool acquireDevice() override
acquire data back end device
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 std::size_t spectrumListSize() const override
get the totat number of spectrum conained in the MSrun data file
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:44
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
Definition: massspectrum.h:55
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:54
MSrun file reader for native Bruker TimsTOF raw data.