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
 

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
 
QMutex m_mutex
 

Detailed Description

Todo
write docs

Definition at line 69 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.

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 throw PappsoException(
55 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 PappsoException(
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 q(qdb);
72 if(!q.exec("select Key, Value from GlobalMetadata where "
73 "Key='TimsCompressionType';"))
74 {
75
76 qDebug();
77 throw PappsoException(
78 QObject::tr("ERROR in TIMS sqlite database file %1, executing SQL "
79 "command %2:\n%3\n%4\n%5")
80 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
81 .arg(q.lastQuery())
82 .arg(q.lastError().databaseText())
83 .arg(q.lastError().driverText())
84 .arg(q.lastError().nativeErrorCode()));
85 }
86
87
88 int compression_type = 0;
89 if(q.next())
90 {
91 compression_type = q.value(1).toInt();
92 }
93 qDebug() << " compression_type=" << compression_type;
94 mpa_timsBinDec = new TimsBinDec(
95 QFileInfo(m_timsDataDirectory.absoluteFilePath("analysis.tdf_bin")),
96 compression_type);
97
98 qDebug();
99
100 try
101 {
102
103 qDebug();
105 }
106 catch(pappso::ExceptionNotFound &not_found)
107 {
108
109 qDebug();
110 mpa_timsDdaPrecursors = nullptr;
111 }
112
113
114 qDebug();
115 try
116 {
117 qDebug();
118 mpa_timsDiaSlices = new TimsDiaSlices(q, this);
119 }
120 catch(pappso::ExceptionNotFound &not_found)
121 {
122 qDebug();
123 mpa_timsDiaSlices = nullptr;
124 }
125
127
128 // get number of scans
129 if(!q.exec("SELECT SUM(NumScans),COUNT(Id) FROM Frames"))
130 {
131 qDebug();
132 throw PappsoException(
133 QObject::tr("ERROR in TIMS sqlite database file %1, executing SQL "
134 "command %2:\n%3\n%4\n%5")
135 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
136 .arg(q.lastQuery())
137 .arg(qdb.lastError().databaseText())
138 .arg(qdb.lastError().driverText())
139 .arg(qdb.lastError().nativeErrorCode()));
140 }
141 if(q.next())
142 {
143 qDebug();
144 m_totalScanCount = q.value(0).toLongLong();
145 m_frameCount = q.value(1).toLongLong();
146 }
147
148 if(!q.exec("select * from MzCalibration;"))
149 {
150 qDebug();
151 throw PappsoException(
152 QObject::tr("ERROR in TIMS sqlite database file %1, executing SQL "
153 "command %2:\n%3\n%4\n%5")
154 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
155 .arg(q.lastQuery())
156 .arg(q.lastError().databaseText())
157 .arg(q.lastError().driverText())
158 .arg(q.lastError().nativeErrorCode()));
159 }
160
161 while(q.next())
162 {
163 QSqlRecord record = q.record();
165 std::pair<int, QSqlRecord>(record.value(0).toInt(), record));
166 }
167
168 // m_mapTimsCalibrationRecord
169
170 if(!q.exec("select * from TimsCalibration;"))
171 {
172 qDebug();
173 throw PappsoException(
174 QObject::tr("ERROR in TIMS sqlite database file %1, executing SQL "
175 "command %2:\n%3\n%4\n%5")
176 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
177 .arg(q.lastQuery())
178 .arg(q.lastError().databaseText())
179 .arg(q.lastError().driverText())
180 .arg(q.lastError().nativeErrorCode()));
181 }
182 while(q.next())
183 {
184 QSqlRecord record = q.record();
186 std::pair<int, QSqlRecord>(record.value(0).toInt(), record));
187 }
188
189
190 // store frames
191 if(!q.exec("select Frames.TimsId, Frames.AccumulationTime, " // 1
192 "Frames.MzCalibration, " // 2
193 "Frames.T1, Frames.T2, " // 4
194 "Frames.Time, Frames.MsMsType, Frames.TimsCalibration, " // 7
195 "Frames.Id " // 8
196 " FROM Frames;"))
197 {
198 qDebug();
199 throw PappsoException(
200 QObject::tr("ERROR in TIMS sqlite database file %1, executing SQL "
201 "command %2:\n%3\n%4\n%5")
202 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
203 .arg(q.lastQuery())
204 .arg(q.lastError().databaseText())
205 .arg(q.lastError().driverText())
206 .arg(q.lastError().nativeErrorCode()));
207 }
208
210 while(q.next())
211 {
212 QSqlRecord record = q.record();
213 TimsFrameRecord &frame_record =
214 m_mapFramesRecord[record.value(8).toULongLong()];
215
216 frame_record.frame_id = record.value(8).toULongLong();
217 frame_record.tims_offset = record.value(0).toULongLong();
218 frame_record.accumulation_time = record.value(1).toDouble();
219 frame_record.mz_calibration_id = record.value(2).toULongLong();
220 frame_record.frame_t1 = record.value(3).toDouble();
221 frame_record.frame_t2 = record.value(4).toDouble();
222 frame_record.frame_time = record.value(5).toDouble();
223 frame_record.msms_type = record.value(6).toInt();
224 frame_record.tims_calibration_id = record.value(7).toULongLong();
225 }
226
227 qDebug();
228}
QSqlDatabase openDatabaseConnection() const
Definition timsdata.cpp:231
TimsDdaPrecursors * mpa_timsDdaPrecursors
Definition timsdata.h:255
friend TimsDdaPrecursors
Definition timsdata.h:71
std::vector< TimsFrameRecord > m_mapFramesRecord
Definition timsdata.h:267
std::size_t m_totalScanCount
Definition timsdata.h:258
std::map< int, QSqlRecord > m_mapMzCalibrationRecord
Definition timsdata.h:265
std::map< int, QSqlRecord > m_mapTimsCalibrationRecord
Definition timsdata.h:266
void fillFrameIdDescrList()
private function to fill m_frameIdDescrList
Definition timsdata.cpp:288
friend TimsDiaSlices
Definition timsdata.h:72
QDir m_timsDataDirectory
Definition timsdata.h:252
MzCalibrationStore * mpa_mzCalibrationStore
Definition timsdata.h:269
TimsBinDec * mpa_timsBinDec
Definition timsdata.h:253
TimsDiaSlices * mpa_timsDiaSlices
Definition timsdata.h:256
std::size_t m_frameCount
Definition timsdata.h:259

