Skip to content

Commit

Permalink
Merge pull request #13 from satijalab/develop
Browse files Browse the repository at this point in the history
SeuratData v0.2.0
  • Loading branch information
mojaveazure authored Dec 9, 2019
2 parents 56a538f + ded404a commit 6bb99eb
Show file tree
Hide file tree
Showing 19 changed files with 644 additions and 83 deletions.
9 changes: 6 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: SeuratData
Type: Package
Title: Install and Manage Seurat Datasets
Version: 0.1.0
Date: 2019-07-17
Version: 0.2.0
Date: 2019-11-15
Authors@R: c(
person(given = 'Rahul', family = 'Satija', email = '[email protected]', role = 'aut', comment = c(ORCID = '0000-0001-9448-8833')),
person(given = 'Paul', family = 'Hoffman', email = '[email protected]', role = c('aut', 'cre'), comment = c(ORCID = '0000-0002-7693-8957')),
Expand All @@ -18,11 +18,14 @@ License: GPL-3 | file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.1
Depends:
R (>= 3.5.0)
Imports:
cli,
crayon,
rappdirs,
stats,
utils
Collate:
Collate:
'zzz.R'
'seurat_data.R'
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export(AvailableData)
export(InstallData)
export(InstalledData)
export(LoadData)
export(RemoveData)
export(UpdateData)
importFrom(cli,rule)
Expand All @@ -14,8 +15,10 @@ importFrom(crayon,col_nchar)
importFrom(crayon,green)
importFrom(crayon,red)
importFrom(crayon,yellow)
importFrom(rappdirs,user_data_dir)
importFrom(stats,na.omit)
importFrom(utils,available.packages)
importFrom(utils,data)
importFrom(utils,install.packages)
importFrom(utils,packageVersion)
importFrom(utils,remove.packages)
Expand Down
114 changes: 107 additions & 7 deletions R/seurat_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ NULL
#'
#' @export
#'
#' @seealso \code{\link{InstallData}} \code{\link{InstalledData}} \code{\link{RemoveData}} \code{\link{UpdateData}}
#' @seealso \code{\link{InstallData}} \code{\link{InstalledData}}
#' \code{\link{RemoveData}} \code{\link{UpdateData}}
#'
#' @examples
#' AvailableData()
#'
AvailableData <- function() {
UpdateManifest()
Expand All @@ -35,18 +39,30 @@ AvailableData <- function() {
#'
#' @export
#'
#' @seealso \code{\link{AvailableData}} \code{\link{InstalledData}} \code{\link{RemoveData}} \code{\link{UpdateData}}
#' @seealso \code{\link{AvailableData}} \code{\link{InstalledData}}
#' \code{\link{RemoveData}} \code{\link{UpdateData}}
#'
#' @examples
#' \dontrun{
#' InstallData('pbmc3k')
#' }
#'
InstallData <- function(ds, force.reinstall = FALSE, ...) {
UpdateManifest()
if (pkg.env$source != 'remote') {
stop(
"No access to remote SeuratData repository, unable to install new datasets",
call. = FALSE
)
}
pkgs <- NameToPackage(ds = ds)
if (!force.reinstall) {
installed <- intersect(x = pkgs, y = rownames(x = InstalledData()))
if (length(x = installed) > 0) {
warning(
"The following packages are already installed and will not be reinstalled: ",
paste(
gsub(pattern = '\\.SeuratData', replacement = '', x = installed),
gsub(pattern = pkg.key, replacement = '', x = installed),
collapse = ', '
),
call. = FALSE,
Expand All @@ -63,7 +79,12 @@ InstallData <- function(ds, force.reinstall = FALSE, ...) {
for (p in pkgs2[pkgs2 %in% search()]) {
detach(name = p, unload = TRUE, character.only = TRUE)
}
install.packages(pkgs = pkgs, repos = getOption(x = "SeuratData.repo.use"), type = 'source', ...)
install.packages(
pkgs = pkgs,
repos = getOption(x = "SeuratData.repo.use"),
type = 'source',
...
)
for (pkg in pkgs) {
attachNamespace(ns = pkg)
pkg.env$attached <- c(pkg.env$attached, pkg)
Expand All @@ -86,13 +107,73 @@ InstallData <- function(ds, force.reinstall = FALSE, ...) {
#'
#' @export
#'
#' @seealso \code{\link{AvailableData}} \code{\link{InstallData}} \code{\link{RemoveData}} \code{\link{UpdateData}}
#' @seealso \code{\link{AvailableData}} \code{\link{InstallData}}
#' \code{\link{RemoveData}} \code{\link{UpdateData}}
#'
#' @examples
#' InstalledData()
#'
InstalledData <- function() {
dat <- AvailableData()
return(dat[which(x = dat$Installed, ), , drop = FALSE])
}

#' Modularly load a dataset
#'
#' @inheritParams LoadH5Seurat
#' @param ds Optional name of dataset to load
#' @param type How to load the \code{Seurat} object; choose from
#' \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{processed}{The proccessed data, modular loading avaible by setting other parameters}
#' }
#'
#' @inherit LoadH5Seurat return
#'
#' @importFrom utils data
#'
#' @export
#'
#' @seealso \code{\link[utils]{data}}
#'
LoadData <- function(
ds,
type = c('info', 'raw', 'processed'),
assays = NULL,
reductions = NULL,
graphs = NULL,
verbose = TRUE
) {
.NotYetImplemented()
installed <- InstalledData()
if (!NameToPackage(ds = ds) %in% rownames(x = installed)) {
stop("Cannot find dataset ", ds, call. = FALSE)
}
ds <- NameToPackage(ds = ds)
type <- match.arg(arg = tolower(x = type), choices = c('info', 'raw', 'processed'))
if (type == 'raw') {
e <- new.env()
ds <- gsub(pattern = '\\.SeuratData', replacement = '', x = ds)
data(list = ds, envir = e)
return(e[[ds]])
}
.NotYetImplemented()
type <- match.arg(arg = type, choices = c('info', 'processed'))
return(LoadH5Seurat(
file = system.file(
file.path('extdata', 'processed.h5Seurat'),
package = ds,
mustWork = TRUE
),
type = ifelse(test = type == 'processed', yes = 'object', no = type),
assays = assays,
reductions = reductions,
graphs = graphs,
verbose = verbose
))
}

#' Remove a dataset
#'
#' @inheritParams utils::remove.packages
Expand All @@ -102,7 +183,13 @@ InstalledData <- function() {
#'
#' @export
#'
#' @seealso \code{\link{AvailableData}} \code{\link{InstallData}} \code{\link{InstalledData}} \code{\link{UpdateData}}
#' @seealso \code{\link{AvailableData}} \code{\link{InstallData}}
#' \code{\link{InstalledData}} \code{\link{UpdateData}}
#'
#' @examples
#' \dontrun{
#' RemoveData('pbmc3k')
#' }
#'
RemoveData <- function(ds, lib) {
UpdateManifest()
Expand All @@ -125,9 +212,22 @@ RemoveData <- function(ds, lib) {
#'
#' @export
#'
#' @seealso \code{\link{AvailableData}} \code{\link{InstallData}} \code{\link{InstalledData}} \code{\link{RemoveData}}
#' @seealso \code{\link{AvailableData}} \code{\link{InstallData}}
#' \code{\link{InstalledData}} \code{\link{RemoveData}}
#'
#' @examples
#' \dontrun{
#' UpdateData(ask = FALSE)
#' }
#'
UpdateData <- function(ask = TRUE, lib.loc = NULL) {
UpdateManifest()
if (pkg.env$source != 'remote') {
stop(
"No access to remote SeuratData repository, unable to update datasets",
call. = FALSE
)
}
update.packages(lib.loc = lib.loc, repos = getOption(x = "SeuratData.repo.use"), ask = ask, type = 'source')
UpdateManifest()
invisible(x = NULL)
Expand Down
Loading

0 comments on commit 6bb99eb

Please sign in to comment.