libpappsomspp
Library for mass spectrometry
pappso::TimsFramesMsRunReader Class Reference

#include <timsframesmsrunreader.h>

Inheritance diagram for pappso::TimsFramesMsRunReader:
pappso::MsRunReader

Public Member Functions

 TimsFramesMsRunReader (MsRunIdCstSPtr &msrun_id_csp)
 
virtual ~TimsFramesMsRunReader ()
 
virtual MassSpectrumSPtr massSpectrumSPtr (std::size_t spectrum_index) override
 get a MassSpectrumSPtr class given its spectrum index More...
 
virtual MassSpectrumCstSPtr massSpectrumCstSPtr (std::size_t spectrum_index) override
 
virtual QualifiedMassSpectrum qualifiedMassSpectrum (std::size_t spectrum_index, bool want_binary_data=true) const override
 get a QualifiedMassSpectrum class given its scan number More...
 
virtual void readSpectrumCollection (SpectrumCollectionHandlerInterface &handler) override
 function to visit an MsRunReader and get each Spectrum in a spectrum collection handler More...
 
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 More...
 
virtual pappso::XicCoordSPtr newXicCoordSPtrFromSpectrumIndex (std::size_t spectrum_index, pappso::PrecisionPtr precision) const override
 get a xic coordinate object from a given spectrum index More...
 
virtual pappso::XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum (const pappso::QualifiedMassSpectrum &mass_spectrum, pappso::PrecisionPtr precision) const override
 get a xic coordinate object from a given spectrum More...
 
virtual std::size_t spectrumListSize () const override
 get the totat number of spectrum conained in the MSrun data file More...
 
virtual bool hasScanNumbers () const override
 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 More...
 
virtual bool releaseDevice () override
 release data back end device if a the data back end is released, the developper has to use acquireDevice before using the msrunreader object More...
 
virtual bool acquireDevice () override
 acquire data back end device More...
 
virtual TimsDataSp getTimsDataSPtr ()
 give an access to the underlying raw data pointer More...
 
virtual Trace getTicChromatogram () override
 get a TIC chromatogram More...
 
virtual Trace computeTicChromatogram ()
 
- Public Member Functions inherited from pappso::MsRunReader
 MsRunReader (MsRunIdCstSPtr &ms_run_id)
 
 MsRunReader (const MsRunReader &other)
 
virtual ~MsRunReader ()
 
const MsRunIdCstSPtrgetMsRunId () const
 
virtual MassSpectrumSPtr massSpectrumSPtr (std::size_t spectrum_index)=0
 get a MassSpectrumSPtr class given its spectrum index More...
 
virtual MassSpectrumCstSPtr massSpectrumCstSPtr (std::size_t spectrum_index)=0
 
virtual QualifiedMassSpectrum qualifiedMassSpectrum (std::size_t spectrum_index, bool want_binary_data=true) const =0
 get a QualifiedMassSpectrum class given its scan number More...
 
virtual XicCoordSPtr newXicCoordSPtrFromSpectrumIndex (std::size_t spectrum_index, PrecisionPtr precision) const =0
 get a xic coordinate object from a given spectrum index More...
 
virtual XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum (const QualifiedMassSpectrum &mass_spectrum, PrecisionPtr precision) const =0
 get a xic coordinate object from a given spectrum More...
 
virtual std::size_t spectrumListSize () const =0
 get the totat number of spectrum conained in the MSrun data file More...
 
virtual void readSpectrumCollection (SpectrumCollectionHandlerInterface &handler)=0
 function to visit an MsRunReader and get each Spectrum in a spectrum collection handler More...
 
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 More...
 
virtual std::size_t scanNumber2SpectrumIndex (std::size_t scan_number)
 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. More...
 
virtual bool hasScanNumbers () const
 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 More...
 
virtual bool releaseDevice ()=0
 release data back end device if a the data back end is released, the developper has to use acquireDevice before using the msrunreader object More...
 
virtual bool acquireDevice ()=0
 acquire data back end device More...
 
virtual std::vector< double > getRetentionTimeLine ()
 retention timeline get retention times along the MSrun in seconds More...
 
