timsframe.h
Go to the documentation of this file.
/**
* \file pappsomspp/vendors/tims/timsframe.h
* \date 23/08/2019
* \author Olivier Langella
* \brief handle a single Bruker's TimsTof frame
*/
/*******************************************************************************
* 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 <memory>
#include <QByteArray>
#include <vector>
#include "../../massspectrum/qualifiedmassspectrum.h"
#include "timsframebase.h"
#include "../../xic/xic.h"
#include "../../msrun/xiccoord/xiccoordtims.h"
namespace pappso
{
class TimsFrame;
typedef std::shared_ptr<TimsFrame> TimsFrameSPtr;
typedef std::shared_ptr<const TimsFrame> TimsFrameCstSPtr;
class TimsBinDec;
class TimsDirectXicExtractor;
/**
* @todo write docs
*/
class TimsFrame : public TimsFrameBase
{
friend TimsDirectXicExtractor;
public:
/**
* @param timsId tims frame id
* @param scanNum total number of scans in this frame
* @param p_bytes pointer on the decompressed binary buffer
* @param len size of the decompressed binary buffer
*/
TimsFrame(std::size_t timsId,
quint32 scanNum,
char *p_bytes,
std::size_t len);
/**
* Copy constructor
*
* @param other TODO
*/
TimsFrame(const TimsFrame &other);
/**
* Destructor
*/
~TimsFrame();
virtual std::size_t getNbrPeaks(std::size_t scanNum) const override;
/** @brief cumulate scan list into a trace
* @param scanNumBegin first scan to cumulate
* @param scanNumEnd last scan to cumulate
* @return Trace mz and intensity values
*/
virtual Trace cumulateScanToTrace(std::size_t scanNumBegin,
std::size_t scanNumEnd) const override;
/** @brief cumulate scan list into a trace into a raw spectrum map
* @param rawSpectrum simple map of integers to cumulate raw counts
* @param scanNumBegin first scan to cumulate
* @param scanNumEnd last scan to cumulate
*/
virtual void cumulateScansInRawMap(std::map<quint32, quint32> &rawSpectrum,
std::size_t scanNumBegin,
std::size_t scanNumEnd) const override;
/** @brief get raw index list for one given scan
* index are not TOF nor m/z, just index on digitizer
*/
virtual std::vector<quint32> getScanIndexList(std::size_t scanNum) const;
/** @brief get raw intensities without transformation from one scan
* it needs intensity normalization
*/
virtual std::vector<quint32> getScanIntensities(std::size_t scanNum) const;
/** @brief get the mass spectrum corresponding to a scan number
* @param scanNum the scan number to retrieve
* */
virtual pappso::MassSpectrumCstSPtr
getMassSpectrumCstSPtr(std::size_t scanNum) const;
virtual pappso::MassSpectrumSPtr
getMassSpectrumSPtr(std::size_t scanNum) const override;
protected:
/** @brief constructor for binary independant tims frame
* @param timsId tims frame identifier in the database
* @param scanNum the total number of scans contained in this frame
*/
TimsFrame(std::size_t timsId, quint32 scanNum);
void extractTimsXicListInRtRange(
std::vector<XicCoordTims *>::iterator &itXicListbegin,
std::vector<XicCoordTims *>::iterator &itXicListend,
XicExtractMethod method) const;
/** @brief cumulate a scan into a map
*
* @param scanNum scan number 0 to (m_scanNumber-1)
*/
virtual void cumulateScan(std::size_t scanNum,
std::map<quint32, quint32> &accumulate_into) const;
/** @brief get the raw index tof_index and intensities (normalized)
*
* @param scanNum the scan number to extract
* @return trace vector
*
*/
virtual pappso::TraceSPtr getRawTraceSPtr(std::size_t scanNum) const;
private:
/** @brief unshuffle data packet of tims compression type 2
* @param src is a zstd decompressed buffer pointer
*/
void unshufflePacket(const char *src);
/** @brief get offset for this spectrum in the binary file
*
* @param scanNum scan number in the frame in the order it lies in binary
* file, from 0 to N-1
*/
std::size_t getScanOffset(std::size_t scanNum) const;
private:
struct XicComputeStructure
{
XicComputeStructure(const TimsFrame *fram_p,
const XicCoordTims &xic_struct);
Xic *xic_ptr = nullptr;
std::size_t mobilityIndexBegin;
std::size_t mobilityIndexEnd;
std::size_t mzIndexLowerBound;
std::size_t mzIndexUpperBound;
double tmpIntensity = 0;
};
protected:
QByteArray m_timsDataFrame;
};
} // namespace pappso
pappso::TimsBinDec
Definition: timsbindec.h:41
pappso::TimsDirectXicExtractor
Definition: timsdirectxicextractor.h:38
pappso::TimsFrameBase
Definition: timsframebase.h:48
pappso::TimsFrame
Definition: timsframe.h:53
pappso::TimsFrame::m_timsDataFrame
QByteArray m_timsDataFrame
Definition: timsframe.h:181
pappso::TimsFrame::getNbrPeaks
virtual std::size_t getNbrPeaks(std::size_t scanNum) const override
get the number of peaks in this spectrum need the binary file
Definition: timsframe.cpp:131
pappso::TimsFrame::~TimsFrame
~TimsFrame()
Definition: timsframe.cpp:98
pappso::TimsFrame::cumulateScan
virtual void cumulateScan(std::size_t scanNum, std::map< quint32, quint32 > &accumulate_into) const
cumulate a scan into a map
Definition: timsframe.cpp:222
pappso::TimsFrame::TimsFrame
TimsFrame(std::size_t timsId, quint32 scanNum, char *p_bytes, std::size_t len)
Definition: timsframe.cpp:63
pappso::TimsFrame::TimsDirectXicExtractor
friend TimsDirectXicExtractor
Definition: timsframe.h:54
pappso::TimsFrame::getMassSpectrumSPtr
virtual pappso::MassSpectrumSPtr getMassSpectrumSPtr(std::size_t scanNum) const override
get Mass spectrum with peaks for this scan number need the binary file
Definition: timsframe.cpp:359
pappso::TimsFrame::unshufflePacket
void unshufflePacket(const char *src)
unshuffle data packet of tims compression type 2
Definition: timsframe.cpp:104
pappso::TimsFrame::getScanOffset
std::size_t getScanOffset(std::size_t scanNum) const
get offset for this spectrum in the binary file
Definition: timsframe.cpp:161
pappso::TimsFrame::cumulateScansInRawMap
virtual void cumulateScansInRawMap(std::map< quint32, quint32 > &rawSpectrum, std::size_t scanNumBegin, std::size_t scanNumEnd) const override
cumulate scan list into a trace into a raw spectrum map
Definition: timsframe.cpp:316
pappso::TimsFrame::cumulateScanToTrace
virtual Trace cumulateScanToTrace(std::size_t scanNumBegin, std::size_t scanNumEnd) const override
cumulate scan list into a trace
Definition: timsframe.cpp:260
pappso::TimsFrame::getScanIndexList
virtual std::vector< quint32 > getScanIndexList(std::size_t scanNum) const
get raw index list for one given scan index are not TOF nor m/z, just index on digitizer
Definition: timsframe.cpp:173
pappso::TimsFrame::getScanIntensities
virtual std::vector< quint32 > getScanIntensities(std::size_t scanNum) const
get raw intensities without transformation from one scan it needs intensity normalization
Definition: timsframe.cpp:198
pappso::TimsFrame::extractTimsXicListInRtRange
void extractTimsXicListInRtRange(std::vector< XicCoordTims * >::iterator &itXicListbegin, std::vector< XicCoordTims * >::iterator &itXicListend, XicExtractMethod method) const
Definition: timsframe.cpp:412
pappso::TimsFrame::getMassSpectrumCstSPtr
virtual pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtr(std::size_t scanNum) const
get the mass spectrum corresponding to a scan number
Definition: timsframe.cpp:352
pappso::TimsFrame::getRawTraceSPtr
virtual pappso::TraceSPtr getRawTraceSPtr(std::size_t scanNum) const
get the raw index tof_index and intensities (normalized)
Definition: timsframe.cpp:504
pappso::Trace
A simple container of DataPoint instances.
Definition: trace.h:148
pappso::Xic
Definition: xic.h:44
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
pappso::TimsFrameSPtr
std::shared_ptr< TimsFrame > TimsFrameSPtr
Definition: timsframe.h:41
pappso::TraceSPtr
std::shared_ptr< Trace > TraceSPtr
Definition: trace.h:135
pappso::MassSpectrumCstSPtr
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
Definition: massspectrum.h:55
pappso::MassSpectrumSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:54
pappso::XicExtractMethod
XicExtractMethod
Definition: types.h:200
pappso::TimsFrameCstSPtr
std::shared_ptr< const TimsFrame > TimsFrameCstSPtr
Definition: timsframe.h:43
pappso::TimsFrame::XicComputeStructure
Definition: timsframe.h:167
pappso::TimsFrame::XicComputeStructure::tmpIntensity
double tmpIntensity
Definition: timsframe.h:177
pappso::TimsFrame::XicComputeStructure::XicComputeStructure
XicComputeStructure(const TimsFrame *fram_p, const XicCoordTims &xic_struct)
Definition: timsframe.cpp:41
pappso::TimsFrame::XicComputeStructure::xic_ptr
Xic * xic_ptr
Definition: timsframe.h:172
pappso::TimsFrame::XicComputeStructure::mobilityIndexBegin
std::size_t mobilityIndexBegin
Definition: timsframe.h:173
pappso::TimsFrame::XicComputeStructure::mzIndexUpperBound
std::size_t mzIndexUpperBound
Definition: timsframe.h:176
pappso::TimsFrame::XicComputeStructure::mzIndexLowerBound
std::size_t mzIndexLowerBound
Definition: timsframe.h:175
pappso::TimsFrame::XicComputeStructure::mobilityIndexEnd
std::size_t mobilityIndexEnd
Definition: timsframe.h:174
pappso::XicCoordTims
coordinates of the XIC to extract and the resulting XIC after extraction
Definition: xiccoordtims.h:51
timsframebase.h
handle a single Bruker's TimsTof frame without binary data