libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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"
35#include "timsdatafastmap.h"
36
37namespace pappso
38{
39
40class TimsFrameBase;
41typedef std::shared_ptr<TimsFrameBase> TimsFrameBaseSPtr;
42typedef std::shared_ptr<const TimsFrameBase> TimsFrameBaseCstSPtr;
43
44
45/**
46 * @todo write docs
47 */
49{
50 public:
51 /** @brief constructor for binary independant tims frame
52 * @param timsId tims frame identifier in the database
53 * @param scanNum the total number of scans contained in this frame
54 */
55 TimsFrameBase(std::size_t timsId, quint32 scanNum);
56 /**
57 * Copy constructor
58 *
59 * @param other TODO
60 */
61 TimsFrameBase(const TimsFrameBase &other);
62
63 /**
64 * Destructor
65 */
66 virtual ~TimsFrameBase();
67
68 /** @brief tells if 2 tims frame has the same calibration data
69 * Usefull to know if raw data can be handled between frames
70 */
71 virtual bool hasSameCalibrationData(const TimsFrameBase &other) const;
72
73 /** @brief get the number of peaks in this spectrum
74 * need the binary file
75 * @param scanNum scan number in the frame in the order it lies in binary
76 * file, from 0 to N-1
77 */
78 virtual std::size_t getNbrPeaks(std::size_t scanNum) const;
79
80 /** @brief get the number of scans contained in this frame
81 * each scan represents an ion mobility slice
82 */
83
84 virtual std::size_t getTotalNumberOfScans() const;
85
86
87 /** @brief get the maximum raw mass index contained in this frame
88 */
89 virtual quint32 getMaximumRawMassIndex() const;
90
91 /** @brief get Mass spectrum with peaks for this scan number
92 * need the binary file
93 * @param scanNum scan number in the frame in the order it lies in binary
94 * file, from 0 to N-1 (this is the mobility index)
95 */
96 virtual MassSpectrumSPtr getMassSpectrumSPtr(std::size_t scanNum) const;
97
98
99 /** @brief get the mass spectrum corresponding to a scan number
100 * @param scanNum the scan number to retrieve
101 * */
103 getMassSpectrumCstSPtr(std::size_t scanNum) const final;
104
105 /** @brief cumulate spectrum given a scan number range
106 * need the binary file
107 * The intensities are normalized with respect to the frame accumulation time
108 *
109 * @param scanNumBegin scan number in the frame in the order it lies in binary
110 * file, from 0 to N-1
111 * @param scanNumEnd scan number in the frame in the order it lies in binary
112 * file, from 0 to N-1
113 */
114 virtual Trace cumulateScansToTrace(std::size_t scanNumBegin,
115 std::size_t scanNumEnd) const;
116
117
118 /** @brief cumulate spectrum given a scan number range
119 * need the binary file
120 * The intensities are normalized with respect to the frame accumulation time
121 * to leverage computing performance, this function decreases the mz
122 * resolution
123 *
124 * @param mzindex_merge_window width of the mzindex window used to merge all
125 * intensities into a single point. This results in faster computing.
126 * @param scanNumBegin scan number in the frame in the order it lies in binary
127 * file, from 0 to N-1
128 * @param scanNumEnd scan number in the frame in the order it lies in binary
129 * file, from 0 to N-1
130 * @param mz_minimum_index report the minimum mz index contained in the
131 * resulting trace
132 * @param mz_maximum_index report the maximum mz index contained in the
133 * resulting trace
134 *
135 */
136 virtual Trace
137 cumulateScansToTraceMzDownResolution(std::size_t mzindex_merge_window,
138 std::size_t scanNumBegin,
139 std::size_t scanNumEnd,
140 quint32 &minimum_index,
141 quint32 &maximum_index) const;
142
143
144 /** @brief cumulate spectrum given a scan number range
145 * need the binary file
146 * The intensities are normalized with respect to the frame accumulation time
147 * to leverage computing performance, this function decreases the mz
148 * resolution
149 *
150 * @param mzindex_merge_window width of the mzindex window used to merge all
151 * intensities into a single point. This results in faster computing.
152 * @param mz_range_begin
153 * @param mz_range_end
154 * @param scanNumBegin scan number in the frame in the order it lies in binary
155 * file, from 0 to N-1
156 * @param scanNumEnd scan number in the frame in the order it lies in binary
157 * file, from 0 to N-1
158 * @param mz_minimum_index report the minimum mz index contained in the
159 * resulting trace (constrained by the mz_range_begin)
160 * @param mz_maximum_index report the maximum mz index contained in the
161 * resulting trace (constrained by the mz_range_end)
162 *
163 */
164 virtual Trace
165 cumulateScansToTraceMzDownResolution2(std::size_t mz_index_merge_window,
166 double mz_range_begin,
167 double mz_range_end,
168 std::size_t mobility_scan_begin,
169 std::size_t mobility_scan_end,
170 quint32 &mz_minimum_index_out,
171 quint32 &mz_maximum_index_out) const;
172
173
174 /** @brief get a single mobility scan m/z + intensities
175 *
176 * @param scanNum scan number in the frame in the order it lies in binary
177 * file, from 0 to N-1
178 * @param mzindex_merge_window width of the mzindex window used to merge all
179 * intensities into a single point. This results in faster computing.
180 * @param mz_range_begin
181 * @param mz_range_end
182 * @param mz_minimum_index report the minimum mz index contained in the
183 * resulting trace (constrained by the mz_range_begin)
184 * @param mz_maximum_index report the maximum mz index contained in the
185 * resulting trace (constrained by the mz_range_end)
186 *
187 */
188 virtual Trace getMobilityScan(std::size_t scanNum,
189 std::size_t mz_index_merge_window,
190 double mz_range_begin,
191 double mz_range_end,
192 quint32 &mz_minimum_index_out,
193 quint32 &mz_maximum_index_out) const;
194
195 /** @brief cumulate scan list into a trace into a raw spectrum map
196 * The intensities are NOT normalized with respect to the frame accumulation
197 * time
198 *
199 * @param rawSpectrum simple map of integers to cumulate raw counts
200 * @param scanNumBegin scan number in the frame in the order it lies in binary
201 * file, from 0 to N-1
202 * @param scanNumEnd scan number in the frame in the order it lies in binary
203 * file, from 0 to N-1
204 */
205 virtual void cumulateScansInRawMap(TimsDataFastMap &rawSpectrum,
206 std::size_t scanNumBegin,
207 std::size_t scanNumEnd) const;
208
209
210 virtual quint64 cumulateSingleScanIntensities(std::size_t scanNum) const;
211
212 virtual quint64 cumulateScansIntensities(std::size_t scanNumBegin,
213 std::size_t scanNumEnd) const;
214
215 /** @brief check that this scan number exists
216 * @param scanNum scan number in the frame in the order it lies in binary
217 * file, from 0 to N-1
218 */
219 bool checkScanNum(std::size_t scanNum) const;
220
221
222 void setAccumulationTime(double accumulation_time_ms);
223 void setMzCalibration(double T1_frame,
224 double T2_frame,
225 double digitizerTimebase,
226 double digitizerDelay,
227 double C0,
228 double C1,
229 double C2,
230 double C3,
231 double C4,
232 double T1_ref,
233 double T2_ref,
234 double dC1,
235 double dC2);
236 void setTimsCalibration(int tims_model_type,
237 double C0,
238 double C1,
239 double C2,
240 double C3,
241 double C4,
242 double C5,
243 double C6,
244 double C7,
245 double C8,
246 double C9);
247 void setTime(double time);
248 void setMsMsType(quint8 type);
249 unsigned int getMsLevel() const;
250 double getTime() const;
251
252 std::size_t getId() const;
253
254 /** @brief get drift time of a scan number in milliseconds
255 * @param scanNum scan number in the frame in the order it lies in binary
256 * file, from 0 to N-1
257 * @return time in milliseconds of mobility delay (drift time)
258 * */
259 double getDriftTime(std::size_t scanNum) const;
260
261 /** @brief get 1/K0 value of a given scan (mobility value)
262 * @param scanNum scan number in the frame in the order it lies in binary
263 * file, from 0 to N-1
264 * */
265 double getOneOverK0Transformation(std::size_t scanNum) const;
266
267
268 /** @brief get the scan number from a given 1/Ko mobility value
269 * @param one_over_k0 the mobility value to tranform
270 * @return integer the scan number in the frame in the order it lies in binary
271 * file, from 0 to N-1
272 */
273 std::size_t getScanNumFromOneOverK0(double one_over_k0) const;
274
275 /** @brief get voltage for a given scan number
276 * @param scanNum scan number in the frame in the order it lies in binary
277 * file, from 0 to N-1
278 * @return double volt measure
279 * */
280 double getVoltageTransformation(std::size_t scanNum) const;
281
282
283 /** @brief transform accumulation of raw scans into a real mass spectrum
284 */
286 getTraceFromCumulatedScans(TimsDataFastMap &accumulated_scans) const;
287
288
289 /** @brief get the MzCalibration model to compute mz and TOF for this frame
290 */
291 virtual const MzCalibrationInterfaceSPtr &
292 getMzCalibrationInterfaceSPtr() const final;
293
295
296
297 /** @brief get raw index list for one given scan
298 * index are not TOF nor m/z, just index on digitizer
299 */
300 virtual std::vector<quint32> getScanIndexList(std::size_t scanNum) const;
301
302 /** @brief get raw intensities without transformation from one scan
303 * it needs intensity normalization
304 */
305 virtual std::vector<quint32> getScanIntensities(std::size_t scanNum) const;
306
307 /** @brief get a mobility trace cumulating intensities inside the given mass
308 * index range
309 * @param mz_index_lower_bound raw mass index lower bound
310 * @param mz_index_upper_bound raw mass index upper bound
311 * @param method max or sum intensities
312 */
313 virtual Trace
314 getIonMobilityTraceByMzIndexRange(std::size_t mz_index_lower_bound,
315 std::size_t mz_index_upper_bound,
316 XicExtractMethod method) const;
317
318 protected:
320 {
323 };
324
325 /** @brief downsize mz resolution to lower the number of real mz computations
326 *
327 * @param mzindex_merge_window width of the mzindex window used to merge all
328 * intensities into a single point. This results in faster computing.
329 * @param rawSpectrum the spectrum to shrink
330 */
331 virtual std::vector<RawValuePair> &
332 downsizeMzRawValuePairList(std::size_t mzindex_merge_window,
333 std::vector<RawValuePair> &spectrum) const;
334
335 protected:
336 /** @brief total number of scans contained in this frame
337 */
339
340 /** @brief Tims frame database id (the SQL identifier of this frame)
341 * @warning in sqlite, there is another field called TimsId : this is not
342 * that, because it is in fact an offset in bytes in the binary file.
343 * */
344 std::size_t m_timsId;
345
346 /** @brief accumulation time in milliseconds
347 */
349
350 quint8 m_msMsType = 0;
351
352 /** @brief retention time
353 */
354 double m_time = 0;
355
356 double m_timsDvStart = 0; // C2 from TimsCalibration
357 double m_timsSlope =
358 0; // (dv_end - dv_start) / ncycles //C3 from TimsCalibration // C2 from
359 // TimsCalibration // C1 from TimsCalibration
360 double m_timsTtrans = 0; // C4 from TimsCalibration
361 double m_timsNdelay = 0; // C0 from TimsCalibration
362 double m_timsVmin = 0; // C8 from TimsCalibration
363 double m_timsVmax = 0; // C9 from TimsCalibration
364 double m_timsC6 = 0;
365 double m_timsC7 = 0;
366
368};
369} // namespace pappso
double m_accumulationTime
accumulation time in milliseconds
virtual std::vector< RawValuePair > & downsizeMzRawValuePairList(std::size_t mzindex_merge_window, std::vector< RawValuePair > &spectrum) const
downsize mz resolution to lower the number of real mz computations
virtual quint64 cumulateSingleScanIntensities(std::size_t scanNum) const
double getVoltageTransformation(std::size_t scanNum) const
get voltage for a given scan number
virtual std::size_t getTotalNumberOfScans() const
get the number of scans contained in this frame each scan represents an ion mobility slice
virtual Trace getIonMobilityTraceByMzIndexRange(std::size_t mz_index_lower_bound, std::size_t mz_index_upper_bound, XicExtractMethod method) const
get a mobility trace cumulating intensities inside the given mass index range
virtual std::size_t getNbrPeaks(std::size_t scanNum) const
get the number of peaks in this spectrum need the binary file
MzCalibrationInterfaceSPtr msp_mzCalibration
virtual MassSpectrumSPtr getMassSpectrumSPtr(std::size_t scanNum) const
get Mass spectrum with peaks for this scan number need the binary file
virtual std::vector< quint32 > getScanIndexList(std::size_t scanNum) const
get raw index list for one given scan index are not TOF nor m/z, just index on digitizer
double getDriftTime(std::size_t scanNum) const
get drift time of a scan number in milliseconds
double m_time
retention time
virtual quint64 cumulateScansIntensities(std::size_t scanNumBegin, std::size_t scanNumEnd) const
void setAccumulationTime(double accumulation_time_ms)
quint32 m_scanNumber
total number of scans contained in this frame
void setTime(double time)
std::size_t m_timsId
Tims frame database id (the SQL identifier of this frame)
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...
virtual quint32 getMaximumRawMassIndex() const
get the maximum raw mass index contained in this frame
unsigned int getMsLevel() const
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)
virtual const MzCalibrationInterfaceSPtr & getMzCalibrationInterfaceSPtr() const final
get the MzCalibration model to compute mz and TOF for this frame
virtual Trace cumulateScansToTraceMzDownResolution(std::size_t mzindex_merge_window, std::size_t scanNumBegin, std::size_t scanNumEnd, quint32 &minimum_index, quint32 &maximum_index) const
cumulate spectrum given a scan number range need the binary file The intensities are normalized with ...
std::size_t getScanNumFromOneOverK0(double one_over_k0) const
get the scan number from a given 1/Ko mobility value
virtual Trace cumulateScansToTrace(std::size_t scanNumBegin, std::size_t scanNumEnd) const
cumulate spectrum given a scan number range need the binary file The intensities are normalized with ...
void setMsMsType(quint8 type)
void setMzCalibration(double T1_frame, double T2_frame, double digitizerTimebase, double digitizerDelay, double C0, double C1, double C2, double C3, double C4, double T1_ref, double T2_ref, double dC1, double dC2)
pappso::Trace getTraceFromCumulatedScans(TimsDataFastMap &accumulated_scans) const
transform accumulation of raw scans into a real mass spectrum
double getOneOverK0Transformation(std::size_t scanNum) const
get 1/K0 value of a given scan (mobility value)
bool checkScanNum(std::size_t scanNum) const
check that this scan number exists
virtual Trace getMobilityScan(std::size_t scanNum, std::size_t mz_index_merge_window, double mz_range_begin, double mz_range_end, quint32 &mz_minimum_index_out, quint32 &mz_maximum_index_out) const
get a single mobility scan m/z + intensities
virtual Trace cumulateScansToTraceMzDownResolution2(std::size_t mz_index_merge_window, double mz_range_begin, double mz_range_end, std::size_t mobility_scan_begin, std::size_t mobility_scan_end, quint32 &mz_minimum_index_out, quint32 &mz_maximum_index_out) const
cumulate spectrum given a scan number range need the binary file The intensities are normalized with ...
virtual void cumulateScansInRawMap(TimsDataFastMap &rawSpectrum, std::size_t scanNumBegin, std::size_t scanNumEnd) const
cumulate scan list into a trace into a raw spectrum map The intensities are NOT normalized with respe...
void setMzCalibrationInterfaceSPtr(MzCalibrationInterfaceSPtr mzCalibration)
std::size_t getId() const
virtual std::vector< quint32 > getScanIntensities(std::size_t scanNum) const
get raw intensities without transformation from one scan it needs intensity normalization
virtual pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtr(std::size_t scanNum) const final
get the mass spectrum corresponding to a scan number
A simple container of DataPoint instances.
Definition trace.h:148
handles different ways to compute m/z using calibration parameters
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::shared_ptr< const TimsFrameBase > TimsFrameBaseCstSPtr
std::shared_ptr< TimsFrameBase > TimsFrameBaseSPtr
std::shared_ptr< MzCalibrationInterface > MzCalibrationInterfaceSPtr
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
XicExtractMethod
Definition types.h:244
replacement for std::map
replacement fot std::map dedicated to tims data for fast computations