libpappsomspp
Library for mass spectrometry
pappso::TimsFrameBase Class Reference

#include <timsframebase.h>

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

Public Member Functions

 TimsFrameBase (std::size_t timsId, quint32 scanNum)
 constructor for binary independant tims frame More...
 
 TimsFrameBase (const TimsFrameBase &other)
 
 ~TimsFrameBase ()
 
virtual std::size_t getNbrPeaks (std::size_t scanNum) const
 
virtual MassSpectrumSPtr getMassSpectrumSPtr (std::size_t scanNum) const
 
virtual Trace cumulateScanToTrace (std::size_t scanNumBegin, std::size_t scanNumEnd) const
 
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...
 

Protected Attributes

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 46 of file timsframebase.h.

Constructor & Destructor Documentation

◆ TimsFrameBase() [1/2]

pappso::TimsFrameBase::TimsFrameBase ( std::size_t  timsId,
quint32  scanNum 
)

constructor for binary independant tims frame

Parameters
timsIdtims frame identifier in the database
scanNumthe total number of scans contained in this frame

Definition at line 37 of file timsframebase.cpp.

38 {
39  qDebug() << timsId;
40  m_timsId = timsId;
41 
42  m_scanNumber = scanNum;
43 }

References m_scanNumber, and m_timsId.

◆ TimsFrameBase() [2/2]

pappso::TimsFrameBase::TimsFrameBase ( const TimsFrameBase other)

Copy constructor

Parameters
otherTODO

◆ ~TimsFrameBase()

pappso::TimsFrameBase::~TimsFrameBase ( )

Destructor

Definition at line 49 of file timsframebase.cpp.

50 {
51 }

Member Function Documentation

◆ checkScanNum()

bool pappso::TimsFrameBase::checkScanNum ( std::size_t  scanNum) const

Definition at line 84 of file timsframebase.cpp.

85 {
86  if(scanNum >= m_scanNumber)
87  {
89  QObject::tr("Invalid scan number : scanNum%1 > m_scanNumber")
90  .arg(scanNum));
91  }
92 
93  return true;
94 }

References m_scanNumber.

Referenced by pappso::TimsFrame::cumulateScan(), pappso::TimsFrame::getMassSpectrumSPtr(), pappso::TimsFrame::getNbrPeaks(), pappso::TimsFrame::getScanIndexList(), and pappso::TimsFrame::getScanIntensities().

◆ cumulateScanToTrace()

Trace pappso::TimsFrameBase::cumulateScanToTrace ( std::size_t  scanNumBegin,
std::size_t  scanNumEnd 
) const
virtual

Reimplemented in pappso::TimsFrame.

Definition at line 114 of file timsframebase.cpp.

116 {
117  throw PappsoException(
118  QObject::tr("ERROR unable to cumulateScanToTrace in TimsFrameBase for scan "
119  "number begin %1 end %2")
120  .arg(scanNumBegin)
121  .arg(scanNumEnd));
122 }

◆ getDriftTime()

double pappso::TimsFrameBase::getDriftTime ( std::size_t  scanNum) const

get drift time of a scan number in milliseconds

Parameters
scanNumthe scan number
Returns
time in milliseconds of mobility delay (drift time)

Definition at line 356 of file timsframebase.cpp.

357 {
358  return (m_accumulationTime / (double)m_scanNumber) * ((double)scanNum);
359 }

References m_accumulationTime, and m_scanNumber.

◆ getId()

std::size_t pappso::TimsFrameBase::getId ( ) const

Definition at line 298 of file timsframebase.cpp.

299 {
300  return m_timsId;
301 }

References m_timsId.

◆ getMassSpectrumSPtr()

MassSpectrumSPtr pappso::TimsFrameBase::getMassSpectrumSPtr ( std::size_t  scanNum) const
virtual

Reimplemented in pappso::TimsFrame.

Definition at line 106 of file timsframebase.cpp.

107 {
108  throw PappsoException(
109  QObject::tr(
110  "ERROR unable to getMassSpectrumSPtr in TimsFrameBase for scan number %1")
111  .arg(scanNum));
112 }

◆ getMsLevel()

unsigned int pappso::TimsFrameBase::getMsLevel ( ) const

Definition at line 284 of file timsframebase.cpp.

285 {
286  if(m_msMsType == 0)
287  return 1;
288  return 2;
289 }

References m_msMsType.

◆ getMzFromTof()

double pappso::TimsFrameBase::getMzFromTof ( double  tof) const

get m/z from time of flight

Parameters
toftime of flight
Returns
m/z value

