Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for azimuth references #52

Merged
merged 6 commits into from Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
@@ -1,7 +1,7 @@
Package: SeuratData
Type: Package
Title: Install and Manage Seurat Datasets
Version: 0.2.1
Version: 0.2.2
Date: 2019-12-09
Authors@R: c(
person(given = 'Rahul', family = 'Satija', email = 'rsatija@nygenome.org', role = 'aut', comment = c(ORCID = '0000-0001-9448-8833')),
Expand All @@ -17,7 +17,7 @@ BugReports: https://github.com/satijalab/seurat-data/issues
License: GPL-3 | file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.0.2
RoxygenNote: 7.1.2
Depends:
R (>= 3.5.0)
Imports:
Expand Down
9 changes: 9 additions & 0 deletions NAMESPACE
Expand Up @@ -6,6 +6,14 @@ export(InstalledData)
export(LoadData)
export(RemoveData)
export(UpdateData)
importFrom(Matrix,sparseMatrix)
importFrom(Seurat,AddMetaData)
importFrom(Seurat,CreateSeuratObject)
AustinHartman marked this conversation as resolved.
Show resolved Hide resolved
importFrom(Seurat,LoadAnnoyIndex)
AustinHartman marked this conversation as resolved.
Show resolved Hide resolved
importFrom(SeuratObject,"Idents<-")
importFrom(SeuratObject,Cells)
importFrom(SeuratObject,Misc)
importFrom(SeuratObject,Tool)
importFrom(cli,rule)
importFrom(cli,symbol)
importFrom(crayon,blue)
Expand All @@ -19,6 +27,7 @@ importFrom(rappdirs,user_data_dir)
importFrom(stats,na.omit)
importFrom(utils,available.packages)
importFrom(utils,data)
importFrom(utils,download.file)
importFrom(utils,install.packages)
importFrom(utils,packageVersion)
importFrom(utils,remove.packages)
Expand Down
76 changes: 74 additions & 2 deletions R/seurat_data.R
Expand Up @@ -128,6 +128,7 @@ InstalledData <- function() {
# \describe{
# \item{info}{Information about the object and what's stored in it}
# \item{raw}{The raw form of the dataset, no other options are evaluated}
# \item{azimuth}{Load the dataset as an azimuth reference}
# \item{processed}{The proccessed data, modular loading avaible by setting other parameters}
# }
#'
Expand Down Expand Up @@ -161,9 +162,11 @@ LoadData <- function(
)
type <- match.arg(
arg = tolower(x = type),
choices = c('raw', 'default', datasets)
choices = c('raw', 'default', 'azimuth', datasets)
)
if (type %in% c('raw', 'default')) {
if (type == 'azimuth') {
return(LoadReference(file.path(system.file(package=ds), type)))
} else if (type %in% c('raw', 'default')) {
type <- gsub(pattern = pkg.key, replacement = '', x = ds)
} else if (type == 'final') {
type <- paste0(gsub(pattern = pkg.key, replacement = '', x = ds), '.final')
Expand Down Expand Up @@ -255,3 +258,72 @@ UpdateData <- function(ask = TRUE, lib.loc = NULL) {
UpdateManifest()
invisible(x = NULL)
}

#' Load the reference RDS files
#'
#' Read in a reference \code{\link[Seurat]{Seurat}} object and annoy index. This
#' function can read from a file path. In order to read properly,
#' there must be the following files:
#' \itemize{
#' \item \dQuote{ref.Rds} for the downsampled reference \code{Seurat}
#' object (for mapping)
#' \item \dQuote{idx.annoy} for the nearest-neighbor index object
#' }
#'
#' @param path Pathto the two RDS files
#'
#' @return A list with two entries:
#' \describe{
#' \item{\code{map}}{
#' The downsampled reference \code{\link[Seurat]{Seurat}}
#' object (for mapping)
#' }
#' \item{\code{plot}}{The reference \code{Seurat} object (for plotting)}
#' }
#'
#' @importFrom SeuratObject Idents<- Tool Cells Misc
#' @importFrom Seurat LoadAnnoyIndex AddMetaData CreateSeuratObject
#' @importFrom utils download.file
#' @importFrom Matrix sparseMatrix
#'
LoadReference <- function(path) {
ref.names <- list(
map = 'ref.Rds',
ann = 'idx.annoy'
)
mapref <- file.path(path, ref.names$map)
annref <- file.path(path, ref.names$ann)
exists <- file.exists(c(mapref, annref))
if (!all(exists)) {
stop(
"Missing the following files from the directory provided: ",
unlist(x = ref.names)[!exists]
)
}
# Load the map reference
map <- readRDS(file = mapref)
# Load the annoy index into the Neighbor object in the neighbors slot
map[["refdr.annoy.neighbors"]] <- LoadAnnoyIndex(
object = map[["refdr.annoy.neighbors"]],
file = annref
)
# Create plotref
ad <- Tool(object = map, slot = "AzimuthReference")
# plotref.dr <- GetPlotRef(object = ad)
print(ad)
plotref.dr <- slot(object = ad, name = "plotref")
cm <- sparseMatrix(
i = 1, j = 1, x = 0, dims = c(1, nrow(x = plotref.dr)),
dimnames = list("placeholder", Cells(x = plotref.dr))
)
plot <- CreateSeuratObject(
counts = cm
)
plot[["refUMAP"]] <- plotref.dr
plot <- AddMetaData(object = plot, metadata = Misc(object = plotref.dr, slot = "plot.metadata"))
gc(verbose = FALSE)
return(list(
map = map,
plot = plot
))
}
Binary file modified inst/extdata/manifest.Rds
Binary file not shown.