-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path13_fig_S4_deconvolution.R
More file actions
51 lines (40 loc) · 1.43 KB
/
13_fig_S4_deconvolution.R
File metadata and controls
51 lines (40 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
figures_dir <- "./export/figures"
objects_dir <- "./export/objects"
dir.create(figures_dir, showWarnings = FALSE, recursive = TRUE)
dir.create(objects_dir, showWarnings = FALSE, recursive = TRUE)
options(stringsAsFactors = FALSE)
library(spacedeconv)
library(SpatialExperiment)
spe <- read10xVisium("./data/maynard/")
rownames(spe) <- rowData(spe)$symbol
# 151673
spatialLIBDAnnotation <- readRDS("./data/maynard/outs/spatial/spatial.rds")
spatialLIBDAnnotation <- filter_sample_id(spatialLIBDAnnotation, "151673")
groundTruth <- spatialLIBDAnnotation$spatialLIBD
spe$groundTruth <- groundTruth
spe <- preprocess(spe)
rownames(spe) <- make.names(rownames(spe), unique = TRUE)
sce <- readRDS("./data/brainAtlas/allenBrain.rds")
sce <- subsetSCE(sce, cell_type_col = "subclass_label", ncells = 40000)
sce$subclass_label <- make.names(sce$subclass_label)
# Note: 'gpu = TRUE' assumes you have a compatible GPU environment configured.
signature <- build_model(
sce,
cell_type_col = "subclass_label",
method = "cell2location",
epochs = 250,
batch_id_col = "external_donor_name_label",
gpu = TRUE,
assay_sc = "counts"
)
deconvC2L <- deconvolute(
spe,
method = "cell2location",
signature = signature,
epochs = 30000,
gpu = TRUE,
assay_sc = "counts",
assay_sp = "counts"
)
saveRDS(deconvC2L, file = "./export/objects/fig_S4_c2l.rds")
cat("Saved deconvolution result to ./export/objects/fig_S4_c2l.rds\n")