Skip to content

Commit

Permalink
Preparations for update: many functions renamed, some bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
enblacar committed Jan 16, 2025
1 parent c1a64a1 commit 2e07864
Show file tree
Hide file tree
Showing 28 changed files with 266 additions and 228 deletions.
10 changes: 5 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ export(do_FeaturePlot)
export(do_GeyserPlot)
export(do_GroupwiseDEPlot)
export(do_LigandReceptorPlot)
export(do_LoadingsPlot)
export(do_LoadingsHeatmap)
export(do_MetadataPlot)
export(do_NebulosaPlot)
export(do_PackageReport)
export(do_PathwayActivityPlot)
export(do_RankedEnrichmentPlot)
export(do_RankedExpressionPlot)
export(do_RankedEnrichmentHeatmap)
export(do_RankedExpressionHeatmap)
export(do_RidgePlot)
export(do_SCEnrichmentHeatmap)
export(do_SCExpressionHeatmap)
export(do_SavePlot)
export(do_TFActivityPlot)
export(do_TermEnrichmentPlot)
export(do_ViolinPlot)
export(do_VolcanoPlot)
export(do_WafflePlot)
export(package_report)
export(save_Plot)
18 changes: 15 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@

## Added functions
- `do_WafflePlot()`: This function displays proportions as a pictogram grid of 10x10 tiles. It helps to visually see at a glance the proportions of your data. This fails to correctly convey decimal proportions and completely ignores heavily under-represented classes in your dataset.
- `do_RankedExpressionPlot()` to plot expression values as a heatmap along a diffusion component.
- `do_RankedExpressionHeatmap()` to plot expression values as a heatmap along a dimensional reduction component.

## Removed functions
- `do_FunctionalAnnotationPlot()`.
- `do_GroupedGOTermPlot()`.

The reason behind it is that they, together with do_TermEnrichmentPlot() targetted the same analysis and, therefore, were redundant.
The reason behind it is that they, together with do_TermEnrichmentPlot() targeted the same analysis and, therefore, were redundant.

## Renamed functions
- `do_DiffusionMapPlot()` is now called `do_RankedEnrichmentPlot()`. As it now accepts any dimensional reduction and not only diffusion maps.
- `do_DiffusionMapPlot()` is now called `do_RankedEnrichmentHeatmap()`. As it now accepts any dimensional reduction and not only diffusion maps.
- `save_plot()` (development release only) is now called `do_SavePlot()`. This is a preparation for the version `2.0.3` which will launch together with the publication.
- `package_report()` is now called `do_PackageReport()`. This is a preparation for the version `2.0.3` which will launch together with the publication.
- `do_LoadingsPlot()` is now called `do_LoadingsHeatmap()`. This is a preparation for the version `2.0.3` which will launch together with the publication.

## Heavily modified functions.
- `do_TermEnrichmentPlot()`: Recoded the whole function. Now accepts the result of using `clusterProfiler::enrichGO()`, `clusterProfiler::enrichKEGG()`, etc. The output is a dot plot with the terms on the Y axis, the Gene Ratio in the X, colored by the adjusted p-value and size mapped to the Gene Count.
Expand All @@ -25,13 +28,22 @@ The reason of these modification is to allow for a much clearer and concise outp

## do_AlluvialPlot()
- Enforced a minimum version of `ggalluvial` to deal with deprecation of functions from `dplyr` and `tidyr` that were still used in `ggalluvial` functions.
- Modified the legend items to have a black border.

## do_BoxPlot()
- Added `legend.ncol`, `legend.nrow` and `legend.byrow` parameters to control legend behavior.
- Fixed a bug in which `map_signif_levels` would only accept a logical and not custom mappings.
- When `map_signif_levels` is used, the mapping now appears as a plot legend for clarity.
- Added black borders to the legend glyphs when using `use_silhouette = FALSE`.

## do_CellularStatesPlot()
- Added reference lines to the plot to better visualize the segments.
- Added black border around the legend items.
- Fixed bug where axis text will always display in bold.

## do_ChortDiagramPlot()
- Added `font.size` parameter to control the font size of the plot.

## do_ColorPalette()
- Changed "Wheel" to "Color wheel" when plotting the output without additional parameters.