virtual Trace getTicChromatogram ()
 get a TIC chromatogram More...
 
void setMonoThread (bool is_mono_thread)
 set only one is_mono_thread to true More...
 
bool isMonoThread () const
 

Protected Member Functions

virtual void initialize () override
 
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, specific of one or more file format More...
 
virtual void initialize ()=0
 
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, specific of one or more file format More...
 

Private Attributes

TimsDataSp msp_timsData = nullptr
 

Friends

class MsFileAccessor
 

Additional Inherited Members

- Protected Attributes inherited from pappso::MsRunReader
MsRunIdCstSPtr mcsp_msRunId
 
MsRunReaderScanNumberMultiMapmpa_multiMapScanNumber = nullptr
 

Detailed Description

Definition at line 43 of file timsframesmsrunreader.h.

Constructor & Destructor Documentation

◆ TimsFramesMsRunReader()

TimsFramesMsRunReader::TimsFramesMsRunReader ( MsRunIdCstSPtr msrun_id_csp)
Todo:
write docs

Definition at line 34 of file timsframesmsrunreader.cpp.

35 : MsRunReader(msrun_id_csp)
36{
37 qDebug() << "Now initializing the TimsFramesMsRunReader.";
38
39 initialize();
40}
MsRunReader(MsRunIdCstSPtr &ms_run_id)
virtual void initialize() override

References initialize().

◆ ~TimsFramesMsRunReader()

TimsFramesMsRunReader::~TimsFramesMsRunReader ( )
virtual

Definition at line 42 of file timsframesmsrunreader.cpp.

43{
44 msp_timsData = nullptr;
45}

References msp_timsData.

Member Function Documentation

◆ accept()

bool TimsFramesMsRunReader::accept ( const QString &  file_name) const
overrideprotectedvirtual

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

Implements pappso::MsRunReader.

Definition at line 62 of file timsframesmsrunreader.cpp.

63{
64 qDebug() << file_name;
65 return true;
66}

◆ acquireDevice()

bool TimsFramesMsRunReader::acquireDevice ( )
overridevirtual

acquire data back end device

Returns
bool true if done

Implements pappso::MsRunReader.

Definition at line 216 of file timsframesmsrunreader.cpp.

217{
218 if(msp_timsData == nullptr)
219 {
220 initialize();
221 }
222 return true;
223}

References initialize(), and msp_timsData.

Referenced by getTicChromatogram(), and getTimsDataSPtr().

◆ computeTicChromatogram()

Trace TimsFramesMsRunReader::computeTicChromatogram ( )
virtual

Definition at line 269 of file timsframesmsrunreader.cpp.

270{
271
272 // We want to compute the TIC chromatogram, not load the chromatogram that is
273 // located in the SQL database.
274 //
275 // For this, we need to iterated into the frames and ask for MS1 spectra only.
276 // msp_timsData has that information:
277 //
278 // std::vector<FrameIdDescr> m_frameIdDescrList;
279 //
280 // and
281
282 // struct FrameIdDescr
283 // {
284 // std::size_t m_frameId; // frame id
285 // std::size_t m_size; // frame size (number of TOF scans in frame)
286 // std::size_t m_cumulSize; // cumulative size
287 // };
288
289 Trace tic_chromatogram;
290
291 const std::vector<FrameIdDescr> frame_descr_list =
292 msp_timsData->getFrameIdDescrList();
293
294 for(FrameIdDescr frame_id_descr : frame_descr_list)
295 {
296 TimsFrameCstSPtr tims_frame_csp =
297 msp_timsData->getTimsFrameCstSPtrCached(frame_id_descr.m_frameId);
298 std::size_t scan_begin = 0;
299 std::size_t scan_end = tims_frame_csp->getTotalNumberOfScans() - 1;
300
301 // By convention, a TIC chromatogram is only performed using MS1 spectra.
302 if(tims_frame_csp->getMsLevel() == 1)
303 {
304
305 double rt = tims_frame_csp->getTime();
306
307 tic_chromatogram.append(DataPoint(
308 rt,
309 tims_frame_csp->cumulateScansIntensities(scan_begin, scan_end)));
310 }
311 else
312 continue;
313 }
314
315 return tic_chromatogram;
316}
A simple container of DataPoint instances.
Definition: trace.h:148
size_t append(const DataPoint &data_point)
appends a datapoint and return new size
Definition: trace.cpp:583
@ rt
Retention time.
std::shared_ptr< const TimsFrame > TimsFrameCstSPtr
Definition: timsframe.h:42