References pappso::TimsFrameRecord::accumulation_time, fillFrameIdDescrList(), pappso::TimsFrameRecord::frame_id, pappso::TimsFrameRecord::frame_t1, pappso::TimsFrameRecord::frame_t2, pappso::TimsFrameRecord::frame_time, m_frameCount, m_mapFramesRecord, 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.

◆ TimsData() [2/2]

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

Copy constructor

Parameters
otherTODO

Definition at line 261 of file timsdata.cpp.

262{
263 qDebug();
264}

◆ ~TimsData()

pappso::TimsData::~TimsData ( )
virtual

Destructor

Definition at line 266 of file timsdata.cpp.

267{
268 // m_qdb.close();
269 if(mpa_timsBinDec != nullptr)
270 {
271 delete mpa_timsBinDec;
272 }
273 if(mpa_mzCalibrationStore != nullptr)
274 {
276 }
277 if(mpa_timsDdaPrecursors != nullptr)
278 {
280 }
281 if(mpa_timsDiaSlices != nullptr)
282 {
283 delete mpa_timsDiaSlices;
284 }
285}

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

289{
290 qDebug();
291 QSqlDatabase qdb = openDatabaseConnection();
292
293 QSqlQuery q =
294 qdb.exec(QString("SELECT Id, NumScans FROM "
295 "Frames ORDER BY Id"));
296 if(q.lastError().isValid())
297 {
298
299 throw PappsoException(
300 QObject::tr("ERROR in TIMS sqlite database file %1, executing SQL "
301 "command %2:\n%3\n%4\n%5")
302 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
303 .arg(q.lastQuery())
304 .arg(qdb.lastError().databaseText())
305 .arg(qdb.lastError().driverText())
306 .arg(qdb.lastError().nativeErrorCode()));
307 }
308 TimsFrameSPtr tims_frame;
309 bool index_found = false;
310 std::size_t timsId;
311 /** @brief number of scans in mobility dimension (number of TOF scans)
312 */
313 std::size_t numberScans;
314 std::size_t cumulScans = 0;
315 while(q.next() && (!index_found))
316 {
317 timsId = q.value(0).toULongLong();
318 numberScans = q.value(1).toULongLong();
319
320 // qDebug() << timsId;
321
323 std::pair<std::size_t, std::size_t>((cumulScans / 1000),
324 m_frameIdDescrList.size()));
325
326 m_frameIdDescrList.push_back({timsId, numberScans, cumulScans});
327 cumulScans += numberScans;
328 }
329 qDebug();
330}
std::vector< FrameIdDescr > m_frameIdDescrList
store every frame id and corresponding sizes
Definition timsdata.h:274
std::map< std::size_t, std::size_t > m_thousandIndexToFrameIdDescrListIndex
index to find quickly a frameId in the description list with the raw index of spectrum modulo 1000 @k...
Definition timsdata.h:281
std::shared_ptr< TimsFrame > TimsFrameSPtr
Definition timsframe.h:42

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

Referenced by TimsData().

◆ getFrameCount()

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

Definition at line 686 of file timsdata.cpp.

687{
688 return m_frameCount;
689}

References m_frameCount.

◆ getFrameIdDescrList()

◆ getGlobalScanIndexByScanCoordinates()

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

Definition at line 381 of file timsdata.cpp.

383{
384
385 for(auto frameDescr : m_frameIdDescrList)
386 {
387 if(frameDescr.m_frameId == frame_id)
388 {
389 return frameDescr.m_globalScanIndex + index;
390 }
391 }
392
393 throw ExceptionNotFound(
394 QObject::tr("ERROR raw index with frame_id=%1 scan_index=%2 not found")
395 .arg(frame_id)
396 .arg(index));
397}

References m_frameIdDescrList.

Referenced by getQualifiedMassSpectrumByGlobalScanIndex(), getRawIndexFromCoordinate(), and pappso::TimsDdaPrecursors::rawReaderSpectrumCollectionByMsLevel().

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

