Skip to content

Commit

Permalink
Fix a test; import Matrix to allow computing rowMeans and similar on …
Browse files Browse the repository at this point in the history
…sparse assays; fix checking of '...' arguments
  • Loading branch information
Nick-Eagles committed Nov 2, 2023
1 parent 6a17ea9 commit a4133b9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Imports:
ggplot2,
SpatialExperiment,
SummarizedExperiment,
rlang
Matrix
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
export(spot_plot)
export(spot_plot_sparsity)
export(spot_plot_z_score)
import(Matrix)
import(SpatialExperiment)
import(SummarizedExperiment)
import(ggplot2)
import(rlang)
import(spatialLIBD)
import(viridisLite)
16 changes: 8 additions & 8 deletions R/multi_gene.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#'
#' @export
#' @author Nicholas J. Eagles
#' @import SpatialExperiment SummarizedExperiment
#' @import SpatialExperiment SummarizedExperiment Matrix
#' @family Spot plots summarizing expression of multiple genes simultaneously
#'
#' @examples
Expand Down Expand Up @@ -55,14 +55,14 @@ spot_plot_z_score = function(
spe = spe[genes, spe$sample_id == sample_id]

# For each spot, average expression Z-scores across all selected genes
gene_z = (assays(spe)[[assayname]] - rowMeans(assays(spe)[[assayname]])) /
(rowSdDiffs(assays(spe)[[assayname]]))
a = assays(spe)[[assayname]]
gene_z = (a - rowMeans(a)) / rowSds(a)
spe$temp_var = colMeans(gene_z, na.rm = TRUE)

# Plot spatial distribution of averaged expression Z-scores for this
# sample
p = spot_plot(
spe, sample_id, var_name = 'temp_var', is_discrete = FALSE,
spe, sample_id, var_name = 'Z_score', is_discrete = FALSE,
minCount = minCount, assayname = assayname, ...
)

Expand All @@ -83,7 +83,7 @@ spot_plot_z_score = function(
#'
#' @export
#' @author Nicholas J. Eagles
#' @import SpatialExperiment SummarizedExperiment
#' @import SpatialExperiment SummarizedExperiment Matrix
#' @family Spot plots summarizing expression of multiple genes simultaneously
#'
#' @examples
Expand Down Expand Up @@ -130,7 +130,7 @@ spot_plot_sparsity = function(
#'
#' @author Nicholas J. Eagles
#' @inheritParams spot_plot_z_score
#' @import SpatialExperiment SummarizedExperiment rlang
#' @import SpatialExperiment SummarizedExperiment
#' @return NULL
.multi_gene_validity_check = function(
spe, genes, sample_id, assayname, minCount, ...
Expand All @@ -147,11 +147,11 @@ spot_plot_sparsity = function(

# 'assayname'
if (!(assayname %in% names(assays(spe)))) {
stop(sprintf("'%s' is not an assay in 'spe'"))
stop(sprintf("'%s' is not an assay in 'spe'", assayname))
}

# Not-allowed '...' parameters
if (!is.missing(var_name) || !is.missing(is_discrete)) {
if (any(c('var_name', 'is_discrete') %in% names(list(...)))) {
stop("The 'var_name' and 'is_discrete' parameters are internally handled and may not be specified through '...' arguments")
}
}
1 change: 1 addition & 0 deletions tests/testthat/test-multi_gene.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ test_plot_fun = function(spe, plot_fun) {
}

spe <- fetch_data(type = "spatialDLPFC_Visium_example_subset")
spe$exclude_overlapping <- FALSE

test_that("spot_plot_z_score", { test_plot_fun(spe, spot_plot_z_score) })
test_that("spot_plot_sparsity", { test_plot_fun(spe, spot_plot_sparsity) })

0 comments on commit a4133b9

Please sign in to comment.