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 scanCount the number of scans in this frame
54 */
55 TimsFrameBase(std::size_t frameId, quint32 scanCount);
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 scanIndex scan index in the frame in the order it lies in
76frame's binary data, from 0 to N-1
77 */
78 virtual std::size_t getScanPeakCount(std::size_t scanIndex) 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 index
92 * need the binary file
93 * @param scan_index scan index 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 scan_index) const;
97
98
99 /** @brief get the mass spectrum corresponding to a scan index
100 * @param scan_index the scan index of the mass spectrum to retrieve
101 * */
103 getMassSpectrumCstSPtr(std::size_t scan_index) 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 scanIndexBegin scan index in the frame in the order it lies in the
110frame in the binary file, from 0 to N-1
111 * @param scanIndexEnd scan number in the frame in the order it lies in the
112frame in the binary file, from 0 to N-1
113 */
114 virtual Trace cumulateScansToTrace(std::size_t scanIndexBegin,
115 std::size_t scanIndexEnd) const;
116
117
118 /** @brief cumulate spectrum given a scan index 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 tof_index_merge_window width of the TOF index window used to merge
125all
126 * intensities into a single point. This results in faster computing.
127 * @param scanIndexBegin scan index in the frame in the order it lies in
128binary
129 * file, from 0 to N-1
130 * @param scanIndexEnd scan index in the frame in the order it lies in binary
131 * file, from 0 to N-1
132 * @param minimum_tof_index_out report the minimum mz index contained in the
133 * resulting trace
134 * @param maximum_tof_index_out report the maximum mz index contained in the
135 * resulting trace
136 *
137 */
139 std::size_t tof_index_merge_window,
140 std::size_t scanIndexBegin,
141 std::size_t scanIndexEnd,
142 quint32 &minimum_tof_index_out,
143 quint32 &maximum_tof_index_out) const;
144
145
146 /** @brief cumulate spectrum given a scan number range
147 * need the binary file
148 * The intensities are normalized with respect to the frame accumulation time
149 * to leverage computing performance, this function decreases the mz
150 * resolution
151 *
152 * @param mzindex_merge_window width of the mzindex window used to merge all
153 * intensities into a single point. This results in faster computing.
154 * @param mz_range_begin
155 * @param mz_range_end
156 * @param scanNumBegin scan number in the frame in the order it lies in binary
157 * file, from 0 to N-1
158 * @param scanNumEnd scan number in the frame in the order it lies in binary
159 * file, from 0 to N-1
160 * @param mz_minimum_index report the minimum mz index contained in the
161 * resulting trace (constrained by the mz_range_begin)
162 * @param mz_maximum_index report the maximum mz index contained in the
163 * resulting trace (constrained by the mz_range_end)
164 *
165 */
167 std::size_t mz_index_merge_window,
168 double mz_range_begin,
169 double mz_range_end,
170 std::size_t mobility_scan_begin,
171 std::size_t mobility_scan_end,
172 quint32 &mz_minimum_index_out,
173 quint32 &mz_maximum_index_out) const;
174
175
176 /** @brief get a single mobility scan m/z + intensities
177 *
178 * @param scanIndex scan number in the frame in the order it lies in binary
179 * file, from 0 to N-1
180 * @param tof_index_merge_window width of the TOF index window used to merge
181all
182 * intensities into a single point. This results in faster computing.
183 * @param mz_range_begin
184 * @param mz_range_end
185 * @param mz_minimum_index report the minimum mz index contained in the
186 * resulting trace (constrained by the mz_range_begin)
187 * @param mz_maximum_index report the maximum mz index contained in the
188 * resulting trace (constrained by the mz_range_end)
189 *
190 */
191 virtual Trace getMobilityScan(std::size_t scan_index,
192 std::size_t tof_index_merge_window,
193 double mz_range_begin,
194 double mz_range_end,
195 quint32 &mz_minimum_index_out,
196 quint32 &mz_maximum_index_out) const;
197
198 /** @brief cumulate scan list into a trace into a raw spectrum map
199 * The intensities are NOT normalized with respect to the frame accumulation
200 * time
201 *
202 * @param tof_index_intensity_map simple map of integers to cumulate raw
203counts
204 * @param scan_index_begin scan index in the frame in the order it lies in
205binary
206 * file, from 0 to N-1
207 * @param scan_index_end scan index in the frame in the order it lies in
208binary
209 * file, from 0 to N-1
210 */
211 virtual void
213 std::size_t scan_index_begin,
214 std::size_t scan_index_end) const;
215
216
217 /** @brief cumulate scan list into a trace into a raw spectrum map
218 * The intensities are NOT normalized with respect to the frame accumulation
219 * time
220 *
221 * @param tof_index_intensity_map simple map of integers to cumulate raw
222counts
223 * @param scan_index_begin scan index in the frame in the order it lies in
224binary
225 * file, from 0 to N-1
226 * @param scan_index_end scan index in the frame in the order it lies in
227binary
228 * file, from 0 to N-1
229 * @param tof_index_begin
230 * @param tof_index_end
231 */
232 virtual void
234 std::size_t scan_index_begin,
235 std::size_t scan_index_end,
236 quint32 tof_index_begin,
237 quint32 tof_index_end) const;
238
239 virtual quint64 cumulateScanIntensities(std::size_t scan_index) const;
240
241 virtual quint64
242 cumulateScanRangeIntensities(std::size_t scan_index_begin,
243 std::size_t scan_index_end) const;
244
245 /** @brief check that this scan number exists
246 * @param scanNum scan number in the frame in the order it lies in binary
247 * file, from 0 to N-1
248 */
249 bool checkScanNum(std::size_t scanNum) const;
250
251
252 void setAcqDurationInMilliseconds(double acquisition_duration_ms);
253 void setMzCalibration(double T1_frame,
254 double T2_frame,
255 double digitizerTimebase,
256 double digitizerDelay,
257 double C0,
258 double C1,
259 double C2,
260 double C3,
261 double C4,
262 double T1_ref,
263 double T2_ref,
264 double dC1,
265 double dC2);
266 void setTimsCalibration(int tims_model_type,
267 double C0,
268 double C1,
269 double C2,
270 double C3,
271 double C4,
272 double C5,
273 double C6,
274 double C7,
275 double C8,
276 double C9);
277 void setRtInSeconds(double time);
278 void setMsMsType(quint8 type);
279 unsigned int getMsLevel() const;
280 double getRtInSeconds() const;
281
282 std::size_t getId() const;
283
284 /** @brief get drift time of a scan number in milliseconds
285 * @param scanNum scan number in the frame in the order it lies in binary
286 * file, from 0 to N-1
287 * @return time in milliseconds of mobility delay (drift time)
288 * */
289 double getDriftTimeInMilliseconds(std::size_t scan_index) const;
290
291 /** @brief get 1/K0 value of a given scan (mobility value)
292 * @param scanNum scan number in the frame in the order it lies in binary
293 * file, from 0 to N-1
294 * */
295 double getOneOverK0Transformation(std::size_t scan_index) const;
296
297
298 /** @brief get the scan number from a given 1/Ko mobility value
299 * @param one_over_k0 the mobility value to tranform
300 * @return integer the scan number in the frame in the order it lies in binary
301 * file, from 0 to N-1
302 */
303 std::size_t getScanIndexFromOneOverK0(double one_over_k0) const;
304
305 /** @brief get voltage for a given scan number
306 * @param scanNum scan number in the frame in the order it lies in binary
307 * file, from 0 to N-1
308 * @return double volt measure
309 * */
310 double getVoltageTransformation(std::size_t scanNum) const;
311
312 /** @brief transform accumulation of raw scans into a real mass spectrum
313 */
315 getTraceFromTofIndexIntensityMap(TimsDataFastMap &accumulated_scans) const;
316
317
318 /** @brief get the MzCalibration model to compute mz and TOF for this frame
319 */
320 virtual const MzCalibrationInterfaceSPtr &
321 getMzCalibrationInterfaceSPtr() const final;
322
324
325
326 /** @brief get raw index list for one given scan
327 * index are not TOF nor m/z, just index on digitizer
328 */
329 virtual std::vector<quint32>
330 getScanTofIndexList(std::size_t scan_index) const;
331
332 /** @brief get raw intensities without transformation from one scan
333 * it needs intensity normalization
334 */
335 virtual std::vector<quint32>
336 getScanIntensityList(std::size_t scan_index) const;
337
338 /** @brief get a mobility trace cumulating intensities inside the given mass
339 * index range
340 * @param tof_index_begin raw mass index lower bound
341 * @param tof_index_end raw mass index upper bound
342 * @param method max or sum intensities
343 * @param scan_index_begin first mobility scan to integrate
344 * @param scan_index_end last mobility scan to integrate
345 */
346 virtual Trace
347 getIonMobilityTraceByTofIndexRange(std::size_t tof_index_begin,
348 std::size_t tof_index_end,
349 XicExtractMethod method,
350 std::size_t scan_index_begin,
351 std::size_t scan_index_end) const;
352
353 protected:
355 {
356 quint32 tof_index;
358 };
359
360 /** @brief Downgrade the TOF index resolution to lower the number of real m/z
361computations
362
363 This function merges together into a single TOF index bin all the TOF
364indices contained in the \a tof_index_merge_window. Then the window is shifted
365and the operation is performed again. When all the list of
366\l{TofIndexIntensityPair}s has been gone through, the resolution of the data
367has effectively been downgrade by a factor corresponding to \a
368tof_index_merge_window.
369 *
370 * @param tof_index_merge_window width of the TOF index window used to merge
371all
372 * intensities into a single point. This results in faster computing.
373 * @param rawSpectrum the spectrum to shrink
374 */
375 virtual std::vector<TofIndexIntensityPair> &
377 std::size_t tof_index_merge_window,
378 std::vector<TofIndexIntensityPair> &spectrum) const;
379
380 protected:
381 /** @brief total number of scans contained in this frame
382 */
383 quint32 m_scanCount;
384
385 /** @brief Tims frame database id (the SQL identifier of this frame)
386 * @warning in sqlite, there is another field called TimsId : this is not
387 * that, because it is in fact an offset in bytes in the binary file.
388 * */
389 std::size_t m_frameId;
390
391 /** @brief acquisition duration in milliseconds
392 */
394
395 quint8 m_msMsType = 0;
396
397 /** @brief retention time
398 */
399 double m_rtInSeconds = 0;
400
401 double m_timsDvStart = 0; // C2 from TimsCalibration
402 double m_timsSlope =
403 0; // (dv_end - dv_start) / ncycles //C3 from TimsCalibration // C2 from
404 // TimsCalibration // C1 from TimsCalibration
405 double m_timsTtrans = 0; // C4 from TimsCalibration
406 double m_timsNdelay = 0; // C0 from TimsCalibration
407 double m_timsVmin = 0; // C8 from TimsCalibration
408 double m_timsVmax = 0; // C9 from TimsCalibration
409 double m_timsC6 = 0;
410 double m_timsC7 = 0;
411
413};
414} // namespace pappso
replacement for std::map
double m_rtInSeconds
retention time
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 pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtr(std::size_t scan_index) const final
get the mass spectrum corresponding to a scan index
MzCalibrationInterfaceSPtr msp_mzCalibration
virtual std::size_t getScanPeakCount(std::size_t scanIndex) const
get the number of peaks in this spectrum need the binary file
double getDriftTimeInMilliseconds(std::size_t scan_index) const
get drift time of a scan number in milliseconds
virtual Trace cumulateScansToTrace(std::size_t scanIndexBegin, std::size_t scanIndexEnd) const
cumulate spectrum given a scan number range need the binary file The intensities are normalized with ...
virtual std::vector< TofIndexIntensityPair > & downgradeResolutionOfTofIndexIntensityPairList(std::size_t tof_index_merge_window, std::vector< TofIndexIntensityPair > &spectrum) const
Downgrade the TOF index resolution to lower the number of real m/z computations.
std::size_t getScanIndexFromOneOverK0(double one_over_k0) const
get the scan number from a given 1/Ko mobility value
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 Trace combineScansToTraceWithDowngradedMzResolution(std::size_t tof_index_merge_window, std::size_t scanIndexBegin, std::size_t scanIndexEnd, quint32 &minimum_tof_index_out, quint32 &maximum_tof_index_out) const
cumulate spectrum given a scan index range need the binary file The intensities are normalized with r...
virtual Trace getIonMobilityTraceByTofIndexRange(std::size_t tof_index_begin, std::size_t tof_index_end, XicExtractMethod method, std::size_t scan_index_begin, std::size_t scan_index_end) const
get a mobility trace cumulating intensities inside the given mass index range
double m_acqDurationInMilliseconds
acquisition duration in milliseconds
double getRtInSeconds() const
virtual quint32 getMaximumRawMassIndex() const
get the maximum raw mass index contained in this frame
pappso::Trace getTraceFromTofIndexIntensityMap(TimsDataFastMap &accumulated_scans) const
transform accumulation of raw scans into a real mass spectrum
virtual Trace combineScansToTraceWithDowngradedMzResolution2(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 ...
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 MassSpectrumSPtr getMassSpectrumSPtr(std::size_t scan_index) const
get Mass spectrum with peaks for this scan index need the binary file
virtual const MzCalibrationInterfaceSPtr & getMzCalibrationInterfaceSPtr() const final
get the MzCalibration model to compute mz and TOF for this frame
virtual quint64 cumulateScanRangeIntensities(std::size_t scan_index_begin, std::size_t scan_index_end) const
void setRtInSeconds(double time)
double getOneOverK0Transformation(std::size_t scan_index) const
get 1/K0 value of a given scan (mobility value)
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)
quint32 m_scanCount
total number of scans contained in this frame
std::size_t m_frameId
Tims frame database id (the SQL identifier of this frame)
void setAcqDurationInMilliseconds(double acquisition_duration_ms)
virtual Trace getMobilityScan(std::size_t scan_index, std::size_t tof_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
bool checkScanNum(std::size_t scanNum) const
check that this scan number exists
virtual void combineScansInTofIndexIntensityMap(TimsDataFastMap &tof_index_intensity_map, std::size_t scan_index_begin, std::size_t scan_index_end) const
cumulate scan list into a trace into a raw spectrum map The intensities are NOT normalized with respe...
void setMzCalibrationInterfaceSPtr(MzCalibrationInterfaceSPtr mzCalibration)
virtual std::vector< quint32 > getScanTofIndexList(std::size_t scan_index) const
get raw index list for one given scan index are not TOF nor m/z, just index on digitizer
virtual std::vector< quint32 > getScanIntensityList(std::size_t scan_index) const
get raw intensities without transformation from one scan it needs intensity normalization
std::size_t getId() const
virtual quint64 cumulateScanIntensities(std::size_t scan_index) const
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:247
replacement fot std::map dedicated to tims data for fast computations