Skip to content

Commit 3512bc4

Browse files
committed
Finish the code for spe_add_info() (still need to test)
1 parent b88a39e commit 3512bc4

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

R/spe_add_info.R

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#' @param spe A [SpatialExperiment-class][SpatialExperiment::SpatialExperiment-class]
99
#' object, such as one created by initially running `VisiumIO::TENxVisium()` or
1010
#' `VisiumIO::TENxVisiumHD()`.
11-
#'
1211
spe_add_info <- function(
1312
spe,
1413
samples,
@@ -101,4 +100,42 @@ spe_add_info <- function(
101100

102101
## Add the gene info to our SPE object
103102
rowRanges(spe) <- gtf[match_genes]
103+
104+
# Add Spaceranger analysis results if applicable
105+
if (add_analysis) {
106+
if (verbose) {
107+
message(
108+
Sys.time(),
109+
" read10xVisiumAnalysis: reading analysis output from SpaceRanger"
110+
)
111+
}
112+
visium_analysis <- read10xVisiumAnalysis(
113+
samples = samples, sample_id = sample_id
114+
)
115+
116+
if (verbose) {
117+
message(
118+
Sys.time(),
119+
" add10xVisiumAnalysis: adding analysis output from SpaceRanger"
120+
)
121+
}
122+
spe <- add10xVisiumAnalysis(spe, visium_analysis)
123+
}
124+
125+
## Add information used by spatialLIBD
126+
if (verbose) message(Sys.time(), " adding information used by spatialLIBD")
127+
spe <- add_key(spe)
128+
spe$sum_umi <- colSums(counts(spe))
129+
spe$sum_gene <- colSums(counts(spe) > 0)
130+
rowData(spe)$gene_search <- paste0(
131+
rowData(spe)$gene_name, "; ", rowData(spe)$gene_id
132+
)
133+
is_mito <- which(seqnames(spe) == chrM)
134+
spe$expr_chrM <- colSums(counts(spe)[is_mito, , drop = FALSE])
135+
spe$expr_chrM_ratio <- spe$expr_chrM / spe$sum_umi
136+
## Add a variable for saving the manual annotations
137+
spe$ManualAnnotation <- "NA"
138+
139+
## Done!
140+
return(spe)
104141
}

0 commit comments

Comments
 (0)