Definition at line 136 of file timsframebase.cpp.

137 {
138  // http://www.alglib.net/equations/polynomial.php
139  // http://www.alglib.net/translator/man/manual.cpp.html#sub_polynomialsolve
140  // https://math.stackexchange.com/questions/1291208/number-of-roots-of-a-polynomial-of-non-integer-degree
141  // https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=2ahUKEwiWhLOFxqrkAhVLxYUKHVqqDFcQFjABegQIAxAB&url=https%3A%2F%2Fkluge.in-chemnitz.de%2Fopensource%2Fspline%2Fexample_alglib.cpp&usg=AOvVaw0guGejJGPmkOVg48_GJYR8
142  // https://stackoverflow.com/questions/26091323/how-to-plot-a-function-curve-in-r
143  /*
144  * beware to put the function on a single line in R:
145 > eq <- function(m){ 1 + (sqrt((10^12)/670) * sqrt(m)) + (207.775676931964 * m)
146 + (59.2526676368822 * (m^1.5)) }
147 > eq <- function(m){ 313.577620892277 + (sqrt((10^12)/157424.07710945) *
148 sqrt(m)) + (0.000338743021989553 * m)
149 + (0 * (m^1.5)) }
150 > plot(eq(1:1000), type='l')
151 
152 
153 
154 > eq2 <- function(m2){ 1 + sqrt((10^12)/670) * m2 + 207.775676931964 * (m2^2)
155 + 59.2526676368822 * (m2^3) }
156 > plot(eq2(1:sqrt(1000)), type='l')
157 */
158  // How to Factor a Trinomial with Fractions as Coefficients
159 
160  // formula
161  // a = c0 = 1
162  // b = sqrt((10^12)/c1), c1 = 670 * m^0.5 (1/2)
163  // c = c2, c2 = 207.775676931964 * m
164  // d = c3, c3 = 59.2526676368822 * m^1.5 (3/2)
165  // double mz = 0;
166  std::vector<double> X;
167  X.push_back((m_mzCalibrationArr[0] - (double)tof));
168  X.push_back(m_mzCalibrationArr[1]);
169  if(m_mzCalibrationArr[2] != 0)
170  {
171  X.push_back(m_mzCalibrationArr[2]);
172  }
173  if(m_mzCalibrationArr[3] != 0)
174  {
175  X.push_back(m_mzCalibrationArr[3]);
176  }
177  else
178  {
179  qDebug() << m_mzCalibrationArr[3];
180  }
181 
182  alglib::real_1d_array polynom_array;
183  try
184  {
185  polynom_array.setcontent(X.size(), &(X[0]));
186  }
187  catch(alglib::ap_error &error)
188  {
189  // PolynomialSolve: A[N]=0
191  QObject::tr("ERROR in alglib::polynom_array.setcontent :\n%1")
192  .arg(error.msg.c_str()));
193  }
194 
195 
196  /*
197  alglib::polynomialsolve(
198 real_1d_array a,
199 ae_int_t n,
200 complex_1d_array& x,
201 polynomialsolverreport& rep,
202 const xparams _params = alglib::xdefault);
203 */
204  alglib::complex_1d_array m;
205  alglib::polynomialsolverreport rep;
206  // qDebug();
207  try
208  {
209  alglib::polynomialsolve(polynom_array, X.size() - 1, m, rep);
210  }
211  catch(alglib::ap_error &error)
212  {
213  qDebug() << " X.size() - 1 = " << X.size() - 1;
214  qDebug() << m_mzCalibrationArr[0];
215  qDebug() << m_mzCalibrationArr[1];
216  qDebug() << m_mzCalibrationArr[2];
217  qDebug() << m_mzCalibrationArr[3];
218 
219  // PolynomialSolve: A[N]=0
221  QObject::tr("ERROR in alglib::polynomialsolve :\n%1")
222  .arg(error.msg.c_str()));
223  }
224 
225 
226  // qDebug();
227 
228  if(m.length() == 0)
229  {
231  QObject::tr("ERROR in TimsFrame::getMzFromTof m.size() == 0"));
232  }
233  // qDebug();
234  if(m[0].y != 0)
235  {
237  QObject::tr("ERROR in TimsFrame::getMzFromTof m[0].y!= 0"));
238  }
239 
240  return pow(m[0].x, 2);
241 }

References m_mzCalibrationArr, and pappso::y.

Referenced by pappso::TimsFrame::cumulateScanToTrace(), pappso::TimsFrame::getMassSpectrumSPtr(), and pappso::TimsFrame::getTraceFromCumulatedScans().

