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 46 of file timsdata.cpp.

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

251{
252 qDebug();
253}

References TimsData().

◆ ~TimsData()

pappso::TimsData::~TimsData ( )
virtual

Destructor

Definition at line 255 of file timsdata.cpp.

256{
257 // m_qdb.close();
258 if(mpa_timsBinDec != nullptr)
259 {
260 delete mpa_timsBinDec;
261 }
262 if(mpa_mzCalibrationStore != nullptr)
263 {
265 }
266 if(mpa_timsDdaPrecursors != nullptr)
267 {
269 }
270 if(mpa_timsDiaSlices != nullptr)
271 {
272 delete mpa_timsDiaSlices;
273 }
274}

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 277 of file timsdata.cpp.

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

650{
651 return m_frameCount;
652}

References m_frameCount.

◆ getFrameIdDescrList()

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

Definition at line 1025 of file timsdata.cpp.

1026{
1027 return m_frameIdDescrList;
1028}

References m_frameIdDescrList.

◆ getGlobalMetadataValue()

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

Definition at line 1088 of file timsdata.cpp.

1089{
1090 auto it = m_mapGlobalMetadaTable.find(key);
1091 if(it == m_mapGlobalMetadaTable.end())
1092 {
1093 throw pappso::PappsoException(QString("TimsData GlobalMetadata key %1 not found").arg(key));
1094 }
1095 return it->second;
1096}

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 363 of file timsdata.cpp.

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

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 632 of file timsdata.cpp.

633{
634 qDebug() << " timsId=" << timsId << " scanNum=" << scanNum;
636
637 return frame->getMassSpectrumCstSPtr(scanNum);
638}
TimsFrameCstSPtr getTimsFrameCstSPtrCached(std::size_t timsId)
get a Tims frame with his database ID but look in the cache first
Definition timsdata.cpp:904
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 390 of file timsdata.cpp.

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

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 384 of file timsdata.cpp.

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

References getMassSpectrumCstSPtrByGlobalScanIndex().

◆ getMsLevelByGlobalScanIndex()

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

Definition at line 676 of file timsdata.cpp.

677{
678 auto coordinate = getScanCoordinatesByGlobalScanIndex(index);
679 auto tims_frame = getTimsFrameCstSPtrCached(coordinate.first);
680 return tims_frame.get()->getMsLevel();
681}

References getScanCoordinatesByGlobalScanIndex(), and getTimsFrameCstSPtrCached().

Referenced by getMsLevelBySpectrumIndex().

◆ getMsLevelBySpectrumIndex()

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

Definition at line 669 of file timsdata.cpp.

670{
671 return getMsLevelByGlobalScanIndex(index);
672}
unsigned int getMsLevelByGlobalScanIndex(std::size_t index)
Definition timsdata.cpp:676

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 696 of file timsdata.cpp.

