correct_rel_bias: Correct systematic bias in metabolomic time-course data

Description Usage Arguments Value Examples

View source: R/correction.R

Description

Identifies systematic deviations in metabolic data using a smoothing fit. Timepoints that have a median relative deviation above a threshold value are assumed to be influenced by a measurement or methodological bias as compared to the overall trends metabolite concentrations.

Usage

1
2
correct_rel_bias(time, concentration, metabolite, f_smooth = met_smooth_gam,
  max.iter = 20, min.deviation = 0.02, ...)

Arguments

time

A vector of times or sample numbers for metabolite time-courses. Note, there should be a time value for every concentration for every metabolite e.g. time = c(1, 2, 3, 1, 2, 3), concentration = c(20, 15, 10, 3, 6, 9), metabolite = c('glc', 'glc', 'glc', 'lac', 'lac', 'lac').

concentration

A vector of metabolite concentrations.

metabolite

A vector of metabolite names that correspond to time and concentration.

f_smooth

Smoothing function (set to met_smooth_gam by default).

max.iter

The algorithm correct the single most deviating point at one time (as it may influence the identification of other deviations). max.iter controls the maximum number of correction passes.

min.deviation

Smallest median relative deviation to identify as a bias. 0.02 has been found to be a good default for a diverse set of metabolic time-courses from higher eukaryote cell culture.

...

Arguments to be passed into f_smooth, (such as k or span parameters for met_smooth_gam and met_smooth_loess respectively).

Value

A vector of corrected concentrations.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Using previously simulated data 40 metabolic trends with 10 time points
data(timecourse)

# Adding an error of 5% at sample 4
logic <- timecourse$sample == 4
timecourse$concentration[logic] <- timecourse$concentration[logic] * 1.05

# Correcting
timecourse$corrected <- correct_rel_bias(timecourse$time,
                                         timecourse$concentration,
                                         timecourse$metabolite)


# Plotting -- the original value of the corrected point is marked in red
par(mfrow = c(8, 5), oma = c(5, 4, 1, 1) + 0.1, mar = c(1, 1, 1, 1) + 0.1)
new.time <- seq(min(timecourse$time), max(timecourse$time), length.out=100)

for (metabolite in unique(timecourse$metabolite)) {

  logic <- timecourse$metabolite == metabolite
  d <- timecourse[logic, ]

  logic2 <- d$concentration != d$corrected

  plot(d$time, d$corrected, pch = 16, xlab = '', ylab = '',
       ylim = c(min(d$concentration), max(d$concentration)))

  smoothed <- met_smooth_gam(d$time, d$corrected,
                             new.time = new.time, k = 5)
  lines(new.time, smoothed)

  points(d$time[logic2], d$concentration[logic2], pch = 16, col = 'red')

}

title(xlab = 'Time post inoculation (hours)',
      ylab = 'Concentration (mM)', outer = TRUE, line = 3)

ssokolen/metcourse documentation built on May 30, 2019, 8:43 a.m.