libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::TimsData Class Reference

#include <timsdata.h>

Public Member Functions

 TimsData (QDir timsDataDirectory)
 build using the tims data directory
 TimsData (const TimsData &other)
virtual ~TimsData ()
bool isDdaRun () const
 tells if this MS run is a DDA run
bool isDiaRun () const
 tells if this MS run is a DIA run
pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtrByRawIndex (std::size_t raw_index)
 get a mass spectrum given its spectrum index
pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtrByGlobalScanIndex (std::size_t index)
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
std::size_t getTotalNumberOfFrames () const
 Get total number of frames.
std::size_t getFrameCount () const
std::size_t getTotalNumberOfScans () const
 get the total number of scans
std::size_t getTotalScanCount () const
unsigned int getMsLevelBySpectrumIndex (std::size_t index)
unsigned int getMsLevelByGlobalScanIndex (std::size_t index)
void getQualifiedMassSpectrumByRawIndex (const MsRunIdCstSPtr &msrun_id, QualifiedMassSpectrum &mass_spectrum, std::size_t global_scan_index, bool want_binary_data)
void getQualifiedMassSpectrumByGlobalScanIndex (const MsRunIdCstSPtr &msrun_id, QualifiedMassSpectrum &mass_spectrum, std::size_t global_scan_index, bool want_binary_data)
Trace getTicChromatogram () const
std::vector< std::size_t > getTimsMS1FrameIdsInRtRange (double rt_begin, double rt_end) const
std::vector< std::size_t > getTimsMS2FrameIdsInRtRange (double rt_begin, double rt_end) const
TimsFrameCstSPtr getTimsFrameCstSPtrCached (std::size_t timsId)
 get a Tims frame with his database ID but look in the cache first
TimsFrameCstSPtr getTimsFrameCstSPtr (std::size_t timsId)
 get a Tims frame with his database ID
TimsDataFastMapgetRawMsBySpectrumIndex (std::size_t index)
 get raw signal for a spectrum index only to use to see the raw signal
TimsDataFastMapgetScanByGlobalScanIndex (std::size_t index)
virtual std::vector< double > getRetentionTimeLine () const
 retention timeline get retention times along the MSrun in seconds
virtual std::vector< double > getRetentionTimeLineInSeconds () const
const std::vector< FrameIdDescr > & getFrameIdDescrList () const
const std::vector< TimsFrameRecord > & getTimsFrameRecordList () const
const QDir & getTimsDataDirectory () const
TimsDdaPrecursorsgetTimsDdaPrecursorsPtr () const
TimsDiaSlicesgetTimsDiaSlicesPtr () const
const QVariant & getGlobalMetadataValue (const QString &key) const

Protected Member Functions

QSqlDatabase openDatabaseConnection () const
TimsBinDecgetTimsBinDecPtr () const

Private Member Functions

std::pair< std::size_t, std::size_t > getScanCoordinateFromRawIndex (std::size_t spectrum_index) const
std::pair< std::size_t, std::size_t > getScanCoordinatesByGlobalScanIndex (std::size_t index) const
std::size_t getRawIndexFromCoordinate (std::size_t frame_id, std::size_t scan_num) const
std::size_t getGlobalScanIndexByScanCoordinates (std::size_t frame_id, std::size_t index) const
TimsFrameBaseCstSPtr getTimsFrameBaseCstSPtr (std::size_t timsId)
 get a Tims frame base (no binary data file access) with his database ID
TimsFrameBaseCstSPtr getTimsFrameBaseCstSPtrCached (std::size_t timsId)
void fillFrameIdDescrList ()
 private function to fill m_frameIdDescrList

Private Attributes

friend TimsDdaPrecursors
friend TimsDiaSlices
QDir m_timsDataDirectory
TimsBinDecmpa_timsBinDec = nullptr
TimsDdaPrecursorsmpa_timsDdaPrecursors = nullptr
TimsDiaSlicesmpa_timsDiaSlices = nullptr
std::size_t m_totalScanCount
std::size_t m_frameCount
std::size_t m_cacheSize = 60
std::deque< TimsFrameCstSPtrm_timsFrameCache
std::deque< TimsFrameBaseCstSPtrm_timsFrameBaseCache
std::map< int, QSqlRecord > m_mapMzCalibrationRecord
std::map< int, QSqlRecord > m_mapTimsCalibrationRecord
std::vector< TimsFrameRecordm_mapFramesRecord
MzCalibrationStorempa_mzCalibrationStore
std::vector< FrameIdDescrm_frameIdDescrList
 store every frame id and corresponding sizes
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 @key thousands of TOF scans @value corresponding m_frameIdDescrList index
std::vector< std::size_t > m_someoneIsLoadingFrameId
 tells if someone is loading a frame id
std::map< QString, QVariant > m_mapGlobalMetadaTable
QMutex m_mutex

Detailed Description

Todo
write docs

Definition at line 67 of file timsdata.h.

Constructor & Destructor Documentation

◆ TimsData() [1/2]

pappso::TimsData::TimsData ( QDir timsDataDirectory)

build using the tims data directory

Definition at line 47 of file timsdata.cpp.

