Skip to content

Commit

Permalink
Merge pull request satijalab#559 from satijalab/feat/AddAzimuthResults
Browse files Browse the repository at this point in the history
Add Azimuth Results to Seurat Object
  • Loading branch information
andrewwbutler authored May 18, 2021
2 parents 9b082a5 + c977212 commit 46b9f0f
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 5 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: Seurat
Version: 4.0.1.9013
Date: 2021-05-14
Version: 4.0.1.9014
Date: 2021-05-17
Title: Tools for Single Cell Genomics
Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) <doi:10.1038/nbt.3192>, Macosko E, Basu A, Satija R, et al (2015) <doi:10.1016/j.cell.2015.05.002>, Stuart T, Butler A, et al (2019) <doi:10.1016/j.cell.2019.05.031>, and Hao, Hao, et al (2020) <doi:10.1101/2020.10.12.335331> for more details.
Authors@R: c(
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export("Project<-")
export("SCTResults<-")
export("Tool<-")
export("VariableFeatures<-")
export(AddAzimuthResults)
export(AddMetaData)
export(AddModuleScore)
export(AggregateExpression)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Seurat develop
## Added
- New `AddAzimuthScores()` function
- New `AddAzimuthScores()` and `AddAzimuthResults()` functions
- Add `shuffle` parameter to `FeatureScatter()` ([#4280](https://github.com/satijalab/seurat/pull/4280))
- Add `lsiproject` and `rpca` options for `FindTransferAnchors()`
- Add `rlsi` option for `FindIntegrationAnchors()`
Expand Down
66 changes: 66 additions & 0 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,72 @@ NULL
# Functions
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

#' Add Azimuth Results
#'
#' Add mapping and prediction scores, UMAP embeddings, and imputed assay (if
#' available)
#' from Azimuth to an existing or new \code{\link[SeuratObject]{Seurat}} object
#'
#' @param object A \code{\link[SeuratObject]{Seurat}} object
#' @param filename Path to Azimuth mapping scores file
#'
#' @return \code{object} with Azimuth results added
#'
#' @examples
#' \dontrun{
#' object <- AddAzimuthResults(object, filename = "azimuth_results.Rds")
#' }
#'
#' @export
AddAzimuthResults <- function(object = NULL, filename) {
if (is.null(x = filename)) {
stop("No Azimuth results provided.")
}
azimuth_results <- readRDS(file = filename)
if (!is.list(x = azimuth_results) || any(!(c('umap', 'pred.df') %in% names(x = azimuth_results)))) {
stop("Expected following format for azimuth_results:
`list(umap = <DimReduc>, pred.df = <data.frame>[, impADT = <Assay>])`")
}

if (is.null(x = object)) {
message("No existing Seurat object provided. Creating new one.")
object <- CreateSeuratObject(
counts = matrix(
nrow = 1,
ncol = nrow(x = azimuth_results$umap),
dimnames = list(
row.names = 'Dummy.feature',
col.names = rownames(x = azimuth_results$umap))
),
assay = 'Dummy'
)
} else {
overlap.cells <- intersect(
x = Cells(x = object),
y = rownames(x = azimuth_results$umap)
)
if (!(all(overlap.cells %in% Cells(x = object)))) {
stop("Cells in object do not match cells in download")
} else if (length(x = overlap.cells) < length(x = Cells(x = object))) {
warning(paste0("Subsetting out ", length(x = Cells(x = object)) - length(x = overlap.cells),
" cells that are absent in downloaded results (perhaps filtered by Azimuth)"))
object <- subset(x = object, cells = overlap.cells)
}
}

azimuth_results$pred.df$cell <- NULL
object <- AddMetaData(object = object, metadata = azimuth_results$pred.df)
object[['umap.proj']] <- azimuth_results$umap
if ('impADT' %in% names(x = azimuth_results)) {
object[['impADT']] <- azimuth_results$impADT
if ('Dummy' %in% Assays(object = object)) {
DefaultAssay(object = object) <- 'impADT'
object[['Dummy']] <- NULL
}
}
return(object)
}

#' Add Azimuth Scores
#'
#' Add mapping and prediction scores from Azimuth to a
Expand Down
27 changes: 27 additions & 0 deletions man/AddAzimuthResults.Rd

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

4 changes: 2 additions & 2 deletions man/as.sparse.Rd

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

0 comments on commit 46b9f0f

Please sign in to comment.