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 */
103 virtual Trace
104 cumulateScansToTraceMzDownResolution(std::size_t mzindex_merge_window,
105 std::size_t scanNumBegin,
106 std::size_t scanNumEnd,
107 quint32 &minimum_index,
108 quint32 &maximum_index) const override;
109
110 Trace
111 cumulateScansToTraceMzDownResolution2(std::size_t mz_index_merge_window,
112 double mz_range_begin,
113 double mz_range_end,
114 std::size_t mobility_scan_begin,
115 std::size_t mobility_scan_end,
116 quint32 &mz_minimum_index_out,
117 quint32 &mz_maximum_index_out) const;
118
119 /** @brief cumulate scan list into a trace into a raw spectrum map
120 * @param rawSpectrum simple map of integers to cumulate raw counts
121 * @param scanNumBegin first scan to cumulate
122 * @param scanNumEnd last scan to cumulate
123 */
124 virtual void cumulateScansInRawMap(std::map<quint32, quint32> &rawSpectrum,
125 std::size_t scanNumBegin,
126 std::size_t scanNumEnd) const override;
127
128 virtual quint64
129 cumulateSingleScanIntensities(std::size_t scanNum) const override;
130
131 virtual quint64
132 cumulateScansIntensities(std::size_t scanNumBegin,
133 std::size_t scanNumEnd) const override;
134
135 /** @brief get raw index list for one given scan
136 * index are not TOF nor m/z, just index on digitizer
137 */
138 virtual std::vector<quint32>
139 getScanIndexList(std::size_t scanNum) const override;
140
141 /** @brief get raw intensities without transformation from one scan
142 * it needs intensity normalization
143 */
144 virtual std::vector<quint32>
145 getScanIntensities(std::size_t scanNum) const override;
146
147 /** @brief get the mass spectrum corresponding to a scan number
148 * @param scanNum the scan number to retrieve
149 * */
151 getMassSpectrumCstSPtr(std::size_t scanNum) const;
152
154 getMassSpectrumSPtr(std::size_t scanNum) const override;
155
156
157 protected:
158 /** @brief constructor for binary independant tims frame
159 * @param timsId tims frame identifier in the database
160 * @param scanNum the total number of scans contained in this frame
161 */
162 TimsFrame(std::size_t timsId, quint32 scanNum);
163
165 std::vector<XicCoordTims *>::iterator &itXicListbegin,
166 std::vector<XicCoordTims *>::iterator &itXicListend,
167 XicExtractMethod method) const;
168
169
170 /** @brief cumulate a scan into a map
171 *
172 * @param scanNum scan number 0 to (m_scanNumber-1)
173 */
174 virtual void cumulateScan(std::size_t scanNum,
175 std::map<quint32, quint32> &accumulate_into) const;
176
177
178 virtual void cumulateScan2(std::size_t scanNum,
179 std::map<quint32, quint32> &accumulate_into,
180 double mz_range_begin,
181 double mz_range_end,
182 quint32 accepted_tof_index_range_begin,
183 quint32 accepted_tof_index_range_end) const;
184
185 /** @brief get the raw index tof_index and intensities (normalized)
186 *
187 * @param scanNum the scan number to extract
188 * @return trace vector
189 *
190 */
191 virtual pappso::TraceSPtr getRawTraceSPtr(std::size_t scanNum) const;
192
193
194 private:
195 /** @brief unshuffle data packet of tims compression type 2
196 * @param src is a zstd decompressed buffer pointer
197 */
198 void unshufflePacket(const char *src);
199
200
201 /** @brief get offset for this spectrum in the binary file
202 *
203 * @param scanNum scan number in the frame in the order it lies in binary
204 * file, from 0 to N-1
205 */
206
207 std::size_t getScanOffset(std::size_t scanNum) const;
208
209 private:
211 {
212 XicComputeStructure(const TimsFrame *fram_p,
213 const XicCoordTims &xic_struct);
214
215
216 Xic *xic_ptr = nullptr;
218 std::size_t mobilityIndexEnd;
219 std::size_t mzIndexLowerBound;
220 std::size_t mzIndexUpperBound;
221 double tmpIntensity = 0;
222 };
223
224 protected:
225 QByteArray m_timsDataFrame;
226};
227} // namespace pappso
228
229
QByteArray m_timsDataFrame
Definition timsframe.h:225
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 &minimum_index, quint32 &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 cumulateScansToTrace(std::size_t scanNumBegin, std::size_t scanNumEnd) const override
cumulate scan list into a trace
virtual void cumulateScan(std::size_t scanNum, std::map< quint32, quint32 > &accumulate_into) const
cumulate a scan into a map
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 void cumulateScan2(std::size_t scanNum, std::map< quint32, quint32 > &accumulate_into, double mz_range_begin, double mz_range_end, quint32 accepted_tof_index_range_begin, quint32 accepted_tof_index_range_end) const
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
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
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::MassSpectrumCstSPtr getMassSpectrumCstSPtr(std::size_t scanNum) const
get the mass spectrum corresponding to a scan number
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< const MassSpectrum > MassSpectrumCstSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
XicExtractMethod
Definition types.h:240
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