47 : m_timsDataDirectory(timsDataDirectory)
48{
49
50 // qDebug() << "Start of construction of TimsData";
51 mpa_mzCalibrationStore = new MzCalibrationStore();
52 if(!m_timsDataDirectory.exists())
53 {
54 qDebug();
55 throw ExceptionNotRecognized(QObject::tr("ERROR TIMS data directory %1 not found")
56 .arg(m_timsDataDirectory.absolutePath()));
57 }
58
59 if(!QFileInfo(m_timsDataDirectory.absoluteFilePath("analysis.tdf")).exists())
60 {
61
62 throw ExceptionNotRecognized(
63 QObject::tr("ERROR TIMS data directory, %1 sqlite file not found")
64 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf")));
65 }
66
67 // Open the database
68 QSqlDatabase qdb = openDatabaseConnection();
69
70
71 QSqlQuery sql_query(qdb);
72 if(!sql_query.exec("select Key, Value from GlobalMetadata;"))
73 {
74
75 qDebug();
76 throw PappsoException(QObject::tr("ERROR in TIMS sqlite database file %1, executing SQL "
77 "command %2:\n%3\n%4\n%5")
78 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
79 .arg(sql_query.lastQuery())
80 .arg(sql_query.lastError().databaseText())
81 .arg(sql_query.lastError().driverText())
82 .arg(sql_query.lastError().nativeErrorCode()));
83 }
84
85 while(sql_query.next())
86 {
87 QSqlRecord record = sql_query.record();
89 std::pair<QString, QVariant>(record.value(0).toString(), record.value(1)));
90 }
91
92 int compression_type = getGlobalMetadataValue("TimsCompressionType").toInt();
93 qDebug() << " compression_type=" << compression_type;
94 mpa_timsBinDec = new TimsBinDec(
95 QFileInfo(m_timsDataDirectory.absoluteFilePath("analysis.tdf_bin")), compression_type);
96
97 qDebug();
98
99 try
100 {
101
102 qDebug();
103 mpa_timsDdaPrecursors = new TimsDdaPrecursors(sql_query, this);
104 }
105 catch(pappso::ExceptionNotFound &not_found)
106 {
107
108 qDebug();
109 mpa_timsDdaPrecursors = nullptr;
110 }
111
112
113 qDebug();
114 try
115 {
116 qDebug();
117 mpa_timsDiaSlices = new TimsDiaSlices(sql_query, this);
118 }
119 catch(pappso::ExceptionNotFound &not_found)
120 {
121 qDebug();
122 mpa_timsDiaSlices = nullptr;
123 }
124
126
127 // get number of scans
128 if(!sql_query.exec("SELECT SUM(NumScans),COUNT(Id) FROM Frames"))
129 {
130 qDebug();
131 throw PappsoException(QObject::tr("ERROR in TIMS sqlite database file %1, executing SQL "
132 "command %2:\n%3\n%4\n%5")
133 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
134 .arg(sql_query.lastQuery())
135 .arg(qdb.lastError().databaseText())
136 .arg(qdb.lastError().driverText())
137 .arg(qdb.lastError().nativeErrorCode()));
138 }
139 if(sql_query.next())
140 {
141 qDebug();
142 m_totalScanCount = sql_query.value(0).toLongLong();
143 m_frameCount = sql_query.value(1).toLongLong();
144 }
145
146 if(!sql_query.exec("select * from MzCalibration;"))
147 {
148 qDebug();
149 throw PappsoException(QObject::tr("ERROR in TIMS sqlite database file %1, executing SQL "
150 "command %2:\n%3\n%4\n%5")
151 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
152 .arg(sql_query.lastQuery())
153 .arg(sql_query.lastError().databaseText())
154 .arg(sql_query.lastError().driverText())
155 .arg(sql_query.lastError().nativeErrorCode()));
156 }
157
158 while(sql_query.next())
159 {
160 QSqlRecord record = sql_query.record();
161 m_mapMzCalibrationRecord.insert(std::pair<int, QSqlRecord>(record.value(0).toInt(), record));
162 }
163
164 // m_mapTimsCalibrationRecord
165
166 if(!sql_query.exec("select * from TimsCalibration;"))
167 {
168 qDebug();
169 throw PappsoException(QObject::tr("ERROR in TIMS sqlite database file %1, executing SQL "
170 "command %2:\n%3\n%4\n%5")
171 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
172 .arg(sql_query.lastQuery())
173 .arg(sql_query.lastError().databaseText())
174 .arg(sql_query.lastError().driverText())
175 .arg(sql_query.lastError().nativeErrorCode()));
176 }
177 while(sql_query.next())
178 {
179 QSqlRecord record = sql_query.record();
181 std::pair<int, QSqlRecord>(record.value(0).toInt(), record));
182 }
183
184
185 // store frames
186 if(!sql_query.exec("select Frames.TimsId, Frames.AccumulationTime, " // 1
187 "Frames.MzCalibration, " // 2
188 "Frames.T1, Frames.T2, " // 4
189 "Frames.Time, Frames.MsMsType, Frames.TimsCalibration, " // 7
190 "Frames.Id " // 8
191 " FROM Frames;"))
192 {
193 qDebug();
194 throw PappsoException(QObject::tr("ERROR in TIMS sqlite database file %1, executing SQL "
195 "command %2:\n%3\n%4\n%5")
196 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
197 .arg(sql_query.lastQuery())
198 .arg(sql_query.lastError().databaseText())
199 .arg(sql_query.lastError().driverText())
200 .arg(sql_query.lastError().nativeErrorCode()));
201 }
202
204 while(sql_query.next())
205 {
206 QSqlRecord record = sql_query.record();
207 TimsFrameRecord &frame_record = m_mapFramesRecord[record.value(8).toULongLong()];
208
209 frame_record.frame_id = record.value(8).toULongLong();
210 frame_record.tims_offset = record.value(0).toULongLong();
211 frame_record.accumulation_time = record.value(1).toDouble();
212 frame_record.mz_calibration_id = record.value(2).toULongLong();
213 frame_record.frame_t1 = record.value(3).toDouble();
214 frame_record.frame_t2 = record.value(4).toDouble();
215 frame_record.frame_time = record.value(5).toDouble();
216 frame_record.msms_type = record.value(6).toInt();
217 frame_record.tims_calibration_id = record.value(7).toULongLong();
218 }
219
220 qDebug();
221}
QSqlDatabase openDatabaseConnection() const
Definition timsdata.cpp:224
TimsDdaPrecursors * mpa_timsDdaPrecursors
Definition timsdata.h:242
friend TimsDdaPrecursors
Definition timsdata.h:69
std::vector< TimsFrameRecord > m_mapFramesRecord
Definition timsdata.h:254
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:280
friend TimsDiaSlices
Definition timsdata.h:70
QDir m_timsDataDirectory
Definition timsdata.h:239
MzCalibrationStore * mpa_mzCalibrationStore
Definition timsdata.h:256
TimsBinDec * mpa_timsBinDec
Definition timsdata.h:240
TimsDiaSlices * mpa_timsDiaSlices
Definition timsdata.h:243
std::size_t m_frameCount
Definition timsdata.h:246
const QVariant & getGlobalMetadataValue(const QString &key) const

References pappso::TimsFrameRecord::accumulation_time, fillFrameIdDescrList(), pappso::TimsFrameRecord::frame_id, pappso::TimsFrameRecord::frame_t1, pappso::TimsFrameRecord::frame_t2, pappso::TimsFrameRecord::frame_time, getGlobalMetadataValue(), m_frameCount, m_mapFramesRecord, m_mapGlobalMetadaTable, m_mapMzCalibrationRecord, m_mapTimsCalibrationRecord, m_timsDataDirectory, m_totalScanCount, mpa_mzCalibrationStore, mpa_timsBinDec, mpa_timsDdaPrecursors, mpa_timsDiaSlices, pappso::TimsFrameRecord::msms_type, pappso::TimsFrameRecord::mz_calibration_id, openDatabaseConnection(), pappso::TimsFrameRecord::tims_calibration_id, pappso::TimsFrameRecord::tims_offset, TimsDdaPrecursors, and TimsDiaSlices.

Referenced by TimsData().

◆ TimsData() [2/2]

pappso::TimsData::TimsData ( const TimsData & other)

Copy constructor

Parameters
otherTODO

Definition at line 253 of file timsdata.cpp.

254{
255 qDebug();
256}

References TimsData().

◆ ~TimsData()

pappso::TimsData::~TimsData ( )
virtual

Destructor

Definition at line 258 of file timsdata.cpp.

259{
260 // m_qdb.close();
261 if(mpa_timsBinDec != nullptr)
262 {
263 delete mpa_timsBinDec;
264 }
265 if(mpa_mzCalibrationStore != nullptr)
266 {
268 }
269 if(mpa_timsDdaPrecursors != nullptr)
270 {
272 }
273 if(mpa_timsDiaSlices != nullptr)
274 {
275 delete mpa_timsDiaSlices;
276 }
277}

References mpa_mzCalibrationStore, mpa_timsBinDec, mpa_timsDdaPrecursors, and mpa_timsDiaSlices.

Member Function Documentation

◆ fillFrameIdDescrList()

void pappso::TimsData::fillFrameIdDescrList ( )
private

private function to fill m_frameIdDescrList

number of scans in mobility dimension (number of TOF scans)

Definition at line 280 of file timsdata.cpp.

281{
282 qDebug();
283 QSqlDatabase qdb = openDatabaseConnection();
284
285 QSqlQuery q(qdb);
286 q.prepare(
287 QString("SELECT Id, NumScans FROM "
288 "Frames ORDER BY Id"));
289 q.exec();
290 if(q.lastError().isValid())
291 {
292
293 throw PappsoException(QObject::tr("ERROR in TIMS sqlite database file %1, executing SQL "
294 "command %2:\n%3\n%4\n%5")
295 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
296 .arg(q.lastQuery())
297 .arg(qdb.lastError().databaseText())
298 .arg(qdb.lastError().driverText())
299 .arg(qdb.lastError().nativeErrorCode()));
300 }
301 TimsFrameSPtr tims_frame;
302 bool index_found = false;
303 std::size_t timsId;
304 /** @brief number of scans in mobility dimension (number of TOF scans)
305 */
306 std::size_t numberScans;
307 std::size_t cumulScans = 0;
308 while(q.next() && (!index_found))
309 {
310 timsId = q.value(0).toULongLong();
311 numberScans = q.value(1).toULongLong();
312
313 // qDebug() << timsId;
314
316 std::pair<std::size_t, std::size_t>((cumulScans / 1000), m_frameIdDescrList.size()));
317
318 m_frameIdDescrList.push_back({timsId, numberScans, cumulScans});
319 cumulScans += numberScans;
320 }
321 qDebug();
322}
std::vector< FrameIdDescr > m_frameIdDescrList
store every frame id and corresponding sizes
Definition timsdata.h:261
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
std::shared_ptr< TimsFrame > TimsFrameSPtr
Definition timsframe.h:43

