libpappsomspp
Library for mass spectrometry
pappso::TimsFrameType1 Class Reference

#include <timsframetype1.h>

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

Public Member Functions

 TimsFrameType1 (std::size_t timsId, quint32 scanNum, char *p_bytes, std::size_t len)
 
 TimsFrameType1 (const TimsFrameType1 &other)
 
virtual ~TimsFrameType1 ()
 
virtual std::size_t getNbrPeaks (std::size_t scanNum) const override
 get the number of peaks in this spectrum need the binary file More...
 
virtual std::vector< quint32 > getScanIndexList (std::size_t scanNum) const override
 get raw index list for one given scan index are not TOF nor m/z, just index on digitizer More...
 
virtual std::vector< quint32 > getScanIntensities (std::size_t scanNum) const override
 get raw intensities without transformation from one scan it needs intensity normalization More...
 
virtual pappso::MassSpectrumSPtr getMassSpectrumSPtr (std::size_t scanNum) const override
 get the mass spectrum corresponding to a scan number More...
 
- Public Member Functions inherited from pappso::TimsFrame
 TimsFrame (std::size_t timsId, quint32 scanNum, char *p_bytes, std::size_t len)
 
 TimsFrame (const TimsFrame &other)
 
virtual ~TimsFrame ()
 
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...
 
virtual pappso::MassSpectrumCstSPtr getMassSpectrumCstSPtr (std::size_t scanNum) const
 get the mass spectrum corresponding to a scan number More...
 
- 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)
 
virtual ~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
 check that this scan number exists More...
 
void setAccumulationTime (double accumulation_time_ms)
 
void setMzCalibration (double T1_frame, double T2_frame, double digitizerTimebase, double digitizerDelay, double C0, double C1, double C2, double C3, double C4, double T1_ref, double T2_ref, double dC1, double dC2)
 
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...
 
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
 get voltage for a given scan number 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...
 
virtual const MzCalibrationInterfaceSPtrgetMzCalibrationInterfaceSPtr () const final
 get the MzCalibration model to compute mz and TOF for this frame More...
 
void setMzCalibrationInterfaceSPtr (MzCalibrationInterfaceSPtr mzCalibration)
 

Protected Member Functions

virtual void cumulateScan (std::size_t scanNum, std::map< quint32, quint32 > &accumulate_into) const override
 cumulate a scan into a map More...
 
virtual pappso::TraceSPtr getRawTraceSPtr (std::size_t scanNum) const override
 get the raw index tof_index and intensities (normalized) More...
 
- Protected Member Functions inherited from pappso::TimsFrame
 TimsFrame (std::size_t timsId, quint32 scanNum)
 constructor for binary independant tims frame More...
 
void extractTimsXicListInRtRange (std::vector< XicCoordTims * >::iterator &itXicListbegin, std::vector< XicCoordTims * >::iterator &itXicListend, XicExtractMethod method) const
 

Private Member Functions

void copyAndLzfDecompress (const char *src, std::size_t len)
 copy buffer header and lzf decompress each scan for tims compression type 1 More...
 
unsigned int lzfDecompressScan (const char *src, unsigned int src_len, char *dest, unsigned int dest_len)
 decompress a single LZF compressed scan buffer More...
 

Private Attributes

std::vector< std::size_t > m_scanOffsetList
 
std::vector< std::size_t > m_scanSizeList
 

Additional Inherited Members

- Protected Attributes inherited from pappso::TimsFrame
QByteArray m_timsDataFrame
 
- 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...
 
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
 
MzCalibrationInterfaceSPtr msp_mzCalibration = nullptr
 

Detailed Description

Todo:
write docs

Definition at line 37 of file timsframetype1.h.

Constructor & Destructor Documentation

◆ TimsFrameType1() [1/2]

pappso::TimsFrameType1::TimsFrameType1 ( std::size_t  timsId,
quint32  scanNum,
char *  p_bytes,
std::size_t  len 
)
Parameters
timsIdtims frame id
scanNumtotal number of scans in this frame
p_bytespointer on the decompressed binary buffer
lensize of the decompressed binary buffer