670{
671 qDebug() << " timsId=" << timsId << " scanNum=" << scanNum;
673
674 return frame->getMassSpectrumCstSPtr(scanNum);
675}
TimsFrameCstSPtr getTimsFrameCstSPtrCached(std::size_t timsId)
get a Tims frame with his database ID but look in the cache first
Definition timsdata.cpp:953
std::shared_ptr< const TimsFrame > TimsFrameCstSPtr
Definition timsframe.h:43

References getTimsFrameCstSPtrCached().

Referenced by getMassSpectrumCstSPtrByGlobalScanIndex().

◆ getMassSpectrumCstSPtrByGlobalScanIndex()

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

Definition at line 410 of file timsdata.cpp.

411{
412
413 qDebug() << " raw_index=" << raw_index;
414 try
415 {
416 auto coordinate = getScanCoordinatesByGlobalScanIndex(raw_index);
417 return getMassSpectrumCstSPtr(coordinate.first, coordinate.second);
418 }
419 catch(PappsoException &error)
420 {
421 throw PappsoException(
422 QObject::tr("Error TimsData::getMassSpectrumCstSPtrByRawIndex "
423 "raw_index=%1 :\n%2")
424 .arg(raw_index)
425 .arg(error.qwhat()));
426 }
427}
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:669
std::pair< std::size_t, std::size_t > getScanCoordinatesByGlobalScanIndex(std::size_t index) const
Definition timsdata.cpp:339

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

Referenced by getMassSpectrumCstSPtrByRawIndex(), pappso::TimsFramesMsRunReader::massSpectrumCstSPtr(), and pappso::TimsMsRunReader::massSpectrumCstSPtr().

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

405{
407}
pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtrByGlobalScanIndex(std::size_t index)
Definition timsdata.cpp:410

References getMassSpectrumCstSPtrByGlobalScanIndex().

◆ getMsLevelByGlobalScanIndex()

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

Definition at line 713 of file timsdata.cpp.

714{
715 auto coordinate = getScanCoordinatesByGlobalScanIndex(index);
716 auto tims_frame = getTimsFrameCstSPtrCached(coordinate.first);
717 return tims_frame.get()->getMsLevel();
718}

References getScanCoordinatesByGlobalScanIndex(), and getTimsFrameCstSPtrCached().

Referenced by getMsLevelBySpectrumIndex().

◆ getMsLevelBySpectrumIndex()

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

Definition at line 706 of file timsdata.cpp.

707{
708 return getMsLevelByGlobalScanIndex(index);
709}
unsigned int getMsLevelByGlobalScanIndex(std::size_t index)
Definition timsdata.cpp:713

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

739{
740
741
742 try
743 {
744 auto coordinate = getScanCoordinatesByGlobalScanIndex(global_scan_index);
745 TimsFrameBaseCstSPtr tims_frame;
746 if(want_binary_data)
747 {
748 tims_frame = getTimsFrameCstSPtrCached(coordinate.first);
749 }
750 else
751 {
752 tims_frame = getTimsFrameBaseCstSPtrCached(coordinate.first);
753 }
754 MassSpectrumId spectrum_id;
755
756 spectrum_id.setSpectrumIndex(global_scan_index);
757 spectrum_id.setMsRunId(msrun_id);
758 spectrum_id.setNativeId(
759 QString("frame_id=%1 scan_index=%2 global_scan_index=%3")
760 .arg(coordinate.first)
761 .arg(coordinate.second)
762 .arg(global_scan_index));
763
764 mass_spectrum.setMassSpectrumId(spectrum_id);
765
766 mass_spectrum.setMsLevel(tims_frame.get()->getMsLevel());
767 mass_spectrum.setRtInSeconds(tims_frame.get()->getRtInSeconds());
768
769 mass_spectrum.setDtInMilliSeconds(
770 tims_frame.get()->getDriftTimeInMilliseconds(coordinate.second));
771 // 1/K0
772 mass_spectrum.setParameterValue(
774 tims_frame.get()->getOneOverK0Transformation(coordinate.second));
775
776 mass_spectrum.setEmptyMassSpectrum(true);
777 if(want_binary_data)
778 {
779 mass_spectrum.setMassSpectrumSPtr(
780 tims_frame.get()->getMassSpectrumSPtr(coordinate.second));
781 if(mass_spectrum.size() > 0)
782 {
783 mass_spectrum.setEmptyMassSpectrum(false);
784 }
785 }
786 else
787 {
788 // if(tims_frame.get()->getNbrPeaks(coordinate.second) > 0)
789 //{
790 mass_spectrum.setEmptyMassSpectrum(false);
791 // }
792 }
793 if(tims_frame.get()->getMsLevel() > 1)
794 {
795
796 if(mpa_timsDdaPrecursors != nullptr)
797 {
798 auto spectrum_descr =
800 coordinate);
801 if(spectrum_descr.precursor_id > 0)
802 {
803
804 mass_spectrum.appendPrecursorIonData(
805 spectrum_descr.precursor_ion_data);
806
807
808 MassSpectrumId spectrum_id;
809 std::size_t prec_spectrum_index =
811 spectrum_descr.parent_frame, coordinate.second);
812
813 mass_spectrum.setPrecursorSpectrumIndex(prec_spectrum_index);
814 mass_spectrum.setPrecursorNativeId(
815 QString("frame_id=%1 scan_index=%2 global_scan_index=%3")
816 .arg(spectrum_descr.parent_frame)
817 .arg(coordinate.second)
818 .arg(prec_spectrum_index));
819
820 mass_spectrum.setParameterValue(
822 spectrum_descr.isolationMz);
823 mass_spectrum.setParameterValue(
825 spectrum_descr.isolationWidth);
826
827 mass_spectrum.setParameterValue(
829 spectrum_descr.collisionEnergy);
830 mass_spectrum.setParameterValue(
832 (quint64)spectrum_descr.precursor_id);
833 }
834 }
835 }
836 }
837 catch(PappsoException &error)
838 {
839 throw PappsoException(
840 QObject::tr("Error TimsData::getQualifiedMassSpectrumByRawIndex "
841 "spectrum_index=%1 :\n%2")
842 .arg(global_scan_index)
843 .arg(error.qwhat()));
844 }
845}
std::size_t getGlobalScanIndexByScanCoordinates(std::size_t frame_id, std::size_t index) const
Definition timsdata.cpp:381
TimsFrameBaseCstSPtr getTimsFrameBaseCstSPtrCached(std::size_t timsId)
Definition timsdata.cpp:932
SpectrumDescr getSpectrumDescrWithScanCoordinates(const std::pair< std::size_t, std::size_t > &scan_coordinates)
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(), pappso::TimsDdaPrecursors::getSpectrumDescrWithScanCoordinates(), 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(), pappso::TimsFramesMsRunReader::qualifiedMassSpectrum(), and pappso::TimsMsRunReader::qualifiedMassSpectrum().

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