References m_frameIdDescrList, m_thousandIndexToFrameIdDescrListIndex, m_timsDataDirectory, and openDatabaseConnection().

Referenced by TimsData().

◆ getFrameCount()

std::size_t pappso::TimsData::getFrameCount ( ) const

Definition at line 659 of file timsdata.cpp.

660{
661 return m_frameCount;
662}

References m_frameCount.

◆ getFrameIdDescrList()

const std::vector< FrameIdDescr > & pappso::TimsData::getFrameIdDescrList ( ) const

Definition at line 1038 of file timsdata.cpp.

1039{
1040 return m_frameIdDescrList;
1041}

References m_frameIdDescrList.

◆ getGlobalMetadataValue()

const QVariant & pappso::TimsData::getGlobalMetadataValue ( const QString & key) const

Definition at line 1101 of file timsdata.cpp.

1102{
1103 auto it = m_mapGlobalMetadaTable.find(key);
1104 if(it == m_mapGlobalMetadaTable.end())
1105 {
1106 throw pappso::PappsoException(QString("TimsData GlobalMetadata key %1 not found").arg(key));
1107 }
1108 return it->second;
1109}

References m_mapGlobalMetadaTable.

Referenced by TimsData().

◆ getGlobalScanIndexByScanCoordinates()

std::size_t pappso::TimsData::getGlobalScanIndexByScanCoordinates ( std::size_t frame_id,
std::size_t index ) const
private

Definition at line 368 of file timsdata.cpp.

369{
370
371 for(auto frameDescr : m_frameIdDescrList)
372 {
373 if(frameDescr.m_frameId == frame_id)
374 {
375 return frameDescr.m_globalScanIndex + index;
376 }
377 }
378
379 throw ExceptionNotFound(QObject::tr("ERROR raw index with frame_id=%1 scan_index=%2 not found")
380 .arg(frame_id)
381 .arg(index));
382}

References m_frameIdDescrList.

Referenced by getQualifiedMassSpectrumByGlobalScanIndex(), and getRawIndexFromCoordinate().

◆ getMassSpectrumCstSPtr()

MassSpectrumCstSPtr pappso::TimsData::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 at line 642 of file timsdata.cpp.

643{
644 qDebug() << " timsId=" << timsId << " scanNum=" << scanNum;
646
647 return frame->getMassSpectrumCstSPtr(scanNum);
648}
TimsFrameCstSPtr getTimsFrameCstSPtrCached(std::size_t timsId)
get a Tims frame with his database ID but look in the cache first
Definition timsdata.cpp:917
std::shared_ptr< const TimsFrame > TimsFrameCstSPtr
Definition timsframe.h:44

References getTimsFrameCstSPtrCached().

Referenced by getMassSpectrumCstSPtrByGlobalScanIndex().

◆ getMassSpectrumCstSPtrByGlobalScanIndex()

pappso::MassSpectrumCstSPtr pappso::TimsData::getMassSpectrumCstSPtrByGlobalScanIndex ( std::size_t index)

Definition at line 395 of file timsdata.cpp.

396{
397
398 qDebug() << " raw_index=" << raw_index;
399 try
400 {
401 auto coordinate = getScanCoordinatesByGlobalScanIndex(raw_index);
402 return getMassSpectrumCstSPtr(coordinate.first, coordinate.second);
403 }
404 catch(PappsoException &error)
405 {
406 throw PappsoException(QObject::tr("Error TimsData::getMassSpectrumCstSPtrByRawIndex "
407 "raw_index=%1 :\n%2")
408 .arg(raw_index)
409 .arg(error.qwhat()));
410 }
411}
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:642
std::pair< std::size_t, std::size_t > getScanCoordinatesByGlobalScanIndex(std::size_t index) const
Definition timsdata.cpp:331

References getMassSpectrumCstSPtr(), getScanCoordinatesByGlobalScanIndex(), and pappso::PappsoException::qwhat().

Referenced by getMassSpectrumCstSPtrByRawIndex().

◆ getMassSpectrumCstSPtrByRawIndex()

MassSpectrumCstSPtr pappso::TimsData::getMassSpectrumCstSPtrByRawIndex ( std::size_t raw_index)

get a mass spectrum given its spectrum index

Parameters
raw_indexa number begining at 0, corresponding to a Tims Scan in the order they lies in the binary data file

Definition at line 389 of file timsdata.cpp.

390{
392}
pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtrByGlobalScanIndex(std::size_t index)
Definition timsdata.cpp:395

References getMassSpectrumCstSPtrByGlobalScanIndex().

◆ getMsLevelByGlobalScanIndex()

unsigned int pappso::TimsData::getMsLevelByGlobalScanIndex ( std::size_t index)

Definition at line 686 of file timsdata.cpp.

687{
688 auto coordinate = getScanCoordinatesByGlobalScanIndex(index);
689 auto tims_frame = getTimsFrameCstSPtrCached(coordinate.first);
690 return tims_frame.get()->getMsLevel();
691}

References getScanCoordinatesByGlobalScanIndex(), and getTimsFrameCstSPtrCached().

Referenced by getMsLevelBySpectrumIndex().

◆ getMsLevelBySpectrumIndex()

unsigned int pappso::TimsData::getMsLevelBySpectrumIndex ( std::size_t index)

Definition at line 679 of file timsdata.cpp.

680{
681 return getMsLevelByGlobalScanIndex(index);
682}
unsigned int getMsLevelByGlobalScanIndex(std::size_t index)
Definition timsdata.cpp:686

References getMsLevelByGlobalScanIndex().

◆ getQualifiedMassSpectrumByGlobalScanIndex()

void pappso::TimsData::getQualifiedMassSpectrumByGlobalScanIndex ( const MsRunIdCstSPtr & msrun_id,
QualifiedMassSpectrum & mass_spectrum,
std::size_t global_scan_index,
bool want_binary_data )

Definition at line 706 of file timsdata.cpp.

