Skip to content

Commit

Permalink
Fixed caption labels in gene-path heatmap; added polish to rotate_hea…
Browse files Browse the repository at this point in the history
…tmap=TRUE; fixed issue where some IPA import files missed the user-defined gene symbol section; changed default enrichment style to dotplot_inverted.
  • Loading branch information
jmw86069 committed Sep 27, 2024
1 parent 870917a commit 163a552
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 105 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: multienrichjam
Type: Package
Title: Analysis and Visualization of Multiple Gene Set Enrichments
Version: 0.0.89.900
Version: 0.0.90.900
Authors@R: person(given="James M.", family="Ward",
email="[email protected]", role=c("aut", "cre"))
Maintainer: James M. Ward <[email protected]>
Expand Down
34 changes: 34 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
# multienrichjam 0.0.90.900

## changes to existing functions

* `mem_plot_folio()`

* help docs changed to use the correct name
`mem_gene_path_heatmap()` from incorrect `mem_gene_pathway_heatmap()`.
* The `column_anno_padding`,`row_anno_padding` are now properly
applied before creating each heatmap, then reverted to previous
state before returning data.
* The Enrichment Heatmap default now uses `style="dotplot_inverted"`,
for previous behavior use `style="dotplot"`.

* `mem_gene_path_heatmap()`

* Fixed visual bug where caption labels indicated "genes" twice, instead
of "genes" and "pathways".
* When `rotate_heatmap=TRUE`, arguments are more consistently flipped
from row to column, and help docs are updated to be explicit about
which arguments are flipped, and which two are not.
* The heatmap caption uses consistent order to describe rows, columns,
and reverses the order when `rotate_heatmap=TRUE`.
* The geneIM legend label now uses title case for consistency:
"Gene Hit By Enrichment", rather than "enrichments per gene" which
was not correct wording.

* `importIPAenrichment()`

* Fixed issue with `"Analysis Ready Molecules"` not having proper
header column pattern matching, causing some imports to skip
applying the user-defined gene symbol.


# multienrichjam 0.0.89.900

