retentionTimeCorrection,peakPantheRAnnotation-method {peakPantheR} | R Documentation

## Apply retention time correction methods to adjust the retention time information in the uROI of peakPantheRAnnotation object

### Description

Performs retention time correction to re-adjust the expected retention time position of compounds. Requires an annotated peakPantheRAnnotation object (`isAnnotated=TRUE`). The original `rt` value is used as expected and the observed deviation measured in the `rt_dev_sec` field is taken as the deviation to be corrected.

### Usage

    ## S4 method for signature 'peakPantheRAnnotation'
    retentionTimeCorrection(
        annotationObject,
        rtCorrectionReferences = NULL,
        method = "polynomial",
        params = list(polynomialOrder = 2),
        robust = FALSE,
        rtWindowWidth = 15,
        diagnostic = TRUE
    )

### Arguments

`annotationObject` | (peakPantheRAnnotation) object with previous fit results to adjust retention time values in uROI and FIR annotationObject, rtCorrectionReferences=NULL,
`rtCorrectionReferences` | (list) of compounds IDs (`cpdID`) to be used as retention time references. All `cpdID` entries must be present in the object and previously annotated. If NULL, use all compounds.
`method` | (str) name of RT correction method to use (currently `polynomial` or `constant`
`params` | (list) list of parameters to pass to each correction method. Currently allowed inputs are `polynomialOrder` for `method='polynomial'`
`robust` | (bool) whether to use the RANSAC algorithm to flag and ignore outliers during retention time correction
`rtWindowWidth` | (numeric) full width in seconds of the retention time window defined around the corrected retention time value for each compound
`diagnostic` | (bool) If TRUE returns diagnostic plots (specific to each correction method)

### Value

(list) containing entries 'annotation', with the new and retention time corrected peakPantheRAnnotation, and 'plot' (if `diagnostic=TRUE`).

### Examples

    if(requireNamespace('faahKO')){
    ## Initialise a peakPantheRAnnotation object with 3 samples and 2 targeted
    ## compounds

    # Paths to spectra files
    library(faahKO)
    spectraPaths <- c(system.file('cdf/KO/ko15.CDF', package = 'faahKO'),
                        system.file('cdf/KO/ko16.CDF', package = 'faahKO'))

    # targetFeatTable
    targetFeatTable <- data.frame(matrix(vector(), 2, 8, dimnames=list(c(),
                        c('cpdID','cpdName','rtMin','rt','rtMax','mzMin','mz',
                        'mzMax'))), stringsAsFactors=FALSE)
    targetFeatTable[1,] <- c('ID-1', 'Cpd 1', 3310., 3344.888, 3390., 522.194778,
                            522.2, 522.205222)
    targetFeatTable[2,] <- c('ID-2', 'Cpd 2', 3280., 3385.577, 3440., 496.195038,
                            496.2, 496.204962)
    targetFeatTable[,c(3:8)] <- vapply(targetFeatTable[,c(3:8)], as.numeric,
                                        FUN.VALUE=numeric(2))

    smallAnnotation  <- peakPantheRAnnotation(spectraPaths=spectraPaths,
                                            targetFeatTable=targetFeatTable)
    # annotate files serially
    annotation_result <- peakPantheR_parallelAnnotation(smallAnnotation,
                                                ncores=0, verbose=TRUE)
    data_annotation   <- annotation_result$annotation

    # Example with constant correction
    rtCorrectionOutput <- retentionTimeCorrection(
                            annotationObject = data_annotation,
                            rtCorrectionReferences=c('ID-1'),
                            method='constant', params=list(),
                            robust=FALSE,
                            rtWindowWidth=15,
                            diagnostic=TRUE)

    rtCorrectedAnnotation <- rtCorrectionOutput$annotation

    # rtCorrectedAnnotation
    # An object of class peakPantheRAnnotation
    #  2 compounds in 2 samples.
    #  updated ROI exists, with a modified rt (uROI)
    #  uses updated ROI (uROI)
    #  uses fallback integration regions (FIR)
    #  is annotated

    rtCorrectionPlot <- rtCorrectionOutput$plot
    # rtCorrectedPlot
    # A ggplot2 object
    #  Scatterplot where x=`r` in the and y=`rt_dev_sec` from data_annotation
    #  Points colored depending on whether the reference was used to fit
    # the correction model
    }

[Package peakPantheR version 1.8.0 Index]