727{
728
730 msrun_id, mass_spectrum, global_scan_index, want_binary_data);
731}
void getQualifiedMassSpectrumByGlobalScanIndex(const MsRunIdCstSPtr &msrun_id, QualifiedMassSpectrum &mass_spectrum, std::size_t global_scan_index, bool want_binary_data)
Definition timsdata.cpp:734

References getQualifiedMassSpectrumByGlobalScanIndex().

◆ getRawIndexFromCoordinate()

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

Definition at line 373 of file timsdata.cpp.

375{
376
377 return getGlobalScanIndexByScanCoordinates(frame_id, index);
378}

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

1054{
1055 return getScanByGlobalScanIndex(index);
1056}
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 1031 of file timsdata.cpp.

1032{
1034}
virtual std::vector< double > getRetentionTimeLineInSeconds() const

References getRetentionTimeLineInSeconds().

◆ getRetentionTimeLineInSeconds()

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

Definition at line 1037 of file timsdata.cpp.

1038{
1039
1040 std::vector<double> timeline;
1041 timeline.reserve(m_mapFramesRecord.size());
1042 for(const TimsFrameRecord &frame_record : m_mapFramesRecord)
1043 {
1044 if(frame_record.mz_calibration_id != 0)
1045 {
1046 timeline.push_back(frame_record.frame_time);
1047 }
1048 }
1049 return timeline;
1050}

References m_mapFramesRecord.

Referenced by getRetentionTimeLine().

◆ getScanByGlobalScanIndex()

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

Definition at line 1059 of file timsdata.cpp.

1060{
1061 qDebug() << " spectrum_index=" << index;
1062 auto coordinate = getScanCoordinatesByGlobalScanIndex(index);
1063 TimsFrameBaseCstSPtr tims_frame;
1064 tims_frame = getTimsFrameCstSPtrCached(coordinate.first);
1065
1066 TimsDataFastMap &raw_spectrum = TimsDataFastMap::getTimsDataFastMapInstance();
1067 raw_spectrum.clear();
1068 tims_frame.get()->combineScansInTofIndexIntensityMap(
1069 raw_spectrum, coordinate.second, coordinate.second);
1070 return raw_spectrum;
1071}
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 333 of file timsdata.cpp.

334{
335 return getScanCoordinatesByGlobalScanIndex(raw_index);
336}

References getScanCoordinatesByGlobalScanIndex().

◆ getScanCoordinatesByGlobalScanIndex()

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

Definition at line 339 of file timsdata.cpp.

340{
341 std::size_t fast_access = raw_index / 1000;
342 qDebug() << " fast_access=" << fast_access;
343 auto map_it = m_thousandIndexToFrameIdDescrListIndex.find(fast_access);
345 {
346 throw ExceptionNotFound(
347 QObject::tr("ERROR raw index %1 not found (fast_access)")
348 .arg(raw_index));
349 }
350 std::size_t start_point_index = map_it->second;
351 while((start_point_index > 0) &&
352 (m_frameIdDescrList[start_point_index].m_globalScanIndex > raw_index))
353 {
354 start_point_index--;
355 }
356 for(std::size_t i = start_point_index; i < m_frameIdDescrList.size(); i++)
357 {
358
359 if(raw_index < (m_frameIdDescrList[i].m_globalScanIndex +
360 m_frameIdDescrList[i].m_scanCount))
361 {
362 return std::pair<std::size_t, std::size_t>(
363 m_frameIdDescrList[i].m_frameId,
364 raw_index - m_frameIdDescrList[i].m_globalScanIndex);
365 }
366 }
367
368 throw ExceptionNotFound(
369 QObject::tr("ERROR raw index %1 not found").arg(raw_index));
370}

References m_frameIdDescrList, and m_thousandIndexToFrameIdDescrListIndex.

