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