Skip to content

Commit

Permalink
Auto-style code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-Eagles committed Apr 9, 2024
1 parent 8e24b3c commit 9e4c25a
Show file tree
Hide file tree
Showing 35 changed files with 424 additions and 404 deletions.
5 changes: 3 additions & 2 deletions R/add10xVisiumAnalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
#'
#' ## Note that ?SpatialExperiment::read10xVisium doesn't include all the files
#' ## we need to illustrate read10xVisiumWrapper().
add10xVisiumAnalysis <- function(spe,
visium_analysis) {
add10xVisiumAnalysis <- function(
spe,
visium_analysis) {
col_info <- colData(spe)
barcode_present <- "barcode" %in% colnames(col_info)
if (!barcode_present) {
Expand Down
13 changes: 7 additions & 6 deletions R/add_images.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@
#' ))
#' }
add_images <-
function(spe,
image_dir,
image_pattern,
image_id_current = "lowres",
image_id = image_pattern,
image_paths = locate_images(spe, image_dir, image_pattern)) {
function(
spe,
image_dir,
image_pattern,
image_id_current = "lowres",
image_id = image_pattern,
image_paths = locate_images(spe, image_dir, image_pattern)) {
stopifnot(length(names(image_paths)) > 0)
stopifnot(all(names(image_paths) %in% unique(spe$sample_id)))
stopifnot(!any(duplicated(names(image_paths))))
Expand Down
16 changes: 9 additions & 7 deletions R/annotate_registered_clusters.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@
#' ## More relaxed merging threshold
#' annotate_registered_clusters(cor_stats_layer, cutoff_merge_ratio = 1)
annotate_registered_clusters <-
function(cor_stats_layer,
confidence_threshold = 0.25,
cutoff_merge_ratio = 0.25) {
function(
cor_stats_layer,
confidence_threshold = 0.25,
cutoff_merge_ratio = 0.25) {
annotated <-
apply(cor_stats_layer,
1,
Expand Down Expand Up @@ -86,10 +87,11 @@ annotate_registered_clusters <-
}

annotate_registered_cluster <-
function(remaining,
label = "",
current = NULL,
cutoff_merge_ratio = 0.25) {
function(
remaining,
label = "",
current = NULL,
cutoff_merge_ratio = 0.25) {
## Filter negative correlations
remaining <- remaining[remaining > 0]

Expand Down
69 changes: 35 additions & 34 deletions R/check_sce.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,41 @@
#' ## Check the object
#' check_sce(sce_example)
#' }
check_sce <- function(sce,
variables = c(
"GraphBased",
"ManualAnnotation",
"Maynard",
"Martinowich",
paste0("SNN_k50_k", 4:28),
"spatialLIBD",
"cell_count",
"sum_umi",
"sum_gene",
"expr_chrM",
"expr_chrM_ratio",
"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"
)) {
check_sce <- function(
sce,
variables = c(
"GraphBased",
"ManualAnnotation",
"Maynard",
"Martinowich",
paste0("SNN_k50_k", 4:28),
"spatialLIBD",
"cell_count",
"sum_umi",
"sum_gene",
"expr_chrM",
"expr_chrM_ratio",
"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"
)) {
## Should be a SingleCellExperiment object
stopifnot(is(sce, "SingleCellExperiment"))

Expand Down
15 changes: 8 additions & 7 deletions R/check_spe.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
#' ## Check the object
#' check_spe(spe)
#' }
check_spe <- function(spe,
variables = c(
"sum_umi",
"sum_gene",
"expr_chrM",
"expr_chrM_ratio"
)) {
check_spe <- function(
spe,
variables = c(
"sum_umi",
"sum_gene",
"expr_chrM",
"expr_chrM_ratio"
)) {
## Should be a SpatialExperiment object
stopifnot(is(spe, "SpatialExperiment"))

Expand Down
41 changes: 20 additions & 21 deletions R/fetch_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,26 @@
#' #> 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"
),
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"
),
destdir = tempdir(),
eh = ExperimentHub::ExperimentHub(),
bfc = BiocFileCache::BiocFileCache()) {
## Some variables
sce <-
sce_layer <- modeling_results <- sce_sub <- spe <- NULL
Expand Down
21 changes: 11 additions & 10 deletions R/frame_limits.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@
#' }
#'
frame_limits <-
function(spe,
sampleid,
image_id = "lowres",
visium_grid = list(
row_min = 0,
row_max = 77,
col_min = 0,
col_max = 127,
fiducial_vs_capture_edge = (8 - 6.5) * 1000 / 2 / 100
)) {
function(
spe,
sampleid,
image_id = "lowres",
visium_grid = list(
row_min = 0,
row_max = 77,
col_min = 0,
col_max = 127,
fiducial_vs_capture_edge = (8 - 6.5) * 1000 / 2 / 100
)) {
## Subset the info we need for the particular sample
d <-
as.data.frame(cbind(colData(spe), SpatialExperiment::spatialCoords(spe))[spe$sample_id == sampleid, ],
Expand Down
11 changes: 6 additions & 5 deletions R/gene_set_enrichment.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@
#' ## Explore the results
#' asd_sfari_enrichment
gene_set_enrichment <-
function(gene_list,
fdr_cut = 0.1,
modeling_results = fetch_data(type = "modeling_results"),
model_type = names(modeling_results)[1],
reverse = FALSE) {
function(
gene_list,
fdr_cut = 0.1,
modeling_results = fetch_data(type = "modeling_results"),
model_type = names(modeling_results)[1],
reverse = FALSE) {
model_results <- modeling_results[[model_type]]

## Keep only the genes present
Expand Down
23 changes: 12 additions & 11 deletions R/gene_set_enrichment_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,18 @@
#' layerHeights = c(0, 40, 55, 75, 85, 110, 120, 135),
#' )
gene_set_enrichment_plot <-
function(enrichment,
xlabs = unique(enrichment$ID),
PThresh = 12,
ORcut = 3,
enrichOnly = FALSE,
layerHeights = c(0, seq_len(length(unique(enrichment$test)))) * 15,
mypal = c(
"white",
grDevices::colorRampPalette(RColorBrewer::brewer.pal(9, "YlOrRd"))(50)
),
cex = 1.2) {
function(
enrichment,
xlabs = unique(enrichment$ID),
PThresh = 12,
ORcut = 3,
enrichOnly = FALSE,
layerHeights = c(0, seq_len(length(unique(enrichment$test)))) * 15,
mypal = c(
"white",
grDevices::colorRampPalette(RColorBrewer::brewer.pal(9, "YlOrRd"))(50)
),
cex = 1.2) {
## Re-order and shorten names if they match our data
if (all(unique(enrichment$test) %in% c("WM", paste0("Layer", seq_len(6))))) {
enrichment$test <-
Expand Down
17 changes: 9 additions & 8 deletions R/geom_spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@
#' ## Clean up
#' rm(spe_sub)
#' }
geom_spatial <- function(mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = FALSE,
...) {
geom_spatial <- function(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = FALSE,
...) {
## To avoid a NOTE on R CMD check
ggname <- function(prefix, grob) {
grob$name <- grid::grobName(grob, prefix)
Expand Down
37 changes: 19 additions & 18 deletions R/img_edit.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,25 @@
#' plot(x)
#' }
img_edit <-
function(spe,
sampleid,
image_id = "lowres",
channel = NA,
brightness = 100,
saturation = 100,
hue = 100,
enhance = FALSE,
contrast_sharpen = NA,
quantize_max = NA,
quantize_dither = TRUE,
equalize = FALSE,
normalize = FALSE,
transparent_color = NA,
transparent_fuzz = 0,
background_color = NA,
median_radius = NA,
negate = FALSE) {
function(
spe,
sampleid,
image_id = "lowres",
channel = NA,
brightness = 100,
saturation = 100,
hue = 100,
enhance = FALSE,
contrast_sharpen = NA,
quantize_max = NA,
quantize_dither = TRUE,
equalize = FALSE,
normalize = FALSE,
transparent_color = NA,
transparent_fuzz = 0,
background_color = NA,
median_radius = NA,
negate = FALSE) {
img <-
magick::image_read(SpatialExperiment::imgRaster(spe, sample_id = sampleid, image_id = image_id))

Expand Down
13 changes: 7 additions & 6 deletions R/img_update.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@
#' imgData(img_update(spe, sampleid = "151507", brightness = 25))
#' }
img_update <-
function(spe,
sampleid,
image_id = "lowres",
new_image_id = paste0("edited_", image_id),
overwrite = FALSE,
...) {
function(
spe,
sampleid,
image_id = "lowres",
new_image_id = paste0("edited_", image_id),
overwrite = FALSE,
...) {
img_data <- SpatialExperiment::imgData(spe)

## Skip this sample if there's no existing image to update
Expand Down
11 changes: 6 additions & 5 deletions R/img_update_all.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
#' imgData(img_update_all(spe, brightness = 25))
#' }
img_update_all <-
function(spe,
image_id = "lowres",
new_image_id = paste0("edited_", image_id),
overwrite = FALSE,
...) {
function(
spe,
image_id = "lowres",
new_image_id = paste0("edited_", image_id),
overwrite = FALSE,
...) {
for (sampleid in unique(spe$sample_id)) {
spe <-
img_update(
Expand Down
Loading

0 comments on commit 9e4c25a

Please sign in to comment.