Skip to content
Snippets Groups Projects
Commit 987ccf30 authored by GUILMINEAU Camille's avatar GUILMINEAU Camille
Browse files

corrections in test_pathway function: test of inputs and documentation

parent 2a1943ac
No related branches found
No related tags found
No related merge requests found
......@@ -4,12 +4,18 @@ S3method(head,pathwayRes)
S3method(plot,pathwayRes)
S3method(print,pathwayRes)
S3method(summary,pathwayRes)
export(PCApath)
export(from_ASICS_to_PHOENICS)
export(overlap_coefficient)
import(blme)
import(lme4)
export(test_pathway)
importFrom(FactoMineR,PCA)
importFrom(KEGGREST,keggList)
importFrom(MetaboAnalystR,CalculateOraScore)
importFrom(MetaboAnalystR,CreateMappingResultTable)
importFrom(MetaboAnalystR,CrossReferencing)
importFrom(MetaboAnalystR,InitDataObjects)
importFrom(MetaboAnalystR,SetKEGG.PathLib)
importFrom(MetaboAnalystR,SetMetabolomeFilter)
importFrom(MetaboAnalystR,Setup.MapData)
importFrom(blme,blmer)
importFrom(factoextra,fviz_eig)
importFrom(factoextra,fviz_pca_ind)
......
#' @title Test of metabolic pathways based on longitudinal metabolomics data
#' @title Pathway differential analysis based on longitudinal metabolomics data
#'
#' @description
#' TODO : explain the main steps of the function
#' @description For each pathway, perform a PCA on the metabolites
#' quantification matrix and select a `npc` number of principal components,
#' then fit a mixed model on the new matrix and test the fixed effects
#' significance
#'
#' @param quantif dataframe or matrix of the quantification of the metabolites, with the samples in rownames and the metabolites codes in colnames
#' @param design dataframe or matrix, contains the samples in rownames and the factors to be included in the model in colnames
#' @param pathways dataframe or matrix, contains a row for each metabolite in a pathway
#' @param quantif dataframe or matrix of the quantification of the metabolites,
#' with the samples in row names and the metabolites codes in column names
#' @param design dataframe or matrix, contains the samples in rownames and the
#' factors to be included in the model in colnames
#' @param pathways dataframe or matrix, contains the columns "pathway_name",
#' "pathway_code", "metabolite_code" and "metabolite_name" and a row for each
#' metabolite in a pathway
#' @param npc number of PC to select
#' @param model a character string indicating if the model should be fitted using lme or blme package
#' @param fixed vector of fixed effects to be included in the model, must be in design colnames
#' @param random vector of random effects to be included in the model, must be in design colnames
#' @param organism organism code in KEGG database, needed if pathways == "auto"
#' @param model a character string indicating if the model should be fitted
#' using lme or blme package
#' @param fixed vector of fixed effects to be included in the model, must be in
#' design colnames
#' @param random vector of random effects to be included in the model, must be
#' in design colnames
#' @param organism organism code in KEGG database (three or four letters),
#' needed if pathways == "auto"
#'
#' @return an object of class pathwayRes
#' TODO : describe the returned object
#' @return an object of class pathwayRes: list of pathways which contains for
#' each pathway:
#' - a dataframe with the pathway name and pathway code
#' - a dataframe with the metabolites names and metabolites codes in the pathway
#' - a PCA object
#' - the output of the model
#' - a list of dataframes with the p-values (before and after correction) of
#' each tested effect
#'
#' @importFrom FactoMineR PCA
#' @importFrom lme4 lmer
#' @importFrom blme blmer
#' @importFrom tibble column_to_rownames
#' @importFrom tibble rownames_to_column
#' @importFrom KEGGREST keggList
#'
#' @examples
#' load(system.file("data", "example.rda", package = "phoenics"))
......@@ -42,7 +58,8 @@
#' @export
test_pathway <- function(quantif, design, pathways = "auto", fixed, random,
npc = 1L, model = c("lmer", "blmer"), organism = NULL) {
npc = 1L, model = c("lmer", "blmer"),
organism = NULL) {
# Inputs tests
if (!is.character(fixed)) {
......@@ -76,7 +93,16 @@ test_pathway <- function(quantif, design, pathways = "auto", fixed, random,
if (is.null(organism)) {
stop("`organism` is missing.")
}
# TODO: pathway_search(quantif, organism)
kegg_org <- keggList("organism")
kegg_org <- as.data.frame(kegg_org)
kegg_org <- unique(kegg_org$organism)
if (organism %in% kegg_org) {
# TODO: pathway_search(quantif, organism)
} else {
stop("`organism` must be KEGG organism code.")
}
} else {
stop("`pathways` must be \"auto\" or a dataframe or a matrix.")
}
......@@ -173,8 +199,7 @@ test_pathway <- function(quantif, design, pathways = "auto", fixed, random,
return(out)
})
simes <- as.data.frame(simes)
simes <- tibble::rownames_to_column(simes, "pathway")
colnames(simes)[2] <- "pval"
colnames(simes)[1] <- "pval"
simes$FDR <- p.adjust(simes$pval)
return(simes)
})
......
......@@ -2,54 +2,67 @@
% Please edit documentation in R/test_pathway.R
\name{test_pathway}
\alias{test_pathway}
\title{Test of metabolic pathways based on longitudinal metabolomics data}
\title{Pathway differential analysis based on longitudinal metabolomics data}
\usage{
test_pathway(
quantif,
design,
pathways,
npc,
model = c("lme", "blme"),
pathways = "auto",
fixed,
random,
organism
npc = 1L,
model = c("lmer", "blmer"),
organism = NULL
)
}
\arguments{
\item{quantif}{dataframe or matrix of the quantification of the metabolites, with the samples in rownames and the metabolites codes in colnames}
\item{quantif}{dataframe or matrix of the quantification of the metabolites,
with the samples in row names and the metabolites codes in column names}
\item{design}{dataframe or matrix, contains the samples in rownames and the factors to be included in the model in colnames}
\item{design}{dataframe or matrix, contains the samples in rownames and the
factors to be included in the model in colnames}
\item{pathways}{dataframe or matrix, contains a row for each metabolite in a pathway}
\item{pathways}{dataframe or matrix, contains the columns "pathway_name",
"pathway_code", "metabolite_code" and "metabolite_name" and a row for each
metabolite in a pathway}
\item{npc}{number of PC to select}
\item{fixed}{vector of fixed effects to be included in the model, must be in
design colnames}
\item{model}{a character string indicating if the model should be fitted using lme or blme package}
\item{random}{vector of random effects to be included in the model, must be
in design colnames}
\item{fixed}{vector of fixed effects to be included in the model, must be in design colnames}
\item{npc}{number of PC to select}
\item{random}{vector of random effects to be included in the model, must be in design colnames}
\item{model}{a character string indicating if the model should be fitted
using lme or blme package}
\item{organism}{organism code in KEGG database, needed if pathways == "auto"}
\item{organism}{organism code in KEGG database (three or four letters),
needed if pathways == "auto"}
}
\value{
an object of class pathwayRes
TODO : describe the returned object
an object of class pathwayRes: list of pathways which contains for
each pathway:
- a dataframe with the pathway name and pathway code
- a dataframe with the metabolites names and metabolites codes in the pathway
- a PCA object
- the output of the model
- a list of dataframes with the p-values (before and after correction) of
each tested effect
}
\description{
TODO : explain the main steps of the function
For each pathway, perform a PCA on the metabolites
quantification matrix and select a `npc` number of principal components,
then fit a mixed model on the new matrix and test the fixed effects
significance
}
\examples{
load(file = "data/design_example.rda")
load(file = "data/pathways_example.rda")
load(file = "data/quantif_example.rda")
quantif <- format_ASICS_quantif(quantif)
object <- test_pathway(quantif, design, pathways, npc = 2, model = "blme",
fixed = c("Age", "Treatment"), random = c("Mouse"))
print.pathwayRes(object)
summary.pathwayRes(object)
plot.pathwayRes(object)
head.pathwayRes(object)
load(system.file("data", "example.rda", package = "phoenics"))
quantif <- from_ASICS_to_PHOENICS(quantif)
out_test <- test_pathway(quantif, design, pathways,
fixed = c("Age", "Treatment"), random = "Mouse", npc = 2L,
model = "blmer")
out_test
}
\references{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment