Group features based on similar retention time. This method is supposed to be used as an initial crude grouping of features based on the median retention time of all their chromatographic peaks. All features with a difference in their retention time which is <= parameter diffRt of the parameter object are grouped together. If a column "feature_group" is found in xcms::featureDefinitions() this is further sub-grouped by this method.

See MsFeatures::SimilarRtimeParam() in MsFeatures for more details.

# S4 method for XCMSnExp,SimilarRtimeParam
groupFeatures(object, param, msLevel = 1L, ...)

Arguments

object

XCMSnExp() object containing also correspondence results.

param

SimilarRtimeParam object with the settings for the method. See MsFeatures::SimilarRtimeParam() for details and options.

msLevel

integer(1) defining the MS level on which the features should be grouped.

...

passed to the groupFeatures function on numeric values.

Value

input XCMSnExp with feature groups added (i.e. in column "feature_group" of its featureDefinitions data frame.

See also

Author

Johannes Rainer

Examples

## Performing a quick preprocessing of a test data set. library(faahKO) fls <- c(system.file('cdf/KO/ko15.CDF', package = "faahKO"), system.file('cdf/KO/ko16.CDF', package = "faahKO"), system.file('cdf/WT/wt19.CDF', package = "faahKO")) od <- readMSData(fls, mode = "onDisk")
#> Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.
xod <- findChromPeaks( od, param = CentWaveParam(noise = 10000, snthresh = 40, prefilter = c(3, 10000)))
#> Detecting mass traces at 25 ppm ...
#> OK
#> Detecting chromatographic peaks in 937 regions of interest ...
#> OK: 87 found.
#> Detecting mass traces at 25 ppm ...
#> OK
#> Detecting chromatographic peaks in 1025 regions of interest ...
#> OK: 100 found.
#> Detecting mass traces at 25 ppm ...
#> OK
#> Detecting chromatographic peaks in 623 regions of interest ...
#> OK: 71 found.
pdp <- PeakDensityParam(sampleGroups = c(1, 1, 2)) xodg <- groupChromPeaks(xod, param = pdp)
#> Processing 2867 mz slices ...
#> OK
## Group features based on similar retention time (i.e. difference <= 2 seconds) xodg_grp <- groupFeatures(xodg, param = SimilarRtimeParam(diffRt = 2)) ## Feature grouping get added to the featureDefinitions in column "feature_group" head(featureDefinitions(xodg_grp)$feature_group)
#> [1] "FG.001" "FG.035" "FG.027" "FG.036" "FG.037" "FG.030"
table(featureDefinitions(xodg_grp)$feature_group)
#> #> FG.001 FG.002 FG.003 FG.004 FG.005 FG.006 FG.007 FG.008 FG.009 FG.010 FG.011 #> 3 3 2 2 4 2 3 2 2 4 3 #> FG.012 FG.013 FG.014 FG.015 FG.016 FG.017 FG.018 FG.019 FG.020 FG.021 FG.022 #> 3 2 2 2 2 3 3 2 2 2 3 #> FG.023 FG.024 FG.025 FG.026 FG.027 FG.028 FG.029 FG.030 FG.031 FG.032 FG.033 #> 2 2 2 2 2 2 2 2 2 2 2 #> FG.034 FG.035 FG.036 FG.037 FG.038 FG.039 FG.040 FG.041 FG.042 FG.043 FG.044 #> 2 1 1 1 1 1 1 1 1 1 1 #> FG.045 FG.046 FG.047 FG.048 FG.049 FG.050 FG.051 FG.052 FG.053 FG.054 FG.055 #> 1 1 1 1 1 1 1 1 1 1 1 #> FG.056 FG.057 FG.058 FG.059 FG.060 FG.061 FG.062 FG.063 FG.064 FG.065 FG.066 #> 1 1 1 1 1 1 1 1 1 1 1 #> FG.067 FG.068 FG.069 FG.070 FG.071 FG.072 FG.073 FG.074 FG.075 FG.076 FG.077 #> 1 1 1 1 1 1 1 1 1 1 1 #> FG.078 FG.079 FG.080 FG.081 FG.082 FG.083 FG.084 FG.085 FG.086 FG.087 FG.088 #> 1 1 1 1 1 1 1 1 1 1 1 #> FG.089 FG.090 FG.091 FG.092 FG.093 FG.094 FG.095 FG.096 FG.097 FG.098 FG.099 #> 1 1 1 1 1 1 1 1 1 1 1 #> FG.100 FG.101 FG.102 FG.103 FG.104 FG.105 FG.106 FG.107 FG.108 FG.109 FG.110 #> 1 1 1 1 1 1 1 1 1 1 1
length(unique(featureDefinitions(xodg_grp)$feature_group))
#> [1] 110
## Using an alternative groupiing method that creates larger groups xodg_grp <- groupFeatures(xodg, param = SimilarRtimeParam(diffRt = 2, groupFun = MsCoreUtils::group)) length(unique(featureDefinitions(xodg_grp)$feature_group))
#> [1] 103