Definition at line 40 of file timsframetype1.cpp.

44  : TimsFrame(timsId, scanNum)
45 {
46  qDebug() << timsId;
47  m_timsDataFrame.resize(len * 2);
48 
49  if(p_bytes != nullptr)
50  {
51  qDebug() << timsId;
52  copyAndLzfDecompress(p_bytes, len);
53  qDebug() << timsId;
54  }
55  else
56  {
57  if(m_scanNumber == 0)
58  {
59 
61  QObject::tr(
62  "TimsFrameType1::TimsFrameType1(%1,%2,nullptr,%3) FAILED")
63  .arg(m_timsId)
64  .arg(m_scanNumber)
65  .arg(len));
66  }
67  }
68 }
quint32 m_scanNumber
total number of scans contained in this frame
std::size_t m_timsId
Tims frame database id (the SQL identifier of this frame)
void copyAndLzfDecompress(const char *src, std::size_t len)
copy buffer header and lzf decompress each scan for tims compression type 1
QByteArray m_timsDataFrame
Definition: timsframe.h:181
TimsFrame(std::size_t timsId, quint32 scanNum, char *p_bytes, std::size_t len)
Definition: timsframe.cpp:63

References copyAndLzfDecompress(), pappso::TimsFrameBase::m_scanNumber, pappso::TimsFrame::m_timsDataFrame, and pappso::TimsFrameBase::m_timsId.

◆ TimsFrameType1() [2/2]

pappso::TimsFrameType1::TimsFrameType1 ( const TimsFrameType1 other)

Copy constructor

Parameters
otherTODO

Definition at line 70 of file timsframetype1.cpp.

70  : TimsFrame(other)
71 {
72 }

◆ ~TimsFrameType1()

pappso::TimsFrameType1::~TimsFrameType1 ( )
virtual

Destructor

Definition at line 74 of file timsframetype1.cpp.

75 {
76 }

Member Function Documentation

◆ copyAndLzfDecompress()

void pappso::TimsFrameType1::copyAndLzfDecompress ( const char *  src,
std::size_t  len 
)
private

copy buffer header and lzf decompress each scan for tims compression type 1

Parameters
srcraw data buffer containing scan offsets and LZF compressed scans
lenlength of the data buffer

Definition at line 80 of file timsframetype1.cpp.

81 {
82 
83  qDebug() << " m_scanNumber=" << m_scanNumber << " len=" << len;
84  // the start position offset for each scan and the length of the last scan
85  // copy first m_scanNumber*4 bytes in qbyte array
86  std::size_t count = (m_scanNumber + 2) * 4;
87 
88  qDebug() << " count=" << count;
89  if(m_timsDataFrame.size() < (long)(count + count))
90  {
91  qDebug() << " m_timsDataFrame.size()=" << m_timsDataFrame.size();
92  m_timsDataFrame.resize(count + count);
93  }
94 
95  /*
96  std::size_t decompressed_size =
97  lzfDecompressScan(src + 3687 - 8,
98  9,
99  m_timsDataFrame.data() + 3660,
100  m_timsDataFrame.size() - 3660);
101 
102  qDebug() << "decompressed_size=" << decompressed_size;
103  */
104  // memcpy(m_timsDataFrame.data(), src, count);
105 
106  qDebug() << "offset begin at last :" << count + 4;
107 
108  // std::vector<std::size_t> compressed_len_list;
109  std::size_t offset;
110  std::size_t previous_offset = (*(quint32 *)(src));
111  qDebug() << "first offset= " << previous_offset;
112  std::size_t cumul_decompressed_size = 0;
113 
114 
115  for(quint32 i = 1; i <= m_scanNumber; i++)
116  {
117  offset = (*(quint32 *)(src + (i * 4)));
118 
119  std::size_t compressed_size = offset - previous_offset;
120 
121  qDebug() << "scan i=" << i << " previous_offset=" << previous_offset
122  << " offset=" << offset << " length=" << compressed_size;
123  // compressed_len_list.push_back(offset - previous_offset);
124  std::size_t remaining_size = m_timsDataFrame.size();
125 
126  if(cumul_decompressed_size < remaining_size)
127  {
128  remaining_size = remaining_size - cumul_decompressed_size;
129  }
130  else
131  {
132  remaining_size = 0;
133  }
134  qDebug() << " remaining_size=" << remaining_size;
135  std::size_t decompressed_size =
136  lzfDecompressScan(src + previous_offset - 8,
137  compressed_size,
138  m_timsDataFrame.data() + cumul_decompressed_size,
139  remaining_size);
140 
141 
142  m_scanOffsetList.push_back(cumul_decompressed_size);
143  m_scanSizeList.push_back(decompressed_size / 4);
144  cumul_decompressed_size += decompressed_size;
145  qDebug() << " decompressed_size=" << decompressed_size;
146 
147 
148  previous_offset = offset;
149  }
150  /*
151  std::size_t last_offset = (*(quint32 *)(src + (m_scanNumber * 4)));
152  qDebug() << "last scan length :" << last_offset;
153 
154  qDebug() << "last scan length bonus:"
155  << (*(quint32 *)(src + (m_scanNumber + 1 * 4)));
156 
157  qDebug() << " m_scanOffsetList.size()=" << m_scanOffsetList.size()
158  << " m_scanNumber=" << m_scanNumber;
159  */
160  /*
161  throw PappsoException(
162  QObject::tr("ERROR reading TimsFrameType1 ").arg(m_timsId));
163  */
164 }
std::vector< std::size_t > m_scanSizeList
unsigned int lzfDecompressScan(const char *src, unsigned int src_len, char *dest, unsigned int dest_len)
decompress a single LZF compressed scan buffer
std::vector< std::size_t > m_scanOffsetList

