libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
timsframe.h
Go to the documentation of this file.
1/**
2 * \file pappsomspp/vendors/tims/timsframe.h
3 * \date 23/08/2019
4 * \author Olivier Langella
5 * \brief handle a single Bruker's TimsTof frame
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 <QByteArray>
32#include <vector>
33#include "timsframebase.h"
34#include "../../xic/xic.h"
36
37
38namespace pappso
39{
40
41class TimsFrame;
42typedef std::shared_ptr<TimsFrame> TimsFrameSPtr;
43typedef std::shared_ptr<const TimsFrame> TimsFrameCstSPtr;
44
45class TimsBinDec;
46
48
49/**
50 * @todo write docs
51 */
53{
55
56 public:
57 /**
58 * @param timsId tims frame id
59 * @param scanNum total number of scans in this frame
60 * @param p_bytes pointer on the decompressed binary buffer
61 * @param len size of the decompressed binary buffer
62 */
63 TimsFrame(std::size_t timsId,
64 quint32 scanNum,
65 char *p_bytes,
66 std::size_t len);
67 /**
68 * Copy constructor
69 *
70 * @param other TODO
71 */
72 TimsFrame(const TimsFrame &other);
73
74 /**
75 * Destructor
76 */
77 virtual ~TimsFrame();
78
79
80 virtual std::size_t getScanPeakCount(std::size_t scanIndex) const override;
81
82 /** @brief cumulate scan list into a trace
83 * @param scanNumBegin first scan to cumulate
84 * @param scanNumEnd last scan to cumulate
85 * @return Trace mz and intensity values
86 */
87 virtual Trace cumulateScansToTrace(std::size_t scanIndexBegin,
88 std::size_t scanIndexEnd) const override;
89
90
91 /** @brief cumulate spectrum given a scan number range
92 * need the binary file
93 * The intensities are normalized with respect to the frame accumulation time
94 * to leverage computing performance, this function decreases the mz
95 * resolution
96 *
97 * @param mzindex_merge_window width of the mzindex window used to merge all
98 * intensities into a single point. This results in faster computing.
99 * @param scanNumBegin scan number in the frame in the order it lies in binary
100 * file, from 0 to N-1
101 * @param scanNumEnd scan number in the frame in the order it lies in binary
102 * file, from 0 to N-1
103 * @param mz_minimum_index report the minimum mz index contained in the
104 * resulting trace
105 * @param mz_maximum_index report the maximum mz index contained in the
106 * resulting trace
107 *
108 */
110 std::size_t mzindex_merge_window,
111 std::size_t scanNumBegin,
112 std::size_t scanNumEnd,
113 quint32 &mz_minimum_index,
114 quint32 &mz_maximum_index) const override;
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 mz_range_begin
126 * @param mz_range_end
127 * @param scanNumBegin scan number in the frame in the order it lies in binary
128 * file, from 0 to N-1
129 * @param scanNumEnd scan number in the frame in the order it lies in binary
130 * file, from 0 to N-1
131 * @param mz_minimum_index report the minimum mz index contained in the
132 * resulting trace (constrained by the mz_range_begin)
133 * @param mz_maximum_index report the maximum mz index contained in the
134 * resulting trace (constrained by the mz_range_end)
135 *
136 */
138 std::size_t mz_index_merge_window,
139 double mz_range_begin,
140 double mz_range_end,
141 std::size_t mobility_scan_begin,
142 std::size_t mobility_scan_end,
143 quint32 &mz_minimum_index_out,
144 quint32 &mz_maximum_index_out) const override;
145
146 /** @brief cumulate scan list into a trace into a raw spectrum map
147 * @param rawSpectrum simple map of integers to cumulate raw counts
148 * @param scanNumBegin first scan to cumulate
149 * @param scanNumEnd last scan to cumulate
150 */
151 void
153 std::size_t scan_index_begin,
154 std::size_t scan_index_end) const override;
155
156 virtual void
158 std::size_t scan_index_begin,
159 std::size_t scan_index_end,
160 quint32 tof_index_begin,
161 quint32 tof_index_end) const override;
162
163
164
165 /** @brief get a single mobility scan m/z + intensities
166 *
167 * @param scanNum scan number in the frame in the order it lies in binary
168 * file, from 0 to N-1
169 * @param mzindex_merge_window width of the mzindex window used to merge all
170 * intensities into a single point. This results in faster computing.
171 * @param mz_range_begin
172 * @param mz_range_end
173 * @param mz_minimum_index report the minimum mz index contained in the
174 * resulting trace (constrained by the mz_range_begin)
175 * @param mz_maximum_index report the maximum mz index contained in the
176 * resulting trace (constrained by the mz_range_end)
177 *
178 */
179 virtual Trace getMobilityScan(std::size_t scanNum,
180 std::size_t mz_index_merge_window,
181 double mz_range_begin,
182 double mz_range_end,
183 quint32 &mz_minimum_index_out,
184 quint32 &mz_maximum_index_out) const override;
185
186 virtual quint64 cumulateScanIntensities(std::size_t scanNum) const override;
187
188 virtual quint64
189 cumulateScanRangeIntensities(std::size_t scanNumBegin,
190 std::size_t scanNumEnd) const override;
191
192 /** @brief get raw index list for one given scan
193 * index are not TOF nor m/z, just index on digitizer
194 */
195 virtual std::vector<quint32>
196 getScanTofIndexList(std::size_t scanNum) const override;
197
198 /** @brief get raw intensities without transformation from one scan
199 * it needs intensity normalization
200 */
201 virtual std::vector<quint32>
202 getScanIntensityList(std::size_t scanNum) const override;
203
205 getMassSpectrumSPtr(std::size_t scanNum) const override;
206
207
208 /** @brief get the raw index tof_index and intensities (normalized)
209 *
210 * @param scanNum the scan number to extract
211 * @param accepted_tof_index_range_begin mz index begin
212 * @param accepted_tof_index_range_end mz index end
213 * @return vector of RawValuePair
214 *
215 */
216 virtual std::vector<TofIndexIntensityPair>
217 getRawValuePairList(std::size_t scanNum,
218 quint32 accepted_tof_index_range_begin,
219 quint32 accepted_tof_index_range_end) const;
220
221 protected:
222 /** @brief constructor for binary independant tims frame
223 * @param timsId tims frame identifier in the database
224 * @param scanNum the total number of scans contained in this frame
225 */
226 TimsFrame(std::size_t timsId, quint32 scanNum);
227
229 std::vector<XicCoordTims *>::iterator &itXicListbegin,
230 std::vector<XicCoordTims *>::iterator &itXicListend,
231 XicExtractMethod method) const;
232
233
234 /** @brief cumulate a scan into a map
235 *
236 * @param scanNum scan number 0 to (m_scanNumber-1)
237 */
238 virtual void cumulateScan(std::size_t scanNum,
239 TimsDataFastMap &accumulate_into) const;
240
241
242 virtual void cumulateScan2(std::size_t scanNum,
243 TimsDataFastMap &accumulate_into,
244 quint32 accepted_tof_index_range_begin,
245 quint32 accepted_tof_index_range_end) const;
246
247 /** @brief get the raw index tof_index and intensities (normalized)
248 *
249 * @param scanNum the scan number to extract
250 * @return trace vector
251 *
252 */
253 virtual pappso::TraceSPtr getRawTraceSPtr(std::size_t scanNum) const;
254
255
256 private:
257 /** @brief unshuffle data packet of tims compression type 2
258 * @param src is a zstd decompressed buffer pointer
259 */
260 void unshufflePacket(const char *src);
261
262
263 /** @brief get offset for this spectrum in the binary file
264 *
265 * @param scanNum scan number in the frame in the order it lies in binary
266 * file, from 0 to N-1
267 */
268
269 std::size_t getScanOffset(std::size_t scanNum) const;
270
271 private:
273 {
274 XicComputeStructure(const TimsFrame *fram_p,
275 const XicCoordTims &xic_struct);
276
277
278 Xic *xic_ptr = nullptr;
280 std::size_t mobilityIndexEnd;
281 std::size_t mzIndexLowerBound;
282 std::size_t mzIndexUpperBound;
283 double tmpIntensity = 0;
284 };
285
286 protected:
287 QByteArray m_binaryData;
288};
289} // namespace pappso
replacement for std::map
virtual Trace combineScansToTraceWithDowngradedMzResolution(std::size_t mzindex_merge_window, std::size_t scanNumBegin, std::size_t scanNumEnd, quint32 &mz_minimum_index, quint32 &mz_maximum_index) const override
cumulate spectrum given a scan number range need the binary file The intensities are normalized with ...
virtual quint64 cumulateScanRangeIntensities(std::size_t scanNumBegin, std::size_t scanNumEnd) const override
...
virtual quint64 cumulateScanIntensities(std::size_t scanNum) const override
virtual ~TimsFrame()
Definition timsframe.cpp:95
TimsFrame(std::size_t timsId, quint32 scanNum, char *p_bytes, std::size_t len)
Definition timsframe.cpp:60
QByteArray m_binaryData
Definition timsframe.h:287
friend TimsDirectXicExtractor
Definition timsframe.h:54
virtual pappso::MassSpectrumSPtr getMassSpectrumSPtr(std::size_t scanNum) const override
get Mass spectrum with peaks for this scan index need the binary file
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 override
cumulate spectrum given a scan number range need the binary file The intensities are normalized with ...
virtual Trace cumulateScansToTrace(std::size_t scanIndexBegin, std::size_t scanIndexEnd) const override
cumulate scan list into a trace
virtual std::vector< quint32 > getScanIntensityList(std::size_t scanNum) const override
get raw intensities without transformation from one scan it needs intensity normalization
void unshufflePacket(const char *src)
unshuffle data packet of tims compression type 2
virtual std::vector< TofIndexIntensityPair > getRawValuePairList(std::size_t scanNum, quint32 accepted_tof_index_range_begin, quint32 accepted_tof_index_range_end) const
get the raw index tof_index and intensities (normalized)
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 override
get a single mobility scan m/z + intensities
virtual void cumulateScan(std::size_t scanNum, TimsDataFastMap &accumulate_into) const
cumulate a scan into a map
virtual void cumulateScan2(std::size_t scanNum, TimsDataFastMap &accumulate_into, quint32 accepted_tof_index_range_begin, quint32 accepted_tof_index_range_end) const
virtual std::size_t getScanPeakCount(std::size_t scanIndex) const override
get the number of peaks in this spectrum need the binary file
std::size_t getScanOffset(std::size_t scanNum) const
get offset for this spectrum in the binary file
virtual std::vector< quint32 > getScanTofIndexList(std::size_t scanNum) const override
get raw index list for one given scan index are not TOF nor m/z, just index on digitizer
void extractTimsXicListInRtRange(std::vector< XicCoordTims * >::iterator &itXicListbegin, std::vector< XicCoordTims * >::iterator &itXicListend, XicExtractMethod method) const
void combineScansInTofIndexIntensityMap(TimsDataFastMap &rawSpectrum, std::size_t scan_index_begin, std::size_t scan_index_end) const override
cumulate scan list into a trace into a raw spectrum map
virtual pappso::TraceSPtr getRawTraceSPtr(std::size_t scanNum) const
get the raw index tof_index and intensities (normalized)
A simple container of DataPoint instances.
Definition trace.h:148
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::shared_ptr< TimsFrame > TimsFrameSPtr
Definition timsframe.h:42
std::shared_ptr< Trace > TraceSPtr
Definition trace.h:135
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
XicExtractMethod
Definition types.h:247
std::shared_ptr< const TimsFrame > TimsFrameCstSPtr
Definition timsframe.h:43
XicComputeStructure(const TimsFrame *fram_p, const XicCoordTims &xic_struct)
Definition timsframe.cpp:38
coordinates of the XIC to extract and the resulting XIC after extraction
handle a single Bruker's TimsTof frame without binary data
XIC coordinate in a Tims MSrun.