References pappso::Trace::append(), msp_timsData, and pappso::rt.

◆ getTicChromatogram()

Trace TimsFramesMsRunReader::getTicChromatogram ( )
overridevirtual

get a TIC chromatogram

for each retention time, computes the sum of all intensities. For IM-MS, combines the mobility spectra

Note that, formally, a TIC chromatogram is computed only for MS1 spectra.

Returns
a trace (x=rt, y=intensities)

Reimplemented from pappso::MsRunReader.

Definition at line 257 of file timsframesmsrunreader.cpp.

258{
259 // Use the Sqlite database to fetch the total ion current chromatogram (TIC
260 // chromatogram).
261
263
264 return msp_timsData->getTicChromatogram();
265}
virtual bool acquireDevice() override
acquire data back end device

References acquireDevice(), and msp_timsData.

◆ getTimsDataSPtr()

TimsDataSp TimsFramesMsRunReader::getTimsDataSPtr ( )
virtual

give an access to the underlying raw data pointer

Definition at line 249 of file timsframesmsrunreader.cpp.

250{
252 return msp_timsData;
253}

References acquireDevice(), and msp_timsData.

◆ hasScanNumbers()

bool TimsFramesMsRunReader::hasScanNumbers ( ) const
overridevirtual

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

Reimplemented from pappso::MsRunReader.

Definition at line 202 of file timsframesmsrunreader.cpp.

203{
204 return false;
205}

◆ initialize()

void TimsFramesMsRunReader::initialize ( )
overrideprotectedvirtual

Implements pappso::MsRunReader.

Definition at line 48 of file timsframesmsrunreader.cpp.

49{
50 msp_timsData = std::make_shared<TimsData>(mcsp_msRunId.get()->getFileName());
51 if(msp_timsData == nullptr)
52 {
53 throw PappsoException(
54 QObject::tr("ERROR in TimsFramesMsRunReader::initialize "
55 "msp_timsData is null for MsRunId %1")
56 .arg(mcsp_msRunId.get()->toString()));
57 }
58}
MsRunIdCstSPtr mcsp_msRunId
Definition: msrunreader.h:301

References pappso::MsRunReader::mcsp_msRunId, and msp_timsData.

Referenced by TimsFramesMsRunReader(), and acquireDevice().

◆ massSpectrumCstSPtr()

pappso::MassSpectrumCstSPtr TimsFramesMsRunReader::massSpectrumCstSPtr ( std::size_t  spectrum_index)
overridevirtual

Implements pappso::MsRunReader.

Definition at line 82 of file timsframesmsrunreader.cpp.

83{
84 return msp_timsData->getMassSpectrumCstSPtrByRawIndex(spectrum_index);
85}

References msp_timsData.

◆ massSpectrumSPtr()

pappso::MassSpectrumSPtr TimsFramesMsRunReader::massSpectrumSPtr ( std::size_t  spectrum_index)
overridevirtual

get a MassSpectrumSPtr class given its spectrum index

Implements pappso::MsRunReader.

Definition at line 70 of file timsframesmsrunreader.cpp.

72{
74 QObject::tr("Not yet implemented in TimsFramesMsRunReader %1.\n")
75 .arg(__LINE__));
76
78}
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:54

◆ newXicCoordSPtrFromQualifiedMassSpectrum()

XicCoordSPtr TimsFramesMsRunReader::newXicCoordSPtrFromQualifiedMassSpectrum ( const pappso::QualifiedMassSpectrum mass_spectrum,
pappso::PrecisionPtr  precision 
) const
overridevirtual

get a xic coordinate object from a given spectrum

Implements pappso::MsRunReader.

Definition at line 238 of file timsframesmsrunreader.cpp.