References lzfDecompressScan(), pappso::TimsFrameBase::m_scanNumber, m_scanOffsetList, m_scanSizeList, and pappso::TimsFrame::m_timsDataFrame.

Referenced by TimsFrameType1().

◆ cumulateScan()

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

cumulate a scan into a map

Parameters
scanNumscan number 0 to (m_scanNumber-1)

Reimplemented from pappso::TimsFrame.

Definition at line 218 of file timsframetype1.cpp.

220 {
221  if(m_timsDataFrame.size() == 0)
222  return;
223  // checkScanNum(scanNum);
224 
225 
226  std::size_t size = m_scanSizeList[scanNum];
227 
228  std::size_t offset = m_scanOffsetList[scanNum];
229 
230  // qDebug() << "begin offset=" << offset << " size=" << size;
231  qint32 value = 0;
232  qint32 tof_index = 0;
233  for(std::size_t i = 0; i < size; i++)
234  {
235  value = (*(qint32 *)(m_timsDataFrame.constData() + offset + (i * 4)));
236  // qDebug() << " i=" << i << " value=" << value;
237 
238  if(value < 0)
239  {
240  tof_index += -1 * value;
241  }
242  else
243  {
244 
245  quint32 x = tof_index;
246  quint32 y = value;
247 
248  auto ret = accumulate_into.insert(std::pair<quint32, quint32>(x, y));
249 
250  if(ret.second == false)
251  {
252  // already existed : cumulate
253  ret.first->second += y;
254  }
255  tof_index++;
256  }
257  }
258  qDebug() << "end";
259 }

References m_scanOffsetList, m_scanSizeList, pappso::TimsFrame::m_timsDataFrame, pappso::x, and pappso::y.

◆ getMassSpectrumSPtr()

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

get the mass spectrum corresponding to a scan number

Parameters
scanNumthe scan number to retrieve

Reimplemented from pappso::TimsFrame.

Definition at line 280 of file timsframetype1.cpp.

