libpappsomspp
Library for mass spectrometry
msrunreader.h
Go to the documentation of this file.
1 /**
2  * \file pappsomspp/msrun/msrunreader.h
3  * \date 29/05/2018
4  * \author Olivier Langella
5  * \brief base interface to read MSrun files
6  */
7 
8 /*******************************************************************************
9  * Copyright (c) 2018 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 #pragma once
29 
30 
31 /////////////////////// StdLib includes
32 #include <memory>
33 #include <map>
34 
35 
36 /////////////////////// Qt includes
37 #include <QMutex>
38 
39 
40 /////////////////////// pappsomspp includes
41 #include "../trace/maptrace.h"
42 
43 /////////////////////// Local includes
44 #include "msrunid.h"
45 #include "../massspectrum/qualifiedmassspectrum.h"
46 #include "../msfile/msfilereader.h"
47 #include "../exportinmportconfig.h"
48 #include "xiccoord/xiccoord.h"
49 
50 namespace pappso
51 {
52 
53 /** @brief interface to collect spectrums from the MsRunReader class
54  */
56 {
57  public:
58  virtual void
60 
61  /** @brief tells if we need the peak list (if we want the binary data) for
62  * each spectrum
63  */
64  virtual bool needPeakList() const = 0;
65 
66  /** @brief tells if we need the peak list (if we want the binary data) for
67  * each spectrum, given an MS level
68  */
69  virtual bool needMsLevelPeakList(unsigned int ms_level) const final;
70 
71  /** @brief tells if we need the peak list given
72  */
73  virtual void setNeedMsLevelPeakList(unsigned int ms_level,
74  bool want_peak_list) final;
75  virtual bool shouldStop();
76  virtual void loadingEnded();
77  virtual void spectrumListHasSize(std::size_t size);
78 
79 
80  /** @brief use threads to read a spectrum by batch of batch_size
81  * @param is_read_ahead boolean to use threads or not
82  */
83  virtual void setReadAhead(bool is_read_ahead) final;
84 
85  /** @brief tells if we want to read ahead spectrum
86  */
87  virtual bool isReadAhead() const;
88 
89  private:
90  bool m_isReadAhead = false;
91 
92  std::vector<bool> m_needPeakListByMsLevel = {true,
93  true,
94  true,
95  true,
96  true,
97  true,
98  true,
99  true,
100  true,
101  true,
102  true,
103  true,
104  true,
105  true,
106  true};
107 };
108 
109 
110 /** @brief example of interface to count MS levels of all spectrum in an MSrun
111  */
114 {
115  private:
116  std::vector<unsigned long> m_countMsLevelSpectrum;
117 
118  public:
119  virtual void
120  setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override;
121  virtual bool needPeakList() const override;
122  virtual void loadingEnded() override;
123 
124  unsigned long getMsLevelCount(unsigned int ms_level) const;
125 
126  unsigned long getTotalCount() const;
127 };
128 
129 /** @brief provides a multimap to find quickly spectrum index from scan number
130  */
133 {
134  private:
135  std::multimap<std::size_t, std::size_t> m_mmap_scan2index;
136 
137  public:
140  virtual void
141  setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override;
142  virtual bool needPeakList() const override;
143 
144  std::size_t getSpectrumIndexFromScanNumber(std::size_t scan_number) const;
145 };
146 
147 
148 /** @brief collect retention times along MS run */
151 {
152  private:
153  std::vector<double> m_retention_time_list;
154 
155  public:
157  virtual ~MsRunReaderRetentionTimeLine();
158  virtual void
159  setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override;
160  virtual bool needPeakList() const override;
161 
162  const std::vector<double> &getRetentionTimeLine() const;
163 };
164 
165 
166 /** @brief calculate a TIC chromatogram */
169 {
170  public:
172  virtual ~MsRunReaderTicChromatogram();
173  virtual void setQualifiedMassSpectrum(
174  const QualifiedMassSpectrum &qualified_mass_spectrum) override;
175  virtual bool needPeakList() const override;
176 
177  Trace getTicChromatogram() const;
178 
179  private:
181 };
182 
183 
185 typedef std::shared_ptr<MsRunReader> MsRunReaderSPtr;
186 typedef std::shared_ptr<const MsRunReader> MsRunReaderCstSPtr;
187 
188 /** @brief base class to read MSrun
189  * the only way to build a MsRunReader object is to use the MsRunReaderFactory
190  */
192 {
193 
194  friend class MsFileAccessor;
195 
196  public:
197  MsRunReader(MsRunIdCstSPtr &ms_run_id);
198  MsRunReader(const MsRunReader &other);
199  virtual ~MsRunReader();
200 
201  const MsRunIdCstSPtr &getMsRunId() const;
202 
203  /** @brief get a MassSpectrumSPtr class given its spectrum index
204  */
205  virtual MassSpectrumSPtr massSpectrumSPtr(std::size_t spectrum_index) = 0;
206  virtual MassSpectrumCstSPtr
207  massSpectrumCstSPtr(std::size_t spectrum_index) = 0;
208 
209  /** @brief get a QualifiedMassSpectrum class given its scan number
210  */
211  virtual QualifiedMassSpectrum
212  qualifiedMassSpectrum(std::size_t spectrum_index,
213  bool want_binary_data = true) const = 0;
214 
215 
216  /** @brief get a xic coordinate object from a given spectrum index
217  */
218  virtual XicCoordSPtr
219  newXicCoordSPtrFromSpectrumIndex(std::size_t spectrum_index,
220  PrecisionPtr precision) const = 0;
221 
222  /** @brief get a xic coordinate object from a given spectrum
223  */
225  const QualifiedMassSpectrum &mass_spectrum,
226  PrecisionPtr precision) const = 0;
227 
228  /** @brief get the totat number of spectrum conained in the MSrun data file
229  */
230  virtual std::size_t spectrumListSize() const = 0;
231 
232  /** @brief function to visit an MsRunReader and get each Spectrum in a
233  * spectrum collection handler
234  */
235  virtual void
237 
238 
239  /** @brief function to visit an MsRunReader and get each Spectrum in a
240  * spectrum collection handler by Ms Levels
241  */
242  virtual void
244  unsigned int ms_level) = 0;
245 
246 
247  /** @brief if possible, converts a scan number into a spectrum index
248  * This is a convenient function to help transition from the old scan number
249  * (not implemented by all vendors) to more secure spectrum index (not vendor
250  * dependant).
251  * It is better to not rely on this function.
252  */
253  virtual std::size_t scanNumber2SpectrumIndex(std::size_t scan_number);
254 
255  /** @brief tells if spectra can be accessed using scan numbers
256  * by default, it returns false. Only overrided functions can check if scan
257  * numbers are available in the current file
258  */
259  virtual bool hasScanNumbers() const;
260 
261 
262  /** @brief release data back end device
263  * if a the data back end is released, the developper has to use acquireDevice
264  * before using the msrunreader object
265  * @return bool true if done
266  */
267  virtual bool releaseDevice() = 0;
268 
269  /** @brief acquire data back end device
270  * @return bool true if done
271  */
272  virtual bool acquireDevice() = 0;
273 
274  /** @brief retention timeline
275  * get retention times along the MSrun in seconds
276  * @return vector of retention times (seconds)
277  */
278  virtual std::vector<double> getRetentionTimeLine();
279 
280  /** @brief get a TIC chromatogram
281  *
282  * for each retention time, computes the sum of all intensities.
283  * For IM-MS, combines the mobility spectra
284  *
285  * Note that, formally, a TIC chromatogram is computed only for MS1 spectra.
286  *
287  * @return a trace (x=rt, y=intensities)
288  */
289  virtual Trace getTicChromatogram();
290 
291 
292  /** @brief set only one is_mono_thread to true
293  *
294  * this avoid to use qtconcurrent
295  */
296  void setMonoThread(bool is_mono_thread);
297 
298  bool isMonoThread() const;
299 
300  protected:
302  MsRunReaderScanNumberMultiMap *mpa_multiMapScanNumber = nullptr;
303 
304  virtual void initialize() = 0;
305 
306  /** @brief tells if the reader is able to handle this file
307  * must be implemented by private MS run reader, specific of one or more file
308  * format
309  */
310  virtual bool accept(const QString &file_name) const = 0;
311 
312  private:
313  bool m_isMonoThread = false;
314 };
315 
316 
317 } // namespace pappso
318 
collect retention times along MS run
Definition: msrunreader.h:151
std::vector< double > m_retention_time_list
Definition: msrunreader.h:153
provides a multimap to find quickly spectrum index from scan number
Definition: msrunreader.h:133
std::multimap< std::size_t, std::size_t > m_mmap_scan2index
Definition: msrunreader.h:135
calculate a TIC chromatogram
Definition: msrunreader.h:169
base class to read MSrun the only way to build a MsRunReader object is to use the MsRunReaderFactory
Definition: msrunreader.h:192
virtual MassSpectrumCstSPtr massSpectrumCstSPtr(std::size_t spectrum_index)=0
virtual std::size_t spectrumListSize() const =0
get the totat number of spectrum conained in the MSrun data file
MsRunIdCstSPtr mcsp_msRunId
Definition: msrunreader.h:301
virtual bool acquireDevice()=0
acquire data back end device
virtual bool accept(const QString &file_name) const =0
tells if the reader is able to handle this file must be implemented by private MS run reader,...
virtual XicCoordSPtr newXicCoordSPtrFromSpectrumIndex(std::size_t spectrum_index, PrecisionPtr precision) const =0
get a xic coordinate object from a given spectrum index
virtual bool releaseDevice()=0
release data back end device if a the data back end is released, the developper has to use acquireDev...
virtual void initialize()=0
virtual XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum(const QualifiedMassSpectrum &mass_spectrum, PrecisionPtr precision) const =0
get a xic coordinate object from a given spectrum
virtual MassSpectrumSPtr massSpectrumSPtr(std::size_t spectrum_index)=0
get a MassSpectrumSPtr class given its spectrum index
virtual void readSpectrumCollection(SpectrumCollectionHandlerInterface &handler)=0
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler
virtual QualifiedMassSpectrum qualifiedMassSpectrum(std::size_t spectrum_index, bool want_binary_data=true) const =0
get a QualifiedMassSpectrum class given its scan number
virtual void readSpectrumCollectionByMsLevel(SpectrumCollectionHandlerInterface &handler, unsigned int ms_level)=0
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler by Ms Levels
example of interface to count MS levels of all spectrum in an MSrun
Definition: msrunreader.h:114
std::vector< unsigned long > m_countMsLevelSpectrum
Definition: msrunreader.h:116
Class representing a fully specified mass spectrum.
interface to collect spectrums from the MsRunReader class
Definition: msrunreader.h:56
virtual bool needPeakList() const =0
tells if we need the peak list (if we want the binary data) for each spectrum
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum)=0
A simple container of DataPoint instances.
Definition: trace.h:148
#define PMSPP_LIB_DECL
Q_DECLARE_METATYPE(pappso::MsRunReaderSPtr)
int msRunReaderSPtrMetaTypeId
Definition: msrunreader.cpp:35
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
std::shared_ptr< MsRunReader > MsRunReaderSPtr
Definition: msrunreader.h:185
std::shared_ptr< const MsRunReader > MsRunReaderCstSPtr
Definition: msrunreader.h:186
class PMSPP_LIB_DECL MsRunReader
Definition: msrunreader.h:184
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
std::shared_ptr< XicCoord > XicCoordSPtr
Definition: xiccoord.h:41
XIC coordinate in MSrun.