msrunreader.h
Go to the documentation of this file.
/**
* \file pappsomspp/msrun/msrunreader.h
* \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/>.
*
******************************************************************************/
#pragma once
/////////////////////// StdLib includes
#include <memory>
#include <map>
/////////////////////// Qt includes
#include <QMutex>
/////////////////////// pappsomspp includes
#include "../trace/maptrace.h"
/////////////////////// Local includes
#include "msrunid.h"
#include "../massspectrum/qualifiedmassspectrum.h"
#include "../msfile/msfilereader.h"
#include "../exportinmportconfig.h"
#include "xiccoord/xiccoord.h"
namespace pappso
{
/** @brief interface to collect spectrums from the MsRunReader class
*/
class PMSPP_LIB_DECL SpectrumCollectionHandlerInterface
{
public:
virtual void
setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) = 0;
/** @brief tells if we need the peak list (if we want the binary data) for
* each spectrum
*/
virtual bool needPeakList() const = 0;
/** @brief tells if we need the peak list (if we want the binary data) for
* each spectrum, given an MS level
*/
virtual bool needMsLevelPeakList(unsigned int ms_level) const final;
/** @brief tells if we need the peak list given
*/
virtual void setNeedMsLevelPeakList(unsigned int ms_level,
bool want_peak_list) final;
virtual bool shouldStop();
virtual void loadingEnded();
virtual void spectrumListHasSize(std::size_t size);
/** @brief use threads to read a spectrum by batch of batch_size
* @param is_read_ahead boolean to use threads or not
*/
virtual void setReadAhead(bool is_read_ahead) final;
/** @brief tells if we want to read ahead spectrum
*/
virtual bool isReadAhead() const;
private:
bool m_isReadAhead = false;
std::vector<bool> m_needPeakListByMsLevel = {true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true};
};
/** @brief example of interface to count MS levels of all spectrum in an MSrun
*/
class PMSPP_LIB_DECL MsRunSimpleStatistics
: public SpectrumCollectionHandlerInterface
{
private:
std::vector<unsigned long> m_countMsLevelSpectrum;
public:
virtual void
setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override;
virtual bool needPeakList() const override;
virtual void loadingEnded() override;
unsigned long getMsLevelCount(unsigned int ms_level) const;
unsigned long getTotalCount() const;
};
/** @brief provides a multimap to find quickly spectrum index from scan number
*/
class PMSPP_LIB_DECL MsRunReaderScanNumberMultiMap
: public SpectrumCollectionHandlerInterface
{
private:
std::multimap<std::size_t, std::size_t> m_mmap_scan2index;
public:
MsRunReaderScanNumberMultiMap();
virtual ~MsRunReaderScanNumberMultiMap();
virtual void
setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override;
virtual bool needPeakList() const override;
std::size_t getSpectrumIndexFromScanNumber(std::size_t scan_number) const;
};
/** @brief collect retention times along MS run */
class PMSPP_LIB_DECL MsRunReaderRetentionTimeLine
: public SpectrumCollectionHandlerInterface
{
private:
std::vector<double> m_retention_time_list;
public:
MsRunReaderRetentionTimeLine();
virtual ~MsRunReaderRetentionTimeLine();
virtual void
setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override;
virtual bool needPeakList() const override;
const std::vector<double> &getRetentionTimeLine() const;
};
/** @brief calculate a TIC chromatogram */
class PMSPP_LIB_DECL MsRunReaderTicChromatogram
: public SpectrumCollectionHandlerInterface
{
public:
MsRunReaderTicChromatogram();
virtual ~MsRunReaderTicChromatogram();
virtual void
setQualifiedMassSpectrum(const QualifiedMassSpectrum &qualified_mass_spectrum) override;
virtual bool needPeakList() const override;
Trace getTicChromatogram() const;
private:
MapTrace m_ticChromMapTrace;
};
class PMSPP_LIB_DECL MsRunReader;
typedef std::shared_ptr<MsRunReader> MsRunReaderSPtr;
typedef std::shared_ptr<const MsRunReader> MsRunReaderCstSPtr;
/** @brief base class to read MSrun
* the only way to build a MsRunReader object is to use the MsRunReaderFactory
*/
class PMSPP_LIB_DECL MsRunReader
{
friend class MsFileAccessor;
public:
MsRunReader(MsRunIdCstSPtr &ms_run_id);
MsRunReader(const MsRunReader &other);
virtual ~MsRunReader();
const MsRunIdCstSPtr &getMsRunId() const;
/** @brief get a MassSpectrumSPtr class given its spectrum index
*/
virtual MassSpectrumSPtr massSpectrumSPtr(std::size_t spectrum_index) = 0;
virtual MassSpectrumCstSPtr
massSpectrumCstSPtr(std::size_t spectrum_index) = 0;
/** @brief get a QualifiedMassSpectrum class given its scan number
*/
virtual QualifiedMassSpectrum
qualifiedMassSpectrum(std::size_t spectrum_index,
bool want_binary_data = true) const = 0;
/** @brief get a xic coordinate object from a given spectrum index
*/
virtual XicCoordSPtr
newXicCoordSPtrFromSpectrumIndex(std::size_t spectrum_index,
PrecisionPtr precision) const = 0;
/** @brief get a xic coordinate object from a given spectrum
*/
virtual XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum(
const QualifiedMassSpectrum &mass_spectrum,
PrecisionPtr precision) const = 0;
/** @brief get the totat number of spectrum conained in the MSrun data file
*/
virtual std::size_t spectrumListSize() const = 0;
/** @brief function to visit an MsRunReader and get each Spectrum in a
* spectrum collection handler
*/
virtual void
readSpectrumCollection(SpectrumCollectionHandlerInterface &handler) = 0;
/** @brief function to visit an MsRunReader and get each Spectrum in a
* spectrum collection handler by Ms Levels
*/
virtual void
readSpectrumCollectionByMsLevel(SpectrumCollectionHandlerInterface &handler,
unsigned int ms_level) = 0;
/** @brief if possible, converts a scan number into a spectrum index
* This is a convenient function to help transition from the old scan number
* (not implemented by all vendors) to more secure spectrum index (not vendor
* dependant).
* It is better to not rely on this function.
*/
virtual std::size_t scanNumber2SpectrumIndex(std::size_t scan_number);
/** @brief tells if spectra can be accessed using scan numbers
* by default, it returns false. Only overrided functions can check if scan
* numbers are available in the current file
*/
virtual bool hasScanNumbers() const;
/** @brief release data back end device
* if a the data back end is released, the developper has to use acquireDevice
* before using the msrunreader object
* @return bool true if done
*/
virtual bool releaseDevice() = 0;
/** @brief acquire data back end device
* @return bool true if done
*/
virtual bool acquireDevice() = 0;
/** @brief retention timeline
* get retention times along the MSrun in seconds
* @return vector of retention times (seconds)
*/
virtual std::vector<double> getRetentionTimeLine();
virtual Trace getTicChromatogram();
protected:
MsRunIdCstSPtr mcsp_msRunId;
MsRunReaderScanNumberMultiMap *mpa_multiMapScanNumber = nullptr;
virtual void initialize() = 0;
/** @brief tells if the reader is able to handle this file
* must be implemented by private MS run reader, specific of one or more file
* format
*/
virtual bool accept(const QString &file_name) const = 0;
};
} // namespace pappso
Q_DECLARE_METATYPE(pappso::MsRunReaderSPtr);
extern int msRunReaderSPtrMetaTypeId;
pappso::MapTrace
Definition: maptrace.h:33
pappso::MsFileAccessor
Definition: msfileaccessor.h:35
pappso::MsRunReaderRetentionTimeLine
collect retention times along MS run
Definition: msrunreader.h:150
pappso::MsRunReaderRetentionTimeLine::m_retention_time_list
std::vector< double > m_retention_time_list
Definition: msrunreader.h:152
pappso::MsRunReaderScanNumberMultiMap
provides a multimap to find quickly spectrum index from scan number
Definition: msrunreader.h:132
pappso::MsRunReaderScanNumberMultiMap::m_mmap_scan2index
std::multimap< std::size_t, std::size_t > m_mmap_scan2index
Definition: msrunreader.h:134
pappso::MsRunReaderTicChromatogram
calculate a TIC chromatogram
Definition: msrunreader.h:168
pappso::MsRunReaderTicChromatogram::m_ticChromMapTrace
MapTrace m_ticChromMapTrace
Definition: msrunreader.h:179
pappso::MsRunReader
base class to read MSrun the only way to build a MsRunReader object is to use the MsRunReaderFactory
Definition: msrunreader.h:191
pappso::MsRunReader::massSpectrumCstSPtr
virtual MassSpectrumCstSPtr massSpectrumCstSPtr(std::size_t spectrum_index)=0
pappso::MsRunReader::spectrumListSize
virtual std::size_t spectrumListSize() const =0
get the totat number of spectrum conained in the MSrun data file
pappso::MsRunReader::mcsp_msRunId
MsRunIdCstSPtr mcsp_msRunId
Definition: msrunreader.h:282
pappso::MsRunReader::acquireDevice
virtual bool acquireDevice()=0
acquire data back end device
pappso::MsRunReader::accept
virtual bool accept(const QString &file_name) const =0
tells if the reader is able to handle this file must be implemented by private MS run reader,...
pappso::MsRunReader::newXicCoordSPtrFromSpectrumIndex
virtual XicCoordSPtr newXicCoordSPtrFromSpectrumIndex(std::size_t spectrum_index, PrecisionPtr precision) const =0
get a xic coordinate object from a given spectrum index
pappso::MsRunReader::releaseDevice
virtual bool releaseDevice()=0
release data back end device if a the data back end is released, the developper has to use acquireDev...
pappso::MsRunReader::initialize
virtual void initialize()=0
pappso::MsRunReader::newXicCoordSPtrFromQualifiedMassSpectrum
virtual XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum(const QualifiedMassSpectrum &mass_spectrum, PrecisionPtr precision) const =0
get a xic coordinate object from a given spectrum
pappso::MsRunReader::massSpectrumSPtr
virtual MassSpectrumSPtr massSpectrumSPtr(std::size_t spectrum_index)=0
get a MassSpectrumSPtr class given its spectrum index
pappso::MsRunReader::readSpectrumCollection
virtual void readSpectrumCollection(SpectrumCollectionHandlerInterface &handler)=0
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler
pappso::MsRunReader::qualifiedMassSpectrum
virtual QualifiedMassSpectrum qualifiedMassSpectrum(std::size_t spectrum_index, bool want_binary_data=true) const =0
get a QualifiedMassSpectrum class given its scan number
pappso::MsRunReader::readSpectrumCollectionByMsLevel
virtual void readSpectrumCollectionByMsLevel(SpectrumCollectionHandlerInterface &handler, unsigned int ms_level)=0
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler by Ms Levels
pappso::MsRunSimpleStatistics
example of interface to count MS levels of all spectrum in an MSrun
Definition: msrunreader.h:113
pappso::MsRunSimpleStatistics::m_countMsLevelSpectrum
std::vector< unsigned long > m_countMsLevelSpectrum
Definition: msrunreader.h:115
pappso::PrecisionBase
Definition: precision.h:44
pappso::QualifiedMassSpectrum
Class representing a fully specified mass spectrum.
Definition: qualifiedmassspectrum.h:85
pappso::SpectrumCollectionHandlerInterface
interface to collect spectrums from the MsRunReader class
Definition: msrunreader.h:56
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::setQualifiedMassSpectrum
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum)=0
pappso::Trace
A simple container of DataPoint instances.
Definition: trace.h:148
PMSPP_LIB_DECL
#define PMSPP_LIB_DECL
Definition: exportinmportconfig.h:14
msrunid.h
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(pappso::MsRunReaderSPtr)
msRunReaderSPtrMetaTypeId
int msRunReaderSPtrMetaTypeId
Definition: msrunreader.cpp:34
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
pappso::MsRunReaderSPtr
std::shared_ptr< MsRunReader > MsRunReaderSPtr
Definition: msrunreader.h:184
pappso::MsRunReaderCstSPtr
std::shared_ptr< const MsRunReader > MsRunReaderCstSPtr
Definition: msrunreader.h:185
pappso::MsRunReader
class PMSPP_LIB_DECL MsRunReader
Definition: msrunreader.h:183
pappso::MsRunIdCstSPtr
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
Definition: msrunid.h:44
pappso::MassSpectrumCstSPtr
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
Definition: massspectrum.h:55
pappso::MassSpectrumSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:54
pappso::XicCoordSPtr
std::shared_ptr< XicCoord > XicCoordSPtr
Definition: xiccoord.h:41
xiccoord.h
XIC coordinate in MSrun.