Skip to content

Commit

Permalink
restore usage of removed params in internal fxns
Browse files Browse the repository at this point in the history
Signed-off-by: Daena Rys <[email protected]>
  • Loading branch information
Daenarys8 committed Jun 19, 2024
1 parent 9b5fda5 commit 7ffb083
Show file tree
Hide file tree
Showing 13 changed files with 380 additions and 189 deletions.
25 changes: 16 additions & 9 deletions R/plotAbundance.R
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ MELT_VALUES <- "Value"
#' @importFrom tidyr pivot_longer nest unnest
#' @importFrom tibble rownames_to_column
#' @importFrom purrr map
.get_abundance_data <- function(x, rank, assay.type, order.row.by = "name",
use.relative = TRUE){
.get_abundance_data <- function(x, rank, assay.type, order.row.by = order_rank_by,
order_rank_by = "name", use.relative = use_relative, use_relative = TRUE){
data <- assay(x, assay.type, withDimnames = TRUE)
if(use.relative){
data <- mia:::.calc_rel_abund(data)
Expand Down Expand Up @@ -322,7 +322,8 @@ MELT_VALUES <- "Value"
data
}

.norm_order_sample_by <- function(order.col.by, factors, x){
.norm_order_sample_by <- function(order.col.by = order_sample_by,
order_sample_by, factors, x){
if(is.null(order.col.by)){
return(order.col.by)
}
Expand Down Expand Up @@ -353,7 +354,8 @@ MELT_VALUES <- "Value"
tmp
}

.get_features_data <- function(col.var, order.col.by, x){
.get_features_data <- function(col.var = features, features,
order.col.by = order_sample_by, order_sample_by, x){
col.var <- unique(c(order.col.by,col.var))
features_data <- lapply(col.var,
.get_feature_data,
Expand All @@ -377,7 +379,7 @@ MELT_VALUES <- "Value"

#' @importFrom dplyr pull
.order_abund_feature_data <- function(abund_data, features_data,
order.col.by, decreasing = TRUE){
order.col.by = order_sample_by, order_sample_by, decreasing = TRUE){
if(!is.null(order.col.by)){
lvl <- levels(abund_data$X)
if(is.null(features_data) ||
Expand Down Expand Up @@ -533,13 +535,18 @@ MELT_VALUES <- "Value"
}

.features_plotter <- function(features_data,
order.col.by = NULL,
order.col.by = order_sample_by,
order_sample_by = NULL,
xlab = NULL,
flipped = FALSE,
add.legend = TRUE,
add.x.text = FALSE,
point.alpha = 1,
add.legend = add_legend,
add_legend = TRUE,
add.x.text = add_x_text,
add_x_text = FALSE,
point.alpha = point_alpha,
point_alpha = point.size,
point.size = 2,

...){
names <- colnames(features_data)
features_data <- lapply(names,
Expand Down
30 changes: 20 additions & 10 deletions R/plotAbundanceDensity.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,14 @@ setMethod("plotAbundanceDensity", signature = c(x = "SummarizedExperiment"),
################################ HELP FUNCTIONS ################################

.incorporate_density_data <- function(x, assay.type, n,
colour.by,
shape.by,
size.by,
order.descending = TRUE){
colour.by = colour_by,
colour_by,
shape.by = shape_by,
shape_by,
size.by = size_by,
size_by,
order.descending = order_descending,
order_descending = TRUE){
# Gets the assay
mat <- assay(x, assay.type, withDimnames = TRUE)
# Gets the most abundant taxa
Expand Down Expand Up @@ -279,15 +283,21 @@ setMethod("plotAbundanceDensity", signature = c(x = "SummarizedExperiment"),

.density_plotter <- function(density_data,
layout,
add.legend = TRUE,
add.legend = add_legend,
add_legend = TRUE,
xlab,
ylab = NULL,
colour.by = NULL,
shape.by = NULL,
size.by = NULL,
colour.by = colour_by,
colour_by = NULL,
shape.by = shape_by,
shape_by = NULL,
size.by = size_by,
size_by = NULL,
point_shape = 21,
point.size = 2,
point.alpha = 0.6,
point.size = point_size,
point_size = 2,
point.alpha = point_alpha,
point_alpha = 0.6,
point_colour = "grey70",
flipped = FALSE,
scales_free = TRUE,
Expand Down
2 changes: 1 addition & 1 deletion R/plotCCA.R
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ setMethod("plotRDA", signature = c(x = "matrix"),
#' @importFrom scater plotReducedDim retrieveCellInfo
#' @importFrom SingleCellExperiment reducedDim reducedDimNames
.incorporate_rda_vis <- function(
tse, dimred, ncomponents = 2, colour.by = color_by, color_by = NULL,
tse, dimred, ncomponents = 2, colour.by = colour_by, colour_by = color_by, color_by = NULL,
add.significance = TRUE, add.expl.var = TRUE, add.ellipse = TRUE,
add.vectors = TRUE, vec.lab = NULL, expl_var = NULL,
sep.group = "\U2012", repl.underscore = " ", ...){
Expand Down
3 changes: 2 additions & 1 deletion R/plotColTile.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ setMethod("plotRowTile", signature = c("SummarizedExperiment"),
}

.tile_plotter <- function(data,
add.legend = TRUE,
add.legend = add_legend,
add_legend = TRUE,
xlab,
ylab,
rect_alpha = 1,
Expand Down
87 changes: 60 additions & 27 deletions R/plotGraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ setGeneric("plotColGraph", signature = c("x","y"),
setGeneric("plotRowGraph", signature = c("x","y"),
function(x, y, ...) standardGeneric("plotRowGraph"))

.check_graph_plot_switches <- function(show.label, add_legend){
.check_graph_plot_switches <- function(show.label = show_label, show_label,
add.legend = add_legend, add_legend){
if(!.is_a_bool(show.label)){
if( (!is.logical(show.label) && !is.character(show.label) &&
!is.numeric(show.label)) ||
Expand All @@ -201,7 +202,7 @@ setGeneric("plotRowGraph", signature = c("x","y"),
}
}

.norm_layout_edge_type <- function(layout, edge.type){
.norm_layout_edge_type <- function(layout, edge.type = edge_type, edge_type){
edge.type <- match.arg(edge.type[1L], c("fan","link","arc","parallel"))
return(list(layout = layout,
edge.type = edge.type))
Expand All @@ -227,7 +228,8 @@ setMethod("plotColGraph",
shape_by = NULL,
size.by = size_by,
size_by = NULL,
assay.type = "counts",
assay.type = by_exprs_values,
by_exprs_values = "counts",
other.fields = other_fields,
other_fields = list(),
...){
Expand Down Expand Up @@ -281,7 +283,8 @@ setMethod("plotRowGraph",
shape.by = shape_by,
shape_by = NULL,
size.by = NULL,
assay.type = "counts",
assay.type = by_exprs_values,
by_exprs_values = "counts",
other.fields = other_fields,
other_fields = list(),
...){
Expand Down Expand Up @@ -317,16 +320,25 @@ setMethod("plotRowGraph",
)

.plot_row_column_graph <- function(x, y,
show.label = FALSE,
show.label = show_label,
show_label = FALSE,
add.legend = add_legend,
add_legend = TRUE,
layout = "kk",
edge.type = c("fan","link","arc","parallel"),
edge.colour.by = NULL,
edge.width.by = NULL,
edge.type = edge_type,
edge_type = c("fan","link","arc","parallel"),
edge.colour.by = edge_colour_by,
edge_colour_by = NULL,
edge.width.by = edge_width_by,
edge_width_by = NULL,
colour.by = colour_by,
colour_by = NULL,
shape.by = NULL,
size.by = NULL,
assay.type = "counts",
shape.by = shape_by,
shape_by = NULL,
size.by = size_by,
size_by = NULL,
assay.type = by_exprs_values,
by_exprs_values = "counts",
other.fields = other_fields,
other_fields = list(),
type = c("row","column"),
Expand Down Expand Up @@ -382,7 +394,7 @@ setMethod("plotRowGraph",

#' @importFrom tidygraph activate
#' @importFrom dplyr mutate
.add_graph_node_labels <- function(graph_data, show.label){
.add_graph_node_labels <- function(graph_data, show.label = show_label, show_label){
if(!("label" %in% .colnames_tbl_graph(graph_data, "nodes")) &&
("name" %in% .colnames_tbl_graph(graph_data, "nodes"))){
graph_data <- graph_data %>%
Expand Down Expand Up @@ -470,13 +482,20 @@ setMethod("plotRowGraph",
#' @importFrom tidygraph activate as_tibble
.incorporate_graph_vis <- function(graph_data,
se,
edge.colour.by,
edge.width.by,
edge.colour.by = edge_colour_by,
edge_colour_by,
edge.width.by = edge_width_by,
edge_width_by,
colour.by = colour_by,
colour_by,
shape.by,
size.by,
assay.type = "counts",
other.fields = list(),
shape.by = shape_by,
shape_by,
size.by = size_by,
size_by,
assay.type = by_exprs_values,
by_exprs_values = "counts",
other.fields = other_fields,
other_fields = list(),
type = c("row","column")){
type <- match.arg(type)
type_FUN <- switch(type,
Expand Down Expand Up @@ -576,20 +595,34 @@ setMethod("plotRowGraph",

.graph_plotter <- function(object,
layout = "kk",
edge.type = "fan",
edge.type = edge_type,
edge_type = "fan",
algorithm = NULL,
add.legend = add_legend,
add_legend = TRUE,
show.label = FALSE,
edge.colour.by = NULL,
edge.width.by = NULL,
show.label = show_label,
show_label = FALSE,
edge.colour.by = edge_colour_by,
edge_colour_by = NULL,
edge.width.by = edge_width_by,
edge_width_by = NULL,
colour.by = colour_by,
colour_by = NULL,
shape.by = NULL,
size.by = NULL,
shape.by = shape_by,
shape_by = NULL,
size.by = size_by,
size_by = NULL,
line.alpha = line_alpha,
line_alpha = 1,
line.width = line_width,
line_width = NULL,
line.width.range = line_width_range,
line_width_range = c(0.5,3),
point.alpha = 1,
point.size = 2,
point.alpha = point_alpha,
point_alpha = 1,
point.size = point_size,
point_size = 2,
point.size.range = point_size_range,
point_size_range = c(1,4)){
# assemble arg list
point_out <- .get_point_args(colour_by,
Expand Down Expand Up @@ -669,7 +702,7 @@ setMethod("plotRowGraph",
}

#' @importFrom tidyr drop_na
.add_graph_labels <- function(plot_out, show.label){
.add_graph_labels <- function(plot_out, show.label = show_label, show_label){
label <- NULL # disable note: no global binding for variable
if(show.label){
label_data <- plot_out$data %>% drop_na(label)
Expand Down
27 changes: 14 additions & 13 deletions R/plotPrevalence.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ setMethod("plotPrevalence", signature = c(x = "SummarizedExperiment"),
#' @importFrom BiocParallel bpmapply bpisup bpstart bpstop SerialParam
#' @importFrom SummarizedExperiment assay
.get_prevalence_plot_data <- function(x, assay.type, detections, prevalences,
as.relative = TRUE,
BPPARAM = BiocParallel::SerialParam()){
as.relative = as_relative, as_relative = TRUE,
BPPARAM = BiocParallel::SerialParam()){
mat <- assay(x, assay.type, withDimnames = TRUE)
if(as.relative){
mat <- mia:::.calc_rel_abund(mat)
Expand Down Expand Up @@ -233,8 +233,8 @@ setMethod("plotPrevalentAbundance", signature = c(x = "SummarizedExperiment"),
function(x,
rank = taxonomyRanks(x)[1L],
assay.type = assay_name, assay_name = "counts",
as.relative = TRUE,
colour.by = NULL,
as.relative = as_relative, as_relative = TRUE,
colour.by = colour_by, colour_by = NULL,
size.by = size_by,
size_by = NULL,
shape.by = shape_by,
Expand Down Expand Up @@ -298,8 +298,8 @@ setMethod("plotPrevalentAbundance", signature = c(x = "SummarizedExperiment"),

#' @importFrom DelayedArray rowMeans
#' @importFrom SummarizedExperiment assay
.get_prevalence_plot_point_data <- function(x, assay.type, as.relative = TRUE,
label = NULL){
.get_prevalence_plot_point_data <- function(x, assay.type, as.relative = as_relative,
as_relative = TRUE, label = NULL){
mat <- assay(x, assay.type, withDimnames = TRUE)
if(as.relative){
mat <- mia:::.calc_rel_abund(mat)
Expand All @@ -314,13 +314,14 @@ setMethod("plotPrevalentAbundance", signature = c(x = "SummarizedExperiment"),
}

#' @importFrom scater retrieveFeatureInfo
.incorporate_prevalence_vis <- function(plot_data,
.incorporate_prevalence_vis <- function(plot.data = plot_data,
plot_data,
se = se,
colour.by = NULL,
size.by = NULL,
shape.by = NULL,
colour.by = colour_by, colour_by = NULL,
size.by = size_by, size_by = NULL,
shape.by = shape_by, shape_by = NULL,
label = NULL,
facet.by = NULL){
facet.by = facet_by, facet_by = NULL){
variables <- c(colour.by = colour.by,
size.by = size.by,
shape.by = shape.by,
Expand Down Expand Up @@ -434,8 +435,8 @@ setMethod("plotFeaturePrevalence", signature = c(x = "SummarizedExperiment"),
#' @importFrom tidyr pivot_longer
#' @importFrom DelayedArray rowSums
.get_prevalence_plot_matrix <- function(x, assay.type, detections,
as.relative = TRUE,
min.prevalence,
as.relative = as_relative, as_relative = TRUE,
min.prevalence = min_prevalence, min_prevalence,
BPPARAM = BiocParallel::SerialParam()){
mat <- assay(x, assay.type, withDimnames = TRUE)
if(as.relative){
Expand Down
21 changes: 16 additions & 5 deletions R/plotSeries.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ setMethod("plotSeries", signature = c(object = "SummarizedExperiment"),
return(assay)
}

.incorporate_series_vis <- function(object, x, colour.by, linetype_by, size.by){
.incorporate_series_vis <- function(object, x, colour.by = colour_by, colour_by,
linetype_by, size.by = size_by, size_by){

# This variable is set by defaults
series_data <- retrieveCellInfo(object, x, search = "colData")
Expand Down Expand Up @@ -296,14 +297,23 @@ setMethod("plotSeries", signature = c(object = "SummarizedExperiment"),
.series_plotter <- function(plot_data,
xlab = NULL,
ylab = NULL,
colour.by = NULL,
colour.by = colour_by,
colour_by = NULL,
linetype.by = linetype_by,
linetype_by = NULL,
size.by = NULL,
add.legend = TRUE,
size.by = size_by,
size_by = NULL,
add.legend = add_legend,
add_legend = TRUE,
line.alpha = line_alpha,
line_alpha = 1,
line.type = line_type,
line_type = NULL,
line.width = line_width,
line_width = 1,
line.width.range = line_width_range,
line_width_range = c(0.5,3),
ribbon.alpha = ribbon_alpha,
ribbon_alpha = 0.3){
# fall back for feature grouping
if(is.null(colour.by)){
Expand Down Expand Up @@ -361,7 +371,8 @@ setMethod("plotSeries", signature = c(object = "SummarizedExperiment"),
plot_out
}

.add_extra_line_guide <- function(plot_out, linetype_by, size.by) {
.add_extra_line_guide <- function(plot.out = plot_out, plot_out,
linetype.by = linetype_by, linetype_by, size.by = size_by, size_by) {
guide_args <- list()
if (!is.null(linetype_by)) {
guide_args$linetype <- guide_legend(title = linetype_by)
Expand Down
Loading

0 comments on commit 7ffb083

Please sign in to comment.