-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added summary.scLANE() function -- closes #151
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#' Summary method for scLANE objects. | ||
#' | ||
#' @name summary.scLANE | ||
#' @author Jack R. Leary | ||
#' @importFrom purrr map reduce | ||
#' @importFrom stats p.adjust | ||
#' @param test.dyn.res The nested list returned by \code{\link{testDynamic}}. Defaults to NULL. | ||
#' @param (Optional) The method used to adjust \emph{p}-values for multiple hypothesis testing. Defaults to "fdr". | ||
#' @param fdr.cutoff (Optional) The FDR threshold for determining statistical significance. Defaults to 0.01. | ||
#' @return A summary list with aggregated statistics concerning the trajectory DE tests from \code{scLANE}. | ||
#' @export | ||
#' @examples | ||
#' data(scLANE_models) | ||
#' summary(scLANE_models) | ||
|
||
summary.scLANE <- function(test.dyn.res = NULL, | ||
p.adj.method = "fdr", | ||
fdr.cutoff = 0.01) { | ||
if (!inherits(test.dyn.res, "scLANE")) { stop("The input must be an object of class 'scLANE'.") } | ||
summary_stats <- list() | ||
summary_stats$n_lineages <- length(test.dyn.res[[1]]) | ||
summary_stats$n_genes <- length(test.dyn.res) | ||
p_values <- purrr::map(test.dyn.res, \(g) { | ||
purrr::map(g, \(l) { | ||
l$P_Val | ||
}) | ||
}) | ||
p_values <- purrr::reduce(purrr::reduce(p_values, c), c) | ||
adj_p_values <- stats::p.adjust(sort(p_values), method = p.adj.method) | ||
summary_stats$n_significant_genes <- sum(adj_p_values < fdr.cutoff, na.rm = TRUE) | ||
summary_stats$mean_adj_p_value <- mean(adj_p_values, na.rm = TRUE) | ||
summary_stats$test_type <- ifelse(test.dyn.res[[1]][[1]]$Test_Stat_Type == "LRT", | ||
"Likelihood Ratio Test", | ||
"Wald Test") | ||
class(summary_stats) <- "summary.scLANE" | ||
return(summary_stats) | ||
} | ||
|
||
#' Print method for summary.scLANE objects. | ||
#' | ||
#' @name print.summary.scLANE | ||
#' @author Jack R. Leary | ||
#' @param x An object of class summary.scLANE. | ||
#' @export | ||
|
||
print.summary.scLANE <- function(x) { | ||
cat("Summary of scLANE Model Results\n") | ||
cat("-------------------------------\n") | ||
cat("Test used: ", x$test_type, "\n") | ||
cat("Total genes analyzed: ", x$n_genes, "\n") | ||
cat("Total lineages analyzed: ", x$n_lineages, "\n") | ||
cat("Mean adjusted p-value: ", format(x$mean_adj_p_value, digits = 5), "\n") | ||
cat("Number of significant gene-lineage tests: ", x$n_significant_genes, "\n") | ||
invisible(x) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.