Referenced by getMassSpectrumCstSPtrByGlobalScanIndex(), pappso::TimsDdaPrecursors::getMatchPrecursorIdByKo(), getMsLevelByGlobalScanIndex(), getQualifiedMassSpectrumByGlobalScanIndex(), getScanByGlobalScanIndex(), and getScanCoordinateFromRawIndex().

◆ getTicChromatogram()

Trace pappso::TimsData::getTicChromatogram ( ) const

Definition at line 848 of file timsdata.cpp.

849{
850 // In the Frames table, each frame has a record describing the
851 // SummedIntensities for all the mobility spectra.
852
853
854 MapTrace rt_tic_map_trace;
855
856 using Pair = std::pair<double, double>;
857 using Map = std::map<double, double>;
858 using Iterator = Map::iterator;
859
860
861 QSqlDatabase qdb = openDatabaseConnection();
862 QSqlQuery q =
863 qdb.exec(QString("SELECT Time, SummedIntensities "
864 "FROM Frames WHERE MsMsType = 0 "
865 "ORDER BY Time;"));
866
867 if(q.lastError().isValid())
868 {
869
870 throw PappsoException(
871 QObject::tr("ERROR in TIMS sqlite database file %1, database name %2, "
872 "executing SQL "
873 "command %3:\n%4\n%5\n%6")
874 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
875 .arg(qdb.databaseName())
876 .arg(q.lastQuery())
877 .arg(qdb.lastError().databaseText())
878 .arg(qdb.lastError().driverText())
879 .arg(qdb.lastError().nativeErrorCode()));
880 }
881
882 while(q.next())
883 {
884
885 bool ok = false;
886
887 int cumulated_results = 2;
888
889 double rt = q.value(0).toDouble(&ok);
890 cumulated_results -= ok;
891
892 double sumY = q.value(1).toDouble(&ok);
893 cumulated_results -= ok;
894
895 if(cumulated_results)
896 {
897 throw PappsoException(
898 QObject::tr(
899 "ERROR in TIMS sqlite database file: could not read either the "
900 "retention time or the summed intensities (%1, database name "
901 "%2, "
902 "executing SQL "
903 "command %3:\n%4\n%5\n%6")
904 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
905 .arg(qdb.databaseName())
906 .arg(q.lastQuery())
907 .arg(qdb.lastError().databaseText())
908 .arg(qdb.lastError().driverText())
909 .arg(qdb.lastError().nativeErrorCode()));
910 }
911
912 // Try to insert value sumY at key rt.
913 std::pair<Iterator, bool> res = rt_tic_map_trace.insert(Pair(rt, sumY));
914
915 if(!res.second)
916 {
917 // One other same rt value was seen already (like in ion mobility
918 // mass spectrometry, for example). Only increment the y value.
919
920 res.first->second += sumY;
921 }
922 }
923
924 // qDebug().noquote() << "The TIC chromatogram:\n"
925 //<< rt_tic_map_trace.toTrace().toString();
926
927 return rt_tic_map_trace.toTrace();
928}
@ rt
Retention time.

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

Referenced by pappso::TimsMsRunReaderMs2::getTicChromatogram().

◆ getTimsBinDecPtr()

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

Definition at line 1102 of file timsdata.cpp.

1103{
1104 return mpa_timsBinDec;
1105}

References mpa_timsBinDec.

Referenced by pappso::TimsDdaPrecursors::ms2ReaderSpectrumCollectionByMsLevel().

◆ getTimsDataDirectory()

◆ getTimsDdaPrecursorsPtr()

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

◆ getTimsDiaSlicesPtr()

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

Definition at line 1124 of file timsdata.cpp.

1125{
1126 qDebug();
1127 if(mpa_timsDiaSlices == nullptr)
1128 {
1129 throw pappso::PappsoException("TimsData does not contain DIA slices");
1130 }
1131 return mpa_timsDiaSlices;
1132}

References mpa_timsDiaSlices.

Referenced by pappso::TimsMsRunReader::readSpectrumCollection2().

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

