libpappsomspp
Library for mass spectrometry
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 cumulateScanToTrace(std::size_t scanNumBegin,
87 std::size_t scanNumEnd) const override;
88
89 /** @brief cumulate scan list into a trace into a raw spectrum map
90 * @param rawSpectrum simple map of integers to cumulate raw counts
91 * @param scanNumBegin first scan to cumulate
92 * @param scanNumEnd last scan to cumulate
93 */
94 virtual void cumulateScansInRawMap(std::map<quint32, quint32> &rawSpectrum,
95 std::size_t scanNumBegin,
96 std::size_t scanNumEnd) const override;
97
98 virtual quint64 cumulateSingleScanIntensities(std::size_t scanNum) const override;
99
100 virtual quint64
101 cumulateScansIntensities(std::size_t scanNumBegin,
102 std::size_t scanNumEnd) const override;
103
104 /** @brief get raw index list for one given scan
105 * index are not TOF nor m/z, just index on digitizer
106 */
107 virtual std::vector<quint32>
108 getScanIndexList(std::size_t scanNum) const override;
109
110 /** @brief get raw intensities without transformation from one scan
111 * it needs intensity normalization
112 */
113 virtual std::vector<quint32>
114 getScanIntensities(std::size_t scanNum) const override;
115
116 /** @brief get the mass spectrum corresponding to a scan number
117 * @param scanNum the scan number to retrieve
118 * */
120 getMassSpectrumCstSPtr(std::size_t scanNum) const;
121
123 getMassSpectrumSPtr(std::size_t scanNum) const override;
124
125
126 protected:
127 /** @brief constructor for binary independant tims frame
128 * @param timsId tims frame identifier in the database
129 * @param scanNum the total number of scans contained in this frame
130 */
131 TimsFrame(std::size_t timsId, quint32 scanNum);
132
134 std::vector<XicCoordTims *>::iterator &itXicListbegin,
135 std::vector<XicCoordTims *>::iterator &itXicListend,
136 XicExtractMethod method) const;
137
138
139 /** @brief cumulate a scan into a map
140 *
141 * @param scanNum scan number 0 to (m_scanNumber-1)
142 */
143 virtual void cumulateScan(std::size_t scanNum,
144 std::map<quint32, quint32> &accumulate_into) const;
145
146
147 /** @brief get the raw index tof_index and intensities (normalized)
148 *
149 * @param scanNum the scan number to extract
150 * @return trace vector
151 *
152 */
153 virtual pappso::TraceSPtr getRawTraceSPtr(std::size_t scanNum) const;
154
155
156 private:
157 /** @brief unshuffle data packet of tims compression type 2
158 * @param src is a zstd decompressed buffer pointer
159 */
160 void unshufflePacket(const char *src);
161
162
163 /** @brief get offset for this spectrum in the binary file
164 *
165 * @param scanNum scan number in the frame in the order it lies in binary
166 * file, from 0 to N-1
167 */
168
169 std::size_t getScanOffset(std::size_t scanNum) const;
170
171 private:
173 {
174 XicComputeStructure(const TimsFrame *fram_p,
175 const XicCoordTims &xic_struct);
176
177
178 Xic *xic_ptr = nullptr;
180 std::size_t mobilityIndexEnd;
181 std::size_t mzIndexLowerBound;
182 std::size_t mzIndexUpperBound;
183 double tmpIntensity = 0;
184 };
185
186 protected:
187 QByteArray m_timsDataFrame;
188};
189} // namespace pappso
QByteArray m_timsDataFrame
Definition: timsframe.h:187
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
Definition: timsframe.cpp:171
virtual std::size_t getNbrPeaks(std::size_t scanNum) const override
get the number of peaks in this spectrum need the binary file
Definition: timsframe.cpp:129
virtual ~TimsFrame()
Definition: timsframe.cpp:96
virtual quint64 cumulateScansIntensities(std::size_t scanNumBegin, std::size_t scanNumEnd) const override
...
Definition: timsframe.cpp:267
virtual void cumulateScan(std::size_t scanNum, std::map< quint32, quint32 > &accumulate_into) const
cumulate a scan into a map
Definition: timsframe.cpp:305
TimsFrame(std::size_t timsId, quint32 scanNum, char *p_bytes, std::size_t len)
Definition: timsframe.cpp:61
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
Definition: timsframe.cpp:448
virtual quint64 cumulateSingleScanIntensities(std::size_t scanNum) const override
Definition: timsframe.cpp:220
virtual std::vector< quint32 > getScanIntensities(std::size_t scanNum) const override
get raw intensities without transformation from one scan it needs intensity normalization
Definition: timsframe.cpp:196
void unshufflePacket(const char *src)
unshuffle data packet of tims compression type 2
Definition: timsframe.cpp:102
std::size_t getScanOffset(std::size_t scanNum) const
get offset for this spectrum in the binary file
Definition: timsframe.cpp:159
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
Definition: timsframe.cpp:403
virtual Trace cumulateScanToTrace(std::size_t scanNumBegin, std::size_t scanNumEnd) const override
cumulate scan list into a trace
Definition: timsframe.cpp:343
void extractTimsXicListInRtRange(std::vector< XicCoordTims * >::iterator &itXicListbegin, std::vector< XicCoordTims * >::iterator &itXicListend, XicExtractMethod method) const
Definition: timsframe.cpp:504
virtual pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtr(std::size_t scanNum) const
get the mass spectrum corresponding to a scan number
Definition: timsframe.cpp:440
virtual pappso::TraceSPtr getRawTraceSPtr(std::size_t scanNum) const
get the raw index tof_index and intensities (normalized)
Definition: timsframe.cpp:597
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
Definition: massspectrum.h:55
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:54
XicExtractMethod
Definition: types.h:201
std::shared_ptr< const TimsFrame > TimsFrameCstSPtr
Definition: timsframe.h:42
XicComputeStructure(const TimsFrame *fram_p, const XicCoordTims &xic_struct)
Definition: timsframe.cpp:39
coordinates of the XIC to extract and the resulting XIC after extraction
Definition: xiccoordtims.h:51
handle a single Bruker's TimsTof frame without binary data