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
50namespace 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:
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
165/** @brief calculate a TIC chromatogram */
168{
169 public:
172 virtual void setQualifiedMassSpectrum(
173 const QualifiedMassSpectrum &qualified_mass_spectrum) override;
174 virtual bool needPeakList() const override;
175
176 Trace getTicChromatogram() const;
177
178 private:
180};
181
182
184typedef std::shared_ptr<MsRunReader> MsRunReaderSPtr;
185typedef std::shared_ptr<const MsRunReader> MsRunReaderCstSPtr;
186
187/** @brief base class to read MSrun
188 * the only way to build a MsRunReader object is to use the MsRunReaderFactory
189 */
191{
192
193 friend class MsFileAccessor;
194
195 public:
196 MsRunReader(MsRunIdCstSPtr &ms_run_id);
197 MsRunReader(const MsRunReader &other);
198 virtual ~MsRunReader();
199
200 const MsRunIdCstSPtr &getMsRunId() const;
201
202 /** @brief get a MassSpectrumSPtr class given its spectrum index
203 */
204 virtual MassSpectrumSPtr massSpectrumSPtr(std::size_t spectrum_index) = 0;
205 virtual MassSpectrumCstSPtr
206 massSpectrumCstSPtr(std::size_t spectrum_index) = 0;
207
208 /** @brief get a QualifiedMassSpectrum class given its scan number
209 */
211 qualifiedMassSpectrum(std::size_t spectrum_index,
212 bool want_binary_data = true) const = 0;
213
214
215 /** @brief get a xic coordinate object from a given spectrum index
216 */
217 virtual XicCoordSPtr
218 newXicCoordSPtrFromSpectrumIndex(std::size_t spectrum_index,
219 PrecisionPtr precision) const = 0;
220
221 /** @brief get a xic coordinate object from a given spectrum
222 */
224 const QualifiedMassSpectrum &mass_spectrum,
225 PrecisionPtr precision) const = 0;
226
227 /** @brief get the totat number of spectrum conained in the MSrun data file
228 */
229 virtual std::size_t spectrumListSize() const = 0;
230
231 /** @brief function to visit an MsRunReader and get each Spectrum in a
232 * spectrum collection handler
233 */
234 virtual void
236
237
238 /** @brief function to visit an MsRunReader and get each Spectrum in a
239 * spectrum collection handler by Ms Levels
240 */
241 virtual void
243 unsigned int ms_level) = 0;
244
245
246 /** @brief if possible, converts a scan number into a spectrum index
247 * This is a convenient function to help transition from the old scan number
248 * (not implemented by all vendors) to more secure spectrum index (not vendor
249 * dependant).
250 * It is better to not rely on this function.
251 */
252 virtual std::size_t scanNumber2SpectrumIndex(std::size_t scan_number);
253
254 /** @brief tells if spectra can be accessed using scan numbers
255 * by default, it returns false. Only overrided functions can check if scan
256 * numbers are available in the current file
257 */
258 virtual bool hasScanNumbers() const;
259
260
261 /** @brief release data back end device
262 * if a the data back end is released, the developper has to use acquireDevice
263 * before using the msrunreader object
264 * @return bool true if done
265 */
266 virtual bool releaseDevice() = 0;
267
268 /** @brief acquire data back end device
269 * @return bool true if done
270 */
271 virtual bool acquireDevice() = 0;
272
273 /** @brief retention timeline
274 * get retention times along the MSrun in seconds
275 * @return vector of retention times (seconds)
276 */
277 virtual std::vector<double> getRetentionTimeLine();
278
279 virtual Trace getTicChromatogram();
280
281
282 /** @brief set only one is_mono_thread to true
283 *
284 * this avoid to use qtconcurrent
285 */
286 void setMonoThread(bool is_mono_thread);
287
288 bool isMonoThread() const;
289
290 protected:
292 MsRunReaderScanNumberMultiMap *mpa_multiMapScanNumber = nullptr;
293
294 virtual void initialize() = 0;
295
296 /** @brief tells if the reader is able to handle this file
297 * must be implemented by private MS run reader, specific of one or more file
298 * format
299 */
300 virtual bool accept(const QString &file_name) const = 0;
301
302 private:
303 bool m_isMonoThread = false;
304};
305
306
307} // namespace pappso
308
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
calculate a TIC chromatogram
Definition: msrunreader.h:168
base class to read MSrun the only way to build a MsRunReader object is to use the MsRunReaderFactory
Definition: msrunreader.h:191
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:291
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
A simple container of DataPoint instances.
Definition: trace.h:147
#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:184
std::shared_ptr< const MsRunReader > MsRunReaderCstSPtr
Definition: msrunreader.h:185
class PMSPP_LIB_DECL MsRunReader
Definition: msrunreader.h:183
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
Definition: msrunid.h:45
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:43
XIC coordinate in MSrun.