431{
432
433 qDebug() << " timsId=" << timsId;
434
435 const TimsFrameRecord &frame_record = m_mapFramesRecord[timsId];
436 if(timsId > m_totalScanCount)
437 {
438 throw ExceptionNotFound(
439 QObject::tr("ERROR Frames database id %1 not found").arg(timsId));
440 }
441 TimsFrameBaseSPtr tims_frame;
442
443
444 tims_frame = std::make_shared<TimsFrameBase>(
445 TimsFrameBase(timsId, frame_record.tims_offset));
446
447 auto it_map_record =
448 m_mapMzCalibrationRecord.find(frame_record.mz_calibration_id);
449 if(it_map_record != m_mapMzCalibrationRecord.end())
450 {
451
452 double T1_frame = frame_record.frame_t1; // Frames.T1
453 double T2_frame = frame_record.frame_t2; // Frames.T2
454
455
456 tims_frame.get()->setMzCalibrationInterfaceSPtr(
458 T1_frame, T2_frame, it_map_record->second));
459 }
460 else
461 {
462 throw ExceptionNotFound(
463 QObject::tr("ERROR MzCalibration database id %1 not found")
464 .arg(frame_record.mz_calibration_id));
465 }
466
467
468 tims_frame.get()->setAcqDurationInMilliseconds(
469 frame_record.accumulation_time);
470
471 tims_frame.get()->setRtInSeconds(frame_record.frame_time);
472 tims_frame.get()->setMsMsType(frame_record.msms_type);
473
474
475 auto it_map_record_tims_calibration =
476 m_mapTimsCalibrationRecord.find(frame_record.tims_calibration_id);
477 if(it_map_record_tims_calibration != m_mapTimsCalibrationRecord.end())
478 {
479
480 tims_frame.get()->setTimsCalibration(
481 it_map_record_tims_calibration->second.value(1).toInt(),
482 it_map_record_tims_calibration->second.value(2).toDouble(),
483 it_map_record_tims_calibration->second.value(3).toDouble(),
484 it_map_record_tims_calibration->second.value(4).toDouble(),
485 it_map_record_tims_calibration->second.value(5).toDouble(),
486 it_map_record_tims_calibration->second.value(6).toDouble(),
487 it_map_record_tims_calibration->second.value(7).toDouble(),
488 it_map_record_tims_calibration->second.value(8).toDouble(),
489 it_map_record_tims_calibration->second.value(9).toDouble(),
490 it_map_record_tims_calibration->second.value(10).toDouble(),
491 it_map_record_tims_calibration->second.value(11).toDouble());
492 }
493 else
494 {
495 throw ExceptionNotFound(
496 QObject::tr("ERROR TimsCalibration database id %1 not found")
497 .arg(frame_record.tims_calibration_id));
498 }
499
500 return tims_frame;
501}
MzCalibrationInterfaceSPtr getInstance(double T1_frame, double T2_frame, const QSqlRecord &mzcalibration_record)
std::shared_ptr< TimsFrameBase > TimsFrameBaseSPtr

References pappso::TimsFrameRecord::accumulation_time, pappso::TimsFrameRecord::frame_t1, pappso::TimsFrameRecord::frame_t2, pappso::TimsFrameRecord::frame_time, pappso::MzCalibrationStore::getInstance(), 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 932 of file timsdata.cpp.

933{
934 QMutexLocker locker(&m_mutex);
935 for(auto &tims_frame : m_timsFrameBaseCache)
936 {
937 if(tims_frame.get()->getId() == timsId)
938 {
939 m_timsFrameBaseCache.push_back(tims_frame);
941 m_timsFrameBaseCache.pop_front();
942 return tims_frame;
943 }
944 }
945
948 m_timsFrameBaseCache.pop_front();
949 return m_timsFrameBaseCache.back();
950}
std::size_t m_cacheSize
Definition timsdata.h:260
TimsFrameBaseCstSPtr getTimsFrameBaseCstSPtr(std::size_t timsId)
get a Tims frame base (no binary data file access) with his database ID
Definition timsdata.cpp:430
std::deque< TimsFrameBaseCstSPtr > m_timsFrameBaseCache
Definition timsdata.h:262

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

Referenced by pappso::TimsDdaPrecursors::getMatchPrecursorIdByKo(), getQualifiedMassSpectrumByGlobalScanIndex(), pappso::TimsDdaPrecursors::getQualifiedMs1MassSpectrumBySpectrumDescr(), pappso::TimsDdaPrecursors::getQualifiedMs2MassSpectrumBySpectrumDescr(), and pappso::TimsDdaPrecursors::rawReaderSpectrumCollectionByMsLevel().

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

580{
581
582 qDebug() << " timsId=" << timsId
583 << " m_mapFramesRecord.size()=" << m_mapFramesRecord.size();
584
585 /*
586 for(auto pair_i : m_mapFramesRecord)
587 {
588
589 qDebug() << " pair_i=" << pair_i.first;
590 }
591 */
592
593 const TimsFrameRecord &frame_record = m_mapFramesRecord[timsId];
594 if(timsId > m_totalScanCount)
595 {
596 throw ExceptionNotFound(
597 QObject::tr("ERROR Frames database id %1 not found").arg(timsId));
598 }
599
600 TimsFrameSPtr tims_frame;
601
602
603 // QMutexLocker lock(&m_mutex);
604 tims_frame =
606 // lock.unlock();
607
608 qDebug();
609 auto it_map_record =
610 m_mapMzCalibrationRecord.find(frame_record.mz_calibration_id);
611 if(it_map_record != m_mapMzCalibrationRecord.end())
612 {
613
614 double T1_frame = frame_record.frame_t1; // Frames.T1
615 double T2_frame = frame_record.frame_t2; // Frames.T2
616
617
618 tims_frame.get()->setMzCalibrationInterfaceSPtr(
620 T1_frame, T2_frame, it_map_record->second));
621 }
622 else
623 {
624 throw ExceptionNotFound(
625 QObject::tr(
626 "ERROR MzCalibration database id %1 not found for frame_id=%2")
627 .arg(frame_record.mz_calibration_id)
628 .arg(timsId));
629 }
630
631
632 tims_frame.get()->setAcqDurationInMilliseconds(
633 frame_record.accumulation_time);
634
635 tims_frame.get()->setRtInSeconds(frame_record.frame_time);
636 tims_frame.get()->setMsMsType(frame_record.msms_type);
637
638 qDebug();
639 auto it_map_record_tims_calibration =
640 m_mapTimsCalibrationRecord.find(frame_record.tims_calibration_id);
641 if(it_map_record_tims_calibration != m_mapTimsCalibrationRecord.end())
642 {
643
644 tims_frame.get()->setTimsCalibration(
645 it_map_record_tims_calibration->second.value(1).toInt(),
646 it_map_record_tims_calibration->second.value(2).toDouble(),
647 it_map_record_tims_calibration->second.value(3).toDouble(),
648 it_map_record_tims_calibration->second.value(4).toDouble(),
649 it_map_record_tims_calibration->second.value(5).toDouble(),
650 it_map_record_tims_calibration->second.value(6).toDouble(),
651 it_map_record_tims_calibration->second.value(7).toDouble(),
652 it_map_record_tims_calibration->second.value(8).toDouble(),
653 it_map_record_tims_calibration->second.value(9).toDouble(),
654 it_map_record_tims_calibration->second.value(10).toDouble(),
655 it_map_record_tims_calibration->second.value(11).toDouble());
656 }
657 else
658 {
659 throw ExceptionNotFound(
660 QObject::tr("ERROR TimsCalibration database id %1 not found")
661 .arg(frame_record.tims_calibration_id));
662 }
663 qDebug();
664 return tims_frame;
665}
TimsFrameSPtr getTimsFrameSPtrByOffset(std::size_t frameId, const std::vector< pappso::TimsFrameRecord > &frame_record_list)