281 {
282 
283  qDebug() << " scanNum=" << scanNum;
284 
285  checkScanNum(scanNum);
286 
287  try
288  {
289  qDebug();
290 
291  pappso::MassSpectrumSPtr mass_spectrum_sptr =
292  std::make_shared<pappso::MassSpectrum>();
293  // std::vector<DataPoint>
294 
295  if(m_timsDataFrame.size() == 0)
296  return mass_spectrum_sptr;
297  qDebug();
298 
299  std::size_t size = m_scanSizeList[scanNum];
300 
301  std::size_t offset = m_scanOffsetList[scanNum];
302 
303  qDebug() << " offset=" << offset << " size=" << size;
304  if(size == 0)
305  return mass_spectrum_sptr;
306 
307 
308  MzCalibrationInterface *mz_calibration_p =
310 
311 
312  qint32 value = 0;
313  qint32 tof_index = 0;
314  // std::vector<quint32> index_list;
315  DataPoint data_point;
316  for(std::size_t i = 0; i < size; i++)
317  {
318  value = (*(qint32 *)(m_timsDataFrame.constData() + offset + (i * 4)));
319 
320  if(value < 0)
321  {
322  tof_index += -1 * value;
323  }
324  else
325  {
326  data_point.y = value;
327 
328  // intensity normalization
329  data_point.y *= 100.0 / m_accumulationTime;
330 
331 
332  // mz calibration
333  data_point.x = mz_calibration_p->getMzFromTofIndex(tof_index);
334  mass_spectrum_sptr.get()->push_back(data_point);
335  tof_index++;
336  }
337  }
338 
339 
340  qDebug() << mass_spectrum_sptr.get()->toString();
341  return mass_spectrum_sptr;
342  }
343  catch(PappsoException &error)
344  {
346  QObject::tr("Error TimsFrameType1::getMassSpectrumSPtr frameId=%1 "
347  "scanNum=%2 :\n%3")
348  .arg(getId())
349  .arg(scanNum)
350  .arg(error.qwhat()));
351  }
352 }
double m_accumulationTime
accumulation time in milliseconds
virtual const MzCalibrationInterfaceSPtr & getMzCalibrationInterfaceSPtr() const final
get the MzCalibration model to compute mz and TOF for this frame
bool checkScanNum(std::size_t scanNum) const
check that this scan number exists
std::size_t getId() const
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:54

References pappso::TimsFrameBase::checkScanNum(), pappso::TimsFrameBase::getId(), pappso::TimsFrameBase::getMzCalibrationInterfaceSPtr(), pappso::MzCalibrationInterface::getMzFromTofIndex(), pappso::TimsFrameBase::m_accumulationTime, m_scanOffsetList, m_scanSizeList, pappso::TimsFrame::m_timsDataFrame, pappso::PappsoException::qwhat(), pappso::DataPoint::x, and pappso::DataPoint::y.

Referenced by getNbrPeaks().

◆ getNbrPeaks()

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

get the number of peaks in this spectrum need the binary file

Parameters
scanNumscan number in the frame in the order it lies in binary file, from 0 to N-1

Reimplemented from pappso::TimsFrame.

Definition at line 210 of file timsframetype1.cpp.

211 {
212  pappso::MassSpectrumSPtr mass_spectrum_sptr = getMassSpectrumSPtr(scanNum);
213  return mass_spectrum_sptr.get()->size();
214 }
virtual pappso::MassSpectrumSPtr getMassSpectrumSPtr(std::size_t scanNum) const override
get the mass spectrum corresponding to a scan number

References getMassSpectrumSPtr().

◆ getRawTraceSPtr()

pappso::TraceSPtr pappso::TimsFrameType1::getRawTraceSPtr ( std::size_t  scanNum) const
overrideprotectedvirtual

get the raw index tof_index and intensities (normalized)

Parameters
scanNumthe scan number to extract
Returns
trace vector

Reimplemented from pappso::TimsFrame.

Definition at line 356 of file timsframetype1.cpp.

