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  * Contributors:
27  * Olivier Langella <Olivier.Langella@u-psud.fr> - initial API and
28  *implementation
29  ******************************************************************************/
30 
31 #pragma once
32 
33 
34 /////////////////////// StdLib includes
35 #include <memory>
36 #include <map>
37 
38 
39 /////////////////////// Qt includes
40 #include <QMutex>
41 
42 
43 /////////////////////// pappsomspp includes
44 
45 
46 /////////////////////// Local includes
47 #include "msrunid.h"
48 #include "../massspectrum/qualifiedmassspectrum.h"
49 #include "../msfile/msfilereader.h"
50 #include "../exportinmportconfig.h"
51 
52 
53 namespace pappso
54 {
55 
56 /** @brief interface to collect spectrums from the MsRunReader class
57  */
59 {
60  public:
61  virtual void
63 
64  /** @brief tells if we need the peak list (if we want the binary data) for
65  * each spectrum
66  */
67  virtual bool needPeakList() const = 0;
68 
69  /** @brief tells if we need the peak list (if we want the binary data) for
70  * each spectrum, given an MS level
71  */
72  virtual bool needMsLevelPeakList(unsigned int ms_level) const final;
73 
74  /** @brief tells if we need the peak list given
75  */
76  virtual void setNeedMsLevelPeakList(unsigned int ms_level,
77  bool want_peak_list) final;
78  virtual bool shouldStop();
79  virtual void loadingEnded();
80  virtual void spectrumListHasSize(std::size_t size);
81 
82 
83  /** @brief use threads to read a spectrum by batch of batch_size
84  * @param is_read_ahead boolean to use threads or not
85  */
86  virtual void setReadAhead(bool is_read_ahead) final;
87 
88  /** @brief tells if we want to read ahead spectrum
89  */
90  virtual bool isReadAhead() const;
91 
92  private:
93  bool m_isReadAhead = false;
94  std::vector<bool> m_needPeakListByMsLevel = {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  true,
108  true};
109 };
110 
111 
112 /** @brief example of interface to count MS levels of all spectrum in an MSrun
113  */
116 {
117  private:
118  std::vector<unsigned long> m_countMsLevelSpectrum;
119 
120  public:
121  virtual void
122  setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override;
123  virtual bool needPeakList() const override;
124  virtual void loadingEnded() override;
125 
126  unsigned long getMsLevelCount(unsigned int ms_level) const;
127 
128  unsigned long getTotalCount() const;
129 };
130 
131 /** @brief provides a multimap to find quickly spectrum index from scan number
132  */
135 {
136  private:
137  std::multimap<std::size_t, std::size_t> m_mmap_scan2index;
138 
139  public:
142  virtual void
143  setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override;
144  virtual bool needPeakList() const override;
145 
146  std::size_t getSpectrumIndexFromScanNumber(std::size_t scan_number) const;
147 };
148 
149 
151 typedef std::shared_ptr<MsRunReader> MsRunReaderSPtr;
152 typedef std::shared_ptr<const MsRunReader> MsRunReaderCstSPtr;
153 
154 /** @brief base class to read MSrun
155  * the only way to build a MsRunReader object is to use the MsRunReaderFactory
156  */
158 {
159 
160  friend class MsFileAccessor;
161 
162  public:
163  MsRunReader(MsRunIdCstSPtr &ms_run_id);
164  MsRunReader(const MsRunReader &other);
165  virtual ~MsRunReader();
166 
167  const MsRunIdCstSPtr &getMsRunId() const;
168 
169  /** @brief get a MassSpectrumSPtr class given its spectrum index
170  */
171  virtual MassSpectrumSPtr massSpectrumSPtr(std::size_t spectrum_index) = 0;
172  virtual MassSpectrumCstSPtr
173  massSpectrumCstSPtr(std::size_t spectrum_index) = 0;
174 
175  /** @brief get a QualifiedMassSpectrum class given its scan number
176  */
177  virtual QualifiedMassSpectrum
178  qualifiedMassSpectrum(std::size_t spectrum_index,
179  bool want_binary_data = true) const = 0;
180 
181  /** @brief get the totat number of spectrum conained in the MSrun data file
182  */
183  virtual std::size_t spectrumListSize() const = 0;
184 
185  /** @brief function to visit an MsRunReader and get each Spectrum in a
186  * spectrum collection handler
187  */
188  virtual void
190 
191 
192  /** @brief function to visit an MsRunReader and get each Spectrum in a
193  * spectrum collection handler by Ms Levels
194  */
195  virtual void
197  unsigned int ms_level) = 0;
198 
199 
200  /** @brief if possible, converts a scan number into a spectrum index
201  * This is a convenient function to help transition from the old scan number
202  * (not implemented by all vendors) to more secure spectrum index (not vendor
203  * dependant).
204  * It is better to not rely on this function.
205  */
206  virtual std::size_t scanNumber2SpectrumIndex(std::size_t scan_number);
207 
208  /** @brief tells if spectra can be accessed using scan numbers
209  * by default, it returns false. Only overrided functions can check if scan
210  * numbers are available in the current file
211  */
212  virtual bool hasScanNumbers() const;
213 
214 
215  /** @brief release data back end device
216  * if a the data back end is released, the developper has to use acquireDevice
217  * before using the msrunreader object
218  * @return bool true if done
219  */
220  virtual bool releaseDevice() = 0;
221 
222  /** @brief acquire data back end device
223  * @return bool true if done
224  */
225  virtual bool acquireDevice() = 0;
226 
227 
228  protected:
230  MsRunReaderScanNumberMultiMap *mpa_multiMapScanNumber = nullptr;
231 
232  virtual void initialize() = 0;
233 
234  /** @brief tells if the reader is able to handle this file
235  * must be implemented by private MS run reader, specific of one or more file
236  * format
237  */
238  virtual bool accept(const QString &file_name) const = 0;
239 };
240 
241 
242 } // namespace pappso
243 
provides a multimap to find quickly spectrum index from scan number
Definition: msrunreader.h:135
std::multimap< std::size_t, std::size_t > m_mmap_scan2index
Definition: msrunreader.h:137
base class to read MSrun the only way to build a MsRunReader object is to use the MsRunReaderFactory
Definition: msrunreader.h:158
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:229
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 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 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:116
std::vector< unsigned long > m_countMsLevelSpectrum
Definition: msrunreader.h:118
Class representing a fully specified mass spectrum.
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 void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum)=0
#define PMSPP_LIB_DECL
Q_DECLARE_METATYPE(pappso::MsRunReaderSPtr)
int msRunReaderSPtrMetaTypeId
Definition: msrunreader.cpp:37
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:151
std::shared_ptr< const MsRunReader > MsRunReaderCstSPtr
Definition: msrunreader.h:152
class PMSPP_LIB_DECL MsRunReader
Definition: msrunreader.h:150
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