710{
711
712
713 try
714 {
715 auto coordinate = getScanCoordinatesByGlobalScanIndex(global_scan_index);
716 TimsFrameBaseCstSPtr tims_frame;
717 if(want_binary_data)
718 {
719 tims_frame = getTimsFrameCstSPtrCached(coordinate.first);
720 }
721 else
722 {
723 tims_frame = getTimsFrameBaseCstSPtrCached(coordinate.first);
724 }
725 MassSpectrumId spectrum_id;
726
727 spectrum_id.setSpectrumIndex(global_scan_index);
728 spectrum_id.setMsRunId(msrun_id);
729 spectrum_id.setNativeId(QString("frame_id=%1 scan_index=%2 global_scan_index=%3")
730 .arg(coordinate.first)
731 .arg(coordinate.second)
732 .arg(global_scan_index));
733
734 mass_spectrum.setMassSpectrumId(spectrum_id);
735
736 mass_spectrum.setMsLevel(tims_frame.get()->getMsLevel());
737 mass_spectrum.setRtInSeconds(tims_frame.get()->getRtInSeconds());
738
739 mass_spectrum.setDtInMilliSeconds(
740 tims_frame.get()->getDriftTimeInMilliseconds(coordinate.second));
741 // 1/K0
742 mass_spectrum.setParameterValue(
744 tims_frame.get()->getOneOverK0Transformation(coordinate.second));
745
746 mass_spectrum.setEmptyMassSpectrum(true);
747 if(want_binary_data)
748 {
749 mass_spectrum.setMassSpectrumSPtr(
750 tims_frame.get()->getMassSpectrumSPtr(coordinate.second));
751 if(mass_spectrum.size() > 0)
752 {
753 mass_spectrum.setEmptyMassSpectrum(false);
754 }
755 }
756 else
757 {
758 // if(tims_frame.get()->getNbrPeaks(coordinate.second) > 0)
759 //{
760 mass_spectrum.setEmptyMassSpectrum(false);
761 // }
762 }
763 if(tims_frame.get()->getMsLevel() > 1)
764 {
765
766 if(mpa_timsDdaPrecursors != nullptr)
767 {
768 auto spectrum_descr =
769 mpa_timsDdaPrecursors->getSpectrumDescrWithScanCoordinates(coordinate);
770 if(spectrum_descr.precursor_id > 0)
771 {
772
773 mass_spectrum.appendPrecursorIonData(spectrum_descr.precursor_ion_data);
774
775
776 MassSpectrumId spectrum_id;
777 std::size_t prec_spectrum_index = getGlobalScanIndexByScanCoordinates(
778 spectrum_descr.parent_frame, coordinate.second);
779
780 mass_spectrum.setPrecursorSpectrumIndex(prec_spectrum_index);
781 mass_spectrum.setPrecursorNativeId(
782 QString("frame_id=%1 scan_index=%2 global_scan_index=%3")
783 .arg(spectrum_descr.parent_frame)
784 .arg(coordinate.second)
785 .arg(prec_spectrum_index));
786
787 mass_spectrum.setParameterValue(QualifiedMassSpectrumParameter::IsolationMz,
788 spectrum_descr.isolationMz);
789 mass_spectrum.setParameterValue(QualifiedMassSpectrumParameter::IsolationMzWidth,
790 spectrum_descr.isolationWidth);
791
792 mass_spectrum.setParameterValue(QualifiedMassSpectrumParameter::CollisionEnergy,
793 spectrum_descr.collisionEnergy);
794 mass_spectrum.setParameterValue(
796 (quint64)spectrum_descr.precursor_id);
797 }
798 }
799 }
800 }
801 catch(PappsoException &error)
802 {
803 throw PappsoException(QObject::tr("Error TimsData::getQualifiedMassSpectrumByRawIndex "
804 "spectrum_index=%1 :\n%2")
805 .arg(global_scan_index)
806 .arg(error.qwhat()));
807 }
808}
std::size_t getGlobalScanIndexByScanCoordinates(std::size_t frame_id, std::size_t index) const
Definition timsdata.cpp:368
TimsFrameBaseCstSPtr getTimsFrameBaseCstSPtrCached(std::size_t timsId)
Definition timsdata.cpp:896
std::shared_ptr< const TimsFrameBase > TimsFrameBaseCstSPtr
@ IsolationMzWidth
m/z isolation window width (left + right)
@ CollisionEnergy
Bruker's timsTOF collision energy.
@ BrukerPrecursorIndex
Bruker's timsTOF precursor index.

References pappso::QualifiedMassSpectrum::appendPrecursorIonData(), pappso::BrukerPrecursorIndex, pappso::CollisionEnergy, getGlobalScanIndexByScanCoordinates(), getScanCoordinatesByGlobalScanIndex(), getTimsFrameBaseCstSPtrCached(), getTimsFrameCstSPtrCached(), pappso::IonMobOneOverK0, pappso::IsolationMz, pappso::IsolationMzWidth, mpa_timsDdaPrecursors, pappso::PappsoException::qwhat(), pappso::QualifiedMassSpectrum::setDtInMilliSeconds(), pappso::QualifiedMassSpectrum::setEmptyMassSpectrum(), pappso::QualifiedMassSpectrum::setMassSpectrumId(), pappso::QualifiedMassSpectrum::setMassSpectrumSPtr(), pappso::QualifiedMassSpectrum::setMsLevel(), pappso::MassSpectrumId::setMsRunId(), pappso::MassSpectrumId::setNativeId(), pappso::QualifiedMassSpectrum::setParameterValue(), pappso::QualifiedMassSpectrum::setPrecursorNativeId(), pappso::QualifiedMassSpectrum::setPrecursorSpectrumIndex(), pappso::QualifiedMassSpectrum::setRtInSeconds(), pappso::MassSpectrumId::setSpectrumIndex(), and pappso::QualifiedMassSpectrum::size().

Referenced by getQualifiedMassSpectrumByRawIndex().

◆ getQualifiedMassSpectrumByRawIndex()

void pappso::TimsData::getQualifiedMassSpectrumByRawIndex ( const MsRunIdCstSPtr & msrun_id,
QualifiedMassSpectrum & mass_spectrum,
std::size_t global_scan_index,
bool want_binary_data )

Definition at line 695 of file timsdata.cpp.

699{
700
702 msrun_id, mass_spectrum, global_scan_index, want_binary_data);
703}
void getQualifiedMassSpectrumByGlobalScanIndex(const MsRunIdCstSPtr &msrun_id, QualifiedMassSpectrum &mass_spectrum, std::size_t global_scan_index, bool want_binary_data)
Definition timsdata.cpp:706

References getQualifiedMassSpectrumByGlobalScanIndex().

◆ getRawIndexFromCoordinate()

std::size_t pappso::TimsData::getRawIndexFromCoordinate ( std::size_t frame_id,
std::size_t scan_num ) const
private

Definition at line 361 of file timsdata.cpp.

362{
363
364 return getGlobalScanIndexByScanCoordinates(frame_id, index);
365}

References getGlobalScanIndexByScanCoordinates().

◆ getRawMsBySpectrumIndex()

TimsDataFastMap & pappso::TimsData::getRawMsBySpectrumIndex ( std::size_t index)

get raw signal for a spectrum index only to use to see the raw signal

Parameters
spectrum_indexspcetrum index
Returns
a map of integers, x=time of flights, y= intensities

Definition at line 1017 of file timsdata.cpp.

1018{
1019 return getScanByGlobalScanIndex(index);
1020}
TimsDataFastMap & getScanByGlobalScanIndex(std::size_t index)

References getScanByGlobalScanIndex().

◆ getRetentionTimeLine()

std::vector< double > pappso::TimsData::getRetentionTimeLine ( ) const
virtual

retention timeline get retention times along the MSrun in seconds

Returns
vector of retention times (seconds)

Definition at line 995 of file timsdata.cpp.

996{
998}
virtual std::vector< double > getRetentionTimeLineInSeconds() const

References getRetentionTimeLineInSeconds().

◆ getRetentionTimeLineInSeconds()

std::vector< double > pappso::TimsData::getRetentionTimeLineInSeconds ( ) const
virtual

Definition at line 1001 of file timsdata.cpp.

1002{
1003
1004 std::vector<double> timeline;
1005 timeline.reserve(m_mapFramesRecord.size());
1006 for(const TimsFrameRecord &frame_record : m_mapFramesRecord)
1007 {
1008 if(frame_record.mz_calibration_id != 0)
1009 {
1010 timeline.push_back(frame_record.frame_time);
1011 }
1012 }
1013 return timeline;
1014}

References m_mapFramesRecord.

Referenced by getRetentionTimeLine().

◆ getScanByGlobalScanIndex()

TimsDataFastMap & pappso::TimsData::getScanByGlobalScanIndex ( std::size_t index)

Definition at line 1023 of file timsdata.cpp.

