Skip to content

Commit

Permalink
Auto-style + re-render docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lcolladotor committed Jul 2, 2024
1 parent 8c25a4c commit d6b6809
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 109 deletions.
47 changes: 24 additions & 23 deletions R/fetch_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,30 @@
#' #> 172.28 MB
#' }
fetch_data <-
function(type = c(
"sce",
"sce_layer",
"modeling_results",
"sce_example",
"spe",
"spatialDLPFC_Visium",
"spatialDLPFC_Visium_example_subset",
"spatialDLPFC_Visium_pseudobulk",
"spatialDLPFC_Visium_modeling_results",
"spatialDLPFC_Visium_SPG",
"spatialDLPFC_snRNAseq",
"Visium_SPG_AD_Visium_wholegenome_spe",
"Visium_SPG_AD_Visium_targeted_spe",
"Visium_SPG_AD_Visium_wholegenome_pseudobulk_spe",
"Visium_SPG_AD_Visium_wholegenome_modeling_results",
"Visium_LS_spe",
"Visium_LS_spaceranger",
"Visium_LS_ImageJ_out"
),
destdir = tempdir(),
eh = ExperimentHub::ExperimentHub(),
bfc = BiocFileCache::BiocFileCache()) {
function(
type = c(
"sce",
"sce_layer",
"modeling_results",
"sce_example",
"spe",
"spatialDLPFC_Visium",
"spatialDLPFC_Visium_example_subset",
"spatialDLPFC_Visium_pseudobulk",
"spatialDLPFC_Visium_modeling_results",
"spatialDLPFC_Visium_SPG",
"spatialDLPFC_snRNAseq",
"Visium_SPG_AD_Visium_wholegenome_spe",
"Visium_SPG_AD_Visium_targeted_spe",
"Visium_SPG_AD_Visium_wholegenome_pseudobulk_spe",
"Visium_SPG_AD_Visium_wholegenome_modeling_results",
"Visium_LS_spe",
"Visium_LS_spaceranger",
"Visium_LS_ImageJ_out"
),
destdir = tempdir(),
eh = ExperimentHub::ExperimentHub(),
bfc = BiocFileCache::BiocFileCache()) {
## Some variables
sce <-
sce_layer <- modeling_results <- sce_sub <- spe <- NULL
Expand Down
102 changes: 52 additions & 50 deletions R/run_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@
#' spe_stitched$ManualAnnotation <- "NA"
#'
#' ## Run the app with this stitched data
#' run_app(spe = spe_stitched,
#' run_app(
#' spe = spe_stitched,
#' sce_layer = NULL, modeling_results = NULL, sig_genes = NULL,
#' title = "visiumStitched example data",
#' spe_discrete_vars = c("capture_area", "scran_quick_cluster", "ManualAnnotation"),
Expand All @@ -224,55 +225,56 @@
#' is_stitched = TRUE
#' )
#' }
run_app <- function(spe = fetch_data(type = "spe"),
sce_layer = fetch_data(type = "sce_layer"),
modeling_results = fetch_data(type = "modeling_results"),
sig_genes = sig_genes_extract_all(
n = nrow(sce_layer),
modeling_results = modeling_results,
sce_layer = sce_layer
),
docs_path = system.file("app", "www", package = "spatialLIBD"),
title = "spatialLIBD",
spe_discrete_vars = c(
"spatialLIBD",
"GraphBased",
"ManualAnnotation",
"Maynard",
"Martinowich",
paste0("SNN_k50_k", 4:28),
"SpatialDE_PCA",
"SpatialDE_pool_PCA",
"HVG_PCA",
"pseudobulk_PCA",
"markers_PCA",
"SpatialDE_UMAP",
"SpatialDE_pool_UMAP",
"HVG_UMAP",
"pseudobulk_UMAP",
"markers_UMAP",
"SpatialDE_PCA_spatial",
"SpatialDE_pool_PCA_spatial",
"HVG_PCA_spatial",
"pseudobulk_PCA_spatial",
"markers_PCA_spatial",
"SpatialDE_UMAP_spatial",
"SpatialDE_pool_UMAP_spatial",
"HVG_UMAP_spatial",
"pseudobulk_UMAP_spatial",
"markers_UMAP_spatial"
),
spe_continuous_vars = c(
"cell_count",
"sum_umi",
"sum_gene",
"expr_chrM",
"expr_chrM_ratio"
),
default_cluster = "spatialLIBD",
auto_crop_default = TRUE,
is_stitched = FALSE,
...) {
run_app <- function(
spe = fetch_data(type = "spe"),
sce_layer = fetch_data(type = "sce_layer"),
modeling_results = fetch_data(type = "modeling_results"),
sig_genes = sig_genes_extract_all(
n = nrow(sce_layer),
modeling_results = modeling_results,
sce_layer = sce_layer
),
docs_path = system.file("app", "www", package = "spatialLIBD"),
title = "spatialLIBD",
spe_discrete_vars = c(
"spatialLIBD",
"GraphBased",
"ManualAnnotation",
"Maynard",
"Martinowich",
paste0("SNN_k50_k", 4:28),
"SpatialDE_PCA",
"SpatialDE_pool_PCA",
"HVG_PCA",
"pseudobulk_PCA",
"markers_PCA",
"SpatialDE_UMAP",
"SpatialDE_pool_UMAP",
"HVG_UMAP",
"pseudobulk_UMAP",
"markers_UMAP",
"SpatialDE_PCA_spatial",
"SpatialDE_pool_PCA_spatial",
"HVG_PCA_spatial",
"pseudobulk_PCA_spatial",
"markers_PCA_spatial",
"SpatialDE_UMAP_spatial",
"SpatialDE_pool_UMAP_spatial",
"HVG_UMAP_spatial",
"pseudobulk_UMAP_spatial",
"markers_UMAP_spatial"
),
spe_continuous_vars = c(
"cell_count",
"sum_umi",
"sum_gene",
"expr_chrM",
"expr_chrM_ratio"
),
default_cluster = "spatialLIBD",
auto_crop_default = TRUE,
is_stitched = FALSE,
...) {
## Run the checks in the relevant order
stopifnot(length(default_cluster) == 1)
stopifnot(default_cluster %in% spe_discrete_vars)
Expand Down
35 changes: 18 additions & 17 deletions R/vis_grid_clus.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,24 @@
#' cowplot::plot_grid(plotlist = p_list, ncol = 2)
#' }
vis_grid_clus <-
function(spe,
clustervar,
pdf_file,
sort_clust = TRUE,
colors = NULL,
return_plots = FALSE,
spatial = TRUE,
height = 24,
width = 36,
image_id = "lowres",
alpha = NA,
sample_order = unique(spe$sample_id),
point_size = 2,
auto_crop = TRUE,
na_color = "#CCCCCC40",
is_stitched = FALSE,
...) {
function(
spe,
clustervar,
pdf_file,
sort_clust = TRUE,
colors = NULL,
return_plots = FALSE,
spatial = TRUE,
height = 24,
width = 36,
image_id = "lowres",
alpha = NA,
sample_order = unique(spe$sample_id),
point_size = 2,
auto_crop = TRUE,
na_color = "#CCCCCC40",
is_stitched = FALSE,
...) {
stopifnot(all(sample_order %in% unique(spe$sample_id)))

if (sort_clust) {
Expand Down
39 changes: 20 additions & 19 deletions R/vis_grid_gene.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,26 @@
#' cowplot::plot_grid(plotlist = p_list, ncol = 2)
#' }
vis_grid_gene <-
function(spe,
geneid = rowData(spe)$gene_search[1],
pdf_file,
assayname = "logcounts",
minCount = 0,
return_plots = FALSE,
spatial = TRUE,
viridis = TRUE,
height = 24,
width = 36,
image_id = "lowres",
alpha = NA,
cont_colors = if (viridis) viridisLite::viridis(21) else c("aquamarine4", "springgreen", "goldenrod", "red"),
sample_order = unique(spe$sample_id),
point_size = 2,
auto_crop = TRUE,
na_color = "#CCCCCC40",
is_stitched = FALSE,
...) {
function(
spe,
geneid = rowData(spe)$gene_search[1],
pdf_file,
assayname = "logcounts",
minCount = 0,
return_plots = FALSE,
spatial = TRUE,
viridis = TRUE,
height = 24,
width = 36,
image_id = "lowres",
alpha = NA,
cont_colors = if (viridis) viridisLite::viridis(21) else c("aquamarine4", "springgreen", "goldenrod", "red"),
sample_order = unique(spe$sample_id),
point_size = 2,
auto_crop = TRUE,
na_color = "#CCCCCC40",
is_stitched = FALSE,
...) {
stopifnot(all(sample_order %in% unique(spe$sample_id)))

plots <- lapply(sample_order, function(sampleid) {
Expand Down
46 changes: 46 additions & 0 deletions man/run_app.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions man/vis_grid_clus.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions man/vis_grid_gene.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d6b6809

Please sign in to comment.