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 "../../massspectrum/qualifiedmassspectrum.h"
34#include "timsframebase.h"
35#include "../../xic/xic.h"
36#include "../../msrun/xiccoord/xiccoordtims.h"
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 cumulateScanToTrace(std::size_t scanNumBegin,
88 std::size_t scanNumEnd) const override;
89
90 /** @brief cumulate scan list into a trace into a raw spectrum map
91 * @param rawSpectrum simple map of integers to cumulate raw counts
92 * @param scanNumBegin first scan to cumulate
93 * @param scanNumEnd last scan to cumulate
94 */
95 virtual void cumulateScansInRawMap(std::map<quint32, quint32> &rawSpectrum,
96 std::size_t scanNumBegin,
97 std::size_t scanNumEnd) const override;
98
99
100 /** @brief get raw index list for one given scan
101 * index are not TOF nor m/z, just index on digitizer
102 */
103 virtual std::vector<quint32> getScanIndexList(std::size_t scanNum) const override;
104
105 /** @brief get raw intensities without transformation from one scan
106 * it needs intensity normalization
107 */
108 virtual std::vector<quint32> getScanIntensities(std::size_t scanNum) const override;
109
110 /** @brief get the mass spectrum corresponding to a scan number
111 * @param scanNum the scan number to retrieve
112 * */
114 getMassSpectrumCstSPtr(std::size_t scanNum) const;
115
117 getMassSpectrumSPtr(std::size_t scanNum) const override;
118
119
120 protected:
121 /** @brief constructor for binary independant tims frame
122 * @param timsId tims frame identifier in the database
123 * @param scanNum the total number of scans contained in this frame
124 */
125 TimsFrame(std::size_t timsId, quint32 scanNum);
126
128 std::vector<XicCoordTims *>::iterator &itXicListbegin,
129 std::vector<XicCoordTims *>::iterator &itXicListend,
130 XicExtractMethod method) const;
131
132
133 /** @brief cumulate a scan into a map
134 *
135 * @param scanNum scan number 0 to (m_scanNumber-1)
136 */
137 virtual void cumulateScan(std::size_t scanNum,
138 std::map<quint32, quint32> &accumulate_into) const;
139
140
141 /** @brief get the raw index tof_index and intensities (normalized)
142 *
143 * @param scanNum the scan number to extract
144 * @return trace vector
145 *
146 */
147 virtual pappso::TraceSPtr getRawTraceSPtr(std::size_t scanNum) const;
148
149
150 private:
151 /** @brief unshuffle data packet of tims compression type 2
152 * @param src is a zstd decompressed buffer pointer
153 */
154 void unshufflePacket(const char *src);
155
156
157 /** @brief get offset for this spectrum in the binary file
158 *
159 * @param scanNum scan number in the frame in the order it lies in binary
160 * file, from 0 to N-1
161 */
162
163 std::size_t getScanOffset(std::size_t scanNum) const;
164
165 private:
167 {
168 XicComputeStructure(const TimsFrame *fram_p,
169 const XicCoordTims &xic_struct);
170
171
172 Xic *xic_ptr = nullptr;
174 std::size_t mobilityIndexEnd;
175 std::size_t mzIndexLowerBound;
176 std::size_t mzIndexUpperBound;
177 double tmpIntensity = 0;
178 };
179
180 protected:
181 QByteArray m_timsDataFrame;
182};
183} // namespace pappso
QByteArray m_timsDataFrame
Definition: timsframe.h:181
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:173
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:131
virtual ~TimsFrame()
Definition: timsframe.cpp:98
virtual void cumulateScan(std::size_t scanNum, std::map< quint32, quint32 > &accumulate_into) const
cumulate a scan into a map
Definition: timsframe.cpp:222
TimsFrame(std::size_t timsId, quint32 scanNum, char *p_bytes, std::size_t len)
Definition: timsframe.cpp:63
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
Definition: timsframe.cpp:359
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:198
void unshufflePacket(const char *src)
unshuffle data packet of tims compression type 2
Definition: timsframe.cpp:104
std::size_t getScanOffset(std::size_t scanNum) const
get offset for this spectrum in the binary file
Definition: timsframe.cpp:161
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:316
virtual Trace cumulateScanToTrace(std::size_t scanNumBegin, std::size_t scanNumEnd) const override
cumulate scan list into a trace
Definition: timsframe.cpp:260
void extractTimsXicListInRtRange(std::vector< XicCoordTims * >::iterator &itXicListbegin, std::vector< XicCoordTims * >::iterator &itXicListend, XicExtractMethod method) const
Definition: timsframe.cpp:412
virtual pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtr(std::size_t scanNum) const
get the mass spectrum corresponding to a scan number
Definition: timsframe.cpp:352
virtual pappso::TraceSPtr getRawTraceSPtr(std::size_t scanNum) const
get the raw index tof_index and intensities (normalized)
Definition: timsframe.cpp:504
A simple container of DataPoint instances.
Definition: trace.h:147
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:134
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
Definition: massspectrum.h:55
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:54
XicExtractMethod
Definition: types.h:200
std::shared_ptr< const TimsFrame > TimsFrameCstSPtr
Definition: timsframe.h:43
XicComputeStructure(const TimsFrame *fram_p, const XicCoordTims &xic_struct)
Definition: timsframe.cpp:41
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