Loading...
Searching...
No Matches
spectrumcollectionhandlerinterface.cpp
Go to the documentation of this file.
/**
* \file pappsomspp/msrun/msrunreader.cpp
* \date 29/05/2018
* \author Olivier Langella
* \brief base interface to read MSrun files
*/
/*******************************************************************************
* Copyright (c) 2018 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 <QDebug>
#include <QObject>
#include "../../pappsomspp/exception/exceptionnotfound.h"
#include "spectrumcollectionhandlerinterface.h"
namespace pappso
{
bool
SpectrumCollectionHandlerInterface::shouldStop()
{
return false;
}
void
SpectrumCollectionHandlerInterface::loadingEnded()
{
}
void
SpectrumCollectionHandlerInterface::spectrumListHasSize(
[[maybe_unused]] std::size_t size)
{
}
void
SpectrumCollectionHandlerInterface::setReadAhead(bool is_read_ahead)
{
m_isReadAhead = is_read_ahead;
}
bool
SpectrumCollectionHandlerInterface::isReadAhead() const
{
return m_isReadAhead;
}
bool
SpectrumCollectionHandlerInterface::needMsLevelPeakList(
unsigned int ms_level) const
{
if(needPeakList() == true)
{
if(ms_level < m_needPeakListByMsLevel.size())
{
return m_needPeakListByMsLevel[ms_level];
}
else
return true;
}
else
{
return false;
}
}
void
SpectrumCollectionHandlerInterface::setNeedMsLevelPeakList(
unsigned int ms_level, bool want_peak_list)
{
if(ms_level < m_needPeakListByMsLevel.size())
{
m_needPeakListByMsLevel[ms_level] = want_peak_list;
}
}
bool
MsRunSimpleStatistics::needPeakList() const
{
return false;
}
void
MsRunSimpleStatistics::loadingEnded()
{
// qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
//<< "The data loading process ended.";
}
void
MsRunSimpleStatistics::setQualifiedMassSpectrum(
const QualifiedMassSpectrum &qspectrum)
{
// The vector[0] contains the number of spectra at MS
// The vector[1] contains the number of spectra at MS^2
// The vector[2] contains the number of spectra at MS^3
// ...
unsigned int ms_level = qspectrum.getMsLevel();
if(ms_level == 0)
return;
if(ms_level > m_countMsLevelSpectrum.size())
{
m_countMsLevelSpectrum.resize(ms_level);
}
m_countMsLevelSpectrum[ms_level - 1]++;
}
unsigned long
MsRunSimpleStatistics::getMsLevelCount(unsigned int ms_level) const
{
if(ms_level == 0)
return 0;
if(ms_level > m_countMsLevelSpectrum.size())
return 0;
return (m_countMsLevelSpectrum[ms_level - 1]);
}
unsigned long
MsRunSimpleStatistics::getTotalCount() const
{
unsigned long total = 0;
for(unsigned long count : m_countMsLevelSpectrum)
{
total += count;
}
return total;
}
MsRunReaderScanNumberMultiMap::MsRunReaderScanNumberMultiMap()
{
// qDebug();
}
MsRunReaderScanNumberMultiMap::~MsRunReaderScanNumberMultiMap()
{
// qDebug();
}
bool
MsRunReaderScanNumberMultiMap::needPeakList() const
{
return false;
}
void
MsRunReaderScanNumberMultiMap::setQualifiedMassSpectrum(
const QualifiedMassSpectrum &qspectrum)
{
qDebug() << " " << qspectrum.getMassSpectrumId().getNativeId();
QStringList native_id_list =
qspectrum.getMassSpectrumId().getNativeId().split("=");
if(native_id_list.size() < 2)
{
return;
}
else
{
std::size_t scan_number = native_id_list.back().toULong();
m_mmap_scan2index.insert(std::pair<std::size_t, std::size_t>(
scan_number, qspectrum.getMassSpectrumId().getSpectrumIndex()));
qDebug() << "scan number " << scan_number << "=>"
<< qspectrum.getMassSpectrumId().getSpectrumIndex();
}
}
std::size_t
MsRunReaderScanNumberMultiMap::getSpectrumIndexFromScanNumber(
std::size_t scan_number) const
{
qDebug() << m_mmap_scan2index.size();
auto it = m_mmap_scan2index.find(scan_number);
if(it == m_mmap_scan2index.end())
{
throw ExceptionNotFound(
QObject::tr("scan number %1 not found").arg(scan_number));
}
std::size_t index = it->second;
it++;
if((it != m_mmap_scan2index.end()) && (it->first == scan_number))
{
throw PappsoException(
QObject::tr("scan number %1 found multiple times").arg(scan_number));
}
return index;
}
MsRunReaderRetentionTimeLine::MsRunReaderRetentionTimeLine()
{
// qDebug();
}
MsRunReaderRetentionTimeLine::~MsRunReaderRetentionTimeLine()
{
// qDebug();
}
bool
MsRunReaderRetentionTimeLine::needPeakList() const
{
return false;
}
void
MsRunReaderRetentionTimeLine::setQualifiedMassSpectrum(
const QualifiedMassSpectrum &qspectrum)
{
qDebug() << " " << qspectrum.getMassSpectrumId().getNativeId();
m_retention_time_list.push_back(qspectrum.getRtInSeconds());
}
const std::vector<double> &
MsRunReaderRetentionTimeLine::getRetentionTimeLine() const
{
return m_retention_time_list;
}
MsRunReaderTicChromatogram::MsRunReaderTicChromatogram()
{
}
MsRunReaderTicChromatogram::~MsRunReaderTicChromatogram()
{
}
bool
MsRunReaderTicChromatogram::needPeakList() const
{
return true;
}
void
MsRunReaderTicChromatogram::setQualifiedMassSpectrum(
const QualifiedMassSpectrum &qualified_mass_spectrum)
{
// In this specialized reader we want to compute the total ion current
// chromatogram that plot the sum of all the ion intensities in the spectra as
// a function of the retention time.
uint spectrum_ms_level = qualified_mass_spectrum.getMsLevel();
if(spectrum_ms_level != 1)
return;
double sumY = qualified_mass_spectrum.getMassSpectrumSPtr()->sumY();
if(!sumY)
return;
double rt = qualified_mass_spectrum.getRtInMinutes();
using Pair = std::pair<double, double>;
using Map = std::map<double, double>;
using Iterator = Map::iterator;
std::pair<Iterator, bool> res = m_ticChromMapTrace.insert(Pair(rt, sumY));
if(!res.second)
{
// One other same rt value was seen already (like in ion mobility mass
// spectrometry, for example). Only increment the y value.
res.first->second += sumY;
}
}
Trace
MsRunReaderTicChromatogram::getTicChromatogram() const
{
return m_ticChromMapTrace.toTrace();
}
MsRunQualifiedSpectrumLoader::MsRunQualifiedSpectrumLoader()
{
}
MsRunQualifiedSpectrumLoader::~MsRunQualifiedSpectrumLoader()
{
}
bool
MsRunQualifiedSpectrumLoader::needPeakList() const
{
return true;
}
void
MsRunQualifiedSpectrumLoader::spectrumListHasSize(std::size_t size
[[maybe_unused]])
{
m_qualifiedSpectrumList.clear();
}
void
MsRunQualifiedSpectrumLoader::setQualifiedMassSpectrum(
const QualifiedMassSpectrum &qualified_mass_spectrum)
{
qDebug() << qualified_mass_spectrum.getMassSpectrumId().getNativeId();
m_qualifiedSpectrumList.push_back(qualified_mass_spectrum);
}
const std::vector<QualifiedMassSpectrum> &
MsRunQualifiedSpectrumLoader::getQualifiedMassSpectrumList() const
{
return m_qualifiedSpectrumList;
}
void
MsRunQualifiedSpectrumLoader::clear()
{
m_qualifiedSpectrumList.clear();
}
} // namespace pappso
pappso::ExceptionNotFound
Definition exceptionnotfound.h:32
pappso::MapTrace::toTrace
Trace toTrace() const
Definition maptrace.cpp:219
pappso::MassSpectrumId::getSpectrumIndex
std::size_t getSpectrumIndex() const
Definition massspectrumid.cpp:113
pappso::MassSpectrumId::getNativeId
const QString & getNativeId() const
Definition massspectrumid.cpp:99
pappso::MsRunQualifiedSpectrumLoader::getQualifiedMassSpectrumList
const std::vector< QualifiedMassSpectrum > & getQualifiedMassSpectrumList() const
Definition spectrumcollectionhandlerinterface.cpp:342
pappso::MsRunQualifiedSpectrumLoader::MsRunQualifiedSpectrumLoader
MsRunQualifiedSpectrumLoader()
Definition spectrumcollectionhandlerinterface.cpp:310
pappso::MsRunQualifiedSpectrumLoader::spectrumListHasSize
virtual void spectrumListHasSize(std::size_t size) override
Definition spectrumcollectionhandlerinterface.cpp:327
pappso::MsRunQualifiedSpectrumLoader::needPeakList
virtual bool needPeakList() const override
tells if we need the peak list (if we want the binary data) for each spectrum
Definition spectrumcollectionhandlerinterface.cpp:321
pappso::MsRunQualifiedSpectrumLoader::clear
void clear()
Definition spectrumcollectionhandlerinterface.cpp:348
pappso::MsRunQualifiedSpectrumLoader::~MsRunQualifiedSpectrumLoader
virtual ~MsRunQualifiedSpectrumLoader()
Definition spectrumcollectionhandlerinterface.cpp:315
pappso::MsRunQualifiedSpectrumLoader::setQualifiedMassSpectrum
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &qualified_mass_spectrum) override
Definition spectrumcollectionhandlerinterface.cpp:334
pappso::MsRunQualifiedSpectrumLoader::m_qualifiedSpectrumList
std::vector< QualifiedMassSpectrum > m_qualifiedSpectrumList
Definition spectrumcollectionhandlerinterface.h:202
pappso::MsRunReaderRetentionTimeLine::getRetentionTimeLine
const std::vector< double > & getRetentionTimeLine() const
Definition spectrumcollectionhandlerinterface.cpp:246
pappso::MsRunReaderRetentionTimeLine::setQualifiedMassSpectrum
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override
Definition spectrumcollectionhandlerinterface.cpp:237
pappso::MsRunReaderRetentionTimeLine::~MsRunReaderRetentionTimeLine
virtual ~MsRunReaderRetentionTimeLine()
Definition spectrumcollectionhandlerinterface.cpp:223
pappso::MsRunReaderRetentionTimeLine::needPeakList
virtual bool needPeakList() const override
tells if we need the peak list (if we want the binary data) for each spectrum
Definition spectrumcollectionhandlerinterface.cpp:230
pappso::MsRunReaderRetentionTimeLine::MsRunReaderRetentionTimeLine
MsRunReaderRetentionTimeLine()
Definition spectrumcollectionhandlerinterface.cpp:217
pappso::MsRunReaderRetentionTimeLine::m_retention_time_list
std::vector< double > m_retention_time_list
Definition spectrumcollectionhandlerinterface.h:153
pappso::MsRunReaderScanNumberMultiMap::needPeakList
virtual bool needPeakList() const override
tells if we need the peak list (if we want the binary data) for each spectrum
Definition spectrumcollectionhandlerinterface.cpp:162
pappso::MsRunReaderScanNumberMultiMap::setQualifiedMassSpectrum
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override
Definition spectrumcollectionhandlerinterface.cpp:168
pappso::MsRunReaderScanNumberMultiMap::getSpectrumIndexFromScanNumber
std::size_t getSpectrumIndexFromScanNumber(std::size_t scan_number) const
Definition spectrumcollectionhandlerinterface.cpp:191
pappso::MsRunReaderScanNumberMultiMap::m_mmap_scan2index
std::multimap< std::size_t, std::size_t > m_mmap_scan2index
Definition spectrumcollectionhandlerinterface.h:135
pappso::MsRunReaderScanNumberMultiMap::~MsRunReaderScanNumberMultiMap
virtual ~MsRunReaderScanNumberMultiMap()
Definition spectrumcollectionhandlerinterface.cpp:155
pappso::MsRunReaderScanNumberMultiMap::MsRunReaderScanNumberMultiMap
MsRunReaderScanNumberMultiMap()
Definition spectrumcollectionhandlerinterface.cpp:149
pappso::MsRunReaderTicChromatogram::~MsRunReaderTicChromatogram
virtual ~MsRunReaderTicChromatogram()
Definition spectrumcollectionhandlerinterface.cpp:256
pappso::MsRunReaderTicChromatogram::setQualifiedMassSpectrum
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &qualified_mass_spectrum) override
Definition spectrumcollectionhandlerinterface.cpp:269
pappso::MsRunReaderTicChromatogram::m_ticChromMapTrace
MapTrace m_ticChromMapTrace
Definition spectrumcollectionhandlerinterface.h:180
pappso::MsRunReaderTicChromatogram::MsRunReaderTicChromatogram
MsRunReaderTicChromatogram()
Definition spectrumcollectionhandlerinterface.cpp:251
pappso::MsRunReaderTicChromatogram::needPeakList
virtual bool needPeakList() const override
tells if we need the peak list (if we want the binary data) for each spectrum
Definition spectrumcollectionhandlerinterface.cpp:262
pappso::MsRunReaderTicChromatogram::getTicChromatogram
Trace getTicChromatogram() const
Definition spectrumcollectionhandlerinterface.cpp:305
pappso::MsRunSimpleStatistics::setQualifiedMassSpectrum
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override
Definition spectrumcollectionhandlerinterface.cpp:107
pappso::MsRunSimpleStatistics::getTotalCount
unsigned long getTotalCount() const
Definition spectrumcollectionhandlerinterface.cpp:138
pappso::MsRunSimpleStatistics::loadingEnded
virtual void loadingEnded() override
Definition spectrumcollectionhandlerinterface.cpp:99
pappso::MsRunSimpleStatistics::m_countMsLevelSpectrum
std::vector< unsigned long > m_countMsLevelSpectrum
Definition spectrumcollectionhandlerinterface.h:116
pappso::MsRunSimpleStatistics::needPeakList
virtual bool needPeakList() const override
tells if we need the peak list (if we want the binary data) for each spectrum
Definition spectrumcollectionhandlerinterface.cpp:92
pappso::MsRunSimpleStatistics::getMsLevelCount
unsigned long getMsLevelCount(unsigned int ms_level) const
Definition spectrumcollectionhandlerinterface.cpp:127
pappso::PappsoException
Definition pappsoexception.h:42
pappso::QualifiedMassSpectrum
Class representing a fully specified mass spectrum.
Definition qualifiedmassspectrum.h:99
pappso::QualifiedMassSpectrum::getMsLevel
uint getMsLevel() const
Get the mass spectrum level.
Definition qualifiedmassspectrum.cpp:192
pappso::QualifiedMassSpectrum::getRtInMinutes
pappso_double getRtInMinutes() const
Get the retention time in minutes.
Definition qualifiedmassspectrum.cpp:216
pappso::QualifiedMassSpectrum::getMassSpectrumId
const MassSpectrumId & getMassSpectrumId() const
Get the MassSpectrumId.
Definition qualifiedmassspectrum.cpp:157
pappso::QualifiedMassSpectrum::getMassSpectrumSPtr
MassSpectrumSPtr getMassSpectrumSPtr() const
Get the MassSpectrumSPtr.
Definition qualifiedmassspectrum.cpp:133
pappso::QualifiedMassSpectrum::getRtInSeconds
pappso_double getRtInSeconds() const
Get the retention time in seconds.
Definition qualifiedmassspectrum.cpp:208
pappso::SpectrumCollectionHandlerInterface::shouldStop
virtual bool shouldStop()
Definition spectrumcollectionhandlerinterface.cpp:38
pappso::SpectrumCollectionHandlerInterface::isReadAhead
virtual bool isReadAhead() const
tells if we want to read ahead spectrum
Definition spectrumcollectionhandlerinterface.cpp:58
pappso::SpectrumCollectionHandlerInterface::needPeakList
virtual bool needPeakList() const =0
tells if we need the peak list (if we want the binary data) for each spectrum
pappso::SpectrumCollectionHandlerInterface::loadingEnded
virtual void loadingEnded()
Definition spectrumcollectionhandlerinterface.cpp:43
pappso::SpectrumCollectionHandlerInterface::needMsLevelPeakList
virtual bool needMsLevelPeakList(unsigned int ms_level) const final
tells if we need the peak list (if we want the binary data) for each spectrum, given an MS level
Definition spectrumcollectionhandlerinterface.cpp:64
pappso::SpectrumCollectionHandlerInterface::setReadAhead
virtual void setReadAhead(bool is_read_ahead) final
use threads to read a spectrum by batch of batch_size
Definition spectrumcollectionhandlerinterface.cpp:52
pappso::SpectrumCollectionHandlerInterface::setNeedMsLevelPeakList
virtual void setNeedMsLevelPeakList(unsigned int ms_level, bool want_peak_list) final
tells if we need the peak list given
Definition spectrumcollectionhandlerinterface.cpp:82
pappso::SpectrumCollectionHandlerInterface::m_needPeakListByMsLevel
std::vector< bool > m_needPeakListByMsLevel
Definition spectrumcollectionhandlerinterface.h:92
pappso::SpectrumCollectionHandlerInterface::spectrumListHasSize
virtual void spectrumListHasSize(std::size_t size)
Definition spectrumcollectionhandlerinterface.cpp:47
pappso::SpectrumCollectionHandlerInterface::m_isReadAhead
bool m_isReadAhead
Definition spectrumcollectionhandlerinterface.h:90
pappso::Trace
A simple container of DataPoint instances.
Definition trace.h:148
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
pappso::PrecisionUnit::res
@ res
pappso::DataKind::rt
@ rt
Retention time.
pappso::uint
unsigned int uint
Definition types.h:57
spectrumcollectionhandlerinterface.h