References pappso::TimsFrameRecord::accumulation_time, pappso::TimsFrameRecord::frame_t1, pappso::TimsFrameRecord::frame_t2, pappso::TimsFrameRecord::frame_time, pappso::MzCalibrationStore::getInstance(), pappso::TimsBinDec::getTimsFrameSPtrByOffset(), 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 953 of file timsdata.cpp.

954{
955 qDebug();
956 QMutexLocker locker(&m_mutex);
957 for(auto &tims_frame : m_timsFrameCache)
958 {
959 if(tims_frame.get()->getId() == timsId)
960 {
961 m_timsFrameCache.push_back(tims_frame);
962 if(m_timsFrameCache.size() > m_cacheSize)
963 m_timsFrameCache.pop_front();
964 return tims_frame;
965 }
966 }
967 TimsFrameCstSPtr frame_sptr = getTimsFrameCstSPtr(timsId);
968
969 // locker.relock();
970 qDebug();
971
972 m_timsFrameCache.push_back(frame_sptr);
973 if(m_timsFrameCache.size() > m_cacheSize)
974 m_timsFrameCache.pop_front();
975 qDebug();
976 return m_timsFrameCache.back();
977
978
979 /*
980// the frame is not in the cache
981if(std::find(m_someoneIsLoadingFrameId.begin(),
982 m_someoneIsLoadingFrameId.end(),
983 timsId) == m_someoneIsLoadingFrameId.end())
984 {
985 // not found, we are alone on this frame
986 m_someoneIsLoadingFrameId.push_back(timsId);
987 qDebug();
988 //locker.unlock();
989 TimsFrameCstSPtr frame_sptr = getTimsFrameCstSPtr(timsId);
990
991 // locker.relock();
992 qDebug();
993 m_someoneIsLoadingFrameId.erase(
994 std::find(m_someoneIsLoadingFrameId.begin(),
995 m_someoneIsLoadingFrameId.end(),
996 timsId));
997
998 m_timsFrameCache.push_back(frame_sptr);
999 if(m_timsFrameCache.size() > m_cacheSize)
1000 m_timsFrameCache.pop_front();
1001 qDebug();
1002 return m_timsFrameCache.back();
1003 }
1004else
1005 {
1006 // this frame is loading by someone else, we have to wait
1007 qDebug();
1008 // locker.unlock();
1009 // std::size_t another_frame_id = timsId;
1010 while(true)
1011 {
1012 QThread::usleep(1);
1013 // locker.relock();
1014
1015 for(auto &tims_frame : m_timsFrameCache)
1016 {
1017 if(tims_frame.get()->getId() == timsId)
1018 {
1019 m_timsFrameCache.push_back(tims_frame);
1020 return tims_frame;
1021 }
1022 }
1023 // locker.unlock();
1024}
1025} // namespace pappso
1026*/
1027}
TimsFrameCstSPtr getTimsFrameCstSPtr(std::size_t timsId)
get a Tims frame with his database ID
Definition timsdata.cpp:579
std::deque< TimsFrameCstSPtr > m_timsFrameCache
Definition timsdata.h:261

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

Referenced by pappso::TimsFramesMsRunReader::computeTicChromatogram(), pappso::TimsDdaPrecursors::getCombinedMs2ScansByPrecursorId(), getMassSpectrumCstSPtr(), getMsLevelByGlobalScanIndex(), getQualifiedMassSpectrumByGlobalScanIndex(), pappso::TimsDdaPrecursors::getQualifiedMs1MassSpectrumBySpectrumDescr(), pappso::TimsDdaPrecursors::getQualifiedMs2MassSpectrumBySpectrumDescr(), getScanByGlobalScanIndex(), pappso::TimsDdaPrecursors::rawReaderSpectrumCollectionByMsLevel(), pappso::TimsFramesMsRunReader::readSpectrumCollection2(), and pappso::TimsMsRunReader::readSpectrumCollection2().