241{
242 throw ExceptionNotImplemented(QObject::tr("Not implemented %1 %2 %3")
243 .arg(__FILE__)
244 .arg(__FUNCTION__)
245 .arg(__LINE__));
246}

◆ newXicCoordSPtrFromSpectrumIndex()

XicCoordSPtr TimsFramesMsRunReader::newXicCoordSPtrFromSpectrumIndex ( std::size_t  spectrum_index,
pappso::PrecisionPtr  precision 
) const
overridevirtual

get a xic coordinate object from a given spectrum index

Implements pappso::MsRunReader.

Definition at line 227 of file timsframesmsrunreader.cpp.

230{
231 throw ExceptionNotImplemented(QObject::tr("Not implemented %1 %2 %3")
232 .arg(__FILE__)
233 .arg(__FUNCTION__)
234 .arg(__LINE__));
235}

◆ qualifiedMassSpectrum()

QualifiedMassSpectrum TimsFramesMsRunReader::qualifiedMassSpectrum ( std::size_t  spectrum_index,
bool  want_binary_data = true 
) const
overridevirtual

get a QualifiedMassSpectrum class given its scan number

Implements pappso::MsRunReader.

Definition at line 89 of file timsframesmsrunreader.cpp.

91{
92
93 QualifiedMassSpectrum mass_spectrum;
94
95 msp_timsData->getQualifiedMassSpectrumByRawIndex(
96 getMsRunId(), mass_spectrum, spectrum_index, want_binary_data);
97 return mass_spectrum;
98}
const MsRunIdCstSPtr & getMsRunId() const
Class representing a fully specified mass spectrum.

References pappso::MsRunReader::getMsRunId(), and msp_timsData.

◆ readSpectrumCollection()

void TimsFramesMsRunReader::readSpectrumCollection ( SpectrumCollectionHandlerInterface handler)
overridevirtual

function to visit an MsRunReader and get each Spectrum in a spectrum collection handler

Implements pappso::MsRunReader.

Definition at line 102 of file timsframesmsrunreader.cpp.

104{
105 // Here we want to only handle mass spectra as combined scans spectra, that
106 // is, for each frame, we want all the mobility scans to be cumulated (at the
107 // integer level, that is, without conversion of all the integers to m/z
108 // values) so as to yield a *single* mass spectrum per frame.
109
110 // We can iterate in the vector of frames records and for each frame ask that
111 // all its scans be combined into a single mass spectrum.
112
113 const std::vector<FrameIdDescr> frame_id_descr_list =
114 msp_timsData->getFrameIdDescrList();
115
116 // The scan index is the index of the scan in the *whole* mass data file, it
117 // is a sequential number of scan over all the frames.
118 std::size_t scan_index = 0; // iterate in each spectrum
119
120 // We'll need it to perform the looping in the spectrum list.
121 std::size_t frames_count = msp_timsData->getTotalNumberOfFrames();
122
123 qDebug() << "The spectrum list has this much frames:" << frames_count;
124
125 // Inform the handler of the spectrum list so that it can handle feedback to
126 // the user.
127 handler.spectrumListHasSize(frames_count);
128
129 for(const FrameIdDescr &current_frame : frame_id_descr_list)
130 {
131 TimsFrameCstSPtr tims_frame =
132 msp_timsData->getTimsFrameCstSPtrCached(current_frame.m_frameId);
133
134 // Get to know the size of the frame, that is, the number of mobility
135 // scans in it.
136
137 quint32 scan_count = tims_frame->getTotalNumberOfScans();
138
139 Trace spectrum = tims_frame->cumulateScanToTrace(0, scan_count - 1);
140
141 QualifiedMassSpectrum mass_spectrum;
142
143 MassSpectrumId spectrum_id;
144
145 spectrum_id.setSpectrumIndex(scan_index);
146
147 spectrum_id.setMsRunId(getMsRunId());
148
149 // Can modify to help our case
150 spectrum_id.setNativeId(QString("frame=%1 index=%1")
151 .arg(current_frame.m_frameId)
152 .arg(scan_index));
153
154 mass_spectrum.setMassSpectrumId(spectrum_id);
155
156 // We want to document the retention time!
157 mass_spectrum.setRtInSeconds(tims_frame.get()->getTime());
158
159 // We do want to document the ms level of the spectrum and possibly the
160 // precursor's m/z and charge.
161 unsigned int frame_ms_level = tims_frame.get()->getMsLevel();
162 mass_spectrum.setMsLevel(frame_ms_level);
163
164 if(frame_ms_level > 1)
165 {
166 // FIXME
167 // We want to document the precusor's m/z, z and index.
168 }
169
170 mass_spectrum.setDtInMilliSeconds(-1);
171
172 mass_spectrum.setEmptyMassSpectrum(false);
173
174 mass_spectrum.setMassSpectrumSPtr(
175 std::make_shared<MassSpectrum>(spectrum));
176
177 handler.setQualifiedMassSpectrum(mass_spectrum);
178
179 scan_index += scan_count;
180 }
181}
void setNativeId(const QString &native_id)
void setMsRunId(MsRunIdCstSPtr other)
void setSpectrumIndex(std::size_t index)
void setDtInMilliSeconds(pappso_double rt)
Set the drift time in milliseconds.
void setMassSpectrumId(const MassSpectrumId &iD)
Set the MassSpectrumId.
void setMsLevel(uint ms_level)
Set the mass spectrum level.
void setMassSpectrumSPtr(MassSpectrumSPtr massSpectrum)
Set the MassSpectrumSPtr.
void setRtInSeconds(pappso_double rt)
Set the retention time in seconds.
void setEmptyMassSpectrum(bool is_empty_mass_spectrum)
virtual void spectrumListHasSize(std::size_t size)
Definition: msrunreader.cpp:53
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum)=0

