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"
35#include "../../msrun/xiccoord/xiccoordtims.h"
36
37namespace pappso
38{
39
40class TimsFrame;
41typedef std::shared_ptr<TimsFrame> TimsFrameSPtr;
42typedef std::shared_ptr<const TimsFrame> TimsFrameCstSPtr;
43
44class TimsBinDec;
45
47
48/**
49 * @todo write docs
50 */
52{
54
55 public:
56 /**
57 * @param timsId tims frame id
58 * @param scanNum total number of scans in this frame
59 * @param p_bytes pointer on the decompressed binary buffer
60 * @param len size of the decompressed binary buffer
61 */
62 TimsFrame(std::size_t timsId,
63 quint32 scanNum,
64 char *p_bytes,
65 std::size_t len);
66 /**
67 * Copy constructor
68 *
69 * @param other TODO
70 */
71 TimsFrame(const TimsFrame &other);
72
73 /**
74 * Destructor
75 */
76 virtual ~TimsFrame();
77
78
79 virtual std::size_t getNbrPeaks(std::size_t scanNum) const override;
80
81 /** @brief cumulate scan list into a trace
82 * @param scanNumBegin first scan to cumulate
83 * @param scanNumEnd last scan to cumulate
84 * @return Trace mz and intensity values
85 */
86 virtual Trace cumulateScansToTrace(std::size_t scanNumBegin,
87 std::size_t scanNumEnd) const override;
88
89
90 /** @brief cumulate spectrum given a scan number range
91 * need the binary file
92 * The intensities are normalized with respect to the frame accumulation time
93 * to leverage computing performance, this function decreases the mz
94 * resolution
95 *
96 * @param mzindex_merge_window width of the mzindex window used to merge all
97 * intensities into a single point. This results in faster computing.
98 * @param scanNumBegin scan number in the frame in the order it lies in binary
99 * file, from 0 to N-1
100 * @param scanNumEnd scan number in the frame in the order it lies in binary
101 * file, from 0 to N-1
102 * @param mz_minimum_index report the minimum mz index contained in the
103 * resulting trace
104 * @param mz_maximum_index report the maximum mz index contained in the
105 * resulting trace
106 *
107 */
109 std::size_t mzindex_merge_window,
110 std::size_t scanNumBegin,
111 std::size_t scanNumEnd,
112 quint32 &mz_minimum_index,
113 quint32 &mz_maximum_index) const override;
114
115
116 /** @brief cumulate spectrum given a scan number range
117 * need the binary file
118 * The intensities are normalized with respect to the frame accumulation time
119 * to leverage computing performance, this function decreases the mz
120 * resolution
121 *
122 * @param mzindex_merge_window width of the mzindex window used to merge all
123 * intensities into a single point. This results in faster computing.
124 * @param mz_range_begin
125 * @param mz_range_end
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 (constrained by the mz_range_begin)
132 * @param mz_maximum_index report the maximum mz index contained in the
133 * resulting trace (constrained by the mz_range_end)
134 *
135 */
137 std::size_t mz_index_merge_window,
138 double mz_range_begin,
139 double mz_range_end,
140 std::size_t mobility_scan_begin,
141 std::size_t mobility_scan_end,
142 quint32 &mz_minimum_index_out,
143 quint32 &mz_maximum_index_out) const override;
144
145 /** @brief cumulate scan list into a trace into a raw spectrum map
146 * @param rawSpectrum simple map of integers to cumulate raw counts
147 * @param scanNumBegin first scan to cumulate
148 * @param scanNumEnd last scan to cumulate
149 */
150 virtual void cumulateScansInRawMap(std::map<quint32, quint32> &rawSpectrum,
151 std::size_t scanNumBegin,
152 std::size_t scanNumEnd) const override;
153
154
155 /** @brief get a single mobility scan m/z + intensities
156 *
157 * @param scanNum scan number in the frame in the order it lies in binary
158 * file, from 0 to N-1
159 * @param mzindex_merge_window width of the mzindex window used to merge all
160 * intensities into a single point. This results in faster computing.
161 * @param mz_range_begin
162 * @param mz_range_end
163 * @param mz_minimum_index report the minimum mz index contained in the
164 * resulting trace (constrained by the mz_range_begin)
165 * @param mz_maximum_index report the maximum mz index contained in the
166 * resulting trace (constrained by the mz_range_end)
167 *
168 */
169 virtual Trace getMobilityScan(std::size_t scanNum,
170 std::size_t mz_index_merge_window,
171 double mz_range_begin,
172 double mz_range_end,
173 quint32 &mz_minimum_index_out,
174 quint32 &mz_maximum_index_out) const override;
175
176 virtual quint64
177 cumulateSingleScanIntensities(std::size_t scanNum) const override;
178
179 virtual quint64
180 cumulateScansIntensities(std::size_t scanNumBegin,
181 std::size_t scanNumEnd) const override;
182
183 /** @brief get raw index list for one given scan
184 * index are not TOF nor m/z, just index on digitizer
185 */
186 virtual std::vector<quint32>
187 getScanIndexList(std::size_t scanNum) const override;
188
189 /** @brief get raw intensities without transformation from one scan
190 * it needs intensity normalization
191 */
192 virtual std::vector<quint32>
193 getScanIntensities(std::size_t scanNum) const override;
194
196 getMassSpectrumSPtr(std::size_t scanNum) const override;
197
198
199 protected:
200 /** @brief constructor for binary independant tims frame
201 * @param timsId tims frame identifier in the database
202 * @param scanNum the total number of scans contained in this frame
203 */
204 TimsFrame(std::size_t timsId, quint32 scanNum);
205
207 std::vector<XicCoordTims *>::iterator &itXicListbegin,
208 std::vector<XicCoordTims *>::iterator &itXicListend,
209 XicExtractMethod method) const;
210
211
212 /** @brief cumulate a scan into a map
213 *
214 * @param scanNum scan number 0 to (m_scanNumber-1)
215 */
216 virtual void cumulateScan(std::size_t scanNum,
217 std::map<quint32, quint32> &accumulate_into) const;
218
219
220 virtual void cumulateScan2(std::size_t scanNum,
221 std::map<quint32, quint32> &accumulate_into,
222 quint32 accepted_tof_index_range_begin,
223 quint32 accepted_tof_index_range_end) const;
224
225 /** @brief get the raw index tof_index and intensities (normalized)
226 *
227 * @param scanNum the scan number to extract
228 * @return trace vector
229 *
230 */
231 virtual pappso::TraceSPtr getRawTraceSPtr(std::size_t scanNum) const;
232
233
234 /** @brief get the raw index tof_index and intensities (normalized)
235 *
236 * @param scanNum the scan number to extract
237 * @param accepted_tof_index_range_begin mz index begin
238 * @param accepted_tof_index_range_end mz index end
239 * @return vector of RawValuePair
240 *
241 */
242 virtual std::vector<RawValuePair>
243 getRawValuePairList(std::size_t scanNum,
244 quint32 accepted_tof_index_range_begin,
245 quint32 accepted_tof_index_range_end) const;
246
247
248 private:
249 /** @brief unshuffle data packet of tims compression type 2
250 * @param src is a zstd decompressed buffer pointer
251 */
252 void unshufflePacket(const char *src);
253
254
255 /** @brief get offset for this spectrum in the binary file
256 *
257 * @param scanNum scan number in the frame in the order it lies in binary
258 * file, from 0 to N-1
259 */
260
261 std::size_t getScanOffset(std::size_t scanNum) const;
262
263 private:
265 {
266 XicComputeStructure(const TimsFrame *fram_p,
267 const XicCoordTims &xic_struct);
268
269
270 Xic *xic_ptr = nullptr;
272 std::size_t mobilityIndexEnd;
273 std::size_t mzIndexLowerBound;
274 std::size_t mzIndexUpperBound;
275 double tmpIntensity = 0;
276 };
277
278 protected:
279 QByteArray m_timsDataFrame;
280};
281} // namespace pappso
QByteArray m_timsDataFrame
Definition timsframe.h:279
virtual std::vector< quint32 > getScanIndexList(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
virtual std::size_t getNbrPeaks(std::size_t scanNum) const override
get the number of peaks in this spectrum need the binary file
virtual Trace cumulateScansToTraceMzDownResolution(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 ~TimsFrame()
Definition timsframe.cpp:96
virtual quint64 cumulateScansIntensities(std::size_t scanNumBegin, std::size_t scanNumEnd) const override
...
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 override
cumulate spectrum given a scan number range need the binary file The intensities are normalized with ...
virtual Trace cumulateScansToTrace(std::size_t scanNumBegin, std::size_t scanNumEnd) const override
cumulate scan list into a trace
virtual void cumulateScan2(std::size_t scanNum, std::map< quint32, quint32 > &accumulate_into, quint32 accepted_tof_index_range_begin, quint32 accepted_tof_index_range_end) const
virtual void cumulateScan(std::size_t scanNum, std::map< quint32, quint32 > &accumulate_into) const
cumulate a scan into a map
virtual std::vector< RawValuePair > 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)
friend TimsDirectXicExtractor
Definition timsframe.h:53
virtual pappso::MassSpectrumSPtr getMassSpectrumSPtr(std::size_t scanNum) const override
get Mass spectrum with peaks for this scan number need the binary file
virtual quint64 cumulateSingleScanIntensities(std::size_t scanNum) const override
virtual std::vector< quint32 > getScanIntensities(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 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
std::size_t getScanOffset(std::size_t scanNum) const
get offset for this spectrum in the binary file
virtual void cumulateScansInRawMap(std::map< quint32, quint32 > &rawSpectrum, std::size_t scanNumBegin, std::size_t scanNumEnd) const override
cumulate scan list into a trace into a raw spectrum map
void extractTimsXicListInRtRange(std::vector< XicCoordTims * >::iterator &itXicListbegin, std::vector< XicCoordTims * >::iterator &itXicListend, XicExtractMethod method) const
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:41
std::shared_ptr< Trace > TraceSPtr
Definition trace.h:135
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
XicExtractMethod
Definition types.h:242
std::shared_ptr< const TimsFrame > TimsFrameCstSPtr
Definition timsframe.h:42
coordinates of the XIC to extract and the resulting XIC after extraction
handle a single Bruker's TimsTof frame without binary data