ptrvDetectStart: ptrvDetectStart

View source: R/ptrvDetectStart.r

ptrvDetectStartR Documentation

ptrvDetectStart

Description

This function allows to estimate the beginning of a peak with three different methods. All these methods depend on the selection of a peak in a specific windows (given by "startPeriod"). Sometimes, this startPeriod contains several peaks. In this case, we select peaks that are high enough. This quantity is defined as a percent of the maximale peak intensity: a value of 100 indicates that only the maximale peak is considered; a value of 0 indicates that the first detected peak is considered. A value of 50 indicates that the first peak higher than 50 The user should use cautiously this option.

Then, three methods are available: "startPeakProportion" and "higherThanNoise" are two methods based on the time (t_imax) obtained for the maximale intensity of the peak. It research t0 as close as possible as t_imax, but with a intensity lower than a given intensity threshold. In startPeakProportion, this threshold is calculated as a proportion of the maximale intensity. This proportion (between 0 and 1) is defined in the proportionOfMax parameter. In higherThanNoise, this threshold is calculated by multiplying the noise estimated by a number (defined by multiplyNoiseBy) The noise can be estimated with different methods:

  • as the average or maximale intensity (statOfNoise="avg" or "max") of a given period (defined in noisePeriod)

  • as the estimation of blank during the total dataframe (statOfNoise="bl")

  • as the estimation of blank during the period defined in noisePeriod (statOfNoise="blperiod")

A last method is based on derivation of the spectra. It finds out where the derivative of order defined by "order" parameter is maximale

Usage

ptrvDetectStart(
  res,
  starts,
  method = "startPeakProportion",
  proportionOfMax = 0.1,
  multiplyNoiseBy = 3,
  peakChoice = "maxIntensity",
  statOfNoise = "max",
  noisePeriod = NULL,
  timeChoice = "interpolation",
  startPeriod = NULL,
  smooth = FALSE,
  nPoints = 1,
  order = 1,
  firstAmongHighThreshold = 50,
  detectionThreshold = NULL,
  detection = "beforePeak"
)

Arguments

res

result of ptrvIntensityByTime$res (data.frame with time, intensity and ion as columns)

starts

name of the ions to be used to detect the starting point

method

"startPeakProportion" "higherThanNoise" "tangential" TODO

proportionOfMax

Number between 0 and 1. If method startPeakProportion is chosen and length(starts)==1, the starting time will be the first time that the intensity reaches this proportion of the maximale intensity of the peak. If length(starts) > 1, the starting time will be the minimum value obtained with this method for all starts.

multiplyNoiseBy

Number higher than 1 (nb). If method "higherThanNoise" is chosen, the maximal (or averaged according to noiseStat) value obtained during the noise period is multiplied by this number to give the intensity to reach for returning the starting period.

peakChoice

"maxIntensity", "first" or "firstAmongHigh"

statOfNoise

"avg" or "max". If method "higherThanNoise" is chosen, the statistic obtained during the noise period to be multiplied by multiplyNoiseBy for returning the starting period.

noisePeriod

Vector of two numbers. If method "higherThanNoise" is chosen and length(starts)==1, the starting time will be the first time that the intensity reaches 3*the maximal value obtained during the noise period. If length(starts) > 1, the starting time will be the minimum value obtained with this method for all starts.

timeChoice

"interpolation", "lower","upper". The time obtained for reaching a given value can be a not observed time (but in a interval of two observed times). "interpolation" returns the not observed time, "lower" returns the lower limit of this interval, "upper" returns the upper limit of this interval

startPeriod

Vector of two numbers. The starting time obtained has to be in this interval.

smooth

If TRUE, the data is previously smoothed with the parameter halfWindowsSize

nPoints

Number of points taken for smoothing

order

order of the derivative

firstAmongHighThreshold

percentage of the maximum value to be reached in order to be considered as a peak when peak choice is firstAmongHigh

detectionThreshold

intensity value to be reached to be considered as a peak (default to NULL corresponds to 0)

Value

a list containing:

  • tx (the obtained starting time);

  • tx_vec (when several starting ions -parameter starts- are selected, return tx for each starting ion);

  • gg a ggplot object displaying the intensity along time and the starting time chosen

  • diagnosis : 'ok' if there was no problem by selecting the start, 'maxPeakTooLow','timeFoundAfterPeak' or 'firstNotMax' if some ambiguity is possible

Examples

# Example without breathing correction

data(longDf)
starts=longDf[1,"ion"]
res_higherThanNoise=ptrvDetectStart(res=longDf,starts=starts,startPeriod=c(33.6, 48),
method="higherThanNoise",
multiplyNoiseBy=1.5,noisePeriod=c(10,30),statOfNoise="avg",peakChoice="firstAmongHigh",nPoints=31,
smooth=TRUE,firstAmongHighThreshold=50)
res_higherThanNoise$potentialPeaks
# Example with breathing correction
data(ptrv)
res_intensity=ptrvIntensityByTime(ptrv,referenceBreath="m69.06989..isoprene...Conc.",
correction = "cycle",removeNoise=FALSE,breathRatio = FALSE)
ion="m115.11139..C7H15O....Conc."
ds=ptrvDetectStart(res=res_intensity$res,starts=ion, method="startPeakProportion")
ds=ptrvDetectStart(res=res_intensity$res,starts=ion, method="higherThanNoise",startPeriod=c(20,150),
noisePeriod=c(20,150))
ds=ptrvDetectStart(res=res_intensity$res,starts=ion, method="higherThanNoise",statOfNoise="avg",
multiplyNoiseBy=1.6,timeChoice="lower",noisePeriod=c(20,150))
ds=ptrvDetectStart(res=res_intensity$res,starts=ion, method="higherThanNoise",statOfNoise="avg",
multiplyNoiseBy=1.6,smooth=TRUE,startPeriod=c(20,150),noisePeriod=c(20,150),nPoints=5)
ds=ptrvDetectStart(res=res_intensity$res,starts=ion, method="startPeakProportion",
proportionOfMax=0.1,smooth=TRUE,startPeriod=c(20,150),nPoints=5)

ChemoSens/PTRMSR documentation built on June 15, 2025, 10:40 a.m.