357 {
358 
359  // qDebug();
360 
361  pappso::TraceSPtr trace_sptr = std::make_shared<pappso::Trace>();
362  // std::vector<DataPoint>
363 
364  if(m_timsDataFrame.size() == 0)
365  return trace_sptr;
366  qDebug();
367 
368  std::size_t size = m_scanSizeList[scanNum];
369 
370  std::size_t offset = m_scanOffsetList[scanNum];
371 
372  qDebug() << " offset=" << offset << " size=" << size;
373  if(size == 0)
374  return trace_sptr;
375 
376  // qDebug();
377  qint32 value = 0;
378  qint32 tof_index = 0;
379 
380  // std::vector<quint32> index_list;
381  DataPoint data_point;
382  for(std::size_t i = 0; i < size; i++)
383  {
384  value = (*(qint32 *)(m_timsDataFrame.constData() + offset + (i * 4)));
385 
386  if(value < 0)
387  {
388  tof_index += -1 * value;
389  }
390  else
391  {
392  data_point.y = value;
393 
394  // intensity normalization
395  data_point.y *= 100.0 / m_accumulationTime;
396 
397 
398  // mz calibration
399  data_point.x = tof_index;
400  trace_sptr.get()->push_back(data_point);
401  tof_index++;
402  }
403  }
404 
405 
406  // qDebug();
407  return trace_sptr;
408 }
std::shared_ptr< Trace > TraceSPtr
Definition: trace.h:135

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

◆ getScanIndexList()

std::vector< quint32 > pappso::TimsFrameType1::getScanIndexList ( std::size_t  scanNum) const
overridevirtual

get raw index list for one given scan index are not TOF nor m/z, just index on digitizer

Reimplemented from pappso::TimsFrame.

Definition at line 262 of file timsframetype1.cpp.

263 {
264  throw pappso::ExceptionNotImplemented(QObject::tr("%1 %2 %3 NOT IMPLEMENTED ")
265  .arg(__FILE__)
266  .arg(__FUNCTION__)
267  .arg(__LINE__));
268 }

◆ getScanIntensities()

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

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

Reimplemented from pappso::TimsFrame.

Definition at line 271 of file timsframetype1.cpp.

272 {
273  throw pappso::ExceptionNotImplemented(QObject::tr("%1 %2 %3 NOT IMPLEMENTED ")
274  .arg(__FILE__)
275  .arg(__FUNCTION__)
276  .arg(__LINE__));
277 }

◆ lzfDecompressScan()

unsigned int pappso::TimsFrameType1::lzfDecompressScan ( const char *  src,
unsigned int  src_len,
char *  dest,
unsigned int  dest_len 
)
private

decompress a single LZF compressed scan buffer

Parameters
srcpointer on the LZF compressed buffer
src_lenlength of the source buffer
destpointer to the destination buffer (in the qbyte array)
dest_lenlength of the destination buffer (max possible in the qbytearray)
Returns
scan decompressed size

Definition at line 168 of file timsframetype1.cpp.

172 {
173  qDebug() << "src=" << src << " src_len=" << src_len
174  << " dest_len=" << dest_len;
175  if(src_len == 0)
176  return 0;
177  unsigned int decompressed_size;
178  unsigned int more_space = src_len * 2;
179  decompressed_size = lzf_decompress(src, src_len, dest, dest_len);
180  while(decompressed_size == 0)
181  {
182  qDebug() << "dest_len=" << dest_len;
183  qDebug() << "decompressed_size=" << decompressed_size;
184 
185  if(errno == EINVAL)
186  {
187  throw PappsoException(
188  QObject::tr("ERROR reading TimsFrameType1 %1 TIMS binary file %2: "
189  "LZF decompression error EINVAL")
190  .arg(m_timsId));
191  }
192  else if(errno == E2BIG)
193  {
194  qDebug() << " m_timsDataFrame.size()=" << m_timsDataFrame.size()
195  << " more_space=" << more_space;
196  m_timsDataFrame.resize(m_timsDataFrame.size() + more_space);
197  dest_len += more_space;
198  qDebug();
199  decompressed_size = lzf_decompress(src, src_len, dest, dest_len);
200  }
201  else
202  {
203  break;
204  }
205  }
206  return decompressed_size;
207 }

References pappso::TimsFrame::m_timsDataFrame, and pappso::TimsFrameBase::m_timsId.

Referenced by copyAndLzfDecompress().

Member Data Documentation

◆ m_scanOffsetList

std::vector<std::size_t> pappso::TimsFrameType1::m_scanOffsetList
private

◆ m_scanSizeList

std::vector<std::size_t> pappso::TimsFrameType1::m_scanSizeList
private

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