1024{
1025 qDebug() << " spectrum_index=" << index;
1026 auto coordinate = getScanCoordinatesByGlobalScanIndex(index);
1027 TimsFrameBaseCstSPtr tims_frame;
1028 tims_frame = getTimsFrameCstSPtrCached(coordinate.first);
1029
1030 TimsDataFastMap &raw_spectrum = TimsDataFastMap::getTimsDataFastMapInstance();
1031 raw_spectrum.clear();
1032 tims_frame.get()->combineScansInTofIndexIntensityMap(
1033 raw_spectrum, coordinate.second, coordinate.second);
1034 return raw_spectrum;
1035}
static TimsDataFastMap & getTimsDataFastMapInstance()

References pappso::TimsDataFastMap::clear(), getScanCoordinatesByGlobalScanIndex(), pappso::TimsDataFastMap::getTimsDataFastMapInstance(), and getTimsFrameCstSPtrCached().

Referenced by getRawMsBySpectrumIndex().

◆ getScanCoordinateFromRawIndex()

std::pair< std::size_t, std::size_t > pappso::TimsData::getScanCoordinateFromRawIndex ( std::size_t spectrum_index) const
private

Definition at line 325 of file timsdata.cpp.

326{
327 return getScanCoordinatesByGlobalScanIndex(raw_index);
328}

References getScanCoordinatesByGlobalScanIndex().

◆ getScanCoordinatesByGlobalScanIndex()

std::pair< std::size_t, std::size_t > pappso::TimsData::getScanCoordinatesByGlobalScanIndex ( std::size_t index) const
private

Definition at line 331 of file timsdata.cpp.

332{
333 std::size_t fast_access = raw_index / 1000;
334 qDebug() << " fast_access=" << fast_access;
335 auto map_it = m_thousandIndexToFrameIdDescrListIndex.find(fast_access);
337 {
338 throw ExceptionNotFound(
339 QObject::tr("ERROR raw index %1 not found (fast_access)").arg(raw_index));
340 }
341 std::size_t start_point_index = map_it->second;
342 while((start_point_index > 0) &&
343 (m_frameIdDescrList[start_point_index].m_globalScanIndex > raw_index))
344 {
345 start_point_index--;
346 }
347 for(std::size_t i = start_point_index; i < m_frameIdDescrList.size(); i++)
348 {
349
350 if(raw_index < (m_frameIdDescrList[i].m_globalScanIndex + m_frameIdDescrList[i].m_scanCount))
351 {
352 return std::pair<std::size_t, std::size_t>(
353 m_frameIdDescrList[i].m_frameId, raw_index - m_frameIdDescrList[i].m_globalScanIndex);
354 }
355 }
356
357 throw ExceptionNotFound(QObject::tr("ERROR raw index %1 not found").arg(raw_index));
358}

References m_frameIdDescrList, and m_thousandIndexToFrameIdDescrListIndex.

Referenced by getMassSpectrumCstSPtrByGlobalScanIndex(), getMsLevelByGlobalScanIndex(), getQualifiedMassSpectrumByGlobalScanIndex(), getScanByGlobalScanIndex(), and getScanCoordinateFromRawIndex().

◆ getTicChromatogram()

Trace pappso::TimsData::getTicChromatogram ( ) const

Definition at line 811 of file timsdata.cpp.

812{
813 // In the Frames table, each frame has a record describing the
814 // SummedIntensities for all the mobility spectra.
815
816
817 MapTrace rt_tic_map_trace;
818
819 using Pair = std::pair<double, double>;
820 using Map = std::map<double, double>;
821 using Iterator = Map::iterator;
822
823
824 QSqlDatabase qdb = openDatabaseConnection();
825 QSqlQuery q(qdb);
826
827 q.prepare(
828 QString("SELECT Time, SummedIntensities "
829 "FROM Frames WHERE MsMsType = 0 "
830 "ORDER BY Time;"));
831 q.exec();
832
833 if(q.lastError().isValid())
834 {
835
836 throw PappsoException(QObject::tr("ERROR in TIMS sqlite database file %1, database name %2, "
837 "executing SQL "
838 "command %3:\n%4\n%5\n%6")
839 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
840 .arg(qdb.databaseName())
841 .arg(q.lastQuery())
842 .arg(qdb.lastError().databaseText())
843 .arg(qdb.lastError().driverText())
844 .arg(qdb.lastError().nativeErrorCode()));
845 }
846
847 while(q.next())
848 {
849
850 bool ok = false;
851
852 int cumulated_results = 2;
853
854 double rt = q.value(0).toDouble(&ok);
855 cumulated_results -= ok;
856
857 double sumY = q.value(1).toDouble(&ok);
858 cumulated_results -= ok;
859
860 if(cumulated_results)
861 {
862 throw PappsoException(
863 QObject::tr("ERROR in TIMS sqlite database file: could not read either the "
864 "retention time or the summed intensities (%1, database name "
865 "%2, "
866 "executing SQL "
867 "command %3:\n%4\n%5\n%6")
868 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
869 .arg(qdb.databaseName())
870 .arg(q.lastQuery())
871 .arg(qdb.lastError().databaseText())
872 .arg(qdb.lastError().driverText())
873 .arg(qdb.lastError().nativeErrorCode()));
874 }
875
876 // Try to insert value sumY at key rt.
877 std::pair<Iterator, bool> res = rt_tic_map_trace.insert(Pair(rt, sumY));
878
879 if(!res.second)
880 {
881 // One other same rt value was seen already (like in ion mobility
882 // mass spectrometry, for example). Only increment the y value.
883
884 res.first->second += sumY;
885 }
886 }
887
888 // qDebug().noquote() << "The TIC chromatogram:\n"
889 //<< rt_tic_map_trace.toTrace().toString();
890
891 return rt_tic_map_trace.toTrace();
892}
@ rt
Retention time.
Definition types.h:251

References m_timsDataDirectory, openDatabaseConnection(), and pappso::MapTrace::toTrace().

◆ getTimsBinDecPtr()

TimsBinDec * pappso::TimsData::getTimsBinDecPtr ( ) const
protected

Definition at line 1066 of file timsdata.cpp.

1067{
1068 return mpa_timsBinDec;
1069}

References mpa_timsBinDec.

◆ getTimsDataDirectory()

const QDir & pappso::TimsData::getTimsDataDirectory ( ) const

Definition at line 1050 of file timsdata.cpp.

1051{
1052 return m_timsDataDirectory;
1053}

References m_timsDataDirectory.

◆ getTimsDdaPrecursorsPtr()

TimsDdaPrecursors * pappso::TimsData::getTimsDdaPrecursorsPtr ( ) const

Definition at line 1056 of file timsdata.cpp.

1057{
1058 if(mpa_timsDdaPrecursors == nullptr)
1059 {
1060 throw pappso::PappsoException("TimsData does not contain DDA precursors");
1061 }
1062 return mpa_timsDdaPrecursors;
1063}

References mpa_timsDdaPrecursors.

◆ getTimsDiaSlicesPtr()

TimsDiaSlices * pappso::TimsData::getTimsDiaSlicesPtr ( ) const

Definition at line 1088 of file timsdata.cpp.

1089{
1090 qDebug();
1091 if(mpa_timsDiaSlices == nullptr)
1092 {
1093 throw pappso::PappsoException("TimsData does not contain DIA slices");
1094 }
1095 return mpa_timsDiaSlices;
1096}

References mpa_timsDiaSlices.

◆ getTimsFrameBaseCstSPtr()

TimsFrameBaseCstSPtr pappso::TimsData::getTimsFrameBaseCstSPtr ( std::size_t timsId)
private

get a Tims frame base (no binary data file access) with his database ID

Definition at line 414 of file timsdata.cpp.

