Skip to content

Commit

Permalink
Merge pull request #67 from yerkes-gencore/convertClID2Name
Browse files Browse the repository at this point in the history
init convertCLID2Name()
  • Loading branch information
derrik-gratz authored Aug 9, 2023
2 parents 23c8297 + 0b3612f commit c22131d
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export(IdentName)
export(NormFindVarFeatScaleData)
export(addQCfilter)
export(addQCmetrics)
export(convertClID2Name)
export(createAzimuthReference)
export(demuxAntibodyData)
export(extractGeneCorrectionsSoupX)
Expand Down
56 changes: 56 additions & 0 deletions R/runSingleR.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,59 @@ runSingleR <- function(obj.seurat,

return(list(obj.seurat, singleR.out))
}

#' Convert cell ontology IDs to names in SingleR output
#'
#' Convert bare cell ontology IDs used in SingleR to human-readable names
#'
#' @param metadata data.frame with labels, pruned.labels and delta.next columns. Typically either:
#' - Seurat object metadata (after running SingleR), or
#' - SingleR output object
#' @param cl Cell ontology database
#' - Can be btained via: `cl <- ontoProc::getOnto('cellOnto')`
#' @param old.prefix The prefix used for the original runSingleR call (e.g. "ImmGen.ont")
#' @param new.prefix The new prefix to use for the human readable column (e.g. "ImmGen.ont.name")
#'
#' @returns data.frame with three new columns: `{new.prefix}.labels`, `{new.prefix}.pruned.labels`, `{new.prefix}.delta.next`.
#'
#'@examples
#' \dontrun{
#' ## Run on bare ontology IDs, then convert to human readable cell type labels
#' # Get cell ontology names and other info
#' cl <- ontoProc::getOnto('cellOnto')
#'
#' # ImmGen.ont
#' c(obj.seurat, SingleR.ImmGen.ont) %<-% obj.seurat %>%
#' Run.SingleR(obj.seurat=.,
#' ref=ref.ImmGen,
#' labels=ref.ImmGen$label.ont,
#' de.method="classic",
#' meta.prefix = "ImmGen.ont")
#'
#' # These labels aren't very informative:
#' SingleR::plotScoreHeatmap(SingleR.ImmGen.ont, show.pruned = TRUE, fontsize=4)
#'
#' # Convert bare cell ontology IDs to informative names in seurat object
#' [email protected] <- convertClID2Name(metadata = [email protected], cl = cl,
#' old.prefix = "ImmGen.ont", new.prefix = "ImmGen.ont.name")
#'
#' # Convert bare cell ontology IDs to informative names in SingleR output and visualize
#' SingleR.ImmGen.ont.names <- convertClID2Name(metadata = SingleR.ImmGen.ont, cl = cl,
#' old.prefix = "ImmGen.ont", new.prefix = "ImmGen.ont.name")
#'
#' SingleR::plotScoreHeatmap(SingleR.ImmGen.ont.names, show.pruned = TRUE, fontsize=4)
#' }
#'
#' @export
# Run SingleR
# Convert bare cell ontology IDs to informative names
convertClID2Name <- function(metadata, cl, old.prefix = "ImmGen.ont", new.prefix = "ImmGen.ont.name") {
op <- old.prefix
np <- new.prefix
md <- metadata
md[[paste0(np, ".labels")]] <- unname(cl$name[unname(md[[paste0(op, ".labels")]])])
md[[paste0(np, ".pruned.labels")]] <- unname(cl$name[unname(md[[paste0(op, ".pruned.labels")]])])
md[[paste0(np, ".delta.next")]] <- md[[paste0(op, ".delta.next")]]
metadata <- md
return(metadata)
}
64 changes: 64 additions & 0 deletions man/convertClID2Name.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c22131d

Please sign in to comment.