References pappso::MsRunReader::getMsRunId(), msp_timsData, pappso::QualifiedMassSpectrum::setDtInMilliSeconds(), pappso::QualifiedMassSpectrum::setEmptyMassSpectrum(), pappso::QualifiedMassSpectrum::setMassSpectrumId(), pappso::QualifiedMassSpectrum::setMassSpectrumSPtr(), pappso::QualifiedMassSpectrum::setMsLevel(), pappso::MassSpectrumId::setMsRunId(), pappso::MassSpectrumId::setNativeId(), pappso::SpectrumCollectionHandlerInterface::setQualifiedMassSpectrum(), pappso::QualifiedMassSpectrum::setRtInSeconds(), pappso::MassSpectrumId::setSpectrumIndex(), and pappso::SpectrumCollectionHandlerInterface::spectrumListHasSize().

◆ readSpectrumCollectionByMsLevel()

void TimsFramesMsRunReader::readSpectrumCollectionByMsLevel ( SpectrumCollectionHandlerInterface handler,
unsigned int  ms_level 
)
overridevirtual

function to visit an MsRunReader and get each Spectrum in a spectrum collection handler by Ms Levels

Implements pappso::MsRunReader.

Definition at line 185 of file timsframesmsrunreader.cpp.

188{
189
190 qDebug();
191}

◆ releaseDevice()

bool TimsFramesMsRunReader::releaseDevice ( )
overridevirtual

release data back end device if a the data back end is released, the developper has to use acquireDevice before using the msrunreader object

Returns
bool true if done

Implements pappso::MsRunReader.

Definition at line 209 of file timsframesmsrunreader.cpp.

210{
211 msp_timsData = nullptr;
212 return true;
213}

References msp_timsData.

◆ spectrumListSize()

std::size_t TimsFramesMsRunReader::spectrumListSize ( ) const
overridevirtual

get the totat number of spectrum conained in the MSrun data file

Implements pappso::MsRunReader.

Definition at line 195 of file timsframesmsrunreader.cpp.

196{
197 return msp_timsData->getTotalNumberOfScans();
198}

References msp_timsData.

Friends And Related Function Documentation

◆ MsFileAccessor

friend class MsFileAccessor
friend

Definition at line 45 of file timsframesmsrunreader.h.

Member Data Documentation

◆ msp_timsData


The documentation for this class was generated from the following files: