# NOT RUN {
# }
# NOT RUN {
#### Different steps of the workflow on an example with microarray data ####
# Step 1: importation, check and normalization of data if needed
#
# Import and check
datafilename <- system.file("extdata", "transcripto_sample.txt", package="DRomics")
# Normalization
# here cyclicloess normalization of a small microarray data set
# (sample of a real data set)
(o <- microarraydata(datafilename, check = TRUE, norm.method = "cyclicloess"))
plot(o)
# Step 2: selection of significantly responding items
#
# The quadratic method is the one we preconize to select both
# monotonic and biphasic curves from
# a typical dose-response design (with few replicates per dose)
(s_quad <- itemselect(o, select.method = "quadratic", FDR = 0.001))
# Step 3: fit of dose-response models, choice of the best fit for each curve
# and definition of the typology of response
#
(f <- drcfit(s_quad, progressbar = TRUE))
# Results of the fit per item are stored in the output fitres
f$fitres
# Default plot provides fitted curves with observed points
plot(f)
# Plot of residuals is also recommended to validate the Gaussian error model
plot(f, plot.type = "fitted_residuals")
# Step 4: calculation of x-fold and z-SD benchmark doses
#
(r <- bmdcalc(f, z = 1, x = 10))
# Distribution of benchmark doses as an ECDF plot
# (ECDF = Empirical Cumulative Density Function)
plot(r, BMDtype = "zSD", plottype = "ecdf")
plot(r, BMDtype = "xfold", plottype = "ecdf")
# Histogram of benchmark doses
plot(r, BMDtype = "zSD", plottype = "hist", hist.bins = 10)
# Density plot of benchmark doses
plot(r, BMDtype = "zSD", plottype = "density")
# Plot of the distribution of benchmark doses grouped by reponse trend
plot(r, BMDtype = "zSD", plottype = "ecdf", by = "trend")
# Same plot with the add of a color gradient for each item coding for
# the intensity of the signal (after shift of the control signal at 0)
# as a function of the dose
bmdplotwithgradient(r$res, BMDtype = "zSD",
facetby = "trend", shapeby = "model")
# Step 5: calculation of confidence intervals on the BMDs by bootstrap
#
(b <- bmdboot(r, niter = 100)) # niter to put at 1000 for a reasonable precision
# Results of the fit per item and confidence intervals are stored in the output res
b$res
# Distribution of benchmark doses as an ECDF plot
# with confidence intervals on each BMD values
plot(b, BMDtype = "zSD")
# Same plot with BMD grouped by rsponse trend
plot(b, BMDtype = "zSD", by = "trend")
# }
# NOT RUN {
# About using the DRomics-shiny app for this workflow
#
if(interactive()) {
appDir <- system.file("DRomics-shiny", package = "DRomics")
shiny::runApp(appDir, display.mode = "normal")
}
#### Help for biological interpretation of DRomics outputs ####
#### based on an example with metabolomic data ####
# }
# NOT RUN {
# 1. Import the dataframe with metabolomic results to use:
# the output $res of bmdcalc() or bmdboot() functions)
# from step 4 or 5 of the main DRomics workflow
# This step will not be necessary if previous steps are done directly
# in R using the DRomics package as described previously
# but in this example we did it to take a real example
# that took a long time to run but from which results are stored in the package
# code to import the file for this example in our package
metabresfilename <- system.file("extdata", "triclosanSVmetabres.txt", package="DRomics")
metabres <- read.table(metabresfilename, header = TRUE, stringsAsFactors = TRUE)
# to see the structure of this file
str(metabres)
# 2. Import the dataframe with functional annotation (or any other
# descriptor/category you want to use, here KEGG metabolic pathway)
# of each item present in the 'res' file.
# Be cautious, this file must be produced by the user.
# Each item may have more than one annotation (-> more than one line)
# code to import the file for this example in our package
metabannotfilename <- system.file("extdata", "triclosanSVmetabannot.txt",
package="DRomics")
metabannot <- read.table(metabannotfilename, header = TRUE, stringsAsFactors = TRUE)
# to see the structure of this file
str(metabannot)
# 3. Merging of both previous dataframes
# in order to obtain a so-called 'extenderes' dataframe
# gathering for each item metrics derived from the DRomics workflow and
# functional annotation
metabextendedres <- merge(x = metabres, y = metabannot, by.x = "id", by.y = "metab.code")
str(metabextendedres)
# 4. Graphical representations provided in the package
# BMDplot with gradient splitted here by metabolic pathway
bmdplotwithgradient(metabextendedres, BMDtype = "zSD",
facetby = "path_class", shapeby = "trend")
# the same representation with labels of items (so without shapeby)
bmdplotwithgradient(metabextendedres, BMDtype = "zSD", facetby = "path_class",
add.label = TRUE)
# an ECDFplot of BMD_zSD with confidence intervals splitted
# here by metabolic pathway
# with color coding for dose-response trend
ecdfplotwithCI(variable = metabextendedres$BMD.zSD,
CI.lower = metabextendedres$BMD.zSD.lower,
CI.upper = metabextendedres$BMD.zSD.upper,
by = metabextendedres$path_class,
CI.col = metabextendedres$trend)
# an ECDFplot of quantiles of BMD-zSD calculated
# here by metabolic pathway
ecdfquantileplot(variable = metabextendedres$BMD.zSD,
by = metabextendedres$path_class,
quantile.prob = 0.25)
# Plot of the dose-response curves for a specific metabolic pathway
# in this example the "lipid metabolism" pathclass
LMmetabextendedres <- metabextendedres[metabextendedres$path_class == "Lipid metabolism", ]
curvesplot(LMmetabextendedres, facetby = "id", npoints = 100, line.size = 1,
colorby = "trend",
xmin = 0, xmax = 8)
#### Help for multiomics approach ####
#### an example with metabolomics and transcriptomics ####
#### data for Scenedesmus and triclosan (cf. Larras et al. 2020 ####
# 5. following the same steps described before for metabolomics
# import and merge the results for microarray data
contigresfilename <- system.file("extdata", "triclosanSVcontigres.txt", package="DRomics")
contigres <- read.table(contigresfilename, header = TRUE, stringsAsFactors = TRUE)
str(contigres)
contigannotfilename <- system.file("extdata", "triclosanSVcontigannot.txt",
package="DRomics")
contigannot <- read.table(contigannotfilename, header = TRUE, stringsAsFactors = TRUE)
str(contigannot)
contigextendedres <- merge(x = contigres, y = contigannot, by.x = "id", by.y = "contig")
str(contigextendedres)
# 6. Comparison of results obtained at both molecular levels (metabolites and contigs)
# Binding of dataframes at both levels adding a variable coding
# for the level
extendedres <- rbind(metabextendedres, contigextendedres)
extendedres$level <- factor(c(rep("metabolites", nrow(metabextendedres)),
rep("contigs", nrow(contigextendedres))))
str(extendedres)
# Frequencies of pathways by molecular levels
(t.pathways <- table(extendedres$path_class, extendedres$level))
original.par <- par()
par(las = 2, mar = c(4,13,1,1))
barplot(t(t.pathways), beside = TRUE, horiz = TRUE,
cex.names = 0.7, legend.text = TRUE,
main = "Frequencies of pathways")
# Proportions of pathways by molecular levels
(t.prop.pathways <- prop.table(t.pathways, margin = 2))
barplot(t(t.prop.pathways), beside = TRUE, horiz = TRUE,
cex.names = 0.7, legend.text = TRUE,
main = "Proportion of pathways")
par(original.par)
if (require(ggplot2))
{
# an ECDF plot of BMD_zSD by pathways
# using color
ggplot(extendedres, aes(x = BMD.zSD, color = level)) +
stat_ecdf(geom = "step") + ylab("ECDF")
# or using facets
ggplot(extendedres, aes(x = BMD.zSD)) + facet_wrap(~ level) +
stat_ecdf(geom = "step") + ylab("ECDF")
}
# an ECDF plot of BMD_zSD with confidence intervals splitted
# here by metabolic pathway
# with color coding for molecular level
ecdfplotwithCI(variable = extendedres$BMD.zSD,
CI.lower = extendedres$BMD.zSD.lower,
CI.upper = extendedres$BMD.zSD.upper,
by = extendedres$path_class,
CI.col = extendedres$level) + labs(col = "Molecular level")
# an ECDFplot of BMD_zSD with confidence intervals splitted
# here by molecular level
ecdfplotwithCI(variable = extendedres$BMD.zSD,
CI.lower = extendedres$BMD.zSD.lower,
CI.upper = extendedres$BMD.zSD.upper,
by = extendedres$level)
# Plot of the dose-response curves for a specific metabolic pathway
# in this example the "lipid metabolism" pathclass
LMres <- extendedres[extendedres$path_class == "Lipid metabolism", ]
curvesplot(LMres, facetby = "level", free.y.scales = TRUE, npoints = 100, line.size = 1,
colorby = "trend",
xmin = 0, xmax = 8) + labs(col = "DR_trend")
# }
Run the code above in your browser using DataLab