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

corrections

parent e041e04c
No related branches found
No related tags found
No related merge requests found
......@@ -3,9 +3,14 @@
S3method(adjust_pval,pathwayRes)
S3method(extract,pathwayRes)
S3method(head,pathwayRes)
S3method(plot,MFApath)
S3method(plot,PCApath)
S3method(plot,pathwayRes)
S3method(print,MFApath)
S3method(print,PCApath)
S3method(print,pathwayRes)
S3method(summary,MFApath)
S3method(summary,PCApath)
S3method(summary,pathwayRes)
export(adjust_pval)
export(extract)
......
......@@ -28,10 +28,23 @@ summary.pathwayRes <- function(object, ...) {
cat("Tested effects:", object[[1]]$test_pathway$Fixed_effect)
}
#' @exportS3Method
summary.PCApath <- function(object, ...) {
cat("phoenics method based on PCA\n")
NextMethod()
}
#' @exportS3Method
summary.MFApath <- function(object, ...) {
cat("phoenics method based on MFA\n")
NextMethod()
}
#' @rdname pathwayRes
#' @aliases print.pathwayRes
#' @examples
#' print(out_test)
#' print(out_test2)
#' @exportS3Method
print.pathwayRes <- function(x, ...) {
cat("A list of pathways which contains for each pathway: \n")
......@@ -39,10 +52,21 @@ print.pathwayRes <- function(x, ...) {
cat("$", names(path_res)[1], ": ", "Pathway name \n", sep = "")
cat("$", names(path_res)[2], ": ", "Pathway code \n", sep = "")
cat("$", names(path_res)[3], ": ", "Metabolites in the pathway \n", sep = "")
cat("$", names(path_res)[4], ": ", "PCA results \n", sep = "")
cat("$", names(path_res)[4], ": ", "Factor analysis results \n", sep = "")
cat("$", names(path_res)[5], ": ", "Model results \n", sep = "")
cat("$", names(path_res)[6], ": ", "Pathway test results \n", sep = "")
cat("$", names(path_res)[7], ": ", "Type of factor analysis \n", sep = "")
}
#' @exportS3Method
print.PCApath <- function(x, ...) {
cat("phoenics method based on PCA\n")
NextMethod()
}
#' @exportS3Method
print.MFApath <- function(x, ...) {
cat("phoenics method based on MFA\n")
NextMethod()
}
#' @rdname pathwayRes
......@@ -97,43 +121,54 @@ plot.PCApath <- function(x, ..., pathway_id = NULL,
object_sub <- extract.pathwayRes(x, pathway_id)
analysis <- object_sub[[1]]$analysis
if (plot == "var") {
p <- factoextra::fviz_pca_var(object_sub[[1]]$PCA,
title = object_sub[[1]]$pathway_name,
repel = TRUE)
return(p)
}
if (plot == "ind") {
p <- factoextra::fviz_pca_ind(object_sub[[1]]$PCA, habillage = habillage,
title = object_sub[[1]]$pathway_name,
geom = "point", pointsize = 2,
mean.point = FALSE)
return(p)
}
NextMethod()
}
#' @exportS3Method
plot.MFApath <- function(x, ..., pathway_id = NULL,
plot = c("eig", "var", "ind", "group"),
habillage = "none") {
plot <- match.arg(plot)
if (analysis == "PCA") {
if (plot == "var") {
p <- factoextra::fviz_pca_var(object_sub[[1]]$PCA,
title = object_sub[[1]]$pathway_name,
repel = TRUE)
return(p)
}
if (plot == "ind") {
p <- factoextra::fviz_pca_ind(object_sub[[1]]$PCA, habillage = habillage,
title = object_sub[[1]]$pathway_name,
geom = "point", pointsize = 2,
mean.point = FALSE)
return(p)
}
if (is.null(pathway_id)) {
message("`pathway_id` not specified... defaulting to the first pathway")
pathway_id <- names(x)[1]
}
if (analysis == "MFA") {
if (plot == "group") {
p <- factoextra::fviz_mfa_var(object_sub[[1]]$PCA, choice = "group",
title = object_sub[[1]]$pathway_name,
repel = TRUE)
return(p)
}
if (plot == "var") {
p <- factoextra::fviz_mfa_var(object_sub[[1]]$PCA, choice = "quanti.var",
title = object_sub[[1]]$pathway_name,
repel = TRUE)
return(p)
}
if (plot == "ind") {
p <- factoextra::fviz_mfa_ind(object_sub[[1]]$PCA, partial = "all",
habillage = habillage,
title = object_sub[[1]]$pathway_name,
pointsize = 2)
return(p)
}
object_sub <- extract.pathwayRes(x, pathway_id)
if (plot == "group") {
p <- factoextra::fviz_mfa_var(object_sub[[1]]$PCA, choice = "group",
title = object_sub[[1]]$pathway_name,
repel = TRUE)
return(p)
}
if (plot == "var") {
p <- factoextra::fviz_mfa_var(object_sub[[1]]$PCA, choice = "quanti.var",
title = object_sub[[1]]$pathway_name,
repel = TRUE)
return(p)
}
if (plot == "ind") {
p <- factoextra::fviz_mfa_ind(object_sub[[1]]$PCA, partial = "all",
habillage = habillage,
title = object_sub[[1]]$pathway_name,
pointsize = 2)
return(p)
}
NextMethod()
}
......@@ -170,10 +205,11 @@ extract <- function(object, pathway_id) {
#' @exportS3Method
extract.pathwayRes <- function(object, pathway_id) {
class_sub <- class(object)
cond <- lapply(object, function(path) path$pathway_code %in% pathway_id |
path$pathway_name %in% pathway_id)
object_sub <- object[unlist(cond)]
class(object_sub) <- c("PCApath", "pathwayRes")
class(object_sub) <- class_sub
return(object_sub)
}
......
......@@ -35,9 +35,9 @@
#' @param analysis character string indicating if the pathway scores are
#' obtained using \link[FactoMineR]{PCA} or \link[FactoMineR]{MFA}
#'
#' @return an object of class \code{PCApath} and \code{pathwayRes} which is a
#' list of pathway results. Each element of the list contain the following
#' entries:
#' @return an object of class \code{PCApath} or \code{MFApath} and
#' \code{pathwayRes} which is a list of pathway results. Each element of the
#' list contain the following entries:
#' \item{pathway_name}{a character corresponding to the pathway name}
#' \item{pathway_code}{a character corresponding to the pathway code}
#' \item{metabolites}{a data.frame with the names and codes of the quantified
......@@ -48,7 +48,6 @@
#' \item{model}{the output of the mixed model fit}
#' \item{test_pathway}{a data.frame with the p-values for each tested fixed
#' effect}
#' \item{analysis}{a character corresponding to the parameter \code{analysis}}
#'
#' @importFrom FactoMineR PCA MFA
#' @importFrom lme4 lmer
......@@ -308,13 +307,18 @@ test_pathway <- function(quantif, design, pathways = "auto", fixed, random,
res <- list("pathway_name" = path_name, "pathway_code" = path_code,
"metabolites" = out_met, "PCA" = res_pca, "model" = res_lmm,
"test_pathway" = res_test, "analysis" = analysis)
"test_pathway" = res_test)
return(res)
})
names(res_pathway) <- unique(pathways$pathway_name)
class(res_pathway) <- c("PCApath", "pathwayRes")
if (analysis == "PCA") {
class(res_pathway) <- c("PCApath", "pathwayRes")
}
if (analysis == "MFA") {
class(res_pathway) <- c("MFApath", "pathwayRes")
}
return(res_pathway)
}
......@@ -82,6 +82,7 @@ out_test2 <- test_pathway(quantif, design, pathways,
npc = 2, model = "blmer", analysis = "MFA")
summary(out_test2)
print(out_test)
print(out_test2)
plot(out_test)
plot(out_test, pathway_id = "mmu00052", plot = "var")
plot(out_test, pathway_id = "mmu00052", plot = "ind", habillage = "Age")
......
......@@ -59,9 +59,9 @@ using \link[lme4]{lmer} or \link[blme]{blmer}. Default to \code{"lmer"}}
obtained using \link[FactoMineR]{PCA} or \link[FactoMineR]{MFA}}
}
\value{
an object of class \code{PCApath} and \code{pathwayRes} which is a
list of pathway results. Each element of the list contain the following
entries:
an object of class \code{PCApath} or \code{MFApath} and
\code{pathwayRes} which is a list of pathway results. Each element of the
list contain the following entries:
\item{pathway_name}{a character corresponding to the pathway name}
\item{pathway_code}{a character corresponding to the pathway code}
\item{metabolites}{a data.frame with the names and codes of the quantified
......@@ -72,7 +72,6 @@ from \link[FactoMineR]{MFA})}
\item{model}{the output of the mixed model fit}
\item{test_pathway}{a data.frame with the p-values for each tested fixed
effect}
\item{analysis}{a character corresponding to the parameter \code{analysis}}
}
\description{
Perform a differential analysis at pathway level based on
......
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