From 9ea00f6fb2fc24e06717770a512a619a6bf8a584 Mon Sep 17 00:00:00 2001 From: Nick-Eagles Date: Thu, 2 Nov 2023 17:17:59 -0400 Subject: [PATCH] Style code --- R/multi_gene.R | 20 ++++++++++---------- R/spot_plot.R | 9 +++++---- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/R/multi_gene.R b/R/multi_gene.R index 7afbf32..1cbb6b0 100644 --- a/R/multi_gene.R +++ b/R/multi_gene.R @@ -46,7 +46,7 @@ #' ) spot_plot_z_score <- function(spe, genes, sample_id, assayname = "logcounts", minCount = 0, ...) { # Check validity of arguments - spe = .multi_gene_validity_check( + spe <- .multi_gene_validity_check( spe, genes, sample_id, assayname, minCount, ... ) @@ -102,7 +102,7 @@ spot_plot_z_score <- function(spe, genes, sample_id, assayname = "logcounts", mi #' ) spot_plot_sparsity <- function(spe, genes, sample_id, assayname = "counts", minCount = 0.1, ...) { # Check validity of arguments - spe = .multi_gene_validity_check( + spe <- .multi_gene_validity_check( spe, genes, sample_id, assayname, minCount, ... ) @@ -160,12 +160,12 @@ spot_plot_sparsity <- function(spe, genes, sample_id, assayname = "counts", minC #' ) spot_plot_pca <- function(spe, genes, sample_id, assayname = "logcounts", minCount = 0, ...) { # Check validity of arguments - spe = .multi_gene_validity_check( + spe <- .multi_gene_validity_check( spe, genes, sample_id, assayname, minCount, ... ) - pc_exp = prcomp(t(assays(spe)[[assayname]]), center = TRUE, scale = TRUE) - spe$pc_select_genes <- pc_exp$x[,'PC1'] + pc_exp <- prcomp(t(assays(spe)[[assayname]]), center = TRUE, scale = TRUE) + spe$pc_select_genes <- pc_exp$x[, "PC1"] # Given that: # - 'genes' is assumed to represent markers of the subregion (and @@ -176,8 +176,8 @@ spot_plot_pca <- function(spe, genes, sample_id, assayname = "logcounts", minCou # plots to have positive values where expression is greater. If most # genes have negative coefficients to the first PC, we reverse the # sign of the coefficients to make visual intrepretation consistent - if (mean(pc_exp$rotation[,1] > 0) < 0.5) { - spe$pc_select_genes = -1 * spe$pc_select_genes + if (mean(pc_exp$rotation[, 1] > 0) < 0.5) { + spe$pc_select_genes <- -1 * spe$pc_select_genes } # Plot spatial distribution of this proportion @@ -192,7 +192,7 @@ spot_plot_pca <- function(spe, genes, sample_id, assayname = "logcounts", minCou #' Check the validity of arguments passed to \code{multi_gene.R} plotting #' functions -#' +#' #' Also subset \code{spe} to the selected sample and genes, dropping genes with #' constant expression across spots #' @@ -228,9 +228,9 @@ spot_plot_pca <- function(spe, genes, sample_id, assayname = "logcounts", minCou # Each multi-gene plotting function expects at least 2 genes with # non-constant expression across spots. Warn if some are dropped, but halt # if less than 2 remain after dropping - spe = spe[genes, spe$sample_id == sample_id] + spe <- spe[genes, spe$sample_id == sample_id] - good_indices = which(rowSds(assays(spe)[[assayname]]) != 0) + good_indices <- which(rowSds(assays(spe)[[assayname]]) != 0) if (length(good_indices) < 2) { stop("After dropping genes with no expression variation, less than 2 genes were left") } diff --git a/R/spot_plot.R b/R/spot_plot.R index 9c118d0..00d8158 100644 --- a/R/spot_plot.R +++ b/R/spot_plot.R @@ -60,10 +60,11 @@ #' assayname = "logcounts" #' ) #' print(p) -spot_plot <- function(spe, sample_id, image_id = "lowres", - title = sprintf("%s_%s", sample_id, var_name), var_name, - include_legend = TRUE, is_discrete, colors = NULL, - assayname = "logcounts", minCount = 0.5, spatial = FALSE) { +spot_plot <- function( + spe, sample_id, image_id = "lowres", + title = sprintf("%s_%s", sample_id, var_name), var_name, + include_legend = TRUE, is_discrete, colors = NULL, + assayname = "logcounts", minCount = 0.5, spatial = FALSE) { # This value was determined empirically, and results in good spot sizes. # Note that it's sample-independent, and the final spot size to pass to # 'vis_gene' or 'vis_clus' uses this value along with the image