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 
37 namespace pappso
38 {
39 
40 class TimsFrame;
41 typedef std::shared_ptr<TimsFrame> TimsFrameSPtr;
42 typedef std::shared_ptr<const TimsFrame> TimsFrameCstSPtr;
43 
44 class TimsBinDec;
45 
46 struct TimsXicStructure;
47 class TimsDirectXicExtractor;
48 
49 /**
50  * @todo write docs
51  */
52 class TimsFrame : public TimsFrameBase
53 {
55 
56  public:
57  /**
58  * Default constructor
59  */
60  TimsFrame(std::size_t timsId,
61  quint32 scanNum,
62  char *p_bytes,
63  std::size_t len);
64  /**
65  * Copy constructor
66  *
67  * @param other TODO
68  */
69  TimsFrame(const TimsFrame &other);
70 
71  /**
72  * Destructor
73  */
74  ~TimsFrame();
75 
76 
77  virtual std::size_t getNbrPeaks(std::size_t scanNum) const override;
78 
79  /** @brief cumulate scan list into a trace
80  * @param scanNumBegin first scan to cumulate
81  * @param scanNumEnd last scan to cumulate
82  * @return Trace mz and intensity values
83  */
84  virtual Trace cumulateScanToTrace(std::size_t scanNumBegin,
85  std::size_t scanNumEnd) const override;
86 
87  /** @brief cumulate a scan list into a map of integers
88  * @param scanNumBegin first scan to cumulate
89  * @param scanNumEnd last scan to cumulate
90  * @param accumulate_into map of x and y integer values
91  */
92  void cumulateScans(std::size_t scanNumBegin,
93  std::size_t scanNumEnd,
94  std::map<quint32, quint32> &accumulate_into) const;
95 
96  /** @brief get raw index list for one given scan
97  * index are not TOF nor m/z, just index on digitizer
98  */
99  std::vector<quint32> getScanIndexList(std::size_t scanNum) const;
100 
101  /** @brief get raw intensities without transformation from one scan
102  * it needs intensity normalization
103  */
104  std::vector<quint32> getScanIntensities(std::size_t scanNum) const;
105 
106  /** @brief get the mass spectrum corresponding to a scan number
107  * @param scanNum the scan number to retrieve
108  * */
109  pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtr(std::size_t scanNum) const;
111  getMassSpectrumSPtr(std::size_t scanNum) const override;
112 
113 
114  /** @brief transform accumulation of raw scans into a real mass spectrum
115  */
117  std::map<quint32, quint32> &accumulated_scans) const;
118 
119  protected:
121  std::vector<TimsXicStructure>::iterator &itXicListbegin,
122  std::vector<TimsXicStructure>::iterator &itXicListend,
123  XicExtractMethod method) const;
124 
125  private:
126  void unshufflePacket(const char *src);
127 
128  std::size_t getScanOffset(std::size_t scanNum) const;
129 
130 
131  /** @brief cumulate a scan into a map
132  */
133  void cumulateScan(std::size_t scanNum,
134  std::map<quint32, quint32> &accumulate_into) const;
135 
136  pappso::TraceSPtr getRawTraceSPtr(std::size_t scanNum) const;
137 
138  private:
139  struct XicComputeStructure
140  {
141  XicComputeStructure(const TimsFrame *fram_p,
142  const TimsXicStructure &xic_struct);
143 
144 
145  Xic *xic_ptr = nullptr;
146  std::size_t mobilityIndexBegin;
147  std::size_t mobilityIndexEnd;
148  std::size_t mzIndexLowerBound;
149  std::size_t mzIndexUpperBound;
150  double tmpIntensity = 0;
151  };
152 
153  private:
154  QByteArray m_timsDataFrame;
155 };
156 } // namespace pappso
pappso::TimsFrame::XicComputeStructure::XicComputeStructure
XicComputeStructure(const TimsFrame *fram_p, const TimsXicStructure &xic_struct)
Definition: timsframe.cpp:59
pappso::TimsFrame::getScanIntensities
std::vector< quint32 > getScanIntensities(std::size_t scanNum) const
get raw intensities without transformation from one scan it needs intensity normalization
Definition: timsframe.cpp:207
pappso::MassSpectrumCstSPtr
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
Definition: massspectrum.h:76
pappso::TimsFrame::XicComputeStructure
Definition: timsframe.h:158
pappso::TimsFrame::getTraceFromCumulatedScans
pappso::Trace getTraceFromCumulatedScans(std::map< quint32, quint32 > &accumulated_scans) const
transform accumulation of raw scans into a real mass spectrum
Definition: timsframe.cpp:321
pappso::Xic
Definition: xic.h:65
pappso::TimsFrameSPtr
std::shared_ptr< TimsFrame > TimsFrameSPtr
Definition: timsframe.h:58
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks
Definition: aa.cpp:39
pappso::TimsFrame::getMassSpectrumSPtr
virtual pappso::MassSpectrumSPtr getMassSpectrumSPtr(std::size_t scanNum) const override
Definition: timsframe.cpp:446
pappso::TimsFrame::cumulateScans
void cumulateScans(std::size_t scanNumBegin, std::size_t scanNumEnd, std::map< quint32, quint32 > &accumulate_into) const
cumulate a scan list into a map of integers
pappso::TimsFrame::XicComputeStructure::xic_ptr
Xic * xic_ptr
Definition: timsframe.h:163
pappso::TimsFrame::XicComputeStructure::mobilityIndexEnd
std::size_t mobilityIndexEnd
Definition: timsframe.h:165
pappso::TimsFrame::getRawTraceSPtr
pappso::TraceSPtr getRawTraceSPtr(std::size_t scanNum) const
Definition: timsframe.cpp:566
pappso::TimsFrame::XicComputeStructure::mzIndexUpperBound
std::size_t mzIndexUpperBound
Definition: timsframe.h:167
pappso::TimsFrame::getMassSpectrumCstSPtr
pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtr(std::size_t scanNum) const
get the mass spectrum corresponding to a scan number
Definition: timsframe.cpp:439
pappso::TimsFrame::TimsFrame
TimsFrame(std::size_t timsId, quint32 scanNum, char *p_bytes, std::size_t len)
Definition: timsframe.cpp:72
pappso::TimsFrame
Definition: timsframe.h:71
pappso::Trace
A simple container of DataPoint instances.
Definition: trace.h:132
pappso::XicExtractMethod
XicExtractMethod
Definition: types.h:204
pappso::TimsFrame::m_timsDataFrame
QByteArray m_timsDataFrame
Definition: timsframe.h:172
pappso::TimsFrame::unshufflePacket
void unshufflePacket(const char *src)
Definition: timsframe.cpp:113
pappso::TraceSPtr
std::shared_ptr< Trace > TraceSPtr
Definition: trace.h:119
pappso::TimsFrame::getNbrPeaks
virtual std::size_t getNbrPeaks(std::size_t scanNum) const override
Definition: timsframe.cpp:140
timsframebase.h
handle a single Bruker's TimsTof frame without binary data
pappso::TimsFrame::XicComputeStructure::mzIndexLowerBound
std::size_t mzIndexLowerBound
Definition: timsframe.h:166
pappso::TimsFrame::cumulateScanToTrace
virtual Trace cumulateScanToTrace(std::size_t scanNumBegin, std::size_t scanNumEnd) const override
cumulate scan list into a trace
Definition: timsframe.cpp:269
pappso::TimsXicStructure
structure needed to extract XIC from Tims data
Definition: timsdata.h:66
pappso::TimsFrame::getScanIndexList
std::vector< quint32 > getScanIndexList(std::size_t scanNum) const
get raw index list for one given scan index are not TOF nor m/z, just index on digitizer
Definition: timsframe.cpp:182
pappso::TimsFrame::TimsDirectXicExtractor
friend TimsDirectXicExtractor
Definition: timsframe.h:72
pappso::TimsFrame::XicComputeStructure::mobilityIndexBegin
std::size_t mobilityIndexBegin
Definition: timsframe.h:164
pappso::TimsFrame::getScanOffset
std::size_t getScanOffset(std::size_t scanNum) const
Definition: timsframe.cpp:170
pappso::TimsFrame::~TimsFrame
~TimsFrame()
Definition: timsframe.cpp:107
pappso::TimsFrameCstSPtr
std::shared_ptr< const TimsFrame > TimsFrameCstSPtr
Definition: timsframe.h:60
pappso::TimsFrame::cumulateScan
void cumulateScan(std::size_t scanNum, std::map< quint32, quint32 > &accumulate_into) const
cumulate a scan into a map
Definition: timsframe.cpp:231
pappso::TimsFrame::extractTimsXicListInRtRange
void extractTimsXicListInRtRange(std::vector< TimsXicStructure >::iterator &itXicListbegin, std::vector< TimsXicStructure >::iterator &itXicListend, XicExtractMethod method) const
Definition: timsframe.cpp:494
pappso::TimsFrame::XicComputeStructure::tmpIntensity
double tmpIntensity
Definition: timsframe.h:168
pappso::MassSpectrumSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:75