◆ getNbrPeaks()

std::size_t pappso::TimsFrameBase::getNbrPeaks ( std::size_t  scanNum) const
virtual

Reimplemented in pappso::TimsFrame.

Definition at line 97 of file timsframebase.cpp.

98 {
99  throw PappsoException(
100  QObject::tr(
101  "ERROR unable to get number of peaks in TimsFrameBase for scan number %1")
102  .arg(scanNum));
103 }

◆ getOneOverK0Transformation()

double pappso::TimsFrameBase::getOneOverK0Transformation ( std::size_t  scanNum) const

get 1/K0 value of a given scan (mobility value)

Parameters
scanNumthe scan number

Definition at line 362 of file timsframebase.cpp.

363 {
364  return 1 / (m_timsC6 + (m_timsC7 / getVoltageTransformation(scanNum)));
365 }

References getVoltageTransformation(), m_timsC6, and m_timsC7.

◆ getRawIndexFromMz()

quint32 pappso::TimsFrameBase::getRawIndexFromMz ( double  mz) const

get raw index of a given m/z

Parameters
mzthe mass to transform
Returns
integer x raw value

Definition at line 244 of file timsframebase.cpp.

245 {
246  // formula
247  // a = c0 = 1
248  // b = sqrt((10^12)/c1), c1 = 670 * m^0.5 (1/2)
249  // c = c2, c2 = 207.775676931964 * m
250  // d = c3, c3 = 59.2526676368822 * m^1.5 (3/2)
251  qDebug() << "mz=" << mz;
252 
253  double tof = m_mzCalibrationArr[0];
254  qDebug() << "tof ( m_mzCalibrationArr[0])=" << tof;
255  // TODO cache value of std::sqrt((std::pow(10, 12) / m_mzCalibrationArr[1]))
256  tof += m_mzCalibrationArr[1] * std::sqrt(mz);
257  qDebug() << "tof=" << tof;
258  tof += m_mzCalibrationArr[2] * mz;
259  qDebug() << "tof=" << tof;
260  tof += m_mzCalibrationArr[3] * std::pow(mz, 1.5);
261  qDebug() << "tof=" << tof;
262  tof -= m_digitizerDelay;
263  qDebug() << "tof=" << tof;
264  tof = tof / m_digitizerTimebase;
265  qDebug() << "index=" << tof;
266  return (quint32)std::round(tof);
267 }

References m_digitizerDelay, m_digitizerTimebase, m_mzCalibrationArr, and pappso::unset.

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

◆ getScanNumFromOneOverK0()

std::size_t pappso::TimsFrameBase::getScanNumFromOneOverK0 ( double  one_over_k0) const

get the scan number from a given 1/Ko mobility value

Parameters
one_over_k0the mobility value to tranform
Returns
integer the scan number

Definition at line 369 of file timsframebase.cpp.

370 {
371  double temp = 1 / one_over_k0;
372  temp = temp - m_timsC6;
373  temp = temp / m_timsC7;
374  temp = 1 / temp;
375  temp = temp - m_timsDvStart;
376  temp = temp / m_timsSlope + m_timsTtrans + m_timsNdelay;
377  return (std::size_t)std::round(temp);
378 }

References m_timsC6, m_timsC7, m_timsDvStart, m_timsNdelay, m_timsSlope, and m_timsTtrans.

◆ getTime()

double pappso::TimsFrameBase::getTime ( ) const

Definition at line 292 of file timsframebase.cpp.

293 {
294  return m_time;
295 }

References m_time.

◆ getTofFromIndex() [1/2]

double pappso::TimsFrameBase::getTofFromIndex ( double  index) const

get time of flight from double index

Definition at line 124 of file timsframebase.cpp.

125 {
126  // mz calibration
127  return (index * m_digitizerTimebase) + m_digitizerDelay;
128 }

References m_digitizerDelay, and m_digitizerTimebase.

◆ getTofFromIndex() [2/2]

double pappso::TimsFrameBase::getTofFromIndex ( quint32  index) const

get time of flight from raw index

Parameters
indexdigitizer x raw value
Returns
tof time of flight

Definition at line 130 of file timsframebase.cpp.

131 {
132  // mz calibration
133  return ((double)index * m_digitizerTimebase) + m_digitizerDelay;
134 }

References m_digitizerDelay, and m_digitizerTimebase.

Referenced by pappso::TimsFrame::cumulateScanToTrace(), and pappso::TimsFrame::getTraceFromCumulatedScans().

◆ getVoltageTransformation()