700{
701
702
703 try
704 {
705 auto coordinate = getScanCoordinatesByGlobalScanIndex(global_scan_index);
706 TimsFrameBaseCstSPtr tims_frame;
707 if(want_binary_data)
708 {
709 tims_frame = getTimsFrameCstSPtrCached(coordinate.first);
710 }
711 else
712 {
713 tims_frame = getTimsFrameBaseCstSPtrCached(coordinate.first);
714 }
715 MassSpectrumId spectrum_id;
716
717 spectrum_id.setSpectrumIndex(global_scan_index);
718 spectrum_id.setMsRunId(msrun_id);
719 spectrum_id.setNativeId(QString("frame_id=%1 scan_index=%2 global_scan_index=%3")
720 .arg(coordinate.first)
721 .arg(coordinate.second)
722 .arg(global_scan_index));
723
724 mass_spectrum.setMassSpectrumId(spectrum_id);
725
726 mass_spectrum.setMsLevel(tims_frame.get()->getMsLevel());
727 mass_spectrum.setRtInSeconds(tims_frame.get()->getRtInSeconds());
728
729 mass_spectrum.setDtInMilliSeconds(
730 tims_frame.get()->getDriftTimeInMilliseconds(coordinate.second));
731 // 1/K0
732 mass_spectrum.setParameterValue(
734 tims_frame.get()->getOneOverK0Transformation(coordinate.second));
735
736 mass_spectrum.setEmptyMassSpectrum(true);
737 if(want_binary_data)
738 {
739 mass_spectrum.setMassSpectrumSPtr(
740 tims_frame.get()->getMassSpectrumSPtr(coordinate.second));
741 if(mass_spectrum.size() > 0)
742 {
743 mass_spectrum.setEmptyMassSpectrum(false);
744 }
745 }
746 else
747 {
748 // if(tims_frame.get()->getNbrPeaks(coordinate.second) > 0)
749 //{
750 mass_spectrum.setEmptyMassSpectrum(false);
751 // }
752 }
753 if(tims_frame.get()->getMsLevel() > 1)
754 {
755
756 if(mpa_timsDdaPrecursors != nullptr)
757 {
758 auto spectrum_descr =
759 mpa_timsDdaPrecursors->getSpectrumDescrWithScanCoordinates(coordinate);
760 if(spectrum_descr.precursor_id > 0)
761 {
762
763 mass_spectrum.appendPrecursorIonData(spectrum_descr.precursor_ion_data);
764
765
766 MassSpectrumId spectrum_id;
767 std::size_t prec_spectrum_index = getGlobalScanIndexByScanCoordinates(
768 spectrum_descr.parent_frame, coordinate.second);
769
770 mass_spectrum.setPrecursorSpectrumIndex(prec_spectrum_index);
771 mass_spectrum.setPrecursorNativeId(
772 QString("frame_id=%1 scan_index=%2 global_scan_index=%3")
773 .arg(spectrum_descr.parent_frame)
774 .arg(coordinate.second)
775 .arg(prec_spectrum_index));
776
777 mass_spectrum.setParameterValue(QualifiedMassSpectrumParameter::IsolationMz,
778 spectrum_descr.isolationMz);
779 mass_spectrum.setParameterValue(QualifiedMassSpectrumParameter::IsolationMzWidth,
780 spectrum_descr.isolationWidth);
781
782 mass_spectrum.setParameterValue(QualifiedMassSpectrumParameter::CollisionEnergy,
783 spectrum_descr.collisionEnergy);
784 mass_spectrum.setParameterValue(
786 (quint64)spectrum_descr.precursor_id);
787 }
788 }
789 }
790 }
791 catch(PappsoException &error)
792 {
793 throw PappsoException(QObject::tr("Error TimsData::getQualifiedMassSpectrumByRawIndex "
794 "spectrum_index=%1 :\n%2")
795 .arg(global_scan_index)
796 .arg(error.qwhat()));
797 }
798}
std::size_t getGlobalScanIndexByScanCoordinates(std::size_t frame_id, std::size_t index) const
Definition timsdata.cpp:363
TimsFrameBaseCstSPtr getTimsFrameBaseCstSPtrCached(std::size_t timsId)
Definition timsdata.cpp:883
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 685 of file timsdata.cpp.

689{
690
692 msrun_id, mass_spectrum, global_scan_index, want_binary_data);
693}
void getQualifiedMassSpectrumByGlobalScanIndex(const MsRunIdCstSPtr &msrun_id, QualifiedMassSpectrum &mass_spectrum, std::size_t global_scan_index, bool want_binary_data)
Definition timsdata.cpp:696

References getQualifiedMassSpectrumByGlobalScanIndex().

◆ getRawIndexFromCoordinate()

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

Definition at line 356 of file timsdata.cpp.

357{
358
359 return getGlobalScanIndexByScanCoordinates(frame_id, index);
360}

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 1004 of file timsdata.cpp.

