libpappsomspp
Library for mass spectrometry
timsframebase.h
Go to the documentation of this file.
1 /**
2  * \file pappsomspp/vendors/tims/timsframebase.h
3  * \date 16/12/2019
4  * \author Olivier Langella
5  * \brief handle a single Bruker's TimsTof frame without binary 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 #pragma once
29 
30 #include <memory>
31 #include <vector>
32 #include <QtGlobal>
33 #include "../../massspectrum/massspectrum.h"
34 
35 namespace pappso
36 {
37 
38 class TimsFrameBase;
39 typedef std::shared_ptr<TimsFrameBase> TimsFrameBaseSPtr;
40 typedef std::shared_ptr<const TimsFrameBase> TimsFrameBaseCstSPtr;
41 
42 
43 /**
44  * @todo write docs
45  */
46 class TimsFrameBase
47 {
48  public:
49  /** @brief constructor for binary independant tims frame
50  * @param timsId tims frame identifier in the database
51  * @param scanNum the total number of scans contained in this frame
52  */
53  TimsFrameBase(std::size_t timsId, quint32 scanNum);
54  /**
55  * Copy constructor
56  *
57  * @param other TODO
58  */
59  TimsFrameBase(const TimsFrameBase &other);
60 
61  /**
62  * Destructor
63  */
65 
66  /** @brief tells if 2 tims frame has the same calibration data
67  * Usefull to know if raw data can be handled between frames
68  */
69  virtual bool hasSameCalibrationData(const TimsFrameBase &other) const;
70 
71  virtual std::size_t getNbrPeaks(std::size_t scanNum) const;
72  virtual MassSpectrumSPtr getMassSpectrumSPtr(std::size_t scanNum) const;
73  virtual Trace cumulateScanToTrace(std::size_t scanNumBegin,
74  std::size_t scanNumEnd) const;
75 
76 
77  /** @brief cumulate scan list into a trace into a raw spectrum map
78  * @param rawSpectrum simple map of integers to cumulate raw counts
79  * @param scanNumBegin first scan to cumulate
80  * @param scanNumEnd last scan to cumulate
81  */
82  virtual void cumulateScansInRawMap(std::map<quint32, quint32> &rawSpectrum,
83  std::size_t scanNumBegin,
84  std::size_t scanNumEnd) const;
85 
86  bool checkScanNum(std::size_t scanNum) const;
87 
88 
89  void setAccumulationTime(double accumulation_time_ms);
90  void setMzCalibration(double temperature_correction,
91  double digitizerTimebase,
92  double digitizerDelay,
93  double C0,
94  double C1,
95  double C2,
96  double C3);
97  void setTimsCalibration(int tims_model_type,
98  double C0,
99  double C1,
100  double C2,
101  double C3,
102  double C4,
103  double C5,
104  double C6,
105  double C7,
106  double C8,
107  double C9);
108  void setTime(double time);
109  void setMsMsType(quint8 type);
110  unsigned int getMsLevel() const;
111  double getTime() const;
112 
113  std::size_t getId() const;
114 
115  /** @brief get drift time of a scan number in milliseconds
116  * @param scanNum the scan number
117  * @return time in milliseconds of mobility delay (drift time)
118  * */
119  double getDriftTime(std::size_t scanNum) const;
120 
121  /** @brief get 1/K0 value of a given scan (mobility value)
122  * @param scanNum the scan number
123  * */
124  double getOneOverK0Transformation(std::size_t scanNum) const;
125 
126 
127  /** @brief get m/z from time of flight
128  * @param tof time of flight
129  * @return m/z value
130  */
131  double getMzFromTof(double tof) const;
132 
133  /** @brief get raw index of a given m/z
134  * @param mz the mass to transform
135  * @return integer x raw value
136  */
137  quint32 getRawIndexFromMz(double mz) const;
138 
139  /** @brief get the scan number from a given 1/Ko mobility value
140  * @param one_over_k0 the mobility value to tranform
141  * @return integer the scan number
142  */
143  std::size_t getScanNumFromOneOverK0(double one_over_k0) const;
144 
145 
146  double getVoltageTransformation(std::size_t scanNum) const;
147 
148  /** @brief get time of flight from raw index
149  * @param index digitizer x raw value
150  * @return tof time of flight
151  */
152  double getTofFromIndex(quint32 index) const;
153 
154  /** @brief get time of flight from double index
155  */
156  double getTofFromIndex(double index) const;
157 
158 
159  /** @brief transform accumulation of raw scans into a real mass spectrum
160  */
162  std::map<quint32, quint32> &accumulated_scans) const;
163 
164  /** @brief transform accumulation of raw scans into a real mass spectrum with
165  * a simple centroid on raw integers
166  */
168  std::map<quint32, quint32> &accumulated_scans) const;
169 
170  protected:
171  /** @brief total number of scans contained in this frame
172  */
173  quint32 m_scanNumber;
174 
175  /** @brief Tims frame database id (the SQL identifier of this frame)
176  * @warning in sqlite, there is another field called TimsId : this is not
177  * that, because it is in fact an offset in bytes in the binary file.
178  * */
179  std::size_t m_timsId;
180 
181  /** @brief accumulation time in milliseconds
182  */
183  double m_accumulationTime = 0;
184 
185  double m_digitizerTimebase = 0;
186  double m_digitizerDelay = 0;
187 
188  /** @brief MZ calibration parameters
189  */
190  std::vector<double> m_mzCalibrationArr;
191 
192  quint8 m_msMsType = 0;
193 
194  /** @brief retention time
195  */
196  double m_time = 0;
197 
198  double m_timsDvStart = 0; // C2 from TimsCalibration
199  double m_timsSlope =
200  0; // (dv_end - dv_start) / ncycles //C3 from TimsCalibration // C2 from
201  // TimsCalibration // C1 from TimsCalibration
202  double m_timsTtrans = 0; // C4 from TimsCalibration
203  double m_timsNdelay = 0; // C0 from TimsCalibration
204  double m_timsVmin = 0; // C8 from TimsCalibration
205  double m_timsVmax = 0; // C9 from TimsCalibration
206  double m_timsC6 = 0;
207  double m_timsC7 = 0;
208 };
209 } // namespace pappso
pappso::TimsFrameBase::m_digitizerTimebase
double m_digitizerTimebase
Definition: timsframebase.h:203
pappso::TimsFrameBase::checkScanNum
bool checkScanNum(std::size_t scanNum) const
Definition: timsframebase.cpp:102
pappso::TimsFrameBase::m_timsId
std::size_t m_timsId
Tims frame database id (the SQL identifier of this frame)
Definition: timsframebase.h:197
pappso::TimsFrameBase::setTimsCalibration
void setTimsCalibration(int tims_model_type, double C0, double C1, double C2, double C3, double C4, double C5, double C6, double C7, double C8, double C9)
Definition: timsframebase.cpp:334
pappso::TimsFrameBase::getMsLevel
unsigned int getMsLevel() const
Definition: timsframebase.cpp:315
pappso::TimsFrameBase::cumulateScanToTrace
virtual Trace cumulateScanToTrace(std::size_t scanNumBegin, std::size_t scanNumEnd) const
Definition: timsframebase.cpp:132
pappso::TimsFrameBase
Definition: timsframebase.h:65
pappso::TimsFrameBase::m_timsSlope
double m_timsSlope
Definition: timsframebase.h:217
pappso::TimsFrameBase::m_timsC7
double m_timsC7
Definition: timsframebase.h:225
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
pappso::TimsFrameBase::setAccumulationTime
void setAccumulationTime(double accumulation_time_ms)
Definition: timsframebase.cpp:72
pappso::TimsFrameBase::setMzCalibration
void setMzCalibration(double temperature_correction, double digitizerTimebase, double digitizerDelay, double C0, double C1, double C2, double C3)
Definition: timsframebase.cpp:79
pappso::TimsFrameBaseCstSPtr
std::shared_ptr< const TimsFrameBase > TimsFrameBaseCstSPtr
Definition: timsframebase.h:58
pappso::TimsFrameBase::setTime
void setTime(double time)
Definition: timsframebase.cpp:301
pappso::TimsFrameBase::getNbrPeaks
virtual std::size_t getNbrPeaks(std::size_t scanNum) const
Definition: timsframebase.cpp:115
pappso::TimsFrameBase::getRawIndexFromMz
quint32 getRawIndexFromMz(double mz) const
get raw index of a given m/z
Definition: timsframebase.cpp:275
pappso::TimsFrameBase::getDriftTime
double getDriftTime(std::size_t scanNum) const
get drift time of a scan number in milliseconds
Definition: timsframebase.cpp:387
pappso::TimsFrameBase::m_accumulationTime
double m_accumulationTime
accumulation time in milliseconds
Definition: timsframebase.h:201
pappso::TimsFrameBase::m_time
double m_time
retention time
Definition: timsframebase.h:214
pappso::TimsFrameBase::getTraceFromCumulatedScansBuiltinCentroid
pappso::Trace getTraceFromCumulatedScansBuiltinCentroid(std::map< quint32, quint32 > &accumulated_scans) const
transform accumulation of raw scans into a real mass spectrum with a simple centroid on raw integers
Definition: timsframebase.cpp:459
pappso::Trace
A simple container of DataPoint instances.
Definition: trace.h:132
pappso::TimsFrameBase::getVoltageTransformation
double getVoltageTransformation(std::size_t scanNum) const
Definition: timsframebase.cpp:365
pappso::TimsFrameBase::getId
std::size_t getId() const
Definition: timsframebase.cpp:329
pappso::TimsFrameBase::m_timsDvStart
double m_timsDvStart
Definition: timsframebase.h:216
pappso::TimsFrameBase::getMassSpectrumSPtr
virtual MassSpectrumSPtr getMassSpectrumSPtr(std::size_t scanNum) const
Definition: timsframebase.cpp:124
pappso::TimsFrameBase::getScanNumFromOneOverK0
std::size_t getScanNumFromOneOverK0(double one_over_k0) const
get the scan number from a given 1/Ko mobility value
Definition: timsframebase.cpp:400
pappso::TimsFrameBaseSPtr
std::shared_ptr< TimsFrameBase > TimsFrameBaseSPtr
Definition: timsframebase.h:56
pappso::TimsFrameBase::~TimsFrameBase
~TimsFrameBase()
Definition: timsframebase.cpp:67
pappso::TimsFrameBase::TimsFrameBase
TimsFrameBase(std::size_t timsId, quint32 scanNum)
constructor for binary independant tims frame
Definition: timsframebase.cpp:55
pappso::TimsFrameBase::setMsMsType
void setMsMsType(quint8 type)
Definition: timsframebase.cpp:307
pappso::TimsFrameBase::m_timsNdelay
double m_timsNdelay
Definition: timsframebase.h:221
pappso::TimsFrameBase::m_timsVmin
double m_timsVmin
Definition: timsframebase.h:222
pappso::TimsFrameBase::cumulateScansInRawMap
virtual void cumulateScansInRawMap(std::map< quint32, quint32 > &rawSpectrum, std::size_t scanNumBegin, std::size_t scanNumEnd) const
cumulate scan list into a trace into a raw spectrum map
Definition: timsframebase.cpp:142
pappso::TimsFrameBase::getOneOverK0Transformation
double getOneOverK0Transformation(std::size_t scanNum) const
get 1/K0 value of a given scan (mobility value)
Definition: timsframebase.cpp:393
pappso::TimsFrameBase::getMzFromTof
double getMzFromTof(double tof) const
get m/z from time of flight
Definition: timsframebase.cpp:167
pappso::TimsFrameBase::m_scanNumber
quint32 m_scanNumber
total number of scans contained in this frame
Definition: timsframebase.h:191
pappso::TimsFrameBase::m_timsC6
double m_timsC6
Definition: timsframebase.h:224
pappso::TimsFrameBase::getTofFromIndex
double getTofFromIndex(quint32 index) const
get time of flight from raw index
Definition: timsframebase.cpp:161
pappso::TimsFrameBase::m_digitizerDelay
double m_digitizerDelay
Definition: timsframebase.h:204
pappso::TimsFrameBase::m_mzCalibrationArr
std::vector< double > m_mzCalibrationArr
MZ calibration parameters.
Definition: timsframebase.h:208
pappso::TimsFrameBase::m_msMsType
quint8 m_msMsType
Definition: timsframebase.h:210
pappso::TimsFrameBase::m_timsVmax
double m_timsVmax
Definition: timsframebase.h:223
pappso::TimsFrameBase::m_timsTtrans
double m_timsTtrans
Definition: timsframebase.h:220
pappso::TimsFrameBase::getTime
double getTime() const
Definition: timsframebase.cpp:323
pappso::MassSpectrumSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:75
pappso::TimsFrameBase::getTraceFromCumulatedScans
pappso::Trace getTraceFromCumulatedScans(std::map< quint32, quint32 > &accumulated_scans) const
transform accumulation of raw scans into a real mass spectrum
Definition: timsframebase.cpp:427
pappso::TimsFrameBase::hasSameCalibrationData
virtual bool hasSameCalibrationData(const TimsFrameBase &other) const
tells if 2 tims frame has the same calibration data Usefull to know if raw data can be handled betwee...
Definition: timsframebase.cpp:412