415{
416
417 qDebug() << " timsId=" << timsId;
418
419 const TimsFrameRecord &frame_record = m_mapFramesRecord[timsId];
420 if(timsId > m_totalScanCount)
421 {
422 throw ExceptionNotFound(QObject::tr("ERROR Frames database id %1 not found").arg(timsId));
423 }
424 TimsFrameBaseSPtr tims_frame;
425
426
427 tims_frame = std::make_shared<TimsFrameBase>(TimsFrameBase(timsId, frame_record.tims_offset));
428
429 auto it_map_record = m_mapMzCalibrationRecord.find(frame_record.mz_calibration_id);
430 if(it_map_record != m_mapMzCalibrationRecord.end())
431 {
432
433 double T1_frame = frame_record.frame_t1; // Frames.T1
434 double T2_frame = frame_record.frame_t2; // Frames.T2
435
436
437 tims_frame.get()->setMzCalibrationInterfaceSPtr(
438 mpa_mzCalibrationStore->getInstance(T1_frame, T2_frame, it_map_record->second));
439 }
440 else
441 {
442 throw ExceptionNotFound(QObject::tr("ERROR MzCalibration database id %1 not found")
443 .arg(frame_record.mz_calibration_id));
444 }
445
446
447 tims_frame.get()->setAcqDurationInMilliseconds(frame_record.accumulation_time);
448
449 tims_frame.get()->setRtInSeconds(frame_record.frame_time);
450 tims_frame.get()->setMsMsType(frame_record.msms_type);
451
452
453 auto it_map_record_tims_calibration =
454 m_mapTimsCalibrationRecord.find(frame_record.tims_calibration_id);
455 if(it_map_record_tims_calibration != m_mapTimsCalibrationRecord.end())
456 {
457
458 tims_frame.get()->setTimsCalibration(
459 it_map_record_tims_calibration->second.value(1).toInt(),
460 it_map_record_tims_calibration->second.value(2).toDouble(),
461 it_map_record_tims_calibration->second.value(3).toDouble(),
462 it_map_record_tims_calibration->second.value(4).toDouble(),
463 it_map_record_tims_calibration->second.value(5).toDouble(),
464 it_map_record_tims_calibration->second.value(6).toDouble(),
465 it_map_record_tims_calibration->second.value(7).toDouble(),
466 it_map_record_tims_calibration->second.value(8).toDouble(),
467 it_map_record_tims_calibration->second.value(9).toDouble(),
468 it_map_record_tims_calibration->second.value(10).toDouble(),
469 it_map_record_tims_calibration->second.value(11).toDouble());
470 }
471 else
472 {
473 throw ExceptionNotFound(QObject::tr("ERROR TimsCalibration database id %1 not found")
474 .arg(frame_record.tims_calibration_id));
475 }
476
477 return tims_frame;
478}
std::shared_ptr< TimsFrameBase > TimsFrameBaseSPtr

References pappso::TimsFrameRecord::accumulation_time, pappso::TimsFrameRecord::frame_t1, pappso::TimsFrameRecord::frame_t2, pappso::TimsFrameRecord::frame_time, m_mapFramesRecord, m_mapMzCalibrationRecord, m_mapTimsCalibrationRecord, m_totalScanCount, mpa_mzCalibrationStore, pappso::TimsFrameRecord::msms_type, pappso::TimsFrameRecord::mz_calibration_id, pappso::TimsFrameRecord::tims_calibration_id, and pappso::TimsFrameRecord::tims_offset.

Referenced by getTimsFrameBaseCstSPtrCached().

◆ getTimsFrameBaseCstSPtrCached()

TimsFrameBaseCstSPtr pappso::TimsData::getTimsFrameBaseCstSPtrCached ( std::size_t timsId)
private

Definition at line 896 of file timsdata.cpp.

897{
898 QMutexLocker locker(&m_mutex);
899 for(auto &tims_frame : m_timsFrameBaseCache)
900 {
901 if(tims_frame.get()->getId() == timsId)
902 {
903 m_timsFrameBaseCache.push_back(tims_frame);
905 m_timsFrameBaseCache.pop_front();
906 return tims_frame;
907 }
908 }
909
912 m_timsFrameBaseCache.pop_front();
913 return m_timsFrameBaseCache.back();
914}
std::size_t m_cacheSize
Definition timsdata.h:247
TimsFrameBaseCstSPtr getTimsFrameBaseCstSPtr(std::size_t timsId)
get a Tims frame base (no binary data file access) with his database ID
Definition timsdata.cpp:414
std::deque< TimsFrameBaseCstSPtr > m_timsFrameBaseCache
Definition timsdata.h:249

References getTimsFrameBaseCstSPtr(), m_cacheSize, m_mutex, and m_timsFrameBaseCache.

Referenced by getQualifiedMassSpectrumByGlobalScanIndex().

◆ getTimsFrameCstSPtr()

TimsFrameCstSPtr pappso::TimsData::getTimsFrameCstSPtr ( std::size_t timsId)

get a Tims frame with his database ID

this function is not thread safe

Definition at line 560 of file timsdata.cpp.

561{
562
563 qDebug() << " timsId=" << timsId << " m_mapFramesRecord.size()=" << m_mapFramesRecord.size();
564
565 /*
566 for(auto pair_i : m_mapFramesRecord)
567 {
568
569 qDebug() << " pair_i=" << pair_i.first;
570 }
571 */
572
573 const TimsFrameRecord &frame_record = m_mapFramesRecord[timsId];
574 if(timsId > m_totalScanCount)
575 {
576 throw ExceptionNotFound(QObject::tr("ERROR Frames database id %1 not found").arg(timsId));
577 }
578
579 TimsFrameSPtr tims_frame;
580
581
582 // QMutexLocker lock(&m_mutex);
583 tims_frame = mpa_timsBinDec->getTimsFrameSPtrByOffset(timsId, m_mapFramesRecord);
584 // lock.unlock();
585
586 qDebug();
587 auto it_map_record = m_mapMzCalibrationRecord.find(frame_record.mz_calibration_id);
588 if(it_map_record != m_mapMzCalibrationRecord.end())
589 {
590
591 double T1_frame = frame_record.frame_t1; // Frames.T1
592 double T2_frame = frame_record.frame_t2; // Frames.T2
593
594
595 tims_frame.get()->setMzCalibrationInterfaceSPtr(
596 mpa_mzCalibrationStore->getInstance(T1_frame, T2_frame, it_map_record->second));
597 }
598 else
599 {
600 throw ExceptionNotFound(
601 QObject::tr("ERROR MzCalibration database id %1 not found for frame_id=%2")
602 .arg(frame_record.mz_calibration_id)
603 .arg(timsId));
604 }
605
606
607 tims_frame.get()->setAcqDurationInMilliseconds(frame_record.accumulation_time);
608
609 tims_frame.get()->setRtInSeconds(frame_record.frame_time);
610 tims_frame.get()->setMsMsType(frame_record.msms_type);
611
612 qDebug();
613 auto it_map_record_tims_calibration =
614 m_mapTimsCalibrationRecord.find(frame_record.tims_calibration_id);
615 if(it_map_record_tims_calibration != m_mapTimsCalibrationRecord.end())
616 {
617
618 tims_frame.get()->setTimsCalibration(
619 it_map_record_tims_calibration->second.value(1).toInt(),
620 it_map_record_tims_calibration->second.value(2).toDouble(),
621 it_map_record_tims_calibration->second.value(3).toDouble(),
622 it_map_record_tims_calibration->second.value(4).toDouble(),
623 it_map_record_tims_calibration->second.value(5).toDouble(),
624 it_map_record_tims_calibration->second.value(6).toDouble(),
625 it_map_record_tims_calibration->second.value(7).toDouble(),
626 it_map_record_tims_calibration->second.value(8).toDouble(),
627 it_map_record_tims_calibration->second.value(9).toDouble(),
628 it_map_record_tims_calibration->second.value(10).toDouble(),
629 it_map_record_tims_calibration->second.value(11).toDouble());
630 }
631 else
632 {
633 throw ExceptionNotFound(QObject::tr("ERROR TimsCalibration database id %1 not found")
634 .arg(frame_record.tims_calibration_id));
635 }
636 qDebug();
637 return tims_frame;
638}

