Skip to content

Commit 423eae4

Browse files
authored
Merge branch 'main' into remove_azimuth
2 parents 9f15c80 + c22131d commit 423eae4

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export(IdentName)
66
export(NormFindVarFeatScaleData)
77
export(addQCfilter)
88
export(addQCmetrics)
9+
export(convertClID2Name)
910
export(demuxAntibodyData)
1011
export(extractGeneCorrectionsSoupX)
1112
export(extractTopRefMapResults)

R/runSingleR.R

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,59 @@ runSingleR <- function(obj.seurat,
7676

7777
return(list(obj.seurat, singleR.out))
7878
}
79+
80+
#' Convert cell ontology IDs to names in SingleR output
81+
#'
82+
#' Convert bare cell ontology IDs used in SingleR to human-readable names
83+
#'
84+
#' @param metadata data.frame with labels, pruned.labels and delta.next columns. Typically either:
85+
#' - Seurat object metadata (after running SingleR), or
86+
#' - SingleR output object
87+
#' @param cl Cell ontology database
88+
#' - Can be btained via: `cl <- ontoProc::getOnto('cellOnto')`
89+
#' @param old.prefix The prefix used for the original runSingleR call (e.g. "ImmGen.ont")
90+
#' @param new.prefix The new prefix to use for the human readable column (e.g. "ImmGen.ont.name")
91+
#'
92+
#' @returns data.frame with three new columns: `{new.prefix}.labels`, `{new.prefix}.pruned.labels`, `{new.prefix}.delta.next`.
93+
#'
94+
#'@examples
95+
#' \dontrun{
96+
#' ## Run on bare ontology IDs, then convert to human readable cell type labels
97+
#' # Get cell ontology names and other info
98+
#' cl <- ontoProc::getOnto('cellOnto')
99+
#'
100+
#' # ImmGen.ont
101+
#' c(obj.seurat, SingleR.ImmGen.ont) %<-% obj.seurat %>%
102+
#' Run.SingleR(obj.seurat=.,
103+
#' ref=ref.ImmGen,
104+
#' labels=ref.ImmGen$label.ont,
105+
#' de.method="classic",
106+
#' meta.prefix = "ImmGen.ont")
107+
#'
108+
#' # These labels aren't very informative:
109+
#' SingleR::plotScoreHeatmap(SingleR.ImmGen.ont, show.pruned = TRUE, fontsize=4)
110+
#'
111+
#' # Convert bare cell ontology IDs to informative names in seurat object
112+
#' [email protected] <- convertClID2Name(metadata = [email protected], cl = cl,
113+
#' old.prefix = "ImmGen.ont", new.prefix = "ImmGen.ont.name")
114+
#'
115+
#' # Convert bare cell ontology IDs to informative names in SingleR output and visualize
116+
#' SingleR.ImmGen.ont.names <- convertClID2Name(metadata = SingleR.ImmGen.ont, cl = cl,
117+
#' old.prefix = "ImmGen.ont", new.prefix = "ImmGen.ont.name")
118+
#'
119+
#' SingleR::plotScoreHeatmap(SingleR.ImmGen.ont.names, show.pruned = TRUE, fontsize=4)
120+
#' }
121+
#'
122+
#' @export
123+
# Run SingleR
124+
# Convert bare cell ontology IDs to informative names
125+
convertClID2Name <- function(metadata, cl, old.prefix = "ImmGen.ont", new.prefix = "ImmGen.ont.name") {
126+
op <- old.prefix
127+
np <- new.prefix
128+
md <- metadata
129+
md[[paste0(np, ".labels")]] <- unname(cl$name[unname(md[[paste0(op, ".labels")]])])
130+
md[[paste0(np, ".pruned.labels")]] <- unname(cl$name[unname(md[[paste0(op, ".pruned.labels")]])])
131+
md[[paste0(np, ".delta.next")]] <- md[[paste0(op, ".delta.next")]]
132+
metadata <- md
133+
return(metadata)
134+
}

man/convertClID2Name.Rd

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)