|
8 | 8 | #' @param spe A [SpatialExperiment-class][SpatialExperiment::SpatialExperiment-class] |
9 | 9 | #' object, such as one created by initially running `VisiumIO::TENxVisium()` or |
10 | 10 | #' `VisiumIO::TENxVisiumHD()`. |
11 | | -#' |
12 | 11 | spe_add_info <- function( |
13 | 12 | spe, |
14 | 13 | samples, |
@@ -101,4 +100,42 @@ spe_add_info <- function( |
101 | 100 |
|
102 | 101 | ## Add the gene info to our SPE object |
103 | 102 | 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) |
104 | 141 | } |
0 commit comments