References pappso::TimsFrameRecord::accumulation_time, pappso::TimsFrameRecord::frame_t1, pappso::TimsFrameRecord::frame_t2, pappso::TimsFrameRecord::frame_time, m_mapFramesRecord, m_mapMzCalibrationRecord, m_mapTimsCalibrationRecord, m_totalScanCount, mpa_mzCalibrationStore, mpa_timsBinDec, pappso::TimsFrameRecord::msms_type, pappso::TimsFrameRecord::mz_calibration_id, and pappso::TimsFrameRecord::tims_calibration_id.

Referenced by getTimsFrameCstSPtrCached().

◆ getTimsFrameCstSPtrCached()

TimsFrameCstSPtr pappso::TimsData::getTimsFrameCstSPtrCached ( std::size_t timsId)

get a Tims frame with his database ID but look in the cache first

thread safe

Definition at line 917 of file timsdata.cpp.

918{
919 qDebug();
920 QMutexLocker locker(&m_mutex);
921 for(auto &tims_frame : m_timsFrameCache)
922 {
923 if(tims_frame.get()->getId() == timsId)
924 {
925 m_timsFrameCache.push_back(tims_frame);
926 if(m_timsFrameCache.size() > m_cacheSize)
927 m_timsFrameCache.pop_front();
928 return tims_frame;
929 }
930 }
931 TimsFrameCstSPtr frame_sptr = getTimsFrameCstSPtr(timsId);
932
933 // locker.relock();
934 qDebug();
935
936 m_timsFrameCache.push_back(frame_sptr);
937 if(m_timsFrameCache.size() > m_cacheSize)
938 m_timsFrameCache.pop_front();
939 qDebug();
940 return m_timsFrameCache.back();
941
942
943 /*
944// the frame is not in the cache
945if(std::find(m_someoneIsLoadingFrameId.begin(),
946 m_someoneIsLoadingFrameId.end(),
947 timsId) == m_someoneIsLoadingFrameId.end())
948 {
949 // not found, we are alone on this frame
950 m_someoneIsLoadingFrameId.push_back(timsId);
951 qDebug();
952 //locker.unlock();
953 TimsFrameCstSPtr frame_sptr = getTimsFrameCstSPtr(timsId);
954
955 // locker.relock();
956 qDebug();
957 m_someoneIsLoadingFrameId.erase(
958 std::find(m_someoneIsLoadingFrameId.begin(),
959 m_someoneIsLoadingFrameId.end(),
960 timsId));
961
962 m_timsFrameCache.push_back(frame_sptr);
963 if(m_timsFrameCache.size() > m_cacheSize)
964 m_timsFrameCache.pop_front();
965 qDebug();
966 return m_timsFrameCache.back();
967 }
968else
969 {
970 // this frame is loading by someone else, we have to wait
971 qDebug();
972 // locker.unlock();
973 // std::size_t another_frame_id = timsId;
974 while(true)
975 {
976 QThread::usleep(1);
977 // locker.relock();
978
979 for(auto &tims_frame : m_timsFrameCache)
980 {
981 if(tims_frame.get()->getId() == timsId)
982 {
983 m_timsFrameCache.push_back(tims_frame);
984 return tims_frame;
985 }
986 }
987 // locker.unlock();
988}
989} // namespace pappso
990*/
991}
TimsFrameCstSPtr getTimsFrameCstSPtr(std::size_t timsId)
get a Tims frame with his database ID
Definition timsdata.cpp:560
std::deque< TimsFrameCstSPtr > m_timsFrameCache
Definition timsdata.h:248

References getTimsFrameCstSPtr(), m_cacheSize, m_mutex, and m_timsFrameCache.

Referenced by getMassSpectrumCstSPtr(), getMsLevelByGlobalScanIndex(), getQualifiedMassSpectrumByGlobalScanIndex(), and getScanByGlobalScanIndex().

◆ getTimsFrameRecordList()

const std::vector< TimsFrameRecord > & pappso::TimsData::getTimsFrameRecordList ( ) const

Definition at line 1044 of file timsdata.cpp.

1045{
1046 return m_mapFramesRecord;
1047}

References m_mapFramesRecord.

◆ getTimsMS1FrameIdsInRtRange()

std::vector< std::size_t > pappso::TimsData::getTimsMS1FrameIdsInRtRange ( double rt_begin,
double rt_end ) const

Definition at line 481 of file timsdata.cpp.

482{
483
484 qDebug() << " rt_begin=" << rt_begin << " rt_end=" << rt_end;
485 if(rt_begin < 0)
486 rt_begin = 0;
487 std::vector<std::size_t> tims_frameid_list;
488 QSqlDatabase qdb = openDatabaseConnection();
489 QSqlQuery q(qdb);
490 q.prepare(QString("SELECT Frames.Id FROM Frames WHERE "
491 "Frames.MsMsType=0 AND (Frames.Time>=%1) "
492 "AND (Frames.Time<=%2) ORDER BY "
493 "Frames.Time;")
494 .arg(rt_begin)
495 .arg(rt_end));
496 q.exec();
497 if(q.lastError().isValid())
498 {
499
500 throw PappsoException(QObject::tr("ERROR in TIMS sqlite database file %1, database name %2, "
501 "executing SQL "
502 "command %3:\n%4\n%5\n%6\nrtbegin=%7 rtend=%8")
503 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
504 .arg(qdb.databaseName())
505 .arg(q.lastQuery())
506 .arg(qdb.lastError().databaseText())
507 .arg(qdb.lastError().driverText())
508 .arg(qdb.lastError().nativeErrorCode())
509 .arg(rt_begin)
510 .arg(rt_end));
511 }
512 while(q.next())
513 {
514
515 tims_frameid_list.push_back(q.value(0).toULongLong());
516 }
517 return tims_frameid_list;
518}

References m_timsDataDirectory, and openDatabaseConnection().

◆ getTimsMS2FrameIdsInRtRange()

std::vector< std::size_t > pappso::TimsData::getTimsMS2FrameIdsInRtRange ( double rt_begin,
double rt_end ) const

Definition at line 521 of file timsdata.cpp.

522{
523
524 qDebug() << " rt_begin=" << rt_begin << " rt_end=" << rt_end;
525 if(rt_begin < 0)
526 rt_begin = 0;
527 std::vector<std::size_t> tims_frameid_list;
528 QSqlDatabase qdb = openDatabaseConnection();
529
530 QSqlQuery q(qdb);
531 q.prepare(QString("SELECT Frames.Id FROM Frames WHERE "
532 "Frames.MsMsType=8 AND "
533 "(Frames.Time>=%1) AND (Frames.Time<=%2) ORDER BY "
534 "Frames.Time;")
535 .arg(rt_begin)
536 .arg(rt_end));
537 q.exec();
538 if(q.lastError().isValid())
539 {
540
541 throw PappsoException(QObject::tr("ERROR in TIMS sqlite database file %1, database name %2, "
542 "executing SQL "
543 "command %3:\n%4\n%5\n%6")
544 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
545 .arg(qdb.databaseName())
546 .arg(q.lastQuery())
547 .arg(qdb.lastError().databaseText())
548 .arg(qdb.lastError().driverText())
549 .arg(qdb.lastError().nativeErrorCode()));
550 }
551 while(q.next())
552 {
553
554 tims_frameid_list.push_back(q.value(0).toULongLong());
555 }
556 return tims_frameid_list;
557}

References m_timsDataDirectory, and openDatabaseConnection().