double pappso::TimsFrameBase::getVoltageTransformation ( std::size_t  scanNum) const

Definition at line 334 of file timsframebase.cpp.

335 {
336  double v = m_timsDvStart +
337  m_timsSlope * ((double)scanNum - m_timsTtrans - m_timsNdelay);
338 
339  if(v < m_timsVmin)
340  {
342  QObject::tr("ERROR in TimsFrame::getVoltageTransformation invalid tims "
343  "calibration, v < m_timsVmin"));
344  }
345 
346 
347  if(v > m_timsVmax)
348  {
350  QObject::tr("ERROR in TimsFrame::getVoltageTransformation invalid tims "
351  "calibration, v > m_timsVmax"));
352  }
353  return v;
354 }

References m_timsDvStart, m_timsNdelay, m_timsSlope, m_timsTtrans, m_timsVmax, and m_timsVmin.

Referenced by getOneOverK0Transformation().

◆ setAccumulationTime()

void pappso::TimsFrameBase::setAccumulationTime ( double  accumulation_time_ms)

Definition at line 54 of file timsframebase.cpp.

55 {
56  m_accumulationTime = accumulation_time_ms;
57 }

References m_accumulationTime.

◆ setMsMsType()

void pappso::TimsFrameBase::setMsMsType ( quint8  type)

Definition at line 276 of file timsframebase.cpp.

277 {
278 
279  qDebug() << " m_msMsType=" << type;
280  m_msMsType = type;
281 }

References m_msMsType.

◆ setMzCalibration()

void pappso::TimsFrameBase::setMzCalibration ( double  temperature_correction,
double  digitizerTimebase,
double  digitizerDelay,
double  C0,
double  C1,
double  C2,
double  C3 
)

Definition at line 61 of file timsframebase.cpp.

68 {
69 
70  // temperature compensation
71  C1 = C1 * temperature_correction;
72  C2 = C2 / temperature_correction;
73 
74  m_digitizerDelay = digitizerDelay;
75  m_digitizerTimebase = digitizerTimebase;
76 
77  m_mzCalibrationArr.push_back(C0);
78  m_mzCalibrationArr.push_back(std::sqrt(std::pow(10, 12) / C1));
79  m_mzCalibrationArr.push_back(C2);
80  m_mzCalibrationArr.push_back(C3);
81 }

References m_digitizerDelay, m_digitizerTimebase, and m_mzCalibrationArr.

◆ setTime()

void pappso::TimsFrameBase::setTime ( double  time)

Definition at line 270 of file timsframebase.cpp.

271 {
272  m_time = time;
273 }

References m_time.

◆ setTimsCalibration()

void pappso::TimsFrameBase::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 
)

Definition at line 303 of file timsframebase.cpp.

314 {
315  if(tims_model_type != 2)
316  {
317  throw pappso::PappsoException(QObject::tr(
318  "ERROR in TimsFrame::setTimsCalibration tims_model_type != 2"));
319  }
320  m_timsDvStart = C2; // C2 from TimsCalibration
321  m_timsTtrans = C4; // C4 from TimsCalibration
322  m_timsNdelay = C0; // C0 from TimsCalibration
323  m_timsVmin = C8; // C8 from TimsCalibration
324  m_timsVmax = C9; // C9 from TimsCalibration
325  m_timsC6 = C6;
326  m_timsC7 = C7;
327 
328 
329  m_timsSlope =
330  (C3 - m_timsDvStart) / C1; // //C3 from TimsCalibration // C2 from
331  // TimsCalibration // C1 from TimsCalibration
332 }

References m_timsC6, m_timsC7, m_timsDvStart, m_timsNdelay, m_timsSlope, m_timsTtrans, m_timsVmax, and m_timsVmin.

Member Data Documentation

◆ m_accumulationTime

double pappso::TimsFrameBase::m_accumulationTime = 0
protected

◆ m_digitizerDelay

double pappso::TimsFrameBase::m_digitizerDelay = 0
protected

◆ m_digitizerTimebase

double pappso::TimsFrameBase::m_digitizerTimebase = 0
protected

◆ m_msMsType

quint8 pappso::TimsFrameBase::m_msMsType = 0
protected

Definition at line 167 of file timsframebase.h.

Referenced by getMsLevel(), and setMsMsType().

◆ m_mzCalibrationArr

std::vector<double> pappso::TimsFrameBase::m_mzCalibrationArr
protected

MZ calibration parameters.

Definition at line 165 of file timsframebase.h.

Referenced by getMzFromTof(), getRawIndexFromMz(), and setMzCalibration().

◆ m_scanNumber

