Loading...
Searching...
No Matches
timsdata.h
Go to the documentation of this file.
/**
* \file pappsomspp/vendors/tims/timsdata.h
* \date 27/08/2019
* \author Olivier Langella
* \brief main Tims data handler
*/
/*******************************************************************************
* Copyright (c) 2019 Olivier Langella <Olivier.Langella@u-psud.fr>.
*
* This file is part of the PAPPSOms++ library.
*
* PAPPSOms++ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAPPSOms++ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
#pragma once
#include <QDir>
#include <QSqlDatabase>
#include "timsbindec.h"
#include "timsframe.h"
#include "../../massspectrum/qualifiedmassspectrum.h"
#include "pappsomspp/core/processing/filters/filterinterface.h"
#include "pappsomspp/core/msrun/xiccoord/xiccoordtims.h"
#include <deque>
#include <QMutex>
#include <QSqlQuery>
#include "mzcalibration/mzcalibrationstore.h"
#include "pappsomspp/core/msrun/spectrumcollectionhandlerinterface.h"
#include "pappsomspp/export-import-config.h"
namespace pappso
{
class TimsData;
class TimsDdaPrecursors;
class TimsDiaSlices;
/** \brief shared pointer on a TimsData object
*/
typedef std::shared_ptr<TimsData> TimsDataSp;
struct PMSPP_LIB_DECL FrameIdDescr
{
std::size_t m_frameId; // frame id
std::size_t m_scanCount; // frame size (number of TOF scans in frame)
std::size_t m_globalScanIndex; // scan index over the whole file
};
/**
* @todo write docs
*/
class PMSPP_LIB_DECL TimsData
{
friend TimsDdaPrecursors;
friend TimsDiaSlices;
public:
/** @brief build using the tims data directory
*/
TimsData(QDir timsDataDirectory);
/**
* Copy constructor
*
* @param other TODO
*/
TimsData(const TimsData &other);
/**
* Destructor
*/
virtual ~TimsData();
/** @brief tells if this MS run is a DDA run
* @result true if it contains DDA precursors
*/
bool isDdaRun() const;
/** @brief tells if this MS run is a DIA run
* @result true if it contains DIA slices
*/
bool isDiaRun() const;
/** @brief get a mass spectrum given its spectrum index
* @param raw_index a number begining at 0, corresponding to a Tims Scan in
* the order they lies in the binary data file
*/
[[deprecated("Please use getMassSpectrumCstSPtrByGlobalScanIndex")]] pappso::MassSpectrumCstSPtr
getMassSpectrumCstSPtrByRawIndex(std::size_t raw_index);
// FIXME NAMING: Identical to above
// Not used in i2mcq
pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtrByGlobalScanIndex(std::size_t index);
/** @brief get a mass spectrum given the tims frame database id and scan
* number within tims frame
*/
pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtr(std::size_t timsId, std::size_t scanNum);
/** @brief Get total number of frames
*/
[[deprecated("Please use getFrameCount")]] std::size_t getTotalNumberOfFrames() const;
// FIXME NAMING : identical to above
// Not used in i2mcq
std::size_t getFrameCount() const;
/** @brief get the total number of scans
*/
[[deprecated("Please use getTotalScanCount")]] std::size_t getTotalNumberOfScans() const;
// FIXME NAMING : identical to above
// Not used in i2mcq
std::size_t getTotalScanCount() const;
[[deprecated("Please use getMsLevelByGlobalScanIndex")]] unsigned int
getMsLevelBySpectrumIndex(std::size_t index);
// FIXME NAMING : identical to above
// Not used in i2mcq
unsigned int getMsLevelByGlobalScanIndex(std::size_t index);
[[deprecated("Please use getQualifiedMassSpectrumByGlobalScanIndex")]] void
getQualifiedMassSpectrumByRawIndex(const MsRunIdCstSPtr &msrun_id,
QualifiedMassSpectrum &mass_spectrum,
std::size_t global_scan_index,
bool want_binary_data);
// FIXME NAMING : identical to above
// Not used in i2mcq
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;
/** @brief get a Tims frame with his database ID
* but look in the cache first
*
* thread safe
*/
TimsFrameCstSPtr getTimsFrameCstSPtrCached(std::size_t timsId);
/** @brief get a Tims frame with his database ID
*
* this function is not thread safe
*/
TimsFrameCstSPtr getTimsFrameCstSPtr(std::size_t timsId);
/** @brief get raw signal for a spectrum index
* only to use to see the raw signal
*
* @param spectrum_index spcetrum index
* @result a map of integers, x=time of flights, y= intensities
*/
[[deprecated("Please use getScanByGlobalScanIndex")]] TimsDataFastMap &
getRawMsBySpectrumIndex(std::size_t index);
// FIXME NAMING: identical to above
// Not used in i2mcq
TimsDataFastMap &getScanByGlobalScanIndex(std::size_t index);
/** @brief retention timeline
* get retention times along the MSrun in seconds
* @return vector of retention times (seconds)
*/
[[deprecated("Please use getRetentionTimeLineInSeconds")]] virtual std::vector<double>
getRetentionTimeLine() const;
// FIXME NAMING: identical to above
virtual std::vector<double> getRetentionTimeLineInSeconds() const;
const std::vector<FrameIdDescr> &getFrameIdDescrList() const;
const std::vector<TimsFrameRecord> &getTimsFrameRecordList() const;
const QDir &getTimsDataDirectory() const;
TimsDdaPrecursors *getTimsDdaPrecursorsPtr() const;
TimsDiaSlices *getTimsDiaSlicesPtr() const;
const QVariant &getGlobalMetadataValue(const QString &key) const;
protected:
QSqlDatabase openDatabaseConnection() const;
TimsBinDec *getTimsBinDecPtr() const;
private:
[[deprecated(
"Please use getScanCoordinatesByGlobalScanIndex")]] std::pair<std::size_t, std::size_t>
getScanCoordinateFromRawIndex(std::size_t spectrum_index) const;
// FIXME NAMING: identical to above
// Not used in i2mcq
std::pair<std::size_t, std::size_t> getScanCoordinatesByGlobalScanIndex(std::size_t index) const;
[[deprecated("Please use getGlobalScanIndexByScanCoordinates")]] std::size_t
getRawIndexFromCoordinate(std::size_t frame_id, std::size_t scan_num) const;
// FIXME NAMING: identical to above
// Not used in i2mcq
std::size_t getGlobalScanIndexByScanCoordinates(std::size_t frame_id, std::size_t index) const;
/** @brief get a Tims frame base (no binary data file access) with his
* database ID
*/
TimsFrameBaseCstSPtr getTimsFrameBaseCstSPtr(std::size_t timsId);
TimsFrameBaseCstSPtr getTimsFrameBaseCstSPtrCached(std::size_t timsId);
/** @brief private function to fill m_frameIdDescrList
*/
void fillFrameIdDescrList();
QDir m_timsDataDirectory;
TimsBinDec *mpa_timsBinDec = nullptr;
TimsDdaPrecursors *mpa_timsDdaPrecursors = nullptr;
TimsDiaSlices *mpa_timsDiaSlices = nullptr;
// QSqlDatabase *mpa_qdb = nullptr;
std::size_t m_totalScanCount;
std::size_t m_frameCount;
std::size_t m_cacheSize = 60;
std::deque<TimsFrameCstSPtr> m_timsFrameCache;
std::deque<TimsFrameBaseCstSPtr> m_timsFrameBaseCache;
std::map<int, QSqlRecord> m_mapMzCalibrationRecord;
std::map<int, QSqlRecord> m_mapTimsCalibrationRecord;
std::vector<TimsFrameRecord> m_mapFramesRecord;
MzCalibrationStore *mpa_mzCalibrationStore;
/** @brief store every frame id and corresponding sizes
*/
std::vector<FrameIdDescr> m_frameIdDescrList;
/** @brief 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::map<std::size_t, std::size_t> m_thousandIndexToFrameIdDescrListIndex;
/** @brief tells if someone is loading a frame id
*/
std::vector<std::size_t> m_someoneIsLoadingFrameId;
std::map<QString, QVariant> m_mapGlobalMetadaTable;
QMutex m_mutex;
};
} // namespace pappso
pappso::MzCalibrationStore
Definition mzcalibrationstore.h:40
pappso::QualifiedMassSpectrum
Class representing a fully specified mass spectrum.
Definition qualifiedmassspectrum.h:99
pappso::TimsBinDec
Definition timsbindec.h:45
pappso::TimsDataFastMap
replacement for std::map
Definition timsdatafastmap.h:46
pappso::TimsData
Definition timsdata.h:68
pappso::TimsData::getGlobalScanIndexByScanCoordinates
std::size_t getGlobalScanIndexByScanCoordinates(std::size_t frame_id, std::size_t index) const
Definition timsdata.cpp:368
pappso::TimsData::openDatabaseConnection
QSqlDatabase openDatabaseConnection() const
Definition timsdata.cpp:224
pappso::TimsData::getTotalScanCount
std::size_t getTotalScanCount() const
Definition timsdata.cpp:673
pappso::TimsData::getTimsDiaSlicesPtr
TimsDiaSlices * getTimsDiaSlicesPtr() const
Definition timsdata.cpp:1088
pappso::TimsData::getTimsFrameCstSPtr
TimsFrameCstSPtr getTimsFrameCstSPtr(std::size_t timsId)
get a Tims frame with his database ID
Definition timsdata.cpp:560
pappso::TimsData::mpa_timsDdaPrecursors
TimsDdaPrecursors * mpa_timsDdaPrecursors
Definition timsdata.h:242
pappso::TimsData::getTimsFrameRecordList
const std::vector< TimsFrameRecord > & getTimsFrameRecordList() const
Definition timsdata.cpp:1044
pappso::TimsData::m_frameIdDescrList
std::vector< FrameIdDescr > m_frameIdDescrList
store every frame id and corresponding sizes
Definition timsdata.h:261
pappso::TimsData::getTimsFrameCstSPtrCached
TimsFrameCstSPtr getTimsFrameCstSPtrCached(std::size_t timsId)
get a Tims frame with his database ID but look in the cache first
Definition timsdata.cpp:917
pappso::TimsData::getMassSpectrumCstSPtrByRawIndex
pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtrByRawIndex(std::size_t raw_index)
get a mass spectrum given its spectrum index
Definition timsdata.cpp:389
pappso::TimsData::getScanByGlobalScanIndex
TimsDataFastMap & getScanByGlobalScanIndex(std::size_t index)
Definition timsdata.cpp:1023
pappso::TimsData::TimsDdaPrecursors
friend TimsDdaPrecursors
Definition timsdata.h:69
pappso::TimsData::getFrameIdDescrList
const std::vector< FrameIdDescr > & getFrameIdDescrList() const
Definition timsdata.cpp:1038
pappso::TimsData::getTotalNumberOfFrames
std::size_t getTotalNumberOfFrames() const
Get total number of frames.
Definition timsdata.cpp:652
pappso::TimsData::getTimsMS1FrameIdsInRtRange
std::vector< std::size_t > getTimsMS1FrameIdsInRtRange(double rt_begin, double rt_end) const
Definition timsdata.cpp:481
pappso::TimsData::getMassSpectrumCstSPtr
pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtr(std::size_t timsId, std::size_t scanNum)
get a mass spectrum given the tims frame database id and scan number within tims frame
Definition timsdata.cpp:642
pappso::TimsData::getTimsBinDecPtr
TimsBinDec * getTimsBinDecPtr() const
Definition timsdata.cpp:1066
pappso::TimsData::TimsData
TimsData(QDir timsDataDirectory)
build using the tims data directory
Definition timsdata.cpp:47
pappso::TimsData::getQualifiedMassSpectrumByRawIndex
void getQualifiedMassSpectrumByRawIndex(const MsRunIdCstSPtr &msrun_id, QualifiedMassSpectrum &mass_spectrum, std::size_t global_scan_index, bool want_binary_data)
Definition timsdata.cpp:695
pappso::TimsData::getTimsMS2FrameIdsInRtRange
std::vector< std::size_t > getTimsMS2FrameIdsInRtRange(double rt_begin, double rt_end) const
Definition timsdata.cpp:521
pappso::TimsData::getTicChromatogram
Trace getTicChromatogram() const
Definition timsdata.cpp:811
pappso::TimsData::getTimsFrameBaseCstSPtrCached
TimsFrameBaseCstSPtr getTimsFrameBaseCstSPtrCached(std::size_t timsId)
Definition timsdata.cpp:896
pappso::TimsData::getQualifiedMassSpectrumByGlobalScanIndex
void getQualifiedMassSpectrumByGlobalScanIndex(const MsRunIdCstSPtr &msrun_id, QualifiedMassSpectrum &mass_spectrum, std::size_t global_scan_index, bool want_binary_data)
Definition timsdata.cpp:706
pappso::TimsData::m_timsFrameCache
std::deque< TimsFrameCstSPtr > m_timsFrameCache
Definition timsdata.h:248
pappso::TimsData::m_cacheSize
std::size_t m_cacheSize
Definition timsdata.h:247
pappso::TimsData::getScanCoordinateFromRawIndex
std::pair< std::size_t, std::size_t > getScanCoordinateFromRawIndex(std::size_t spectrum_index) const
Definition timsdata.cpp:325
pappso::TimsData::m_mapFramesRecord
std::vector< TimsFrameRecord > m_mapFramesRecord
Definition timsdata.h:254
pappso::TimsData::getMsLevelBySpectrumIndex
unsigned int getMsLevelBySpectrumIndex(std::size_t index)
Definition timsdata.cpp:679
pappso::TimsData::m_totalScanCount
std::size_t m_totalScanCount
Definition timsdata.h:245
pappso::TimsData::m_mapMzCalibrationRecord
std::map< int, QSqlRecord > m_mapMzCalibrationRecord
Definition timsdata.h:252
pappso::TimsData::m_mapTimsCalibrationRecord
std::map< int, QSqlRecord > m_mapTimsCalibrationRecord
Definition timsdata.h:253
pappso::TimsData::m_mutex
QMutex m_mutex
Definition timsdata.h:277
pappso::TimsData::m_mapGlobalMetadaTable
std::map< QString, QVariant > m_mapGlobalMetadaTable
Definition timsdata.h:275
pappso::TimsData::fillFrameIdDescrList
void fillFrameIdDescrList()
private function to fill m_frameIdDescrList
Definition timsdata.cpp:280
pappso::TimsData::getTimsFrameBaseCstSPtr
TimsFrameBaseCstSPtr getTimsFrameBaseCstSPtr(std::size_t timsId)
get a Tims frame base (no binary data file access) with his database ID
Definition timsdata.cpp:414
pappso::TimsData::m_someoneIsLoadingFrameId
std::vector< std::size_t > m_someoneIsLoadingFrameId
tells if someone is loading a frame id
Definition timsdata.h:273
pappso::TimsData::getMsLevelByGlobalScanIndex
unsigned int getMsLevelByGlobalScanIndex(std::size_t index)
Definition timsdata.cpp:686
pappso::TimsData::TimsDiaSlices
friend TimsDiaSlices
Definition timsdata.h:70
pappso::TimsData::m_timsDataDirectory
QDir m_timsDataDirectory
Definition timsdata.h:239
pappso::TimsData::mpa_mzCalibrationStore
MzCalibrationStore * mpa_mzCalibrationStore
Definition timsdata.h:256
pappso::TimsData::getMassSpectrumCstSPtrByGlobalScanIndex
pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtrByGlobalScanIndex(std::size_t index)
Definition timsdata.cpp:395
pappso::TimsData::getRetentionTimeLineInSeconds
virtual std::vector< double > getRetentionTimeLineInSeconds() const
Definition timsdata.cpp:1001
pappso::TimsData::getRetentionTimeLine
virtual std::vector< double > getRetentionTimeLine() const
retention timeline get retention times along the MSrun in seconds
Definition timsdata.cpp:995
pappso::TimsData::getTimsDataDirectory
const QDir & getTimsDataDirectory() const
Definition timsdata.cpp:1050
pappso::TimsData::getRawMsBySpectrumIndex
TimsDataFastMap & getRawMsBySpectrumIndex(std::size_t index)
get raw signal for a spectrum index only to use to see the raw signal
Definition timsdata.cpp:1017
pappso::TimsData::getFrameCount
std::size_t getFrameCount() const
Definition timsdata.cpp:659
pappso::TimsData::isDiaRun
bool isDiaRun() const
tells if this MS run is a DIA run
Definition timsdata.cpp:1080
pappso::TimsData::m_timsFrameBaseCache
std::deque< TimsFrameBaseCstSPtr > m_timsFrameBaseCache
Definition timsdata.h:249
pappso::TimsData::m_thousandIndexToFrameIdDescrListIndex
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
pappso::TimsData::mpa_timsBinDec
TimsBinDec * mpa_timsBinDec
Definition timsdata.h:240
pappso::TimsData::isDdaRun
bool isDdaRun() const
tells if this MS run is a DDA run
Definition timsdata.cpp:1072
pappso::TimsData::getTotalNumberOfScans
std::size_t getTotalNumberOfScans() const
get the total number of scans
Definition timsdata.cpp:666
pappso::TimsData::getTimsDdaPrecursorsPtr
TimsDdaPrecursors * getTimsDdaPrecursorsPtr() const
Definition timsdata.cpp:1056
pappso::TimsData::mpa_timsDiaSlices
TimsDiaSlices * mpa_timsDiaSlices
Definition timsdata.h:243
pappso::TimsData::m_frameCount
std::size_t m_frameCount
Definition timsdata.h:246
pappso::TimsData::getRawIndexFromCoordinate
std::size_t getRawIndexFromCoordinate(std::size_t frame_id, std::size_t scan_num) const
Definition timsdata.cpp:361
pappso::TimsData::getScanCoordinatesByGlobalScanIndex
std::pair< std::size_t, std::size_t > getScanCoordinatesByGlobalScanIndex(std::size_t index) const
Definition timsdata.cpp:331
pappso::TimsData::getGlobalMetadataValue
const QVariant & getGlobalMetadataValue(const QString &key) const
Definition timsdata.cpp:1101
pappso::TimsDdaPrecursors
Definition timsddaprecursors.h:38
pappso::TimsDiaSlices
Definition timsdiaslices.h:38
pappso::Trace
A simple container of DataPoint instances.
Definition trace.h:152
export-import-config.h
PMSPP_LIB_DECL
#define PMSPP_LIB_DECL
Definition export-import-config.h:14
filterinterface.h
mzcalibrationstore.h
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
pappso::TimsFrameBaseCstSPtr
std::shared_ptr< const TimsFrameBase > TimsFrameBaseCstSPtr
Definition timsframebase.h:43
pappso::MsRunIdCstSPtr
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
Definition msrunid.h:46
pappso::TimsDataSp
std::shared_ptr< TimsData > TimsDataSp
shared pointer on a TimsData object
Definition timsdata.h:54
pappso::MassSpectrumCstSPtr
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
Definition massspectrum.h:54
pappso::TimsFrameCstSPtr
std::shared_ptr< const TimsFrame > TimsFrameCstSPtr
Definition timsframe.h:44
qualifiedmassspectrum.h
spectrumcollectionhandlerinterface.h
base interface to read MSrun files
pappso::FrameIdDescr
Definition timsdata.h:58
pappso::FrameIdDescr::m_globalScanIndex
std::size_t m_globalScanIndex
Definition timsdata.h:61
pappso::FrameIdDescr::m_frameId
std::size_t m_frameId
Definition timsdata.h:59
pappso::FrameIdDescr::m_scanCount
std::size_t m_scanCount
Definition timsdata.h:60
timsbindec.h
timsframe.h
xiccoordtims.h