Expand Down
4 changes: 3 additions & 1 deletion R/do_AlluvialPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ do_AlluvialPlot <- function(sample,
ggplot2::labs(title = plot.title,
subtitle = plot.subtitle,
caption = plot.caption) +
ggplot2::guides(fill = ggplot2::guide_legend(title = legend.title)) +
ggplot2::guides(fill = ggplot2::guide_legend(title = legend.title,
override.aes = list(color = "black",
shape = 22))) +
ggplot2::theme_minimal(base_size = font.size) +
ggplot2::theme(axis.title = ggplot2::element_text(color = "black",
face = axis.title.face),
Expand Down
14 changes: 12 additions & 2 deletions R/do_CellularStatesPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ do_CellularStatesPlot <- function(sample,
pixels = c(raster.dpi, raster.dpi))
}
p <- p +
ggplot2::geom_hline(yintercept = 0, linetype = "dashed") +
ggplot2::geom_vline(xintercept = 0, linetype = "dashed") +
ggplot2::scale_color_manual(values = colors.use) +
ggplot2::guides(color = ggplot2::guide_legend(title = "")) +
ggplot2::xlab(x_lab) +
Expand Down Expand Up @@ -357,6 +359,8 @@ do_CellularStatesPlot <- function(sample,
pixels = c(raster.dpi, raster.dpi))
}
p <- p +
ggplot2::geom_hline(yintercept = 0, linetype = "dashed") +
ggplot2::geom_vline(xintercept = 0, linetype = "dashed") +
ggplot2::scale_color_manual(values = colors.use) +
ggplot2::xlab(x_lab) +
ggplot2::ylab(y_lab) +
Expand Down Expand Up @@ -465,6 +469,8 @@ do_CellularStatesPlot <- function(sample,
pixels = c(raster.dpi, raster.dpi))
}
p <- p +
ggplot2::geom_hline(yintercept = 0, linetype = "dashed") +
ggplot2::geom_vline(xintercept = 0, linetype = "dashed") +
ggplot2::scale_color_manual(values = colors.use) +
ggplot2::xlab(x_lab1) +
ggplot2::ylab(y_lab1) +
Expand All @@ -485,6 +491,8 @@ do_CellularStatesPlot <- function(sample,

suppressMessages({
p <- p +
ggplot2::geom_hline(yintercept = 0, linetype = "dashed") +
ggplot2::geom_vline(xintercept = 0, linetype = "dashed") +
ggplot2::xlim(lim) +
ggplot2::ylim(lim) +
ggplot2::scale_y_continuous(sec.axis = ggplot2::sec_axis(~., name = y_lab2)) +
Expand All @@ -510,7 +518,6 @@ do_CellularStatesPlot <- function(sample,
axis.text.y.right = ggplot2::element_text(face = axis.text.face, color = "black"),
axis.title.x.top = ggplot2::element_text(face = axis.title.face, color = "black"),
axis.title.y.right = ggplot2::element_text(face = axis.title.face, color = "black"),
axis.text = ggplot2::element_text(face = "bold", color = "black"),
plot.title = ggplot2::element_text(face = plot.title.face, hjust = 0),
plot.subtitle = ggplot2::element_text(face = plot.subtitle.face, hjust = 0),
plot.caption = ggplot2::element_text(face = plot.caption.face, hjust = 1),
Expand All @@ -532,7 +539,10 @@ do_CellularStatesPlot <- function(sample,
ncol = legend.ncol,
nrow = legend.nrow,
byrow = legend.byrow,
override.aes = list(size = legend.icon.size)))
override.aes = list(size = legend.icon.size,
color = "black",
fill = colors.use,
shape = 21)))

# Add cell borders.
if (isTRUE(plot_cell_borders)){
Expand Down
7 changes: 5 additions & 2 deletions R/do_ChordDiagramPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ do_ChordDiagramPlot <- function(sample = NULL,
alignment = "default",
annotationTrack = c("grid", "axis"),
padding_labels = 4,
font.size = 1,
...){
# Add lengthy error messages.
withr::local_options(.new = list("warning.length" = 8170))
Expand All @@ -90,7 +91,8 @@ do_ChordDiagramPlot <- function(sample = NULL,
"alpha.highlight" = alpha.highlight,
"self.link" = self.link,
"directional" = directional,
"padding_labels" = padding_labels)
"padding_labels" = padding_labels,
"font.size" = font.size)
check_type(parameters = numeric_list, required_type = "numeric", test_function = is.numeric)
# Check character parameters.

Expand Down Expand Up @@ -352,7 +354,8 @@ do_ChordDiagramPlot <- function(sample = NULL,
facing = "clockwise",
niceFacing = TRUE,
adj = c(-0.15, 0.5),
font = 2)},
font = 2,
cex = font.size)},
bg.border = NA)
p <- grDevices::recordPlot()
circlize::circos.clear()
Expand Down
4 changes: 2 additions & 2 deletions R/do_GeyserPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ do_GeyserPlot <- function(sample,
diverging.palette = "RdBu",
diverging.direction = -1,
sequential.palette = "YlGnBu",
sequential.direction = -1,
use_viridis = TRUE,
sequential.direction = 1,
use_viridis = FALSE,
plot.title.face = "bold",
plot.subtitle.face = "plain",
plot.caption.face = "italic",
Expand Down
17 changes: 12 additions & 5 deletions R/do_LoadingsPlot.R → R/do_LoadingsHeatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
#' @return A ggplot2 object.
#' @export
#'
#' @example /man/examples/examples_do_LoadingsPlot.R
do_LoadingsPlot <- function(sample,
#' @example /man/examples/examples_do_LoadingsHeatmap.R
do_LoadingsHeatmap <- function(sample,
group.by = NULL,
subsample = NA,
dims = 1:10,
top_loadings = 5,
assay = "SCT",
assay = NULL,
slot = "data",
grid.color = "white",
border.color = "black",
Expand Down Expand Up @@ -56,7 +56,7 @@ do_LoadingsPlot <- function(sample,
# Add lengthy error messages.
withr::local_options(.new = list("warning.length" = 8170))

check_suggests("do_LoadingsPlot")
check_suggests("do_LoadingsHeatmap")

# Check logical parameters.
logical_list <- list("use_viridis" = use_viridis,
Expand Down Expand Up @@ -139,7 +139,14 @@ do_LoadingsPlot <- function(sample,
use_viridis = use_viridis,
direction = ifelse(isTRUE(use_viridis), viridis.direction, sequential.direction),
enforce_symmetry = FALSE)



# Check assay.
assay <- if (is.null(assay)){Seurat::DefaultAssay(sample)} else {assay}

Seurat::DefaultAssay(sample) <- assay


# Check group.by.
out <- check_group_by(sample = sample,
group.by = group.by,
Expand Down
14 changes: 8 additions & 6 deletions R/do_RankedEnrichmentPlot.R → R/do_RankedEnrichmentHeatmap.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#' Compute a heatmap of enrichment of gene sets on the context of a diffusion component.
#' Compute a heatmap of enrichment of gene sets on the context of a dimensional reduction component.
#'
#' @inheritParams doc_function
#' @param colors.use \strong{\code{\link[base]{list}}} | A named list of named vectors. The names of the list correspond to the names of the values provided to metadata and the names of the items in the named vectors correspond to the unique values of that specific metadata variable. The values are the desired colors in HEX code for the values to plot. The used are pre-defined by the package but, in order to get the most out of the plot, please provide your custom set of colors for each metadata column!
#' @param main.heatmap.size \strong{\code{\link[base]{numeric}}} | A number from 0 to 1 corresponding to how big the main heatmap plot should be with regards to the rest (corresponds to the proportion in size).
#' @param scale.enrichment \strong{\code{\link[base]{logical}}} | Should the enrichment scores be scaled (z-scored) for better comparison in between gene sets? Setting this to TRUE should make intra- gene set comparisons easier at the cost ot not being able to compare inter- gene sets in absolute values.
#' @return A list of ggplot2 objects and a Seurat object if desired.
#' @return A list of ggplot2 objects, one per dimensional reduction component, and a Seurat object if desired.
#' @export
#'
#' @example /man/examples/examples_do_RankedEnrichmentPlot.R
do_RankedEnrichmentPlot <- function(sample,
#' @example /man/examples/examples_do_RankedEnrichmentHeatmap.R
do_RankedEnrichmentHeatmap <- function(sample,
input_gene_list,
assay = NULL,
slot = NULL,
Expand Down Expand Up @@ -61,7 +61,7 @@ do_RankedEnrichmentPlot <- function(sample,
# Add lengthy error messages.
withr::local_options(.new = list("warning.length" = 8170))

check_suggests("do_RankedEnrichmentPlot")
check_suggests("do_RankedEnrichmentHeatmap")
check_Seurat(sample = sample)

# Check the reduction.
Expand Down Expand Up @@ -264,7 +264,7 @@ do_RankedEnrichmentPlot <- function(sample,
data.use <- data.use %>%
tidyr::pivot_longer(cols = dplyr::all_of(c(names(input_gene_list))),
names_to = "Gene_Set",
values_to = "Enrichment")
values_to = "Enrichment")


# Generate DC-based heatmaps.
Expand Down Expand Up @@ -373,6 +373,8 @@ do_RankedEnrichmentPlot <- function(sample,
ggplot2::guides(fill = ggplot2::guide_legend(title = name,
title.position = "top",
title.hjust = 0.5,
override.aes = list(color = "black",
shape = 22),
ncol = legend.ncol,
nrow = legend.nrow,
byrow = legend.byrow)) +
Expand Down
15 changes: 9 additions & 6 deletions R/do_RankedExpressionPlot.R → R/do_RankedExpressionHeatmap.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#' Compute a heatmap of enrichment of gene sets on the context of a diffusion component.
#' Compute a heatmap of expression of genes on the context of a dimensional reduction component.
#'
#' @inheritParams doc_function
#' @param colors.use \strong{\code{\link[base]{list}}} | A named list of named vectors. The names of the list correspond to the names of the values provided to metadata and the names of the items in the named vectors correspond to the unique values of that specific metadata variable. The values are the desired colors in HEX code for the values to plot. The used are pre-defined by the package but, in order to get the most out of the plot, please provide your custom set of colors for each metadata column!
#' @param main.heatmap.size \strong{\code{\link[base]{numeric}}} | A number from 0 to 1 corresponding to how big the main heatmap plot should be with regards to the rest (corresponds to the proportion in size).
#' @return A list of ggplot2 objects and a Seurat object if desired.
#' @return A list of ggplot2 objects, one per dimensional reduction component, and a Seurat object if desired.
#' @export
#'
#' @example /man/examples/examples_do_RankedExpressionPlot.R
do_RankedExpressionPlot <- function(sample,
#' @example /man/examples/examples_do_RankedExpressionHeatmap.R
do_RankedExpressionHeatmap <- function(sample,
features,
assay = NULL,
slot = NULL,
Expand Down Expand Up @@ -58,7 +58,7 @@ do_RankedExpressionPlot <- function(sample,
# Add lengthy error messages.
withr::local_options(.new = list("warning.length" = 8170))

check_suggests("do_RankedExpressionPlot")
check_suggests("do_RankedExpressionHeatmap")
check_Seurat(sample = sample)

# Check the reduction.
Expand Down Expand Up @@ -242,7 +242,8 @@ do_RankedExpressionPlot <- function(sample,
data.use <- data.use %>%
tidyr::pivot_longer(cols = dplyr::all_of(c(features)),
names_to = "Feature",
values_to = "Expression")
values_to = "Expression") %>%
dplyr::mutate("Feature" = factor(.data$Feature, levels = genes.use))


# Generate DC-based heatmaps.
Expand Down Expand Up @@ -350,6 +351,8 @@ do_RankedExpressionPlot <- function(sample,
ggplot2::guides(fill = ggplot2::guide_legend(title = name,
title.position = "top",
title.hjust = 0.5,
override.aes = list(color = "black",
shape = 22),
ncol = legend.ncol,
nrow = legend.nrow,
byrow = legend.byrow)) +
Expand Down
20 changes: 10 additions & 10 deletions R/save_Plot.R → R/do_SavePlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
#' @return Nothing.
#' @export
#'
#' @example /man/examples/examples_save_Plot.R
save_Plot <- function(plot,
figure_path = NULL,
create_path = TRUE,
file_name = NULL,
dpi = 300,
output_format = "publication",
width = 8,
height = 8){
#' @example /man/examples/examples_do_SavePlot.R
do_SavePlot <- function(plot,
figure_path = NULL,
create_path = TRUE,
file_name = NULL,
dpi = 300,
output_format = "publication",
width = 8,
height = 8){
# nocov start

# Checks for packages.
check_suggests(function_name = "save_Plot")
check_suggests(function_name = "do_SavePlot")

# Check logical parameters.
logical_list <- list("create_path" = create_path)
Expand Down
Loading

0 comments on commit 2e07864

Please sign in to comment.