## changes to existing functions
Expand Down
2 changes: 1 addition & 1 deletion R/jamenrich-import.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
#' @export
importIPAenrichment <- function
(ipaFile,
headerGrep="(^|\t)((expr.|-log.|)p-value|Pvalue|Score\t|Symbol\t|Ratio\t|Consistency.Score|Master.Regulator\t)",
headerGrep="(^|\t)((expr.|-log.|)p-value|Pvalue|Score($|\t)|Symbol($|\t)|Ratio($|\t)|Consistency.Score|Master.Regulator($|\t))",
ipaNameGrep=c("Pathway",
"Regulator$",
"Regulators",
Expand Down
64 changes: 39 additions & 25 deletions R/jamenrich-mem-plot-folio.R
Original file line number Diff line number Diff line change
Expand Up @@ -355,18 +355,18 @@
#' will auto-detect whether there is directionality present in the
#' data, and will set `apply_direction=TRUE` only when there are non-NA
#' values that differ from zero.
#' @param rotate_heatmap `logical` passed to `mem_gene_pathway_heatmap()`
#' @param rotate_heatmap `logical` passed to `mem_gene_path_heatmap()()`
#' and only this function, default `FALSE`. It indicates whether to
#' rotate the heatmap to have gene columns and pathway rows.
#' If you find most people tilt their head to read the pathways,
#' it might be preferable.
#' @param row_anno_padding,column_anno_padding `grid::unit` or `numeric`
#' which will be converted to "mm" units. These values control the
#' space between the heatmap body and row/column annotations,
#' respectively, only relevant for `mem_gene_pathway_heatmap()`.
#' respectively, only relevant for `mem_gene_path_heatmap()()`.
#' The value is only applied during `draw()` and cannot be
#' defined in the `Heatmap` object itself, which is why it is
#' included here and not `mem_gene_pathway_heatmap()`.
#' included here and not `mem_gene_path_heatmap()()`.
#' @param do_plot `logical` indicating whether to render each plot.
#' When `do_plot=FALSE` the plot objects will be created and returned,
#' but the plot itself will not be rendered. This option may be
Expand Down Expand Up @@ -416,7 +416,7 @@ mem_plot_folio <- function
repulse=4,
use_shadowText=FALSE,
color_by_column=FALSE,
style="dotplot",
style="dotplot_inverted",
enrich_im_weight=0.3,
gene_im_weight=0.5,
colorize_by_gene=TRUE,
Expand Down Expand Up @@ -446,6 +446,34 @@ mem_plot_folio <- function
do_which <- seq_len(50);
}

#############################################################
# Apply optional heatmap padding parameters
rowpad <- NULL;
columnpad <- NULL;
if (length(row_anno_padding) > 0) {
if (!grid::is.unit(row_anno_padding)) {
row_anno_padding <- grid::unit(row_anno_padding, "mm");
}
rowpad <- ComplexHeatmap::ht_opt("ROW_ANNO_PADDING")
ComplexHeatmap::ht_opt(ROW_ANNO_PADDING=row_anno_padding)
}
if (length(column_anno_padding) > 0) {
if (!grid::is.unit(column_anno_padding)) {
column_anno_padding <- grid::unit(column_anno_padding, "mm");
}
columnpad <- ComplexHeatmap::ht_opt("COLUMN_ANNO_PADDING")
ComplexHeatmap::ht_opt(COLUMN_ANNO_PADDING=column_anno_padding)
}
# revert changes later
revert_hm_padding <- function(...){
if (length(rowpad) > 0) {
ComplexHeatmap::ht_opt(ROW_ANNO_PADDING=rowpad)
}
if (length(columnpad) > 0) {
ComplexHeatmap::ht_opt(COLUMN_ANNO_PADDING=columnpad)
}
}

#############################################################
# First step: Define the Gene-Pathway Heatmap
#
Expand Down Expand Up @@ -538,20 +566,6 @@ mem_plot_folio <- function
do_plot=do_plot,
...);
if (do_plot) {
if (length(row_anno_padding) > 0) {
if (!grid::is.unit(row_anno_padding)) {
row_anno_padding <- grid::unit(row_anno_padding, "mm");
}
rowpad <- ComplexHeatmap::ht_opt("ROW_ANNO_PADDING")
ComplexHeatmap::ht_opt(ROW_ANNO_PADDING=row_anno_padding)
}
if (length(column_anno_padding) > 0) {
if (!grid::is.unit(column_anno_padding)) {
column_anno_padding <- grid::unit(column_anno_padding, "mm");
}
columnpad <- ComplexHeatmap::ht_opt("COLUMN_ANNO_PADDING")
ComplexHeatmap::ht_opt(COLUMN_ANNO_PADDING=column_anno_padding)
}
if (!color_by_column) {
if ("annotation_legend_list" %in% names(attributes(mem_hm))) {
annotation_legend_list <- attributes(mem_hm)$annotation_legend_list;
Expand All @@ -567,12 +581,6 @@ mem_plot_folio <- function
}
}
}
if (length(row_anno_padding) > 0) {
ComplexHeatmap::ht_opt(ROW_ANNO_PADDING=rowpad)
}
if (length(column_anno_padding) > 0) {
ComplexHeatmap::ht_opt(COLUMN_ANNO_PADDING=columnpad)
}
}
ret_vals$enrichment_hm <- mem_hm;
}
Expand All @@ -581,6 +589,7 @@ mem_plot_folio <- function
#############################################################
## Gene-Pathway Heatmap
if (length(do_which) > 0 && !any(do_which > plot_num)) {
revert_hm_padding();
return(invisible(ret_vals));
}
## All subsequent plots depend upon mem_gene_path_heatmap()
Expand Down Expand Up @@ -696,7 +705,10 @@ mem_plot_folio <- function
NULL;
});
if (length(cnet_collapsed) == 0) {
return(list(mem=mem, clusters_mem=clusters_mem, ret_vals=ret_vals))
revert_hm_padding();
return(list(mem=mem,
clusters_mem=clusters_mem,
ret_vals=ret_vals))
}
igraph::V(cnet_collapsed)$pie.color <- lapply(
igraph::V(cnet_collapsed)$pie.color, function(i){
Expand Down Expand Up @@ -984,5 +996,7 @@ mem_plot_folio <- function
plot_num <- plot_num + pathway_clusters_n;
}

revert_hm_padding();

invisible(ret_vals);
}
Loading

0 comments on commit 163a552

Please sign in to comment.