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