From 25dc155d0551a0a823a9ef939c86595e86fc92c1 Mon Sep 17 00:00:00 2001 From: Nick-Eagles Date: Tue, 7 Nov 2023 14:05:47 -0500 Subject: [PATCH] Clean up imports by importing individual functions where possible --- NAMESPACE | 7 ++++--- R/multi_gene.R | 15 ++++++++++----- R/spe_seurat.R | 9 +++++---- R/spot_plot.R | 4 +++- man/spe_to_seurat.Rd | 4 ++-- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 16c03b0..c1c02ae 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,9 +7,10 @@ export(spot_plot_sparsity) export(spot_plot_z_score) import(Matrix) import(MatrixGenerics) -import(SummarizedExperiment) -import(SpatialExperiment) import(Seurat) +import(SpatialExperiment) import(ggplot2) import(spatialLIBD) -import(viridisLite) +importFrom(SummarizedExperiment,colData) +importFrom(stats,prcomp) +importFrom(viridisLite,plasma) diff --git a/R/multi_gene.R b/R/multi_gene.R index 2d51676..6909d6b 100644 --- a/R/multi_gene.R +++ b/R/multi_gene.R @@ -23,7 +23,8 @@ #' #' @export #' @author Nicholas J. Eagles -#' @import SpatialExperiment SummarizedExperiment Matrix MatrixGenerics +#' @import SpatialExperiment Matrix MatrixGenerics +#' @importFrom SummarizedExperiment colData #' @family Spot plots summarizing expression of multiple genes simultaneously #' #' @examples @@ -80,7 +81,8 @@ spot_plot_z_score <- function(spe, genes, sample_id, assayname = "logcounts", mi #' #' @export #' @author Nicholas J. Eagles -#' @import SpatialExperiment SummarizedExperiment Matrix MatrixGenerics +#' @import SpatialExperiment Matrix MatrixGenerics +#' @importFrom SummarizedExperiment colData #' @family Spot plots summarizing expression of multiple genes simultaneously #' #' @examples @@ -138,7 +140,9 @@ spot_plot_sparsity <- function(spe, genes, sample_id, assayname = "counts", minC #' #' @export #' @author Nicholas J. Eagles -#' @import SpatialExperiment SummarizedExperiment +#' @import SpatialExperiment +#' @importFrom SummarizedExperiment colData +#' @importFrom stats prcomp #' @family Spot plots summarizing expression of multiple genes simultaneously #' #' @examples @@ -164,7 +168,7 @@ spot_plot_pca <- function(spe, genes, sample_id, assayname = "logcounts", minCou spe, genes, sample_id, assayname, minCount, ... ) - pc_exp <- prcomp(t(assays(spe)[[assayname]]), center = TRUE, scale = TRUE) + pc_exp <- stats::prcomp(t(assays(spe)[[assayname]]), center = TRUE, scale = TRUE) spe$pc_select_genes <- pc_exp$x[, "PC1"] # Given that: @@ -198,7 +202,8 @@ spot_plot_pca <- function(spe, genes, sample_id, assayname = "logcounts", minCou #' #' @author Nicholas J. Eagles #' @inheritParams spot_plot_z_score -#' @import SpatialExperiment SummarizedExperiment +#' @import SpatialExperiment +#' @importFrom SummarizedExperiment colData #' @return \code{SpatialExperiment} subsetted to the specified sample and to #' each of the non-constant-expression genes .multi_gene_validity_check <- function(spe, genes, sample_id, assayname, minCount, ...) { diff --git a/R/spe_seurat.R b/R/spe_seurat.R index 43289b2..f15932d 100644 --- a/R/spe_seurat.R +++ b/R/spe_seurat.R @@ -15,7 +15,8 @@ #' #' @export #' @author Nicholas J. Eagles -#' @import SummarizedExperiment SpatialExperiment spatialLIBD Seurat +#' @import SpatialExperiment spatialLIBD Seurat +#' @importFrom SummarizedExperiment colData #' #' @examples #' @@ -24,8 +25,8 @@ #' spe <- spatialLIBD::fetch_data(type = "spatialDLPFC_Visium_example_subset") #' spe$array_row_transformed = spe$array_row #' spe$array_col_transformed = spe$array_col -#' spe$pxl_row_in_fullres_transformed = spatialCoords(spe)[,'pxl_row_in_fullres'] -#' spe$pxl_col_in_fullres_transformed = spatialCoords(spe)[,'pxl_col_in_fullres'] +#' spe$pxl_row_in_fullres_transformed = SpatialExperiment::spatialCoords(spe)[,'pxl_row_in_fullres'] +#' spe$pxl_col_in_fullres_transformed = SpatialExperiment::spatialCoords(spe)[,'pxl_col_in_fullres'] #' colnames(spe) = spe$key #' #' # Convert @@ -59,7 +60,7 @@ spe_to_seurat = function(spe, verbose = TRUE) { } if (verbose) message("Running 'as.Seurat(spe)'...") - seur = as.Seurat(spe) + seur = Seurat::as.Seurat(spe) for (sample_id in unique(spe$sample_id)) { if (verbose) { diff --git a/R/spot_plot.R b/R/spot_plot.R index 00d8158..13d204d 100644 --- a/R/spot_plot.R +++ b/R/spot_plot.R @@ -40,7 +40,9 @@ #' #' @export #' @author Nicholas J. Eagles -#' @import viridisLite spatialLIBD ggplot2 SpatialExperiment SummarizedExperiment +#' @import spatialLIBD ggplot2 SpatialExperiment +#' @importFrom viridisLite plasma +#' @importFrom SummarizedExperiment colData #' #' @examples #' diff --git a/man/spe_to_seurat.Rd b/man/spe_to_seurat.Rd index b93bf89..2e86dfd 100644 --- a/man/spe_to_seurat.Rd +++ b/man/spe_to_seurat.Rd @@ -30,8 +30,8 @@ appearance of images are buggy for now. spe <- spatialLIBD::fetch_data(type = "spatialDLPFC_Visium_example_subset") spe$array_row_transformed = spe$array_row spe$array_col_transformed = spe$array_col -spe$pxl_row_in_fullres_transformed = spatialCoords(spe)[,'pxl_row_in_fullres'] -spe$pxl_col_in_fullres_transformed = spatialCoords(spe)[,'pxl_col_in_fullres'] +spe$pxl_row_in_fullres_transformed = SpatialExperiment::spatialCoords(spe)[,'pxl_row_in_fullres'] +spe$pxl_col_in_fullres_transformed = SpatialExperiment::spatialCoords(spe)[,'pxl_col_in_fullres'] colnames(spe) = spe$key # Convert