◆ getTotalNumberOfFrames()

std::size_t pappso::TimsData::getTotalNumberOfFrames ( ) const

Get total number of frames.

Definition at line 652 of file timsdata.cpp.

653{
654 return m_frameCount;
655}

References m_frameCount.

◆ getTotalNumberOfScans()

std::size_t pappso::TimsData::getTotalNumberOfScans ( ) const

get the total number of scans

Definition at line 666 of file timsdata.cpp.

667{
668 return m_totalScanCount;
669}

References m_totalScanCount.

◆ getTotalScanCount()

std::size_t pappso::TimsData::getTotalScanCount ( ) const

Definition at line 673 of file timsdata.cpp.

674{
675 return m_totalScanCount;
676}

References m_totalScanCount.

◆ isDdaRun()

bool pappso::TimsData::isDdaRun ( ) const

tells if this MS run is a DDA run

Returns
true if it contains DDA precursors

Definition at line 1072 of file timsdata.cpp.

1073{
1074 if(mpa_timsDdaPrecursors == nullptr)
1075 return false;
1076 return true;
1077}

References mpa_timsDdaPrecursors.

◆ isDiaRun()

bool pappso::TimsData::isDiaRun ( ) const

tells if this MS run is a DIA run

Returns
true if it contains DIA slices

Definition at line 1080 of file timsdata.cpp.

1081{
1082 if(mpa_timsDiaSlices == nullptr)
1083 return false;
1084 return true;
1085}

References mpa_timsDiaSlices.

◆ openDatabaseConnection()

QSqlDatabase pappso::TimsData::openDatabaseConnection ( ) const
protected

Definition at line 224 of file timsdata.cpp.

225{
226 QString database_connection_name = QString("%1_%2")
227 .arg(m_timsDataDirectory.absolutePath())
228 .arg((quintptr)QThread::currentThread());
229 // Open the database
230 QSqlDatabase qdb = QSqlDatabase::database(database_connection_name);
231 if(!qdb.isValid())
232 {
233 qDebug() << database_connection_name;
234 qdb = QSqlDatabase::addDatabase("QSQLITE", database_connection_name);
235 qdb.setDatabaseName(m_timsDataDirectory.absoluteFilePath("analysis.tdf"));
236 }
237
238
239 if(!qdb.open())
240 {
241 qDebug();
242 throw PappsoException(QObject::tr("ERROR opening TIMS sqlite database file %1, database name "
243 "%2 :\n%3\n%4\n%5")
244 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
245 .arg(database_connection_name)
246 .arg(qdb.lastError().databaseText())
247 .arg(qdb.lastError().driverText())
248 .arg(qdb.lastError().nativeErrorCode()));
249 }
250 return qdb;
251}

References m_timsDataDirectory.

Referenced by TimsData(), fillFrameIdDescrList(), getTicChromatogram(), getTimsMS1FrameIdsInRtRange(), and getTimsMS2FrameIdsInRtRange().

Member Data Documentation

◆ m_cacheSize

std::size_t pappso::TimsData::m_cacheSize = 60
private

Definition at line 247 of file timsdata.h.

Referenced by getTimsFrameBaseCstSPtrCached(), and getTimsFrameCstSPtrCached().

◆ m_frameCount

std::size_t pappso::TimsData::m_frameCount
private

Definition at line 246 of file timsdata.h.

Referenced by TimsData(), getFrameCount(), and getTotalNumberOfFrames().

◆ m_frameIdDescrList

std::vector<FrameIdDescr> pappso::TimsData::m_frameIdDescrList
private

store every frame id and corresponding sizes

Definition at line 261 of file timsdata.h.

Referenced by fillFrameIdDescrList(), getFrameIdDescrList(), getGlobalScanIndexByScanCoordinates(), and getScanCoordinatesByGlobalScanIndex().

◆ m_mapFramesRecord

std::vector<TimsFrameRecord> pappso::TimsData::m_mapFramesRecord
private

◆ m_mapGlobalMetadaTable

std::map<QString, QVariant> pappso::TimsData::m_mapGlobalMetadaTable
private

Definition at line 275 of file timsdata.h.

Referenced by TimsData(), and getGlobalMetadataValue().

◆ m_mapMzCalibrationRecord

std::map<int, QSqlRecord> pappso::TimsData::m_mapMzCalibrationRecord
private

Definition at line 252 of file timsdata.h.

Referenced by TimsData(), getTimsFrameBaseCstSPtr(), and getTimsFrameCstSPtr().

◆ m_mapTimsCalibrationRecord

std::map<int, QSqlRecord> pappso::TimsData::m_mapTimsCalibrationRecord
private

Definition at line 253 of file timsdata.h.

Referenced by TimsData(), getTimsFrameBaseCstSPtr(), and getTimsFrameCstSPtr().

◆ m_mutex

QMutex pappso::TimsData::m_mutex
private

Definition at line 277 of file timsdata.h.

Referenced by getTimsFrameBaseCstSPtrCached(), and getTimsFrameCstSPtrCached().

◆ m_someoneIsLoadingFrameId

std::vector<std::size_t> pappso::TimsData::m_someoneIsLoadingFrameId
private

tells if someone is loading a frame id

Definition at line 273 of file timsdata.h.

◆ m_thousandIndexToFrameIdDescrListIndex

std::map<std::size_t, std::size_t> pappso::TimsData::m_thousandIndexToFrameIdDescrListIndex
private

index to find quickly a frameId in the description list with the raw index of spectrum modulo 1000 @key thousands of TOF scans @value corresponding m_frameIdDescrList index

Definition at line 268 of file timsdata.h.

Referenced by fillFrameIdDescrList(), and getScanCoordinatesByGlobalScanIndex().

◆ m_timsDataDirectory

QDir pappso::TimsData::m_timsDataDirectory
private

◆ m_timsFrameBaseCache

std::deque<TimsFrameBaseCstSPtr> pappso::TimsData::m_timsFrameBaseCache
private

Definition at line 249 of file timsdata.h.

Referenced by getTimsFrameBaseCstSPtrCached().

◆ m_timsFrameCache

std::deque<TimsFrameCstSPtr> pappso::TimsData::m_timsFrameCache
private

Definition at line 248 of file timsdata.h.

Referenced by getTimsFrameCstSPtrCached().

◆ m_totalScanCount

std::size_t pappso::TimsData::m_totalScanCount
private

◆ mpa_mzCalibrationStore

MzCalibrationStore* pappso::TimsData::mpa_mzCalibrationStore
private

Definition at line 256 of file timsdata.h.

Referenced by TimsData(), ~TimsData(), getTimsFrameBaseCstSPtr(), and getTimsFrameCstSPtr().

◆ mpa_timsBinDec

TimsBinDec* pappso::TimsData::mpa_timsBinDec = nullptr
private

Definition at line 240 of file timsdata.h.

Referenced by TimsData(), ~TimsData(), getTimsBinDecPtr(), and getTimsFrameCstSPtr().

◆ mpa_timsDdaPrecursors

TimsDdaPrecursors* pappso::TimsData::mpa_timsDdaPrecursors = nullptr
private

◆ mpa_timsDiaSlices

TimsDiaSlices* pappso::TimsData::mpa_timsDiaSlices = nullptr
private

Definition at line 243 of file timsdata.h.

Referenced by TimsData(), ~TimsData(), getTimsDiaSlicesPtr(), and isDiaRun().

◆ TimsDdaPrecursors

friend pappso::TimsData::TimsDdaPrecursors
private

Definition at line 69 of file timsdata.h.

Referenced by TimsData().

◆ TimsDiaSlices

friend pappso::TimsData::TimsDiaSlices
private

Definition at line 70 of file timsdata.h.

Referenced by TimsData().


The documentation for this class was generated from the following files: