libpappsomspp
Library for mass spectrometry
pappso::TimsFrame Class Reference

#include <timsframe.h>

Inheritance diagram for pappso::TimsFrame:
pappso::TimsFrameBase

Classes

struct  XicComputeStructure
 

Public Member Functions

 TimsFrame (std::size_t timsId, quint32 scanNum, char *p_bytes, std::size_t len)
 
 TimsFrame (const TimsFrame &other)
 
 ~TimsFrame ()
 
virtual std::size_t getNbrPeaks (std::size_t scanNum) const override
 
virtual Trace cumulateScanToTrace (std::size_t scanNumBegin, std::size_t scanNumEnd) const override
 cumulate scan list into a trace More...
 
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 More...
 
void cumulateScans (std::size_t scanNumBegin, std::size_t scanNumEnd, std::map< quint32, quint32 > &accumulate_into) const
 cumulate a scan list into a map of integers More...
 
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 More...
 
std::vector< quint32 > getScanIntensities (std::size_t scanNum) const
 get raw intensities without transformation from one scan it needs intensity normalization More...
 
pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtr (std::size_t scanNum) const
 get the mass spectrum corresponding to a scan number More...
 
virtual pappso::MassSpectrumSPtr getMassSpectrumSPtr (std::size_t scanNum) const override
 
- Public Member Functions inherited from pappso::TimsFrameBase
 TimsFrameBase (std::size_t timsId, quint32 scanNum)
 constructor for binary independant tims frame More...
 
 TimsFrameBase (const TimsFrameBase &other)
 
 ~TimsFrameBase ()
 
virtual bool hasSameCalibrationData (const TimsFrameBase &other) const
 tells if 2 tims frame has the same calibration data Usefull to know if raw data can be handled between frames More...
 
bool checkScanNum (std::size_t scanNum) const
 
void setAccumulationTime (double accumulation_time_ms)
 
void setMzCalibration (double temperature_correction, double digitizerTimebase, double digitizerDelay, double C0, double C1, double C2, double C3)
 
void setTimsCalibration (int tims_model_type, double C0, double C1, double C2, double C3, double C4, double C5, double C6, double C7, double C8, double C9)
 
void setTime (double time)
 
void setMsMsType (quint8 type)
 
unsigned int getMsLevel () const
 
double getTime () const
 
std::size_t getId () const
 
double getDriftTime (std::size_t scanNum) const
 get drift time of a scan number in milliseconds More...
 
double getOneOverK0Transformation (std::size_t scanNum) const
 get 1/K0 value of a given scan (mobility value) More...
 
double getMzFromTof (double tof) const
 get m/z from time of flight More...
 
quint32 getRawIndexFromMz (double mz) const
 get raw index of a given m/z More...
 
std::size_t getScanNumFromOneOverK0 (double one_over_k0) const
 get the scan number from a given 1/Ko mobility value More...
 
double getVoltageTransformation (std::size_t scanNum) const
 
double getTofFromIndex (quint32 index) const
 get time of flight from raw index More...
 
double getTofFromIndex (double index) const
 get time of flight from double index More...
 
pappso::Trace getTraceFromCumulatedScans (std::map< quint32, quint32 > &accumulated_scans) const
 transform accumulation of raw scans into a real mass spectrum More...
 
pappso::Trace getTraceFromCumulatedScansBuiltinCentroid (std::map< quint32, quint32 > &accumulated_scans) const
 transform accumulation of raw scans into a real mass spectrum with a simple centroid on raw integers More...
 

Protected Member Functions

void extractTimsXicListInRtRange (std::vector< TimsXicStructure >::iterator &itXicListbegin, std::vector< TimsXicStructure >::iterator &itXicListend, XicExtractMethod method) const
 

Private Member Functions

void unshufflePacket (const char *src)
 
std::size_t getScanOffset (std::size_t scanNum) const
 
void cumulateScan (std::size_t scanNum, std::map< quint32, quint32 > &accumulate_into) const
 cumulate a scan into a map More...
 
pappso::TraceSPtr getRawTraceSPtr (std::size_t scanNum) const
 

Private Attributes

friend TimsDirectXicExtractor
 
QByteArray m_timsDataFrame
 

Additional Inherited Members

- Protected Attributes inherited from pappso::TimsFrameBase
quint32 m_scanNumber
 total number of scans contained in this frame More...
 
std::size_t m_timsId
 Tims frame database id (the SQL identifier of this frame) More...
 
double m_accumulationTime = 0
 accumulation time in milliseconds More...
 
double m_digitizerTimebase = 0
 
double m_digitizerDelay = 0
 
std::vector< double > m_mzCalibrationArr
 MZ calibration parameters. More...
 
quint8 m_msMsType = 0
 
double m_time = 0
 retention time More...
 
double m_timsDvStart = 0
 
double m_timsSlope
 
double m_timsTtrans = 0
 
double m_timsNdelay = 0
 
double m_timsVmin = 0
 
double m_timsVmax = 0
 
double m_timsC6 = 0
 
double m_timsC7 = 0
 

Detailed Description

Todo:
write docs

Definition at line 70 of file timsframe.h.

Constructor & Destructor Documentation

◆ TimsFrame() [1/2]

pappso::TimsFrame::TimsFrame ( std::size_t  timsId,
quint32  scanNum,
char *  p_bytes,
std::size_t  len 
)

Default constructor

Definition at line 72 of file timsframe.cpp.

72  {
73  if(m_scanNumber == 0)
74  {
75 
77  QObject::tr("TimsFrame::TimsFrame(%1,%2,nullptr,%3) FAILED")
78  .arg(m_timsId)
79  .arg(m_scanNumber)
80  .arg(len));
81  }
82  }
83 }
84 
85 TimsFrame::TimsFrame(const TimsFrame &other) : TimsFrameBase(other)
86 {
87 }
88 
90 {
91 }
92 
93 
94 void
95 TimsFrame::unshufflePacket(const char *src)
96 {
97  qDebug();
98  quint64 len = m_timsDataFrame.size();
99  if(len % 4 != 0)
100  {

References pappso::TimsFrameBase::m_scanNumber, and pappso::TimsFrameBase::m_timsId.

◆ TimsFrame() [2/2]

pappso::TimsFrame::TimsFrame ( const TimsFrame other)

Copy constructor

Parameters
otherTODO

Definition at line 103 of file timsframe.cpp.

111  {

◆ ~TimsFrame()

pappso::TimsFrame::~TimsFrame ( )

Destructor

Definition at line 107 of file timsframe.cpp.

111  {

Member Function Documentation

◆ cumulateScan()

void pappso::TimsFrame::cumulateScan ( std::size_t  scanNum,
std::map< quint32, quint32 > &  accumulate_into 
) const
private

cumulate a scan into a map

Definition at line 231 of file timsframe.cpp.

241  {
242  // already existed : cumulate
243  ret.first->second += y;
244  }
245  }
246  qDebug();
247 }
248 
249 
250 Trace
251 TimsFrame::cumulateScanToTrace(std::size_t scanNumBegin,
252  std::size_t scanNumEnd) const
253 {
254  qDebug();
255 
256  Trace new_trace;
257 
258  try
259  {
260  if(m_timsDataFrame.size() == 0)
261  return new_trace;
262  std::map<quint32, quint32> raw_spectrum;
263  // double local_accumulationTime = 0;
264 
265  std::size_t imax = scanNumEnd + 1;

References pappso::x, and pappso::y.

◆ cumulateScans()

void pappso::TimsFrame::cumulateScans ( std::size_t  scanNumBegin,
std::size_t  scanNumEnd,
std::map< quint32, quint32 > &  accumulate_into 
) const

cumulate a scan list into a map of integers

Parameters
scanNumBeginfirst scan to cumulate
scanNumEndlast scan to cumulate
accumulate_intomap of x and y integer values

◆ cumulateScansInRawMap()

void pappso::TimsFrame::cumulateScansInRawMap ( std::map< quint32, quint32 > &  rawSpectrum,
std::size_t  scanNumBegin,
std::size_t  scanNumEnd 
) const
overridevirtual

cumulate scan list into a trace into a raw spectrum map

Parameters
rawSpectrumsimple map of integers to cumulate raw counts
scanNumBeginfirst scan to cumulate
scanNumEndlast scan to cumulate

Reimplemented from pappso::TimsFrameBase.

Definition at line 320 of file timsframe.cpp.

325  {
326  qDebug() << QString("Failure in %1 %2 to %3 :\n %4")
327  .arg(__FUNCTION__)
328  .arg(scanNumBegin)
329  .arg(scanNumEnd)
330  .arg(error.what());
331  }
332 }
333 
334 
336 TimsFrame::getMassSpectrumCstSPtr(std::size_t scanNum) const
337 {
338  qDebug();
339  return getMassSpectrumSPtr(scanNum);
340 }
341 
343 TimsFrame::getMassSpectrumSPtr(std::size_t scanNum) const
344 {
345 
346  qDebug() << " scanNum=" << scanNum;
347 
348  checkScanNum(scanNum);
349 
350  qDebug();

◆ cumulateScanToTrace()

Trace pappso::TimsFrame::cumulateScanToTrace ( std::size_t  scanNumBegin,
std::size_t  scanNumEnd 
) const
overridevirtual

cumulate scan list into a trace

Parameters
scanNumBeginfirst scan to cumulate
scanNumEndlast scan to cumulate
Returns
Trace mz and intensity values

Reimplemented from pappso::TimsFrameBase.

Definition at line 269 of file timsframe.cpp.

277  : raw_spectrum)
278  {
279  data_point_cumul.x =
280  getMzFromTof(getTofFromIndex(pair_tof_intensity.first));
281  // normalization
282  data_point_cumul.y =
283  pair_tof_intensity.second * ((double)100.0 / m_accumulationTime);
284  new_trace.push_back(data_point_cumul);
285  }
286  new_trace.sortX();
287  qDebug();
288  }
289 
290  catch(std::exception &error)
291  {
292  qDebug() << QString(
293  "Failure in TimsFrame::cumulateScanToTrace %1 to %2 :\n %3")
294  .arg(scanNumBegin, scanNumEnd)
295  .arg(error.what());
296  }
297  return new_trace;
298 }
299 
300 
301 void
302 TimsFrame::cumulateScansInRawMap(std::map<quint32, quint32> &rawSpectrum,
303  std::size_t scanNumBegin,
304  std::size_t scanNumEnd) const
305 {
306  qDebug();
307 
308  if(m_timsDataFrame.size() == 0)
309  return;
310  try
311  {
312 
313  std::size_t imax = scanNumEnd + 1;
314  qDebug();
315  for(std::size_t i = scanNumBegin; i < imax; i++)
316  {

◆ extractTimsXicListInRtRange()

void pappso::TimsFrame::extractTimsXicListInRtRange ( std::vector< TimsXicStructure >::iterator &  itXicListbegin,
std::vector< TimsXicStructure >::iterator &  itXicListend,
XicExtractMethod  method 
) const
protected

Definition at line 409 of file timsframe.cpp.

411  : tmp_xic_list)
412  {
413  for(std::size_t scan = struct_xic.mobilityIndexBegin;
414  scan <= struct_xic.mobilityIndexEnd;
415  scan++)
416  {
417  unique_scan_num_list.push_back(scan);
418  }
419  }
420  std::sort(unique_scan_num_list.begin(), unique_scan_num_list.end());
421  auto it_scan_num_end =
422  std::unique(unique_scan_num_list.begin(), unique_scan_num_list.end());
423  auto it_scan_num = unique_scan_num_list.begin();
424 
425  while(it_scan_num != it_scan_num_end)
426  {
427  TraceSPtr ms_spectrum = getRawTraceSPtr(*it_scan_num);
428  for(auto &&tmp_xic_struct : tmp_xic_list)
429  {
430  if(((*it_scan_num) >= tmp_xic_struct.mobilityIndexBegin) &&
431  ((*it_scan_num) <= tmp_xic_struct.mobilityIndexEnd))
432  {
433  if(method == XicExtractMethod::max)
434  {
435  tmp_xic_struct.tmpIntensity +=
436  ms_spectrum.get()->maxY(tmp_xic_struct.mzIndexLowerBound,
437  tmp_xic_struct.mzIndexUpperBound);
438  }
439  else
440  {
441  // sum
442  tmp_xic_struct.tmpIntensity +=
443  ms_spectrum.get()->sumY(tmp_xic_struct.mzIndexLowerBound,
444  tmp_xic_struct.mzIndexUpperBound);
445  }
446  }
447  }
448  it_scan_num++;
449  }
450 
451  for(auto &&tmp_xic_struct : tmp_xic_list)
452  {
453  if(tmp_xic_struct.tmpIntensity != 0)
454  {
455  tmp_xic_struct.xic_ptr->push_back(
456  {m_time, tmp_xic_struct.tmpIntensity});
457  }
458  }
459 }
460 
461 
463 TimsFrame::getRawTraceSPtr(std::size_t scanNum) const
464 {
465 
466  qDebug();
467 
468  pappso::TraceSPtr trace_sptr = std::make_shared<pappso::Trace>();
469  // std::vector<DataPoint>
470 
471  if(m_timsDataFrame.size() == 0)
472  return trace_sptr;
473  qDebug();
474 
475  std::size_t size = getNbrPeaks(scanNum);
476 
477  std::size_t offset = getScanOffset(scanNum);

◆ getMassSpectrumCstSPtr()

pappso::MassSpectrumCstSPtr pappso::TimsFrame::getMassSpectrumCstSPtr ( std::size_t  scanNum) const

get the mass spectrum corresponding to a scan number

Parameters
scanNumthe scan number to retrieve

Definition at line 354 of file timsframe.cpp.

◆ getMassSpectrumSPtr()

pappso::MassSpectrumSPtr pappso::TimsFrame::getMassSpectrumSPtr ( std::size_t  scanNum) const
overridevirtual

Reimplemented from pappso::TimsFrameBase.

Definition at line 361 of file timsframe.cpp.

367  {
368  DataPoint data_point(
369  (*(quint32 *)((m_timsDataFrame.constData() + (offset * 4) + (i * 8))) +
370  previous),
371  (*(quint32 *)(m_timsDataFrame.constData() + (offset * 4) + (i * 8) +
372  4)));
373 
374  // intensity normalization
375  data_point.y *= 100.0 / m_accumulationTime;
376 
377  previous = data_point.x;
378 
379 
380  // mz calibration
381  double tof = (data_point.x * m_digitizerTimebase) + m_digitizerDelay;
382  data_point.x = getMzFromTof(tof);
383  mass_spectrum_sptr.get()->push_back(data_point);
384  }
385  qDebug();
386  return mass_spectrum_sptr;
387 }
388 
389 
390 void
392  std::vector<TimsXicStructure>::iterator &itXicListbegin,
393  std::vector<TimsXicStructure>::iterator &itXicListend,
394  XicExtractMethod method) const
395 {
396  std::vector<TimsFrame::XicComputeStructure> tmp_xic_list;
397 
398  for(auto it = itXicListbegin; it != itXicListend; it++)
399  {
400  tmp_xic_list.push_back(TimsFrame::XicComputeStructure(this, *it));
401  }
402  if(tmp_xic_list.size() == 0)
403  return;
404  /*
405  std::sort(tmp_xic_list.begin(), tmp_xic_list.end(), [](const TimsXicStructure

◆ getNbrPeaks()

std::size_t pappso::TimsFrame::getNbrPeaks ( std::size_t  scanNum) const
overridevirtual

Reimplemented from pappso::TimsFrameBase.

Definition at line 140 of file timsframe.cpp.

153 {
154  std::size_t offset = 0;
155  for(std::size_t i = 0; i < (scanNum + 1); i++)
156  {
157  offset += (*(quint32 *)(m_timsDataFrame.constData() + (i * 4)));
158  }
159  return offset;
160 }
161 
162 
163 std::vector<quint32>
164 TimsFrame::getScanIndexList(std::size_t scanNum) const
165 {
166  qDebug();
167  checkScanNum(scanNum);

◆ getRawTraceSPtr()

pappso::TraceSPtr pappso::TimsFrame::getRawTraceSPtr ( std::size_t  scanNum) const
private

Definition at line 481 of file timsframe.cpp.

482  {
483  DataPoint data_point(
484  (*(quint32 *)((m_timsDataFrame.constData() + (offset * 4) + (i * 8))) +
485  previous),
486  (*(quint32 *)(m_timsDataFrame.constData() + (offset * 4) + (i * 8) +
487  4)));
488 
489  // intensity normalization
490  data_point.y *= 100.0 / m_accumulationTime;
491 
492  previous = data_point.x;
493  }
494  qDebug();
495  return trace_sptr;
496 }
497 
498 } // namespace pappso

References pappso::TimsFrameBase::m_accumulationTime, m_timsDataFrame, pappso::DataPoint::x, and pappso::DataPoint::y.

◆ getScanIndexList()

std::vector< quint32 > pappso::TimsFrame::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 at line 182 of file timsframe.cpp.

190 {
191  qDebug();
192  checkScanNum(scanNum);
193  std::vector<quint32> scan_intensities;
194 
195  if(m_timsDataFrame.size() == 0)
196  return scan_intensities;
197 
198  scan_intensities.resize(getNbrPeaks(scanNum));
199 
200  std::size_t offset = getScanOffset(scanNum);
201 
202  for(std::size_t i = 0; i < scan_intensities.size(); i++)
203  {
204  scan_intensities[i] = (*(quint32 *)(m_timsDataFrame.constData() +

◆ getScanIntensities()

std::vector< quint32 > pappso::TimsFrame::getScanIntensities ( std::size_t  scanNum) const

get raw intensities without transformation from one scan it needs intensity normalization

Definition at line 207 of file timsframe.cpp.

215 {
216  qDebug();
217 
218  if(m_timsDataFrame.size() == 0)
219  return;
220  // checkScanNum(scanNum);
221 
222 
223  std::size_t size = getNbrPeaks(scanNum);
224 
225  std::size_t offset = getScanOffset(scanNum);
226 
227  qint32 previous = -1;

◆ getScanOffset()

std::size_t pappso::TimsFrame::getScanOffset ( std::size_t  scanNum) const
private

Definition at line 170 of file timsframe.cpp.

178  {

◆ unshufflePacket()

void pappso::TimsFrame::unshufflePacket ( const char *  src)
private

Definition at line 113 of file timsframe.cpp.

113  {
114  dest[(i * 4) + j] = src[src_offset];
115  src_offset++;
116  }
117  }
118  qDebug();
119 }
120 
121 std::size_t
122 TimsFrame::getNbrPeaks(std::size_t scanNum) const
123 {
124  if(m_timsDataFrame.size() == 0)
125  return 0;
126  /*
127  if(scanNum == 0)
128  {
129  quint32 res = (*(quint32 *)(m_timsDataFrame.constData() + 4)) -
130  (*(quint32 *)(m_timsDataFrame.constData()-4));
131  return res / 2;
132  }*/
133  if(scanNum == (m_scanNumber - 1))
134  {
135  auto nb_uint4 = m_timsDataFrame.size() / 4;
136 
137  std::size_t cumul = 0;

Referenced by pappso::TimsFrame::XicComputeStructure::XicComputeStructure().

Member Data Documentation

◆ m_timsDataFrame

QByteArray pappso::TimsFrame::m_timsDataFrame
private

◆ TimsDirectXicExtractor

friend pappso::TimsFrame::TimsDirectXicExtractor
private

Definition at line 72 of file timsframe.h.


The documentation for this class was generated from the following files:
pappso::TimsFrameBase::m_digitizerTimebase
double m_digitizerTimebase
Definition: timsframebase.h:203
pappso::TimsFrameBase::checkScanNum
bool checkScanNum(std::size_t scanNum) const
Definition: timsframebase.cpp:102
pappso::MassSpectrumCstSPtr
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
Definition: massspectrum.h:76
pappso::TimsFrameBase::m_timsId
std::size_t m_timsId
Tims frame database id (the SQL identifier of this frame)
Definition: timsframebase.h:197
pappso::TimsFrame::getMassSpectrumSPtr
virtual pappso::MassSpectrumSPtr getMassSpectrumSPtr(std::size_t scanNum) const override
Definition: timsframe.cpp:361
pappso::TimsFrame::getRawTraceSPtr
pappso::TraceSPtr getRawTraceSPtr(std::size_t scanNum) const
Definition: timsframe.cpp:481
pappso::PeptideIonCter::y
@ y
pappso::TimsFrame::getMassSpectrumCstSPtr
pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtr(std::size_t scanNum) const
get the mass spectrum corresponding to a scan number
Definition: timsframe.cpp:354
pappso::TimsFrame::TimsFrame
TimsFrame(std::size_t timsId, quint32 scanNum, char *p_bytes, std::size_t len)
Definition: timsframe.cpp:72
pappso::TimsFrameBase::m_accumulationTime
double m_accumulationTime
accumulation time in milliseconds
Definition: timsframebase.h:201
pappso::TimsFrameBase::m_time
double m_time
retention time
Definition: timsframebase.h:214
pappso::XicExtractMethod
XicExtractMethod
Definition: types.h:221
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:320
pappso::TimsFrame::m_timsDataFrame
QByteArray m_timsDataFrame
Definition: timsframe.h:176
pappso::TimsFrame::unshufflePacket
void unshufflePacket(const char *src)
Definition: timsframe.cpp:113
pappso::TraceSPtr
std::shared_ptr< Trace > TraceSPtr
Definition: trace.h:119
pappso::TimsFrame::getNbrPeaks
virtual std::size_t getNbrPeaks(std::size_t scanNum) const override
Definition: timsframe.cpp:140
pappso::XicExtractMethod::max
@ max
maximum of intensities
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:269
pappso::TimsFrameBase::TimsFrameBase
TimsFrameBase(std::size_t timsId, quint32 scanNum)
constructor for binary independant tims frame
Definition: timsframebase.cpp:55
pappso::TimsFrame::getScanIndexList
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:182
pappso::TimsFrameBase::getMzFromTof
double getMzFromTof(double tof) const
get m/z from time of flight
Definition: timsframebase.cpp:167
pappso::TimsFrame::getScanOffset
std::size_t getScanOffset(std::size_t scanNum) const
Definition: timsframe.cpp:170
pappso::TimsFrameBase::m_scanNumber
quint32 m_scanNumber
total number of scans contained in this frame
Definition: timsframebase.h:191
pappso::TimsFrame::~TimsFrame
~TimsFrame()
Definition: timsframe.cpp:107
pappso::TimsFrameBase::getTofFromIndex
double getTofFromIndex(quint32 index) const
get time of flight from raw index
Definition: timsframebase.cpp:161
pappso::TimsFrameBase::m_digitizerDelay
double m_digitizerDelay
Definition: timsframebase.h:204
pappso::TimsFrame::extractTimsXicListInRtRange
void extractTimsXicListInRtRange(std::vector< TimsXicStructure >::iterator &itXicListbegin, std::vector< TimsXicStructure >::iterator &itXicListend, XicExtractMethod method) const
Definition: timsframe.cpp:409
pappso::MassSpectrumSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:75
pappso::PappsoException
Definition: pappsoexception.h:63