Loading...
Searching...
No Matches
timsmsrunreaderms2.cpp
Go to the documentation of this file.
/**
* \file pappsomspp/msrun/private/timsmsrunreaderms2.cpp
* \date 10/09/2019
* \author Olivier Langella
* \brief MSrun file reader for native Bruker TimsTOF specialized for MS2
* purpose
*/
/*******************************************************************************
* 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/>.
*
******************************************************************************/
#include "pappsomspp/core/msrun/private/timsmsrunreaderms2.h"
#include "pappsomspp/core/exception/exceptionnotfound.h"
#include "pappsomspp/core/exception/exceptionnotimplemented.h"
#include "pappsomspp/core/msrun/xiccoord/xiccoordtims.h"
#include "../../vendors/tims/timsddaprecursors.h"
#include <QDebug>
using namespace pappso;
TimsMsRunReaderMs2::TimsMsRunReaderMs2(MsRunIdCstSPtr &msrun_id_csp)
: TimsMsRunReaderBase(msrun_id_csp)
{
initialize();
}
TimsMsRunReaderMs2::TimsMsRunReaderMs2(const TimsMsRunReaderBase &msrun_reader_base)
: TimsMsRunReaderBase(msrun_reader_base)
{
initialize();
}
TimsMsRunReaderMs2::~TimsMsRunReaderMs2()
{
if(msp_timsData != nullptr)
{
msp_timsData = nullptr;
}
}
void
pappso::TimsMsRunReaderMs2::initialize()
{
if(msp_timsData == nullptr)
msp_timsData = std::make_shared<TimsData>(mcsp_msRunId.get()->getFileName());
if(msp_timsData == nullptr)
{
throw PappsoException(QObject::tr("ERROR in TimsMsRunReaderMs2::initialize "
"msp_timsData is null for MsRunId %1")
.arg(mcsp_msRunId.get()->toString()));
}
mp_timsDdaPrecursors = msp_timsData.get()->getTimsDdaPrecursorsPtr();
}
void
TimsMsRunReaderMs2::setMs2BuiltinCentroid(bool centroid)
{
m_builtinMs2Centroid = centroid;
if(mp_timsDdaPrecursors != nullptr)
{
mp_timsDdaPrecursors->setMs2BuiltinCentroid(m_builtinMs2Centroid);
}
else
{
throw PappsoException(
QObject::tr("ERROR in TimsMsRunReaderMs2::setMs2BuiltinCentroid "
"mp_timsDdaPrecursors is null"));
}
}
void
TimsMsRunReaderMs2::setMs2FilterCstSPtr(pappso::FilterInterfaceCstSPtr filter)
{
msp_ms2Filter = filter;
if(mp_timsDdaPrecursors != nullptr)
{
mp_timsDdaPrecursors->setMs2FilterCstSPtr(msp_ms2Filter);
}
else
{
throw PappsoException(
QObject::tr("ERROR in TimsMsRunReaderMs2::setMs2FilterCstSPtr "
"mp_timsDdaPrecursors is null"));
}
}
void
TimsMsRunReaderMs2::setMs1FilterCstSPtr(pappso::FilterInterfaceCstSPtr filter)
{
msp_ms1Filter = filter;
if(mp_timsDdaPrecursors != nullptr)
{
mp_timsDdaPrecursors->setMs1FilterCstSPtr(filter);
}
else
{
throw PappsoException(
QObject::tr("ERROR in TimsMsRunReaderMs2::setMs1FilterCstSPtr "
"msp_timsData is null"));
}
}
bool
TimsMsRunReaderMs2::accept(const QString &file_name [[maybe_unused]]) const
{
// qDebug() << file_name;
return true;
}
pappso::MassSpectrumSPtr
TimsMsRunReaderMs2::massSpectrumSPtr(std::size_t spectrum_index)
{
QualifiedMassSpectrum mass_spectrum = qualifiedMassSpectrum(spectrum_index, true);
return mass_spectrum.getMassSpectrumSPtr();
}
pappso::MassSpectrumCstSPtr
TimsMsRunReaderMs2::massSpectrumCstSPtr(std::size_t spectrum_index)
{
QualifiedMassSpectrum mass_spectrum = qualifiedMassSpectrum(spectrum_index, true);
return mass_spectrum.getMassSpectrumSPtr();
}
QualifiedMassSpectrum
TimsMsRunReaderMs2::qualifiedMassSpectrum(std::size_t spectrum_index, bool want_binary_data) const
{
std::size_t precursor_index = (spectrum_index / 2) + 1;
TimsDdaPrecursors::SpectrumDescr spectrum_descr;
try
{
spectrum_descr = mp_timsDdaPrecursors->getSpectrumDescrWithPrecursorId(precursor_index);
}
catch(ExceptionNotFound &error)
{
throw ExceptionNotFound(QObject::tr("spectrum_index %1 NOT FOUND in file %2 : %3")
.arg(spectrum_index)
.arg(getMsRunId().get()->getFileName())
.arg(error.qwhat()));
}
if(spectrum_index % 2 == 0)
{
// qDebug() << "MS1 spectrum precursor_index=" << precursor_index;
// this is an MS1 spectrum
QualifiedMassSpectrum mass_spectrum_ms1;
mp_timsDdaPrecursors->getQualifiedMs1MassSpectrumBySpectrumDescr(
getMsRunId(), mass_spectrum_ms1, spectrum_descr, want_binary_data);
// qDebug(); // << mass_spectrum_ms1.toString();
// qDebug() << mass_spectrum_ms1.getMassSpectrumSPtr().get()->toString();
return mass_spectrum_ms1;
}
else
{
// qDebug() << "MS2 spectrum precursor_index=" << precursor_index;
QualifiedMassSpectrum mass_spectrum_ms2;
if(spectrum_descr.ms2_index != spectrum_index)
{
// qDebug();
throw PappsoException(QObject::tr("ERROR in %1 %2 %3 spectrum_descr.ms2_index(%4) != "
"spectrum_index(%5)")
.arg(__FILE__)
.arg(__FUNCTION__)
.arg(__LINE__)
.arg(spectrum_descr.ms2_index)
.arg(spectrum_index));
}
mp_timsDdaPrecursors->getQualifiedMs2MassSpectrumBySpectrumDescr(
getMsRunId(), mass_spectrum_ms2, spectrum_descr, want_binary_data);
// qDebug() << mass_spectrum_ms2.toString();
// qDebug() << mass_spectrum_ms2.getMassSpectrumSPtr().get()->toString();
return mass_spectrum_ms2;
}
}
void
TimsMsRunReaderMs2::readSpectrumCollection(SpectrumCollectionHandlerInterface &handler)
{
readSpectrumCollectionByMsLevel(handler, 0);
}
void
TimsMsRunReaderMs2::readSpectrumCollection2(
[[maybe_unused]] const MsRunReadConfig &config,
[[maybe_unused]] SpectrumCollectionHandlerInterface &handler)
{
readSpectrumCollectionByMsLevel(handler, 0);
}
void
TimsMsRunReaderMs2::readSpectrumCollectionByMsLevel(SpectrumCollectionHandlerInterface &handler,
unsigned int ms_level)
{
// qDebug() << " ms_level=" << ms_level;
// We'll need it to perform the looping in the spectrum list.
std::size_t spectrum_list_size = spectrumListSize();
// qDebug() << "The spectrum list has size:" << spectrum_list_size;
// Inform the handler of the spectrum list so that it can handle feedback to
// the user.
handler.spectrumListHasSize(spectrum_list_size);
mp_timsDdaPrecursors->setMonoThread(isMonoThread());
mp_timsDdaPrecursors->ms2ReaderSpectrumCollectionByMsLevel(getMsRunId(), handler, ms_level);
// Now let the loading handler know that the loading of the data has ended.
// The handler might need this "signal" to perform additional tasks or to
// cleanup cruft.
// qDebug() << "Loading ended";
handler.loadingEnded();
}
std::size_t
TimsMsRunReaderMs2::spectrumListSize() const
{
return (mp_timsDdaPrecursors->getTotalPrecursorCount() * 2);
}
bool
TimsMsRunReaderMs2::hasScanNumbers() const
{
return false;
}
bool
TimsMsRunReaderMs2::releaseDevice()
{
msp_timsData = nullptr;
return true;
}
bool
TimsMsRunReaderMs2::acquireDevice()
{
if(msp_timsData == nullptr)
{
initialize();
mp_timsDdaPrecursors->setMs2BuiltinCentroid(m_builtinMs2Centroid);
mp_timsDdaPrecursors->setMs1FilterCstSPtr(msp_ms1Filter);
mp_timsDdaPrecursors->setMs2FilterCstSPtr(msp_ms2Filter);
}
return true;
}
std::vector<std::size_t>
pappso::TimsMsRunReaderMs2::getPrecursorsIDFromMzRt(int charge,
double mz_val,
double rt_sec,
double k0)
{
return mp_timsDdaPrecursors->getPrecursorsByMzRtCharge(charge, mz_val, rt_sec, k0);
}
pappso::TimsDataSp
pappso::TimsMsRunReaderMs2::getTimsDataSPtr()
{
acquireDevice();
return msp_timsData;
}
XicCoordSPtr
TimsMsRunReaderMs2::newXicCoordSPtrFromSpectrumIndex(std::size_t spectrum_index,
pappso::PrecisionPtr precision) const
{
XicCoordTimsSPtr xic_coord = std::make_shared<XicCoordTims>();
std::size_t precursor_index = (spectrum_index / 2) + 1;
auto xic = this->msp_timsData.get()->getTimsDdaPrecursorsPtr()->getXicCoordTimsFromPrecursorId(
precursor_index, precision);
xic_coord.get()->mzRange = xic.mzRange;
xic_coord.get()->rtTarget = xic.rtTarget;
xic_coord.get()->scanNumBegin = xic.scanNumBegin;
xic_coord.get()->scanNumEnd = xic.scanNumEnd;
return xic_coord;
}
pappso::XicCoordSPtr
TimsMsRunReaderMs2::newXicCoordSPtrFromQualifiedMassSpectrum(
const pappso::QualifiedMassSpectrum &mass_spectrum, pappso::PrecisionPtr precision) const
{
return newXicCoordSPtrFromSpectrumIndex(mass_spectrum.getMassSpectrumId().getSpectrumIndex(),
precision);
}
std::vector<double>
pappso::TimsMsRunReaderMs2::getRetentionTimeLine()
{
return msp_timsData.get()->getRetentionTimeLineInSeconds();
}
Trace
TimsMsRunReaderMs2::getTicChromatogram()
{
// Use the Sqlite database to fetch the total ion current chromatogram (TIC
// chromatogram).
acquireDevice();
return msp_timsData->getTicChromatogram();
}
std::size_t
TimsMsRunReaderMs2::spectrumStringIdentifier2SpectrumIndex(const QString &spectrum_identifier
[[maybe_unused]])
{
throw pappso::ExceptionNotImplemented(
QObject::tr("%1 %2 %3 not implemented").arg(__FILE__).arg(__FUNCTION__).arg(__LINE__));
}
pappso::ExceptionNotFound
Definition exceptionnotfound.h:32
pappso::ExceptionNotImplemented
Definition exceptionnotimplemented.h:32
pappso::MassSpectrumId::getSpectrumIndex
std::size_t getSpectrumIndex() const
Definition massspectrumid.cpp:113
pappso::MsRunReadConfig
Definition msrunreadconfig.h:62
pappso::MsRunReader::mcsp_msRunId
MsRunIdCstSPtr mcsp_msRunId
Definition msrunreader.h:194
pappso::MsRunReader::isMonoThread
bool isMonoThread() const
Definition msrunreader.cpp:74
pappso::MsRunReader::getMsRunId
const MsRunIdCstSPtr & getMsRunId() const
Definition msrunreader.cpp:55
pappso::PappsoException
Definition pappsoexception.h:41
pappso::PappsoException::qwhat
virtual const QString & qwhat() const
Definition pappsoexception.h:66
pappso::QualifiedMassSpectrum
Class representing a fully specified mass spectrum.
Definition qualifiedmassspectrum.h:99
pappso::QualifiedMassSpectrum::getMassSpectrumId
const MassSpectrumId & getMassSpectrumId() const
Get the MassSpectrumId.
Definition qualifiedmassspectrum.cpp:154
pappso::QualifiedMassSpectrum::getMassSpectrumSPtr
MassSpectrumSPtr getMassSpectrumSPtr() const
Get the MassSpectrumSPtr.
Definition qualifiedmassspectrum.cpp:130
pappso::SpectrumCollectionHandlerInterface
interface to collect spectrums from the MsRunReader class
Definition spectrumcollectionhandlerinterface.h:52
pappso::SpectrumCollectionHandlerInterface::loadingEnded
virtual void loadingEnded()
Definition spectrumcollectionhandlerinterface.cpp:43
pappso::SpectrumCollectionHandlerInterface::spectrumListHasSize
virtual void spectrumListHasSize(std::size_t size)
Definition spectrumcollectionhandlerinterface.cpp:47
pappso::TimsMsRunReaderBase::TimsMsRunReaderBase
TimsMsRunReaderBase(MsRunIdCstSPtr &msrun_id_csp)
Definition timsmsrunreaderbase.cpp:38
pappso::TimsMsRunReaderMs2::setMs2FilterCstSPtr
void setMs2FilterCstSPtr(pappso::FilterInterfaceCstSPtr filter)
Definition timsmsrunreaderms2.cpp:92
pappso::TimsMsRunReaderMs2::setMs1FilterCstSPtr
void setMs1FilterCstSPtr(pappso::FilterInterfaceCstSPtr filter)
Definition timsmsrunreaderms2.cpp:108
pappso::TimsMsRunReaderMs2::qualifiedMassSpectrum
virtual QualifiedMassSpectrum qualifiedMassSpectrum(std::size_t spectrum_index, bool want_binary_data=true) const override
get a QualifiedMassSpectrum class given its scan number
Definition timsmsrunreaderms2.cpp:148
pappso::TimsMsRunReaderMs2::TimsMsRunReaderMs2
TimsMsRunReaderMs2(MsRunIdCstSPtr &msrun_id_csp)
Definition timsmsrunreaderms2.cpp:39
pappso::TimsMsRunReaderMs2::newXicCoordSPtrFromSpectrumIndex
virtual pappso::XicCoordSPtr newXicCoordSPtrFromSpectrumIndex(std::size_t spectrum_index, pappso::PrecisionPtr precision) const override
get a xic coordinate object from a given spectrum index
Definition timsmsrunreaderms2.cpp:296
pappso::TimsMsRunReaderMs2::msp_timsData
TimsDataSp msp_timsData
Definition timsmsrunreaderms2.h:117
pappso::TimsMsRunReaderMs2::massSpectrumSPtr
virtual MassSpectrumSPtr massSpectrumSPtr(std::size_t spectrum_index) override
get a MassSpectrumSPtr class given its spectrum index
Definition timsmsrunreaderms2.cpp:132
pappso::TimsMsRunReaderMs2::msp_ms2Filter
pappso::FilterInterfaceCstSPtr msp_ms2Filter
Definition timsmsrunreaderms2.h:120
pappso::TimsMsRunReaderMs2::mp_timsDdaPrecursors
TimsDdaPrecursors * mp_timsDdaPrecursors
Definition timsmsrunreaderms2.h:114
pappso::TimsMsRunReaderMs2::spectrumListSize
virtual std::size_t spectrumListSize() const override
get the totat number of spectrum conained in the MSrun data file
Definition timsmsrunreaderms2.cpp:245
pappso::TimsMsRunReaderMs2::releaseDevice
virtual bool releaseDevice() override
release data back end device if a the data back end is released, the developper has to use acquireDev...
Definition timsmsrunreaderms2.cpp:259
pappso::TimsMsRunReaderMs2::msp_ms1Filter
pappso::FilterInterfaceCstSPtr msp_ms1Filter
Definition timsmsrunreaderms2.h:119
pappso::TimsMsRunReaderMs2::readSpectrumCollection
virtual void readSpectrumCollection(SpectrumCollectionHandlerInterface &handler) override
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler
Definition timsmsrunreaderms2.cpp:204
pappso::TimsMsRunReaderMs2::getPrecursorsIDFromMzRt
virtual std::vector< std::size_t > getPrecursorsIDFromMzRt(int charge, double mz_val, double rt_sec, double k0)
Get all the precursors id which match the values.
Definition timsmsrunreaderms2.cpp:279
pappso::TimsMsRunReaderMs2::initialize
virtual void initialize() override
Definition timsmsrunreaderms2.cpp:60
pappso::TimsMsRunReaderMs2::getTimsDataSPtr
virtual TimsDataSp getTimsDataSPtr() override
give an access to the underlying raw data pointer
Definition timsmsrunreaderms2.cpp:288
pappso::TimsMsRunReaderMs2::getRetentionTimeLine
virtual std::vector< double > getRetentionTimeLine() override
retention timeline get retention times along the MSrun in seconds
Definition timsmsrunreaderms2.cpp:322
pappso::TimsMsRunReaderMs2::spectrumStringIdentifier2SpectrumIndex
virtual std::size_t spectrumStringIdentifier2SpectrumIndex(const QString &spectrum_identifier) override
if possible, get the spectrum index given a string identifier throw a not found exception if spectrum...
Definition timsmsrunreaderms2.cpp:340
pappso::TimsMsRunReaderMs2::m_builtinMs2Centroid
bool m_builtinMs2Centroid
enable builtin centroid on raw tims integers by default
Definition timsmsrunreaderms2.h:123
pappso::TimsMsRunReaderMs2::getTicChromatogram
virtual Trace getTicChromatogram() override
get a TIC chromatogram
Definition timsmsrunreaderms2.cpp:328
pappso::TimsMsRunReaderMs2::setMs2BuiltinCentroid
void setMs2BuiltinCentroid(bool centroid)
enable or disable simple centroid filter on raw tims data for MS2
Definition timsmsrunreaderms2.cpp:76
pappso::TimsMsRunReaderMs2::readSpectrumCollection2
virtual void readSpectrumCollection2(const MsRunReadConfig &config, SpectrumCollectionHandlerInterface &handler) override
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler
Definition timsmsrunreaderms2.cpp:210
pappso::TimsMsRunReaderMs2::readSpectrumCollectionByMsLevel
virtual void readSpectrumCollectionByMsLevel(SpectrumCollectionHandlerInterface &handler, unsigned int ms_level) override
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler by Ms Levels
Definition timsmsrunreaderms2.cpp:218
pappso::TimsMsRunReaderMs2::acquireDevice
virtual bool acquireDevice() override
acquire data back end device
Definition timsmsrunreaderms2.cpp:266
pappso::TimsMsRunReaderMs2::hasScanNumbers
virtual bool hasScanNumbers() const override
tells if spectra can be accessed using scan numbers by default, it returns false. Only overrided func...
Definition timsmsrunreaderms2.cpp:252
pappso::TimsMsRunReaderMs2::~TimsMsRunReaderMs2
virtual ~TimsMsRunReaderMs2()
Definition timsmsrunreaderms2.cpp:51
pappso::TimsMsRunReaderMs2::massSpectrumCstSPtr
virtual MassSpectrumCstSPtr massSpectrumCstSPtr(std::size_t spectrum_index) override
Definition timsmsrunreaderms2.cpp:140
pappso::TimsMsRunReaderMs2::accept
virtual bool accept(const QString &file_name) const override
tells if the reader is able to handle this file must be implemented by private MS run reader,...
Definition timsmsrunreaderms2.cpp:124
pappso::TimsMsRunReaderMs2::newXicCoordSPtrFromQualifiedMassSpectrum
virtual pappso::XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum(const pappso::QualifiedMassSpectrum &mass_spectrum, pappso::PrecisionPtr precision) const override
get a xic coordinate object from a given spectrum
Definition timsmsrunreaderms2.cpp:314
pappso::Trace
A simple container of DataPoint instances.
Definition trace.h:152
exceptionnotfound.h
exceptionnotimplemented.h
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
pappso::ProjectParamCategory::filter
@ filter
concerning filters (psm, peptide, protein validation)
Definition projectparameters.h:48
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::FilterInterfaceCstSPtr
std::shared_ptr< const FilterInterface > FilterInterfaceCstSPtr
Definition filterinterface.h:47
pappso::PrecisionPtr
const PrecisionBase * PrecisionPtr
Definition precision.h:122
pappso::MassSpectrumSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition massspectrum.h:53
pappso::XicCoordTimsSPtr
std::shared_ptr< XicCoordTims > XicCoordTimsSPtr
Definition xiccoordtims.h:40
pappso::XicCoordSPtr
std::shared_ptr< XicCoord > XicCoordSPtr
Definition xiccoord.h:44
pappso::TimsDdaPrecursors::SpectrumDescr
Definition timsddaprecursors.h:63
pappso::TimsDdaPrecursors::SpectrumDescr::ms2_index
std::size_t ms2_index
Definition timsddaprecursors.h:69
pappso::XicCoordTims::scanNumEnd
std::size_t scanNumEnd
mobility index end
Definition xiccoordtims.h:101
pappso::XicCoordTims::scanNumBegin
std::size_t scanNumBegin
mobility index begin
Definition xiccoordtims.h:97
pappso::XicCoord::rtTarget
double rtTarget
the targeted retention time to extract around intended in seconds, and related to one msrun....
Definition xiccoord.h:131
pappso::XicCoord::mzRange
MzRange mzRange
the mass to extract
Definition xiccoord.h:125
timsddaprecursors.h
timsmsrunreaderms2.h
xiccoordtims.h