Skip to content

Commit 2fb4351

Browse files
committed
Ran code from dev/04_update.R
1 parent 2b5e841 commit 2fb4351

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+591
-557
lines changed

R/add10xVisiumAnalysis.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@
2929
#'
3030
#' ## Note that ?SpatialExperiment::read10xVisium doesn't include all the files
3131
#' ## we need to illustrate read10xVisiumWrapper().
32-
add10xVisiumAnalysis <- function(
33-
spe,
34-
visium_analysis) {
32+
add10xVisiumAnalysis <- function(spe,
33+
visium_analysis) {
3534
col_info <- colData(spe)
3635
barcode_present <- "barcode" %in% colnames(col_info)
3736
if (!barcode_present) {

R/add_images.R

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@
4343
#' ))
4444
#' }
4545
add_images <-
46-
function(
47-
spe,
48-
image_dir,
49-
image_pattern,
50-
image_id_current = "lowres",
51-
image_id = image_pattern,
52-
image_paths = locate_images(spe, image_dir, image_pattern)) {
46+
function(spe,
47+
image_dir,
48+
image_pattern,
49+
image_id_current = "lowres",
50+
image_id = image_pattern,
51+
image_paths = locate_images(spe, image_dir, image_pattern)) {
5352
stopifnot(length(names(image_paths)) > 0)
5453
stopifnot(all(names(image_paths) %in% unique(spe$sample_id)))
5554
stopifnot(!any(duplicated(names(image_paths))))

R/annotate_registered_clusters.R

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@
4848
#' ## More relaxed merging threshold
4949
#' annotate_registered_clusters(cor_stats_layer, cutoff_merge_ratio = 1)
5050
annotate_registered_clusters <-
51-
function(
52-
cor_stats_layer,
53-
confidence_threshold = 0.25,
54-
cutoff_merge_ratio = 0.25) {
51+
function(cor_stats_layer,
52+
confidence_threshold = 0.25,
53+
cutoff_merge_ratio = 0.25) {
5554
annotated <-
5655
apply(cor_stats_layer,
5756
1,
@@ -76,25 +75,24 @@ annotate_registered_clusters <-
7675
result$layer_label,
7776
ifelse(result$layer_confidence == "good", "", "*")
7877
)
79-
78+
8079
## Add simplified label for WM/Layer annotations
8180
if (all(colnames(cor_stats_layer) %in% c("WM", paste0("Layer", seq_len(6))))) {
8281
result$layer_label_simple <- result$layer_label
8382
## Simplify names when working with the default data
84-
result$layer_label_simple <- gsub("ayer", "", result$layer_label_simple )
85-
result$layer_label_simple <- gsub("\\/L", "\\/", result$layer_label_simple )
86-
result$layer_label_simple <- gsub("^WM\\/", "WM\\/L", result$layer_label_simple )
83+
result$layer_label_simple <- gsub("ayer", "", result$layer_label_simple)
84+
result$layer_label_simple <- gsub("\\/L", "\\/", result$layer_label_simple)
85+
result$layer_label_simple <- gsub("^WM\\/", "WM\\/L", result$layer_label_simple)
8786
}
88-
87+
8988
return(result)
9089
}
9190

9291
annotate_registered_cluster <-
93-
function(
94-
remaining,
95-
label = "",
96-
current = NULL,
97-
cutoff_merge_ratio = 0.25) {
92+
function(remaining,
93+
label = "",
94+
current = NULL,
95+
cutoff_merge_ratio = 0.25) {
9896
## Filter negative correlations
9997
remaining <- remaining[remaining > 0]
10098

R/app_server.R

Lines changed: 80 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -224,74 +224,80 @@ app_server <- function(input, output, session) {
224224
})
225225

226226
static_gene <- reactive({
227-
gene_warning = NULL
228-
withCallingHandlers({
229-
p <- vis_gene(
230-
spe,
231-
sampleid = input$sample,
232-
geneid = input$geneid,
233-
multi_gene_method = input$multi_gene_method,
234-
assayname = input$assayname,
235-
minCount = input$minCount,
236-
cont_colors = cont_colors(),
237-
image_id = input$imageid,
238-
alpha = input$alphalevel,
239-
point_size = input$pointsize,
240-
auto_crop = input$auto_crop,
241-
is_stitched = is_stitched
242-
)
243-
if (!input$side_by_side_gene) {
244-
p_result = p
245-
} else {
246-
p_no_spots <- p
247-
p_no_spots$layers[[2]] <- NULL
248-
249-
p_no_spatial <- p
250-
p_no_spatial$layers[[1]] <- NULL
251-
p_result = cowplot::plot_grid(
252-
plotlist = list(
253-
p_no_spots,
254-
p_no_spatial + ggplot2::theme(legend.position = "none")
255-
),
256-
nrow = 1,
257-
ncol = 2
227+
gene_warning <- NULL
228+
withCallingHandlers(
229+
{
230+
p <- vis_gene(
231+
spe,
232+
sampleid = input$sample,
233+
geneid = input$geneid,
234+
multi_gene_method = input$multi_gene_method,
235+
assayname = input$assayname,
236+
minCount = input$minCount,
237+
cont_colors = cont_colors(),
238+
image_id = input$imageid,
239+
alpha = input$alphalevel,
240+
point_size = input$pointsize,
241+
auto_crop = input$auto_crop,
242+
is_stitched = is_stitched
258243
)
244+
if (!input$side_by_side_gene) {
245+
p_result <- p
246+
} else {
247+
p_no_spots <- p
248+
p_no_spots$layers[[2]] <- NULL
249+
250+
p_no_spatial <- p
251+
p_no_spatial$layers[[1]] <- NULL
252+
p_result <- cowplot::plot_grid(
253+
plotlist = list(
254+
p_no_spots,
255+
p_no_spatial + ggplot2::theme(legend.position = "none")
256+
),
257+
nrow = 1,
258+
ncol = 2
259+
)
260+
}
261+
},
262+
warning = function(w) {
263+
gene_warning <<- conditionMessage(w)
264+
invokeRestart("muffleWarning")
259265
}
260-
}, warning = function(w) {
261-
gene_warning <<- conditionMessage(w)
262-
invokeRestart("muffleWarning")
263-
})
266+
)
264267
return(list(p = p_result, gene_warning = gene_warning))
265268
})
266269

267270
static_gene_grid <- reactive({
268271
input$gene_grid_update
269272

270-
gene_grid_warnings = NULL
271-
withCallingHandlers({
272-
plots <-
273-
vis_grid_gene(
274-
spe,
275-
geneid = isolate(input$geneid),
276-
multi_gene_method = input$multi_gene_method,
277-
assayname = isolate(input$assayname),
278-
minCount = isolate(input$minCount),
279-
return_plots = TRUE,
280-
spatial = isolate(input$grid_spatial_gene),
281-
cont_colors = isolate(cont_colors()),
282-
image_id = isolate(input$imageid),
283-
alpha = isolate(input$alphalevel),
284-
point_size = isolate(input$pointsize),
285-
sample_order = isolate(input$gene_grid_samples),
286-
auto_crop = isolate(input$auto_crop),
287-
is_stitched = is_stitched
288-
)
289-
}, warning = function(w) {
290-
gene_grid_warnings <<- c(gene_grid_warnings, conditionMessage(w))
291-
invokeRestart("muffleWarning")
292-
})
273+
gene_grid_warnings <- NULL
274+
withCallingHandlers(
275+
{
276+
plots <-
277+
vis_grid_gene(
278+
spe,
279+
geneid = isolate(input$geneid),
280+
multi_gene_method = input$multi_gene_method,
281+
assayname = isolate(input$assayname),
282+
minCount = isolate(input$minCount),
283+
return_plots = TRUE,
284+
spatial = isolate(input$grid_spatial_gene),
285+
cont_colors = isolate(cont_colors()),
286+
image_id = isolate(input$imageid),
287+
alpha = isolate(input$alphalevel),
288+
point_size = isolate(input$pointsize),
289+
sample_order = isolate(input$gene_grid_samples),
290+
auto_crop = isolate(input$auto_crop),
291+
is_stitched = is_stitched
292+
)
293+
},
294+
warning = function(w) {
295+
gene_grid_warnings <<- c(gene_grid_warnings, conditionMessage(w))
296+
invokeRestart("muffleWarning")
297+
}
298+
)
293299

294-
p_result = cowplot::plot_grid(
300+
p_result <- cowplot::plot_grid(
295301
plotlist = plots,
296302
nrow = isolate(input$gene_grid_nrow),
297303
ncol = isolate(input$gene_grid_ncol)
@@ -455,7 +461,7 @@ app_server <- function(input, output, session) {
455461
height = 8,
456462
width = 8 * ifelse(input$side_by_side_gene, 2, 1)
457463
)
458-
print(static_gene()[['p']])
464+
print(static_gene()[["p"]])
459465
dev.off()
460466
}
461467
)
@@ -483,7 +489,7 @@ app_server <- function(input, output, session) {
483489
height = 8 * isolate(input$gene_grid_nrow),
484490
width = 8 * isolate(input$gene_grid_ncol)
485491
)
486-
print(static_gene_grid()[['p']])
492+
print(static_gene_grid()[["p"]])
487493
dev.off()
488494
}
489495
)
@@ -548,7 +554,7 @@ app_server <- function(input, output, session) {
548554

549555
output$gene <- renderPlot(
550556
{
551-
static_gene()[['p']]
557+
static_gene()[["p"]]
552558
},
553559
width = function() {
554560
600 * ifelse(input$side_by_side_gene, 2, 1)
@@ -560,9 +566,12 @@ app_server <- function(input, output, session) {
560566
# Since 'static_gene()' is invoked twice (once also in the assignment
561567
# of 'output$gene'), we silence any errors that occur in this second
562568
# invocation to not duplicate error messages
563-
this_warning = NULL
564-
temp = try(
565-
{ this_warning = static_gene()[['gene_warning']] }, silent = TRUE
569+
this_warning <- NULL
570+
temp <- try(
571+
{
572+
this_warning <- static_gene()[["gene_warning"]]
573+
},
574+
silent = TRUE
566575
)
567576

568577
if (!is.null(this_warning)) {
@@ -585,7 +594,7 @@ app_server <- function(input, output, session) {
585594

586595
output$gene_grid <- renderPlot(
587596
{
588-
print(static_gene_grid()[['p']])
597+
print(static_gene_grid()[["p"]])
589598
},
590599
width = "auto",
591600
height = "auto"
@@ -595,9 +604,11 @@ app_server <- function(input, output, session) {
595604
# Since 'static_gene_grid()' is invoked twice (once also in the
596605
# assignment of 'output$gene_grid'), we silence any errors that occur
597606
# in this second invocation to not duplicate error messages
598-
these_warnings = NULL
599-
temp = try(
600-
{ these_warnings = static_gene_grid()[['gene_grid_warnings']] },
607+
these_warnings <- NULL
608+
temp <- try(
609+
{
610+
these_warnings <- static_gene_grid()[["gene_grid_warnings"]]
611+
},
601612
silent = TRUE
602613
)
603614

R/check_sce.R

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,40 @@
2424
#' ## Check the object
2525
#' check_sce(sce_example)
2626
#' }
27-
check_sce <- function(
28-
sce,
29-
variables = c(
30-
"GraphBased",
31-
"ManualAnnotation",
32-
"Maynard",
33-
"Martinowich",
34-
paste0("SNN_k50_k", 4:28),
35-
"spatialLIBD",
36-
"cell_count",
37-
"sum_umi",
38-
"sum_gene",
39-
"expr_chrM",
40-
"expr_chrM_ratio",
41-
"SpatialDE_PCA",
42-
"SpatialDE_pool_PCA",
43-
"HVG_PCA",
44-
"pseudobulk_PCA",
45-
"markers_PCA",
46-
"SpatialDE_UMAP",
47-
"SpatialDE_pool_UMAP",
48-
"HVG_UMAP",
49-
"pseudobulk_UMAP",
50-
"markers_UMAP",
51-
"SpatialDE_PCA_spatial",
52-
"SpatialDE_pool_PCA_spatial",
53-
"HVG_PCA_spatial",
54-
"pseudobulk_PCA_spatial",
55-
"markers_PCA_spatial",
56-
"SpatialDE_UMAP_spatial",
57-
"SpatialDE_pool_UMAP_spatial",
58-
"HVG_UMAP_spatial",
59-
"pseudobulk_UMAP_spatial",
60-
"markers_UMAP_spatial"
61-
)) {
27+
check_sce <- function(sce,
28+
variables = c(
29+
"GraphBased",
30+
"ManualAnnotation",
31+
"Maynard",
32+
"Martinowich",
33+
paste0("SNN_k50_k", 4:28),
34+
"spatialLIBD",
35+
"cell_count",
36+
"sum_umi",
37+
"sum_gene",
38+
"expr_chrM",
39+
"expr_chrM_ratio",
40+
"SpatialDE_PCA",
41+
"SpatialDE_pool_PCA",
42+
"HVG_PCA",
43+
"pseudobulk_PCA",
44+
"markers_PCA",
45+
"SpatialDE_UMAP",
46+
"SpatialDE_pool_UMAP",
47+
"HVG_UMAP",
48+
"pseudobulk_UMAP",
49+
"markers_UMAP",
50+
"SpatialDE_PCA_spatial",
51+
"SpatialDE_pool_PCA_spatial",
52+
"HVG_PCA_spatial",
53+
"pseudobulk_PCA_spatial",
54+
"markers_PCA_spatial",
55+
"SpatialDE_UMAP_spatial",
56+
"SpatialDE_pool_UMAP_spatial",
57+
"HVG_UMAP_spatial",
58+
"pseudobulk_UMAP_spatial",
59+
"markers_UMAP_spatial"
60+
)) {
6261
## Should be a SingleCellExperiment object
6362
stopifnot(is(sce, "SingleCellExperiment"))
6463

R/check_spe.R

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@
2525
#' ## Check the object
2626
#' check_spe(spe)
2727
#' }
28-
check_spe <- function(
29-
spe,
30-
variables = c(
31-
"sum_umi",
32-
"sum_gene",
33-
"expr_chrM",
34-
"expr_chrM_ratio"
35-
)) {
28+
check_spe <- function(spe,
29+
variables = c(
30+
"sum_umi",
31+
"sum_gene",
32+
"expr_chrM",
33+
"expr_chrM_ratio"
34+
)) {
3635
## Should be a SpatialExperiment object
3736
stopifnot(is(spe, "SpatialExperiment"))
3837

0 commit comments

Comments
 (0)