Skip to content

Commit

Permalink
update to match new MultiEWCE
Browse files Browse the repository at this point in the history
  • Loading branch information
bschilder committed Jan 24, 2024
1 parent 7f8ade5 commit c822c26
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 46 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ importFrom(orthogene,create_background)
importFrom(orthogene,map_genes)
importFrom(simona,LCA_depth)
importFrom(stats,as.dist)
importFrom(stats,cor)
importFrom(stats,cutree)
importFrom(stats,hclust)
importFrom(stringr,str_wrap)
Expand Down
1 change: 1 addition & 0 deletions R/make_cannot.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
make_cannot <- function(annot,
col_side_vars){
annot <- data.table::copy(annot)
col <- map_colors(annot,
columns = col_side_vars,
as = "function")
Expand Down
2 changes: 1 addition & 1 deletion R/make_rannot.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
make_rannot <- function(annot,
row_side_vars){
annot_i <- annot[,row_side_vars,with=FALSE]
annot_i <- data.table::copy(annot)[,row_side_vars,with=FALSE]
col <- map_colors(annot_i,
as = "vector")
ra <- ComplexHeatmap::HeatmapAnnotation(
Expand Down
8 changes: 8 additions & 0 deletions R/plot_graph_visnetwork.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#' @describeIn plot_ plot_
#' Plot graph using visNetwork.
#' @param add_visExport Add PDF download button.
#' @inheritParams map_colors
#' @inheritParams visNetwork::visIgraph
#' @inheritParams visNetwork::visIgraphLayout
#' @inheritParams visNetwork::visPhysics
#' @inheritParams visNetwork::visNodes
#' @inheritParams visNetwork::visEdges
#' @inheritParams visNetwork::visOptions
#' @inheritParams visNetwork::visNetwork
#' @export
#' @examples
#' ont <- get_ontology("hpo", terms=10)
Expand Down
41 changes: 21 additions & 20 deletions R/plot_ontology_heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,38 @@
#' metadata annotations.
#' @param col_side_vars Variables to include in column-side
#' metadata annotations.
#' @param fontsize Axis labels font size.
#' @param show_plot Print the plot after generating it.
#' @param save_plot Path to save plot to.
#' @param fontsize Axis labels font size.
#' @param seed Set the seed for reproducible clustering.
#' @inheritParams map_
#' @inheritParams ComplexHeatmap::Heatmap
#' @inheritParams grDevices::pdf
#' @returns Plot
#'
#' @export
#' @importFrom stats cor
#' @examples
#' ont <- get_ontology("hpo", terms=2)
#' hm <- plot_ontology_heatmap(ont)
plot_ontology_heatmap <- function(ont,
to = "similarity",
annot = data.table::data.table(
ont@elementMetadata
),
X = ontology_to(ont, to = "similarity"),
fontsize = ont@n_terms*4e-4,
row_labels = ont@terms,
column_labels = row_labels,
name = NULL,
row_side_vars = c("ancestor_name"),
col_side_vars = c("IC",
"depth",
"n_children",
"n_offspring",
"n_connected_leaves"),
col = pals::gnuplot(),
row_labels = ont@elementMetadata$name,
column_labels = row_labels,
show_plot = TRUE,
save_plot = tempfile(
save_path = tempfile(
fileext = "plot_ontology_heatmap.pdf"),
height = 12,
width = height*1.1,
fontsize = ont@n_terms*4e-4,
width = height*1.1,
# row_km = 3,
# column_km = row_km,
# row_km_repeats = 1000,
Expand All @@ -48,16 +49,16 @@ plot_ontology_heatmap <- function(ont,
"ComplexHeatmap")[2],
...
){
if(!is.null(seed)) set.seed(seed)
X <- ontology_to(ont, to = "similarity")
if(!is.null(seed)) set.seed(seed)
## Check if we need to add ancestors
if(any(c("ancestor","ancestor_name") %in% c(row_side_vars,col_side_vars))){
if(any(c("ancestor","ancestor_name") %in% c(row_side_vars,col_side_vars))
&& !is.null(ont)){
ont <- add_ancestors(ont)
}
annot <- data.table::data.table(ont@elementMetadata)
}
#### Heatmaply version ####
if("heatmaply" %in% types){
requireNamespace("heatmaply")
messager("Creating heatmap: heatmaply")
X[is.na(X)] <- 0
hm <- heatmaply::heatmaply(X,
row_side_colors = annot[,row_side_vars,
Expand All @@ -77,13 +78,13 @@ plot_ontology_heatmap <- function(ont,
} else {
requireNamespace("ComplexHeatmap")
requireNamespace("grid")

messager("Creating heatmap: ComplexHeatmap")
ra <- make_rannot(annot = annot,
row_side_vars = row_side_vars)
ca <- make_cannot(annot = annot,
col_side_vars = col_side_vars)
hm <- ComplexHeatmap::Heatmap(matrix = X,
name = to,
name = name,
col = col,
right_annotation = ra,
top_annotation = ca,
Expand All @@ -110,17 +111,17 @@ plot_ontology_heatmap <- function(ont,
...)
# ComplexHeatmap::row_order(hm)
#### Save plot ####
if(!is.null(save_plot)){
if(!is.null(save_path)){
plot_save(plt = hm,
path = save_plot,
path = save_path,
height = height,
width = width)
}
}
#### Show plot ####
if(isTRUE(show_plot)) {
methods::show(hm)
if(file.exists(save_plot)) utils::browseURL(save_plot)
if(file.exists(save_path)) utils::browseURL(save_path)
}
#### Return ####
return(hm)
Expand Down
109 changes: 85 additions & 24 deletions man/plot_.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c822c26

Please sign in to comment.