libpappsomspp
Library for mass spectrometry
timsdata.h
Go to the documentation of this file.
1 /**
2  * \file pappsomspp/vendors/tims/timsdata.h
3  * \date 27/08/2019
4  * \author Olivier Langella
5  * \brief main Tims data handler
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 <QDir>
31 #include <QSqlDatabase>
32 #include "timsbindec.h"
33 #include "timsframe.h"
34 #include "../../massspectrum/qualifiedmassspectrum.h"
35 #include "../../processing/filters/filterinterface.h"
36 #include <deque>
37 #include <QMutex>
38 #include <QSqlQuery>
39 
40 namespace pappso
41 {
42 
43 
44 /** @brief structure needed to extract XIC from Tims data
45  */
46 
48 {
50  : mzRange(pappso_double(1), PrecisionFactory::getPpmInstance(10.0)){};
51  std::size_t precursorId;
53  std::size_t scanNumBegin;
54  std::size_t scanNumEnd;
56  XicSPtr xicSptr = nullptr;
57  unsigned int charge;
58 };
59 
60 
61 /**
62  * @todo write docs
63  */
65 {
66  public:
67  /** @brief build using the tims data directory
68  */
69  TimsData(QDir timsDataDirectory);
70 
71  /**
72  * Copy constructor
73  *
74  * @param other TODO
75  */
76  TimsData(const TimsData &other);
77 
78  /**
79  * Destructor
80  */
81  ~TimsData();
82 
83 
84  /** @brief get a mass spectrum given its spectrum index
85  * @param raw_index a number begining at 0, corresponding to a Tims Scan in
86  * the order they lies in the binary data file
87  */
89  getMassSpectrumCstSPtrByRawIndex(std::size_t raw_index);
90 
91  /** @brief get a mass spectrum given the tims frame database id and scan
92  * number within tims frame
93  */
94  pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtr(std::size_t timsId,
95  std::size_t scanNum);
96 
97  /** @brief get the total number of scans
98  */
99  std::size_t getTotalNumberOfScans() const;
100 
101  /** @brief get the number of precursors analyzes by PASEF
102  */
103  std::size_t getTotalNumberOfPrecursors() const;
104 
105 
106  unsigned int getMsLevelBySpectrumIndex(std::size_t spectrum_index);
107 
109  getQualifiedMassSpectrumByRawIndex(std::size_t spectrum_index,
110  bool want_binary_data);
111 
112  void
113  getQualifiedMs2MassSpectrumByPrecursorId(QualifiedMassSpectrum &mass_spectrum,
114  std::size_t ms2_index,
115  std::size_t precursor_index,
116  bool want_binary_data);
117 
118  QualifiedMassSpectrum getQualifiedMs1MassSpectrumByPrecursorId(
119  std::size_t ms2_index, std::size_t precursor_index, bool want_binary_data);
120 
121  void setMs2FilterCstSPtr(pappso::FilterInterfaceCstSPtr &filter);
122  void setMs1FilterCstSPtr(pappso::FilterInterfaceCstSPtr &filter);
123 
124 
125  std::vector<std::size_t> getTimsMS1FrameIdRange(double rt_begin,
126  double rt_end) const;
127 
128 
129  /** @brief get a Tims frame with his database ID
130  */
131  TimsFrameCstSPtr getTimsFrameCstSPtr(std::size_t timsId) const;
132 
133  private:
134  std::pair<std::size_t, std::size_t>
135  getScanCoordinateFromRawIndex(std::size_t spectrum_index) const;
136 
137  std::size_t getRawIndexFromCoordinate(std::size_t frame_id,
138  std::size_t scan_num) const;
139 
140  QSqlDatabase openDatabaseConnection() const;
141 
142 
143  /** @brief get a Tims frame base (no binary data file access) with his
144  * database ID
145  */
146  TimsFrameBaseCstSPtr getTimsFrameBaseCstSPtr(std::size_t timsId) const;
147 
148 
149  /** @brief get a Tims frame with his database ID
150  * but look in the cache first
151  */
152  TimsFrameCstSPtr getTimsFrameCstSPtrCached(std::size_t timsId);
153 
154  TimsFrameBaseCstSPtr getTimsFrameBaseCstSPtrCached(std::size_t timsId);
155 
156  /** @brief extract a list of XICs from Tims data
157  *
158  * @param precursor_id_list the list of precursors to extract
159  * @param precision_ptr precision to compute the mz range to extract for each
160  * precursor mass
161  * @param xicExtractMethod XIC extraction method (sum or max) to use
162  * @param rtRange retention time range in seconds to extract XIC from rtTarget
163  * - rtRange to rtTarget + rtRange
164  * @result the corresponding XIC list as a specific structure
165  */
166  std::vector<TimsXicStructure> extractXicListByPrecursorIds(
167  const std::vector<std::size_t> &precursor_id_list,
168  PrecisionPtr precision_ptr,
169  XicExtractMethod xicExtractMethod,
170  double rtRange) const;
171 
172  private:
174  TimsBinDec *mpa_timsBinDec = nullptr;
175  // QSqlDatabase *mpa_qdb = nullptr;
176  std::size_t m_totalNumberOfScans;
178  std::size_t m_cacheSize = 60;
179  std::deque<TimsFrameCstSPtr> m_timsFrameCache;
180  std::deque<TimsFrameBaseCstSPtr> m_timsFrameBaseCache;
181 
182  pappso::FilterInterfaceCstSPtr mcsp_ms2Filter = nullptr;
183  pappso::FilterInterfaceCstSPtr mcsp_ms1Filter = nullptr;
184  QMutex m_mutex;
185 };
186 } // namespace pappso
pappso::TimsData::m_totalNumberOfPrecursors
std::size_t m_totalNumberOfPrecursors
Definition: timsdata.h:177
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:48
pappso::MassSpectrumCstSPtr
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
Definition: massspectrum.h:55
pappso::TimsXicStructure::TimsXicStructure
TimsXicStructure()
Definition: timsdata.h:49
pappso::PrecisionFactory
Definition: precision.h:127
pappso::XicSPtr
std::shared_ptr< Xic > XicSPtr
Definition: xic.h:39
pappso::TimsXicStructure::precursorId
std::size_t precursorId
Definition: timsdata.h:50
timsbindec.h
binary file handler of Bruker's TimsTof raw data
pappso::TimsData::m_timsFrameBaseCache
std::deque< TimsFrameBaseCstSPtr > m_timsFrameBaseCache
Definition: timsdata.h:180
pappso::TimsBinDec
Definition: timsbindec.h:41
PMSPP_LIB_DECL
#define PMSPP_LIB_DECL
Definition: exportinmportconfig.h:14
timsframe.h
handle a single Bruker's TimsTof frame
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks
Definition: aa.cpp:39
pappso::FilterInterfaceCstSPtr
std::shared_ptr< const FilterInterface > FilterInterfaceCstSPtr
Definition: filterinterface.h:46
pappso::TimsFrameBaseCstSPtr
std::shared_ptr< const TimsFrameBase > TimsFrameBaseCstSPtr
Definition: timsframebase.h:40
pappso::TimsXicStructure::scanNumBegin
std::size_t scanNumBegin
Definition: timsdata.h:53
pappso::TimsXicStructure::charge
unsigned int charge
Definition: timsdata.h:57
pappso::TimsData
Definition: timsdata.h:65
pappso::TimsData::m_mutex
QMutex m_mutex
Definition: timsdata.h:184
pappso::MzRange
Definition: mzrange.h:46
pappso::TimsXicStructure::xicSptr
XicSPtr xicSptr
Definition: timsdata.h:56
pappso::XicExtractMethod
XicExtractMethod
Definition: types.h:183
pappso::QualifiedMassSpectrum
Class representing a fully specified mass spectrum.
Definition: qualifiedmassspectrum.h:68
pappso::TimsData::m_timsDataDirectory
QDir m_timsDataDirectory
Definition: timsdata.h:173
pappso::TimsData::m_totalNumberOfScans
std::size_t m_totalNumberOfScans
Definition: timsdata.h:176
pappso::TimsData::m_timsFrameCache
std::deque< TimsFrameCstSPtr > m_timsFrameCache
Definition: timsdata.h:179
pappso::TimsXicStructure
structure needed to extract XIC from Tims data
Definition: timsdata.h:48
pappso::PrecisionBase
Definition: precision.h:44
pappso::TimsXicStructure::mzRange
MzRange mzRange
Definition: timsdata.h:52
pappso::TimsData::TimsData
TimsData(const TimsData &other)
pappso::TimsXicStructure::scanNumEnd
std::size_t scanNumEnd
Definition: timsdata.h:54
pappso::TimsFrameCstSPtr
std::shared_ptr< const TimsFrame > TimsFrameCstSPtr
Definition: timsframe.h:42
pappso::TimsXicStructure::rtTarget
pappso::pappso_double rtTarget
Definition: timsdata.h:55