libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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"
37#include <deque>
38#include <QMutex>
39#include <QSqlQuery>
42
43namespace pappso
44{
45
46class TimsData;
47class TimsDdaPrecursors;
48class TimsDiaSlices;
49
50/** \brief shared pointer on a TimsData object
51 */
52typedef std::shared_ptr<TimsData> TimsDataSp;
53
54
56{
57 std::size_t m_frameId; // frame id
58 // FIXME: we use size to define the number of peaks in spectra
59 // should not this variable be m_scanCount ? Same below.
60 std::size_t m_scanCount; // frame size (number of TOF scans in frame)
61 // FIXME: m_cumulatedScanCount ? Or global scan index, in the end, or scan
62 // position, since it is from the beginning of the binary data?
63 std::size_t m_globalScanIndex; // cumulative size
64};
65
66/**
67 * @todo write docs
68 */
70{
73
74 public:
75 /** @brief build using the tims data directory
76 */
77 TimsData(QDir timsDataDirectory);
78
79 /**
80 * Copy constructor
81 *
82 * @param other TODO
83 */
84 TimsData(const TimsData &other);
85
86 /**
87 * Destructor
88 */
89 virtual ~TimsData();
90
91 /** @brief tells if this MS run is a DDA run
92 * @result true if it contains DDA precursors
93 */
94 bool isDdaRun() const;
95
96
97 /** @brief tells if this MS run is a DIA run
98 * @result true if it contains DIA slices
99 */
100 bool isDiaRun() const;
101
102 /** @brief get a mass spectrum given its spectrum index
103 * @param raw_index a number begining at 0, corresponding to a Tims Scan in
104 * the order they lies in the binary data file
105 */
106 [[deprecated("Please use getMassSpectrumCstSPtrByGlobalScanIndex")]] pappso::
107 MassSpectrumCstSPtr
108 getMassSpectrumCstSPtrByRawIndex(std::size_t raw_index);
109 // FIXME NAMING: Identical to above
110 // Not used in i2mcq
112 getMassSpectrumCstSPtrByGlobalScanIndex(std::size_t index);
113
114 /** @brief get a mass spectrum given the tims frame database id and scan
115 * number within tims frame
116 */
117 pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtr(std::size_t timsId,
118 std::size_t scanNum);
119
120 /** @brief Get total number of frames
121 */
122 [[deprecated("Please use getFrameCount")]] std::size_t
123 getTotalNumberOfFrames() const;
124 // FIXME NAMING : identical to above
125 // Not used in i2mcq
126 std::size_t getFrameCount() const;
127
128 /** @brief get the total number of scans
129 */
130 [[deprecated("Please use getTotalScanCount")]] std::size_t
131 getTotalNumberOfScans() const;
132
133 // FIXME NAMING : identical to above
134 // Not used in i2mcq
135 std::size_t getTotalScanCount() const;
136
137
138 [[deprecated("Please use getMsLevelByGlobalScanIndex")]] unsigned int
139 getMsLevelBySpectrumIndex(std::size_t index);
140 // FIXME NAMING : identical to above
141 // Not used in i2mcq
142 unsigned int getMsLevelByGlobalScanIndex(std::size_t index);
143
144 [[deprecated("Please use getQualifiedMassSpectrumByGlobalScanIndex")]] void
145 getQualifiedMassSpectrumByRawIndex(const MsRunIdCstSPtr &msrun_id,
146 QualifiedMassSpectrum &mass_spectrum,
147 std::size_t global_scan_index,
148 bool want_binary_data);
149 // FIXME NAMING : identical to above
150 // Not used in i2mcq
151 void getQualifiedMassSpectrumByGlobalScanIndex(
152 const MsRunIdCstSPtr &msrun_id,
153 QualifiedMassSpectrum &mass_spectrum,
154 std::size_t global_scan_index,
155 bool want_binary_data);
156 Trace getTicChromatogram() const;
157
158
159 std::vector<std::size_t> getTimsMS1FrameIdsInRtRange(double rt_begin,
160 double rt_end) const;
161
162 std::vector<std::size_t> getTimsMS2FrameIdsInRtRange(double rt_begin,
163 double rt_end) const;
164
165
166 /** @brief get a Tims frame with his database ID
167 * but look in the cache first
168 *
169 * thread safe
170 */
171 TimsFrameCstSPtr getTimsFrameCstSPtrCached(std::size_t timsId);
172
173 /** @brief get a Tims frame with his database ID
174 *
175 * this function is not thread safe
176 */
177 TimsFrameCstSPtr getTimsFrameCstSPtr(std::size_t timsId);
178
179
180 /** @brief get raw signal for a spectrum index
181 * only to use to see the raw signal
182 *
183 * @param spectrum_index spcetrum index
184 * @result a map of integers, x=time of flights, y= intensities
185 */
186 [[deprecated("Please use getScanByGlobalScanIndex")]] TimsDataFastMap &
187 getRawMsBySpectrumIndex(std::size_t index);
188 // FIXME NAMING: identical to above
189 // Not used in i2mcq
190 TimsDataFastMap &getScanByGlobalScanIndex(std::size_t index);
191
192 /** @brief retention timeline
193 * get retention times along the MSrun in seconds
194 * @return vector of retention times (seconds)
195 */
196 [[deprecated(
197 "Please use getRetentionTimeLineInSeconds")]] virtual std::vector<double>
198 getRetentionTimeLine() const;
199 // FIXME NAMING: identical to above
200 virtual std::vector<double> getRetentionTimeLineInSeconds() const;
201
202
203 const std::vector<FrameIdDescr> &getFrameIdDescrList() const;
204 const std::vector<TimsFrameRecord> &getTimsFrameRecordList() const;
205
206
207 const QDir &getTimsDataDirectory() const;
208
209 TimsDdaPrecursors *getTimsDdaPrecursorsPtr() const;
210 TimsDiaSlices *getTimsDiaSlicesPtr() const;
211
212
213 protected:
214 QSqlDatabase openDatabaseConnection() const;
215
216 TimsBinDec *getTimsBinDecPtr() const;
217
218
219 private:
220 [[deprecated(
221 "Please use getScanCoordinatesByGlobalScanIndex")]] std::pair<std::size_t,
222 std::size_t>
223 getScanCoordinateFromRawIndex(std::size_t spectrum_index) const;
224 // FIXME NAMING: identical to above
225 // Not used in i2mcq
226 std::pair<std::size_t, std::size_t>
227 getScanCoordinatesByGlobalScanIndex(std::size_t index) const;
228
229 [[deprecated("Please use getGlobalScanIndexByScanCoordinates")]] std::size_t
230 getRawIndexFromCoordinate(std::size_t frame_id, std::size_t scan_num) const;
231
232 // FIXME NAMING: identical to above
233 // Not used in i2mcq
234 std::size_t getGlobalScanIndexByScanCoordinates(std::size_t frame_id,
235 std::size_t index) const;
236
237
238 /** @brief get a Tims frame base (no binary data file access) with his
239 * database ID
240 */
241 TimsFrameBaseCstSPtr getTimsFrameBaseCstSPtr(std::size_t timsId);
242
243
244 TimsFrameBaseCstSPtr getTimsFrameBaseCstSPtrCached(std::size_t timsId);
245
246
247 /** @brief private function to fill m_frameIdDescrList
248 */
249 void fillFrameIdDescrList();
250
251
253 TimsBinDec *mpa_timsBinDec = nullptr;
254
255 TimsDdaPrecursors *mpa_timsDdaPrecursors = nullptr;
256 TimsDiaSlices *mpa_timsDiaSlices = nullptr;
257 // QSqlDatabase *mpa_qdb = nullptr;
258 std::size_t m_totalScanCount;
259 std::size_t m_frameCount;
260 std::size_t m_cacheSize = 60;
261 std::deque<TimsFrameCstSPtr> m_timsFrameCache;
262 std::deque<TimsFrameBaseCstSPtr> m_timsFrameBaseCache;
263
264
265 std::map<int, QSqlRecord> m_mapMzCalibrationRecord;
266 std::map<int, QSqlRecord> m_mapTimsCalibrationRecord;
267 std::vector<TimsFrameRecord> m_mapFramesRecord;
268
270
271
272 /** @brief store every frame id and corresponding sizes
273 */
274 std::vector<FrameIdDescr> m_frameIdDescrList;
275
276 /** @brief index to find quickly a frameId in the description list with the
277 * raw index of spectrum modulo 1000
278 * @key thousands of TOF scans
279 * @value corresponding m_frameIdDescrList index
280 */
281 std::map<std::size_t, std::size_t> m_thousandIndexToFrameIdDescrListIndex;
282
283
284 /** @brief tells if someone is loading a frame id
285 */
286 std::vector<std::size_t> m_someoneIsLoadingFrameId;
287
288 QMutex m_mutex;
289};
290} // namespace pappso
Class representing a fully specified mass spectrum.
replacement for std::map
std::vector< FrameIdDescr > m_frameIdDescrList
store every frame id and corresponding sizes
Definition timsdata.h:274
friend TimsDdaPrecursors
Definition timsdata.h:71
std::deque< TimsFrameCstSPtr > m_timsFrameCache
Definition timsdata.h:261
std::vector< TimsFrameRecord > m_mapFramesRecord
Definition timsdata.h:267
std::size_t m_totalScanCount
Definition timsdata.h:258
std::map< int, QSqlRecord > m_mapMzCalibrationRecord
Definition timsdata.h:265
std::map< int, QSqlRecord > m_mapTimsCalibrationRecord
Definition timsdata.h:266
std::vector< std::size_t > m_someoneIsLoadingFrameId
tells if someone is loading a frame id
Definition timsdata.h:286
friend TimsDiaSlices
Definition timsdata.h:72
QDir m_timsDataDirectory
Definition timsdata.h:252
MzCalibrationStore * mpa_mzCalibrationStore
Definition timsdata.h:269
std::deque< TimsFrameBaseCstSPtr > m_timsFrameBaseCache
Definition timsdata.h:262
std::map< std::size_t, std::size_t > m_thousandIndexToFrameIdDescrListIndex
index to find quickly a frameId in the description list with the raw index of spectrum modulo 1000 @k...
Definition timsdata.h:281
std::size_t m_frameCount
Definition timsdata.h:259
A simple container of DataPoint instances.
Definition trace.h:148
#define PMSPP_LIB_DECL
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::shared_ptr< const TimsFrameBase > TimsFrameBaseCstSPtr
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
Definition msrunid.h:46
std::shared_ptr< TimsData > TimsDataSp
shared pointer on a TimsData object
Definition timsdata.h:52
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
std::shared_ptr< const TimsFrame > TimsFrameCstSPtr
Definition timsframe.h:43
std::size_t m_globalScanIndex
Definition timsdata.h:63
std::size_t m_frameId
Definition timsdata.h:57
std::size_t m_scanCount
Definition timsdata.h:60
binary file handler of Bruker's TimsTof raw data
handle a single Bruker's TimsTof frame
XIC coordinate in a Tims MSrun.