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