1005{
1006 return getScanByGlobalScanIndex(index);
1007}
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 982 of file timsdata.cpp.

983{
985}
virtual std::vector< double > getRetentionTimeLineInSeconds() const
Definition timsdata.cpp:988

References getRetentionTimeLineInSeconds().

◆ getRetentionTimeLineInSeconds()

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

Definition at line 988 of file timsdata.cpp.

989{
990
991 std::vector<double> timeline;
992 timeline.reserve(m_mapFramesRecord.size());
993 for(const TimsFrameRecord &frame_record : m_mapFramesRecord)
994 {
995 if(frame_record.mz_calibration_id != 0)
996 {
997 timeline.push_back(frame_record.frame_time);
998 }
999 }
1000 return timeline;
1001}

References m_mapFramesRecord.

Referenced by getRetentionTimeLine().

◆ getScanByGlobalScanIndex()

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

Definition at line 1010 of file timsdata.cpp.

1011{
1012 qDebug() << " spectrum_index=" << index;
1013 auto coordinate = getScanCoordinatesByGlobalScanIndex(index);
1014 TimsFrameBaseCstSPtr tims_frame;
1015 tims_frame = getTimsFrameCstSPtrCached(coordinate.first);
1016
1017 TimsDataFastMap &raw_spectrum = TimsDataFastMap::getTimsDataFastMapInstance();
1018 raw_spectrum.clear();
1019 tims_frame.get()->combineScansInTofIndexIntensityMap(
1020 raw_spectrum, coordinate.second, coordinate.second);
1021 return raw_spectrum;
1022}
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 320 of file timsdata.cpp.

321{
322 return getScanCoordinatesByGlobalScanIndex(raw_index);
323}

References getScanCoordinatesByGlobalScanIndex().

◆ getScanCoordinatesByGlobalScanIndex()

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

Definition at line 326 of file timsdata.cpp.

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

References m_frameIdDescrList, and m_thousandIndexToFrameIdDescrListIndex.

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

◆ getTicChromatogram()

Trace pappso::TimsData::getTicChromatogram ( ) const

Definition at line 801 of file timsdata.cpp.

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

1054{
1055 return mpa_timsBinDec;
1056}

References mpa_timsBinDec.

◆ getTimsDataDirectory()

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

Definition at line 1037 of file timsdata.cpp.

1038{
1039 return m_timsDataDirectory;
1040}

References m_timsDataDirectory.

◆ getTimsDdaPrecursorsPtr()

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

Definition at line 1043 of file timsdata.cpp.

1044{
1045 if(mpa_timsDdaPrecursors == nullptr)
1046 {
1047 throw pappso::PappsoException("TimsData does not contain DDA precursors");
1048 }
1049 return mpa_timsDdaPrecursors;
1050}

References mpa_timsDdaPrecursors.

◆ getTimsDiaSlicesPtr()

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

Definition at line 1075 of file timsdata.cpp.

1076{
1077 qDebug();
1078 if(mpa_timsDiaSlices == nullptr)
1079 {
1080 throw pappso::PappsoException("TimsData does not contain DIA slices");
1081 }
1082 return mpa_timsDiaSlices;
1083}

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 409 of file timsdata.cpp.

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

884{
885 QMutexLocker locker(&m_mutex);
886 for(auto &tims_frame : m_timsFrameBaseCache)
887 {
888 if(tims_frame.get()->getId() == timsId)
889 {
890 m_timsFrameBaseCache.push_back(tims_frame);
892 m_timsFrameBaseCache.pop_front();
893 return tims_frame;
894 }
895 }
896
899 m_timsFrameBaseCache.pop_front();
900 return m_timsFrameBaseCache.back();
901}
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:409
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 550 of file timsdata.cpp.

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

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 904 of file timsdata.cpp.

