Commit 9955e64b authored by Christian Arnold's avatar Christian Arnold
Browse files

Further improvements and fixing small issues

parent 832b1992
......@@ -36,13 +36,11 @@ export(plotPCA_all)
export(plotTFEnrichment)
export(plot_stats_connectionSummary)
import(BiocManager)
import(DOSE)
import(GenomicRanges)
import(IRanges)
import(ReactomePA)
import(checkmate)
import(clusterProfiler)
import(ggplot2)
import(grDevices)
import(graphics)
import(grid)
import(magrittr)
......
# GRaNIE 0.15-0.17 (2021-12-13)
## Major changes
- all enrichment analyses have been extended and improved, we added additional ontologies (KEGG, DO, and Reactome), more information in the resulting summary plots
- all plotting functions have been homogenized and extended, PDF width and height can now be set for all exported plot functions. Also, the possibility to not to a PDF but instead to the currently active graphics device is possible. Lastly, setting a different filename is finally possible. Collectively, this provides ultimate flexibility for customizing file names, the output devices used and PDF sizes
- we added a function to build the eGRN network that can be parameterized and that allows future developmemt more easily. Now, network-specific parameters can be changed, such as whether loops should be allowed
- we removed the GRaNIEdev package, the development now happens in a separate branch rather than a different package
- we added Leiden clustering for community clustering (see https://www.nature.com/articles/s41598-019-41695-z for a comparison with louvain)
- extensive vignette updates
## Bug fixes
- various minor bug fixes
## Minor changes
- changed the object structure slightly (graph slot and structure within the stats$enrichment slot)
# GRaNIE 0.9-0.14 (2021-12-13)
## Major changes
......
......@@ -4083,13 +4083,13 @@ getGRNConnections <- function(GRN, type = "all.filtered", permuted = FALSE, inc
"plot_class_densityClass" = "TF_classification_summaryHeatmap",
"plot_peakGene_diag" = "peakGene_diagnosticPlots",
"plot_peakGene_IHW_diag" = "peakGene_IHW.diagnosticPlots",
"plot_connectionSummary_heatmap" = "GRN.connectionSummary_heatmap.pdf",
"plot_connectionSummary_boxplot" = "GRN.connectionSummary_boxplot.pdf",
"plot_generalEnrichment" = "GRN.overall_enrichment.pdf",
"plot_communityStats" = "GRN.community_stats.pdf",
"plot_communityEnrichment" = "GRN.community_enrichment.pdf",
"plot_generalNetworkStats" = "GRN.overall_stats.pdf",
"plot_TFEnrichment" = "GRN.TF_enrichment.pdf"
"plot_connectionSummary_heatmap" = "GRN.connectionSummary_heatmap",
"plot_connectionSummary_boxplot" = "GRN.connectionSummary_boxplot",
"plot_generalEnrichment" = "GRN.overall_enrichment",
"plot_communityStats" = "GRN.community_stats",
"plot_communityEnrichment" = "GRN.community_enrichment",
"plot_generalNetworkStats" = "GRN.overall_stats",
"plot_TFEnrichment" = "GRN.TF_enrichment"
)
......@@ -4106,9 +4106,9 @@ getGRNConnections <- function(GRN, type = "all.filtered", permuted = FALSE, inc
.getPermutationSuffixStr <- function(permutation) {
if (permutation == 0) {
suffixFile = "_original.pdf"
suffixFile = "_original"
} else {
suffixFile = "_permuted.pdf"
suffixFile = "_permuted"
}
suffixFile
......
......@@ -286,6 +286,7 @@
futile.logger::flog.info(paste0(prefix, "Finished successfully. Execution time: ", round(endTime - startTime, 1), " ", units(endTime - startTime)))
}
#' @import grDevices
.checkAndLogWarningsAndErrors <- function(object, checkResult, isWarning = FALSE) {
checkmate::assert(checkmate::checkCharacter(checkResult, len = 1), checkmate::checkLogical(checkResult))
......@@ -313,6 +314,8 @@
warning(messageWarning)
} else {
futile.logger::flog.error(messageError)
# Close all open devices
while (grDevices::dev.cur()>1) grDevices::dev.off()
stop(messageError)
}
}
......
......@@ -156,9 +156,9 @@ build_eGRN_graph <- function(GRN, model_TF_gene_nodes_separately = FALSE,
multipleEdges = graph_table %>%
dplyr::group_by(V1,V2) %>%
dplyr::summarize(n = n(), .groups = "keep") %>%
dplyr::summarize(n = dplyr::n(), .groups = "keep") %>%
dplyr::ungroup() %>%
dplyr::filter(n>1)
dplyr::filter(.data$n>1)
if (nrow(multipleEdges) > 0) {
if (!silent) futile.logger::flog.info(paste0(" ", nrow(multipleEdges), " edges have the same vertices. This is often caused by multiple TF belonging to the same gene ID."))
......@@ -218,12 +218,11 @@ performAllNetworkAnalyses <- function(GRN, ontology = c("GO_BP", "GO_MF"),
GRN = plotCommunitiesEnrichment(GRN, outputFolder = outputFolder, display = display, communities = communities,
display_pAdj = display_pAdj, forceRerun = forceRerun)
# TODO: Broken
GRN = calculateTFEnrichment(GRN, ontology = ontology, algorithm = algorithm, statistic = statistic,
background = background, pAdjustMethod = "BH",
forceRerun = forceRerun)
# GRN = plotTFEnrichment(GRN, display_pAdj = display_pAdj, forceRerun = forceRerun)
GRN = plotTFEnrichment(GRN, display_pAdj = display_pAdj, forceRerun = forceRerun)
.printExecutionTime(start)
......@@ -282,9 +281,6 @@ performAllNetworkAnalyses <- function(GRN, ontology = c("GO_BP", "GO_MF"),
#' GRN = calculateGeneralEnrichment(GRN, ontology = "GO_BP")
#' @export
#' @import topGO
#' @import clusterProfiler
#' @import ReactomePA
#' @import DOSE
#' @import BiocManager
calculateGeneralEnrichment <- function(GRN, ontology = c("GO_BP", "GO_MF"),
algorithm = "weight01", statistic = "fisher",
......@@ -375,11 +371,11 @@ calculateGeneralEnrichment <- function(GRN, ontology = c("GO_BP", "GO_MF"),
}
# Merge all community-specific results to one data frame
resultsCombined.df = GRN@stats[["Enrichment"]][[type]] %>%
resultsCombined.df = suppressWarnings(GRN@stats[["Enrichment"]][[type]] %>%
lapply(function(x) {x[[ontology]]$results}) %>%
dplyr::bind_rows(.id = idMerge) %>%
dplyr::select(-tidyselect::starts_with("topG")) %>%
tibble::as_tibble()
tibble::as_tibble())
# p-adjust only available for non-GO ontologies
if (display_pAdj && !stringr::str_starts("GO_", ontology)) {
......@@ -704,7 +700,8 @@ calculateGeneralEnrichment <- function(GRN, ontology = c("GO_BP", "GO_MF"),
#'
#' This function generates the TF-gene graph from the filtered GRN object, and clusters its vertices into communities using established community detection algorithms.
#' @template GRN
#' @param clustering Character. Default "louvain". One of: "louvain", "leading_eigen", "fast_greedy", "optimal", "walktrap". The community detection algorithm to be used. Please bear in mind the robustness and time consumption of the algorithms when opting for an alternative to the default.
#' @param clustering Character. Default \code{louvain}. One of: \code{louvain}, \code{leiden}, \code{leading_eigen}, \code{fast_greedy}, \code{optimal}, \code{walktrap}. The community detection algorithm to be used. Please bear in mind the robustness and time consumption of the algorithms when opting for an alternative to the default.
#' @param ... Additional parameters for the used clustering method, see the \code{igraph::cluster_*} methods for details on the specific parameters and what they do. For \code{leiden} clustering, for example, you may add a \code{resolution_parameter} to control the granularity of the community detection or \code{n_iterations} to modify the number of iterations.
#' @template forceRerun
#' @return The same \code{\linkS4class{GRN}} object, with a table that consists of the connections clustered into communities stored in the \code{stats$communities} slot.
#' @import patchwork
......@@ -717,7 +714,7 @@ calculateCommunitiesStats <- function(GRN, clustering = "louvain", forceRerun =
GRN = .addFunctionLogToObject(GRN)
checkmate::assertClass(GRN, "GRN")
checkmate::assertSubset(clustering, c("louvain", "leading_eigen", "fast_greedy", "optimal", "walktrap"))
checkmate::assertSubset(clustering, c("louvain", "leading_eigen", "fast_greedy", "optimal", "walktrap", "leiden"))
checkmate::assertFlag(forceRerun)
if (is.null(igraph::vertex.attributes(GRN@graph$TF_gene$graph)$community) | forceRerun) {
......@@ -744,8 +741,15 @@ calculateCommunitiesStats <- function(GRN, clustering = "louvain", forceRerun =
communities_cluster = igraph::cluster_walktrap(GRN@graph$TF_gene$graph, ...)
} else if (clustering == "leiden") {
# The default, see https://www.nature.com/articles/s41598-019-41695-z for a reasoning
communities_cluster = igraph::cluster_leiden(GRN@graph$TF_gene$graph, ...)
}
# TODO: How redundant is it to store this separately?
GRN@graph$TF_gene$clusterGraph = communities_cluster
......@@ -1072,6 +1076,8 @@ calculateTFEnrichment <- function(GRN, rankType = "degree", n = 0.1, TF.names =
TFset = getTopNodes(GRN, nodeType = "TF", rankType = rankType, n, use_TF_gene_network = TRUE) %>% dplyr::pull(TF.name)
}
# TODO: Continue working on the TF.name level or switch to Ensembl? Should be in concordance with the graph!
mapping = .getGenomeObject(GRN@config$parameters$genomeAssembly, type = "packageName")
if (is.null(GRN@stats[["Enrichment"]][["byTF"]])) {
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment