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