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 
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  std::vector<bool> m_needPeakListByMsLevel = {true,
92  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 };
107 
108 
109 /** @brief example of interface to count MS levels of all spectrum in an MSrun
110  */
113 {
114  private:
115  std::vector<unsigned long> m_countMsLevelSpectrum;
116 
117  public:
118  virtual void
119  setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override;
120  virtual bool needPeakList() const override;
121  virtual void loadingEnded() override;
122 
123  unsigned long getMsLevelCount(unsigned int ms_level) const;
124 
125  unsigned long getTotalCount() const;
126 };
127 
128 /** @brief provides a multimap to find quickly spectrum index from scan number
129  */
132 {
133  private:
134  std::multimap<std::size_t, std::size_t> m_mmap_scan2index;
135 
136  public:
139  virtual void
140  setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override;
141  virtual bool needPeakList() const override;
142 
143  std::size_t getSpectrumIndexFromScanNumber(std::size_t scan_number) const;
144 };
145 
146 
147 /** @brief collect retention times along MS run */
150 {
151  private:
152  std::vector<double> m_retention_time_list;
153 
154  public:
156  virtual ~MsRunReaderRetentionTimeLine();
157  virtual void
158  setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override;
159  virtual bool needPeakList() const override;
160 
161  const std::vector<double> &getRetentionTimeLine() const;
162 };
163 
164 
166 typedef std::shared_ptr<MsRunReader> MsRunReaderSPtr;
167 typedef std::shared_ptr<const MsRunReader> MsRunReaderCstSPtr;
168 
169 /** @brief base class to read MSrun
170  * the only way to build a MsRunReader object is to use the MsRunReaderFactory
171  */
173 {
174 
175  friend class MsFileAccessor;
176 
177  public:
178  MsRunReader(MsRunIdCstSPtr &ms_run_id);
179  MsRunReader(const MsRunReader &other);
180  virtual ~MsRunReader();
181 
182  const MsRunIdCstSPtr &getMsRunId() const;
183 
184  /** @brief get a MassSpectrumSPtr class given its spectrum index
185  */
186  virtual MassSpectrumSPtr massSpectrumSPtr(std::size_t spectrum_index) = 0;
187  virtual MassSpectrumCstSPtr
188  massSpectrumCstSPtr(std::size_t spectrum_index) = 0;
189 
190  /** @brief get a QualifiedMassSpectrum class given its scan number
191  */
192  virtual QualifiedMassSpectrum
193  qualifiedMassSpectrum(std::size_t spectrum_index,
194  bool want_binary_data = true) const = 0;
195 
196 
197  /** @brief get a xic coordinate object from a given spectrum index
198  */
199  virtual XicCoordSPtr
200  newXicCoordSPtrFromSpectrumIndex(std::size_t spectrum_index,
201  PrecisionPtr precision) const = 0;
202 
203  /** @brief get a xic coordinate object from a given spectrum
204  */
206  const QualifiedMassSpectrum &mass_spectrum,
207  PrecisionPtr precision) const = 0;
208 
209  /** @brief get the totat number of spectrum conained in the MSrun data file
210  */
211  virtual std::size_t spectrumListSize() const = 0;
212 
213  /** @brief function to visit an MsRunReader and get each Spectrum in a
214  * spectrum collection handler
215  */
216  virtual void
218 
219 
220  /** @brief function to visit an MsRunReader and get each Spectrum in a
221  * spectrum collection handler by Ms Levels
222  */
223  virtual void
225  unsigned int ms_level) = 0;
226 
227 
228  /** @brief if possible, converts a scan number into a spectrum index
229  * This is a convenient function to help transition from the old scan number
230  * (not implemented by all vendors) to more secure spectrum index (not vendor
231  * dependant).
232  * It is better to not rely on this function.
233  */
234  virtual std::size_t scanNumber2SpectrumIndex(std::size_t scan_number);
235 
236  /** @brief tells if spectra can be accessed using scan numbers
237  * by default, it returns false. Only overrided functions can check if scan
238  * numbers are available in the current file
239  */
240  virtual bool hasScanNumbers() const;
241 
242 
243  /** @brief release data back end device
244  * if a the data back end is released, the developper has to use acquireDevice
245  * before using the msrunreader object
246  * @return bool true if done
247  */
248  virtual bool releaseDevice() = 0;
249 
250  /** @brief acquire data back end device
251  * @return bool true if done
252  */
253  virtual bool acquireDevice() = 0;
254 
255  /** @brief retention timeline
256  * get retention times along the MSrun in seconds
257  * @return vector of retention times (seconds)
258  */
259  virtual std::vector<double> getRetentionTimeLine();
260 
261 
262  protected:
264  MsRunReaderScanNumberMultiMap *mpa_multiMapScanNumber = nullptr;
265 
266  virtual void initialize() = 0;
267 
268  /** @brief tells if the reader is able to handle this file
269  * must be implemented by private MS run reader, specific of one or more file
270  * format
271  */
272  virtual bool accept(const QString &file_name) const = 0;
273 };
274 
275 
276 } // namespace pappso
277 
collect retention times along MS run
Definition: msrunreader.h:150
std::vector< double > m_retention_time_list
Definition: msrunreader.h:152
provides a multimap to find quickly spectrum index from scan number
Definition: msrunreader.h:132
std::multimap< std::size_t, std::size_t > m_mmap_scan2index
Definition: msrunreader.h:134
base class to read MSrun the only way to build a MsRunReader object is to use the MsRunReaderFactory
Definition: msrunreader.h:173
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:263
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:113
std::vector< unsigned long > m_countMsLevelSpectrum
Definition: msrunreader.h:115
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
#define PMSPP_LIB_DECL
Q_DECLARE_METATYPE(pappso::MsRunReaderSPtr)
int msRunReaderSPtrMetaTypeId
Definition: msrunreader.cpp:34
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:166
std::shared_ptr< const MsRunReader > MsRunReaderCstSPtr
Definition: msrunreader.h:167
class PMSPP_LIB_DECL MsRunReader
Definition: msrunreader.h:165
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.