◆ getTimsFrameRecordList()

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

◆ getTimsMS1FrameIdsInRtRange()

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

Definition at line 504 of file timsdata.cpp.

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

References m_timsDataDirectory, and openDatabaseConnection().

◆ getTimsMS2FrameIdsInRtRange()

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

Definition at line 541 of file timsdata.cpp.

542{
543
544 qDebug() << " rt_begin=" << rt_begin << " rt_end=" << rt_end;
545 if(rt_begin < 0)
546 rt_begin = 0;
547 std::vector<std::size_t> tims_frameid_list;
548 QSqlDatabase qdb = openDatabaseConnection();
549 QSqlQuery q =
550 qdb.exec(QString("SELECT Frames.Id FROM Frames WHERE "
551 "Frames.MsMsType=8 AND "
552 "(Frames.Time>=%1) AND (Frames.Time<=%2) ORDER BY "
553 "Frames.Time;")
554 .arg(rt_begin)
555 .arg(rt_end));
556 if(q.lastError().isValid())
557 {
558
559 throw PappsoException(
560 QObject::tr("ERROR in TIMS sqlite database file %1, database name %2, "
561 "executing SQL "
562 "command %3:\n%4\n%5\n%6")
563 .arg(m_timsDataDirectory.absoluteFilePath("analysis.tdf"))
564 .arg(qdb.databaseName())
565 .arg(q.lastQuery())
566 .arg(qdb.lastError().databaseText())
567 .arg(qdb.lastError().driverText())
568 .arg(qdb.lastError().nativeErrorCode()));
569 }
570 while(q.next())
571 {
572
573 tims_frameid_list.push_back(q.value(0).toULongLong());
574 }
575 return tims_frameid_list;
576}

References m_timsDataDirectory, and openDatabaseConnection().

◆ getTotalNumberOfFrames()

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

Get total number of frames.

Definition at line 679 of file timsdata.cpp.

680{
681 return m_frameCount;
682}

References m_frameCount.

◆ getTotalNumberOfScans()

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

get the total number of scans

Definition at line 693 of file timsdata.cpp.

694{
695 return m_totalScanCount;
696}

References m_totalScanCount.

◆ getTotalScanCount()

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

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

1109{
1110 if(mpa_timsDdaPrecursors == nullptr)
1111 return false;
1112 return true;
1113}

References mpa_timsDdaPrecursors.

Referenced by pappso::TimsMsRunReader::readSpectrumCollection2(), and pappso::TimsMsRunReader::readSpectrumCollectionByMsLevel().

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

1117{
1118 if(mpa_timsDiaSlices == nullptr)
1119 return false;
1120 return true;
1121}

Referenced by pappso::TimsMsRunReader::readSpectrumCollection2().

◆ openDatabaseConnection()

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

Definition at line 231 of file timsdata.cpp.

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

References m_timsDataDirectory.

Referenced by TimsData(), fillFrameIdDescrList(), pappso::TimsDdaPrecursors::getCombinedMs2ScansByPrecursorId(), pappso::TimsDdaPrecursors::getPrecursorsByMzRtCharge(), pappso::TimsDdaPrecursors::getSpectrumDescrListByFrameId(), pappso::TimsDdaPrecursors::getSpectrumDescrWithPrecursorId(), pappso::TimsDdaPrecursors::getSpectrumDescrWithScanCoordinates(), getTicChromatogram(), getTimsMS1FrameIdsInRtRange(), getTimsMS2FrameIdsInRtRange(), pappso::TimsDdaPrecursors::getXicCoordTimsFromPrecursorId(), pappso::TimsDdaPrecursors::ms2ReaderSpectrumCollectionByMsLevel(), and pappso::TimsDdaPrecursors::rawReaderSpectrumCollectionByMsLevel().

Member Data Documentation

◆ m_cacheSize

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

Definition at line 260 of file timsdata.h.

Referenced by getTimsFrameBaseCstSPtrCached(), and getTimsFrameCstSPtrCached().

◆ m_frameCount

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

Definition at line 259 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 274 of file timsdata.h.

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

◆ m_mapFramesRecord

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

◆ m_mapMzCalibrationRecord

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

Definition at line 265 of file timsdata.h.

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

◆ m_mapTimsCalibrationRecord

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

Definition at line 266 of file timsdata.h.

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

◆ m_mutex

QMutex pappso::TimsData::m_mutex
private

Definition at line 288 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 286 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 281 of file timsdata.h.

Referenced by fillFrameIdDescrList(), and getScanCoordinatesByGlobalScanIndex().

◆ m_timsDataDirectory

◆ m_timsFrameBaseCache

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

Definition at line 262 of file timsdata.h.

Referenced by getTimsFrameBaseCstSPtrCached().

◆ m_timsFrameCache

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

Definition at line 261 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 269 of file timsdata.h.

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

◆ mpa_timsBinDec

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

Definition at line 253 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 256 of file timsdata.h.

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

◆ TimsDdaPrecursors

friend pappso::TimsData::TimsDdaPrecursors
private

Definition at line 71 of file timsdata.h.

Referenced by TimsData().

◆ TimsDiaSlices

friend pappso::TimsData::TimsDiaSlices
private

Definition at line 72 of file timsdata.h.

Referenced by TimsData().


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