905{
906 qDebug();
907 QMutexLocker locker(&m_mutex);
908 for(auto &tims_frame : m_timsFrameCache)
909 {
910 if(tims_frame.get()->getId() == timsId)
911 {
912 m_timsFrameCache.push_back(tims_frame);
913 if(m_timsFrameCache.size() > m_cacheSize)
914 m_timsFrameCache.pop_front();
915 return tims_frame;
916 }
917 }
918 TimsFrameCstSPtr frame_sptr = getTimsFrameCstSPtr(timsId);
919
920 // locker.relock();
921 qDebug();
922
923 m_timsFrameCache.push_back(frame_sptr);
924 if(m_timsFrameCache.size() > m_cacheSize)
925 m_timsFrameCache.pop_front();
926 qDebug();
927 return m_timsFrameCache.back();
928
929
930 /*
931// the frame is not in the cache
932if(std::find(m_someoneIsLoadingFrameId.begin(),
933 m_someoneIsLoadingFrameId.end(),
934 timsId) == m_someoneIsLoadingFrameId.end())
935 {
936 // not found, we are alone on this frame
937 m_someoneIsLoadingFrameId.push_back(timsId);
938 qDebug();
939 //locker.unlock();
940 TimsFrameCstSPtr frame_sptr = getTimsFrameCstSPtr(timsId);
941
942 // locker.relock();
943 qDebug();
944 m_someoneIsLoadingFrameId.erase(
945 std::find(m_someoneIsLoadingFrameId.begin(),
946 m_someoneIsLoadingFrameId.end(),
947 timsId));
948
949 m_timsFrameCache.push_back(frame_sptr);
950 if(m_timsFrameCache.size() > m_cacheSize)
951 m_timsFrameCache.pop_front();
952 qDebug();
953 return m_timsFrameCache.back();
954 }
955else
956 {
957 // this frame is loading by someone else, we have to wait
958 qDebug();
959 // locker.unlock();
960 // std::size_t another_frame_id = timsId;
961 while(true)
962 {
963 QThread::usleep(1);
964 // locker.relock();
965
966 for(auto &tims_frame : m_timsFrameCache)
967 {
968 if(tims_frame.get()->getId() == timsId)
969 {
970 m_timsFrameCache.push_back(tims_frame);
971 return tims_frame;
972 }
973 }
974 // locker.unlock();
975}
976} // namespace pappso
977*/
978}
TimsFrameCstSPtr getTimsFrameCstSPtr(std::size_t timsId)
get a Tims frame with his database ID
Definition timsdata.cpp:550
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 1031 of file timsdata.cpp.

1032{
1033 return m_mapFramesRecord;
1034}

References m_mapFramesRecord.

◆ getTimsMS1FrameIdsInRtRange()

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

Definition at line 476 of file timsdata.cpp.

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

References m_timsDataDirectory, and openDatabaseConnection().

◆ getTimsMS2FrameIdsInRtRange()

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

Definition at line 514 of file timsdata.cpp.

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

References m_timsDataDirectory, and openDatabaseConnection().

◆ getTotalNumberOfFrames()

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

Get total number of frames.

Definition at line 642 of file timsdata.cpp.

643{
644 return m_frameCount;
645}

References m_frameCount.

◆ getTotalNumberOfScans()

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

get the total number of scans

Definition at line 656 of file timsdata.cpp.

657{
658 return m_totalScanCount;
659}

References m_totalScanCount.

◆ getTotalScanCount()

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

Definition at line 663 of file timsdata.cpp.

664{
665 return m_totalScanCount;
666}

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 1059 of file timsdata.cpp.

1060{
1061 if(mpa_timsDdaPrecursors == nullptr)
1062 return false;
1063 return true;
1064}

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 1067 of file timsdata.cpp.

1068{
1069 if(mpa_timsDiaSlices == nullptr)
1070 return false;
1071 return true;
1072}

References mpa_timsDiaSlices.

◆ openDatabaseConnection()

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

Definition at line 221 of file timsdata.cpp.

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

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: