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
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 getNbrPeaks(std::size_t scanNum) 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 scanNumBegin,
88 std::size_t scanNumEnd) 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 virtual void cumulateScansInRawMap(TimsDataFastMap &rawSpectrum,
152 std::size_t scanNumBegin,
153 std::size_t scanNumEnd) const override;
154
155
156 /** @brief get a single mobility scan m/z + intensities
157 *
158 * @param scanNum scan number in the frame in the order it lies in binary
159 * file, from 0 to N-1
160 * @param mzindex_merge_window width of the mzindex window used to merge all
161 * intensities into a single point. This results in faster computing.
162 * @param mz_range_begin
163 * @param mz_range_end
164 * @param mz_minimum_index report the minimum mz index contained in the
165 * resulting trace (constrained by the mz_range_begin)
166 * @param mz_maximum_index report the maximum mz index contained in the
167 * resulting trace (constrained by the mz_range_end)
168 *
169 */
170 virtual Trace getMobilityScan(std::size_t scanNum,
171 std::size_t mz_index_merge_window,
172 double mz_range_begin,
173 double mz_range_end,
174 quint32 &mz_minimum_index_out,
175 quint32 &mz_maximum_index_out) const override;
176
177 virtual quint64
178 cumulateSingleScanIntensities(std::size_t scanNum) const override;
179
180 virtual quint64
181 cumulateScansIntensities(std::size_t scanNumBegin,
182 std::size_t scanNumEnd) const override;
183
184 /** @brief get raw index list for one given scan
185 * index are not TOF nor m/z, just index on digitizer
186 */
187 virtual std::vector<quint32>
188 getScanIndexList(std::size_t scanNum) const override;
189
190 /** @brief get raw intensities without transformation from one scan
191 * it needs intensity normalization
192 */
193 virtual std::vector<quint32>
194 getScanIntensities(std::size_t scanNum) const override;
195
197 getMassSpectrumSPtr(std::size_t scanNum) const override;
198
199
200 /** @brief get the raw index tof_index and intensities (normalized)
201 *
202 * @param scanNum the scan number to extract
203 * @param accepted_tof_index_range_begin mz index begin
204 * @param accepted_tof_index_range_end mz index end
205 * @return vector of RawValuePair
206 *
207 */
208 virtual std::vector<RawValuePair>
209 getRawValuePairList(std::size_t scanNum,
210 quint32 accepted_tof_index_range_begin,
211 quint32 accepted_tof_index_range_end) const;
212
213 protected:
214 /** @brief constructor for binary independant tims frame
215 * @param timsId tims frame identifier in the database
216 * @param scanNum the total number of scans contained in this frame
217 */
218 TimsFrame(std::size_t timsId, quint32 scanNum);
219
221 std::vector<XicCoordTims *>::iterator &itXicListbegin,
222 std::vector<XicCoordTims *>::iterator &itXicListend,
223 XicExtractMethod method) const;
224
225
226 /** @brief cumulate a scan into a map
227 *
228 * @param scanNum scan number 0 to (m_scanNumber-1)
229 */
230 virtual void cumulateScan(std::size_t scanNum,
231 TimsDataFastMap &accumulate_into) const;
232
233
234 virtual void cumulateScan2(std::size_t scanNum,
235 TimsDataFastMap &accumulate_into,
236 quint32 accepted_tof_index_range_begin,
237 quint32 accepted_tof_index_range_end) const;
238
239 /** @brief get the raw index tof_index and intensities (normalized)
240 *
241 * @param scanNum the scan number to extract
242 * @return trace vector
243 *
244 */
245 virtual pappso::TraceSPtr getRawTraceSPtr(std::size_t scanNum) 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:95
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 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:54
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
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
std::size_t getScanOffset(std::size_t scanNum) const
get offset for this spectrum in the binary file
virtual void cumulateScansInRawMap(TimsDataFastMap &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:42
std::shared_ptr< Trace > TraceSPtr
Definition trace.h:135
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
XicExtractMethod
Definition types.h:244
std::shared_ptr< const TimsFrame > TimsFrameCstSPtr
Definition timsframe.h:43
replacement for std::map
coordinates of the XIC to extract and the resulting XIC after extraction
handle a single Bruker's TimsTof frame without binary data