quint32 pappso::TimsFrameBase::m_scanNumber
protected

total number of scans contained in this frame

Definition at line 148 of file timsframebase.h.

Referenced by pappso::TimsFrame::TimsFrame(), TimsFrameBase(), checkScanNum(), getDriftTime(), and pappso::TimsFrame::getNbrPeaks().

◆ m_time

double pappso::TimsFrameBase::m_time = 0
protected

retention time

Definition at line 171 of file timsframebase.h.

Referenced by pappso::TimsFrame::extractTimsXicListInRtRange(), getTime(), and setTime().

◆ m_timsC6

double pappso::TimsFrameBase::m_timsC6 = 0
protected

◆ m_timsC7

double pappso::TimsFrameBase::m_timsC7 = 0
protected

◆ m_timsDvStart

double pappso::TimsFrameBase::m_timsDvStart = 0
protected

◆ m_timsId

std::size_t pappso::TimsFrameBase::m_timsId
protected

Tims frame database id (the SQL identifier of this frame)

Warning
in sqlite, there is another field called TimsId : this is not that, because it is in fact an offset in bytes in the binary file.

Definition at line 154 of file timsframebase.h.

Referenced by pappso::TimsFrame::TimsFrame(), TimsFrameBase(), and getId().

◆ m_timsNdelay

double pappso::TimsFrameBase::m_timsNdelay = 0
protected

◆ m_timsSlope

double pappso::TimsFrameBase::m_timsSlope
protected
Initial value:
=
0

Definition at line 174 of file timsframebase.h.

Referenced by getScanNumFromOneOverK0(), getVoltageTransformation(), and setTimsCalibration().

◆ m_timsTtrans

double pappso::TimsFrameBase::m_timsTtrans = 0
protected

◆ m_timsVmax

double pappso::TimsFrameBase::m_timsVmax = 0
protected

Definition at line 180 of file timsframebase.h.

Referenced by getVoltageTransformation(), and setTimsCalibration().

◆ m_timsVmin

double pappso::TimsFrameBase::m_timsVmin = 0
protected

Definition at line 179 of file timsframebase.h.

Referenced by getVoltageTransformation(), and setTimsCalibration().


The documentation for this class was generated from the following files:
pappso::TimsFrameBase::m_digitizerTimebase
double m_digitizerTimebase
Definition: timsframebase.h:160
pappso::TimsFrameBase::m_timsId
std::size_t m_timsId
Tims frame database id (the SQL identifier of this frame)
Definition: timsframebase.h:154
pappso::TimsFrameBase::m_timsSlope
double m_timsSlope
Definition: timsframebase.h:174
pappso::TimsFrameBase::m_timsC7
double m_timsC7
Definition: timsframebase.h:182
pappso::TimsFrameBase::m_accumulationTime
double m_accumulationTime
accumulation time in milliseconds
Definition: timsframebase.h:158
pappso::TimsFrameBase::m_time
double m_time
retention time
Definition: timsframebase.h:171
pappso::ExceptionOutOfRange
Definition: exceptionoutofrange.h:32
pappso::TimsFrameBase::getVoltageTransformation
double getVoltageTransformation(std::size_t scanNum) const
Definition: timsframebase.cpp:334
pappso::TimsFrameBase::m_timsDvStart
double m_timsDvStart
Definition: timsframebase.h:173
pappso::TimsFrameBase::m_timsNdelay
double m_timsNdelay
Definition: timsframebase.h:178
pappso::TimsFrameBase::m_timsVmin
double m_timsVmin
Definition: timsframebase.h:179
pappso::DataKind::unset
@ unset
not set
pappso::TimsFrameBase::m_scanNumber
quint32 m_scanNumber
total number of scans contained in this frame
Definition: timsframebase.h:148
pappso::TimsFrameBase::m_timsC6
double m_timsC6
Definition: timsframebase.h:181
pappso::TimsFrameBase::m_digitizerDelay
double m_digitizerDelay
Definition: timsframebase.h:161
pappso::TimsFrameBase::m_mzCalibrationArr
std::vector< double > m_mzCalibrationArr
MZ calibration parameters.
Definition: timsframebase.h:165
pappso::TimsFrameBase::m_msMsType
quint8 m_msMsType
Definition: timsframebase.h:167
pappso::TimsFrameBase::m_timsVmax
double m_timsVmax
Definition: timsframebase.h:180
pappso::TimsFrameBase::m_timsTtrans
double m_timsTtrans
Definition: timsframebase.h:177
pappso::PappsoException
Definition: pappsoexception.h:42