From 58110b1859f3478e3d0495513bd3c7a746d03c46 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Mon, 9 Dec 2019 19:43:11 -0500 Subject: [PATCH 1/3] Update LoadData Allow type to specify Rda dataset to load --- DESCRIPTION | 2 +- R/seurat_data.R | 87 ++++++++++++++++++++++++--------------- R/zzz.R | 12 +++--- man/LoadData.Rd | 15 ++++--- man/SeuratData-package.Rd | 6 +-- man/UpdateData.Rd | 2 +- 6 files changed, 72 insertions(+), 52 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ffe4fb1..29b2bbf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,7 +17,7 @@ BugReports: https://github.com/satijalab/seurat-data/issues License: GPL-3 | file LICENSE Encoding: UTF-8 LazyData: true -RoxygenNote: 6.1.1 +RoxygenNote: 7.0.2 Depends: R (>= 3.5.0) Imports: diff --git a/R/seurat_data.R b/R/seurat_data.R index c0bfe09..2eca95a 100644 --- a/R/seurat_data.R +++ b/R/seurat_data.R @@ -120,16 +120,19 @@ InstalledData <- function() { #' Modularly load a dataset #' -#' @inheritParams LoadH5Seurat +# @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 +#' @param type How to load the \code{Seurat} object; choose from either 'default' +#' for the default dataset or any dataset listed in the \code{default.dataset} +#' or \code{other.datasets} sections of the data manifest +# \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 +#' @return A \code{Seurat} object with the dataset asked for #' #' @importFrom utils data #' @@ -139,39 +142,57 @@ InstalledData <- function() { #' LoadData <- function( ds, - type = c('info', 'raw', 'processed'), - assays = NULL, - reductions = NULL, - graphs = NULL, - verbose = TRUE + type = 'default' + # 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') { + datasets <- trimws(x = unlist(x = strsplit( + x = na.omit(object = unlist( + x = installed[ds, c('default.dataset', 'other.datasets')], + use.names = FALSE + )), + split = ',' + ))) + type <- match.arg( + arg = tolower(x = type), + choices = c('raw', 'default', datasets) + ) + if (type %in% c('raw', 'default')) { + type <- datasets[1] + } + 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') + } + if (type %in% data(package = ds)$results[, 'Item', drop = TRUE]) { e <- new.env() - ds <- gsub(pattern = '\\.SeuratData', replacement = '', x = ds) - data(list = ds, envir = e) - return(e[[ds]]) + data(list = type, package = ds, envir = e) + # ds <- gsub(pattern = '\\.SeuratData', replacement = '', x = ds) + # data(list = ds, envir = e) + return(e[[type]]) } .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 - )) + # 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 diff --git a/R/zzz.R b/R/zzz.R index 51681a0..11cd337 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -448,12 +448,12 @@ UpdateManifest <- function() { x = avail.pkgs$InstalledVersion, strict = FALSE ) - # TODO: remove these when we allow loading of processed datasets - cols.remove <- c('default.dataset', 'other.datasets') - if (any(cols.remove %in% colnames(x = avail.pkgs))) { - ds.index <- which(x = colnames(x = avail.pkgs) %in% cols.remove) - avail.pkgs <- avail.pkgs[, -ds.index] - } + # # TODO: remove these when we allow loading of processed datasets + # cols.remove <- c('default.dataset', 'other.datasets') + # if (any(cols.remove %in% colnames(x = avail.pkgs))) { + # ds.index <- which(x = colnames(x = avail.pkgs) %in% cols.remove) + # avail.pkgs <- avail.pkgs[, -ds.index] + # } pkg.env$manifest <- avail.pkgs # Cache the manifest if (getOption(x = 'SeuratData.manifest.cache', default = FALSE)) { diff --git a/man/LoadData.Rd b/man/LoadData.Rd index e3ca9a5..5301a2d 100644 --- a/man/LoadData.Rd +++ b/man/LoadData.Rd @@ -4,18 +4,17 @@ \alias{LoadData} \title{Modularly load a dataset} \usage{ -LoadData(ds, type = c("info", "raw", "processed"), assays = NULL, - reductions = NULL, graphs = NULL, verbose = TRUE) +LoadData(ds, type = "default") } \arguments{ \item{ds}{Optional name of dataset to load} -\item{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} -}} +\item{type}{How to load the \code{Seurat} object; choose from either 'default' +for the default dataset or any dataset listed in the \code{default.dataset} +or \code{other.datasets} sections of the data manifest} +} +\value{ +A \code{Seurat} object with the dataset asked for } \description{ Modularly load a dataset diff --git a/man/SeuratData-package.Rd b/man/SeuratData-package.Rd index 18498c2..03f1925 100644 --- a/man/SeuratData-package.Rd +++ b/man/SeuratData-package.Rd @@ -40,12 +40,12 @@ Useful links: } \author{ -\strong{Maintainer}: Paul Hoffman \email{phoffman@nygenome.org} (0000-0002-7693-8957) +\strong{Maintainer}: Paul Hoffman \email{phoffman@nygenome.org} (\href{https://orcid.org/0000-0002-7693-8957}{ORCID}) Authors: \itemize{ - \item Rahul Satija \email{rsatija@nygenome.org} (0000-0001-9448-8833) - \item Andrew Butler \email{abutler@nygenome.org} (0000-0003-3608-0463) + \item Rahul Satija \email{rsatija@nygenome.org} (\href{https://orcid.org/0000-0001-9448-8833}{ORCID}) + \item Andrew Butler \email{abutler@nygenome.org} (\href{https://orcid.org/0000-0003-3608-0463}{ORCID}) } } diff --git a/man/UpdateData.Rd b/man/UpdateData.Rd index f389c41..b1b807a 100644 --- a/man/UpdateData.Rd +++ b/man/UpdateData.Rd @@ -12,7 +12,7 @@ UpdateData(ask = TRUE, lib.loc = NULL) string \code{"graphics"}, which brings up a widget to allow the user to (de-)select from the list of packages which could be updated. (The latter value only works on systems with a GUI version of - \code{\link{select.list}}, and is otherwise equivalent to + \code{\link[utils]{select.list}}, and is otherwise equivalent to \code{ask = TRUE}.) } From 4c40409249189a71a30a95f2b81b2d16a903abad Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Mon, 9 Dec 2019 19:48:00 -0500 Subject: [PATCH 2/3] Bump version information --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 29b2bbf..473f161 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: SeuratData Type: Package Title: Install and Manage Seurat Datasets -Version: 0.2.0 -Date: 2019-11-15 +Version: 0.2.1 +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')), person(given = 'Paul', family = 'Hoffman', email = 'phoffman@nygenome.org', role = c('aut', 'cre'), comment = c(ORCID = '0000-0002-7693-8957')), From 39967a13551b7657ebe57cd135adf99111e16f28 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Mon, 9 Dec 2019 20:10:24 -0500 Subject: [PATCH 3/3] More fixes for LoadData --- R/seurat_data.R | 28 +++++++++++++++------------- man/LoadData.Rd | 6 +++--- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/R/seurat_data.R b/R/seurat_data.R index 2eca95a..ea9ab2a 100644 --- a/R/seurat_data.R +++ b/R/seurat_data.R @@ -122,9 +122,9 @@ InstalledData <- function() { #' # @inheritParams LoadH5Seurat #' @param ds Optional name of dataset to load -#' @param type How to load the \code{Seurat} object; choose from either 'default' -#' for the default dataset or any dataset listed in the \code{default.dataset} -#' or \code{other.datasets} sections of the data manifest +#' @param type How to load the \code{Seurat} object; choose from either +#' 'default' for the default dataset or any dataset listed in the +#' \code{other.datasets} section of the data manifest # \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} @@ -153,20 +153,16 @@ LoadData <- function( stop("Cannot find dataset ", ds, call. = FALSE) } ds <- NameToPackage(ds = ds) - datasets <- trimws(x = unlist(x = strsplit( - x = na.omit(object = unlist( - x = installed[ds, c('default.dataset', 'other.datasets')], - use.names = FALSE - )), - split = ',' - ))) + datasets <- c( + installed[ds, 'default.dataset', drop = TRUE], + trimws(x = unlist(x = strsplit( + x = installed[ds, 'other.datasets', drop = TRUE], split = ',' + ))) + ) type <- match.arg( arg = tolower(x = type), choices = c('raw', 'default', datasets) ) - if (type %in% c('raw', 'default')) { - type <- datasets[1] - } if (type %in% c('raw', 'default')) { type <- gsub(pattern = pkg.key, replacement = '', x = ds) } else if (type == 'final') { @@ -179,6 +175,12 @@ LoadData <- function( # data(list = ds, envir = e) return(e[[type]]) } + stop( + "Could not find dataset '", + type, + "', please check manifest and try again", + call. = FALSE + ) .NotYetImplemented() # type <- match.arg(arg = type, choices = c('info', 'processed')) # return(LoadH5Seurat( diff --git a/man/LoadData.Rd b/man/LoadData.Rd index 5301a2d..4256610 100644 --- a/man/LoadData.Rd +++ b/man/LoadData.Rd @@ -9,9 +9,9 @@ LoadData(ds, type = "default") \arguments{ \item{ds}{Optional name of dataset to load} -\item{type}{How to load the \code{Seurat} object; choose from either 'default' -for the default dataset or any dataset listed in the \code{default.dataset} -or \code{other.datasets} sections of the data manifest} +\item{type}{How to load the \code{Seurat} object; choose from either +'default' for the default dataset or any dataset listed in the +\code{other.datasets} section of the data manifest} } \value{ A \code{Seurat} object with the dataset asked for