Skip to content

Commit 6bb99eb

Browse files
authored
Merge pull request #13 from satijalab/develop
SeuratData v0.2.0
2 parents 56a538f + ded404a commit 6bb99eb

19 files changed

Lines changed: 644 additions & 83 deletions

DESCRIPTION

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: SeuratData
22
Type: Package
33
Title: Install and Manage Seurat Datasets
4-
Version: 0.1.0
5-
Date: 2019-07-17
4+
Version: 0.2.0
5+
Date: 2019-11-15
66
Authors@R: c(
77
person(given = 'Rahul', family = 'Satija', email = 'rsatija@nygenome.org', role = 'aut', comment = c(ORCID = '0000-0001-9448-8833')),
88
person(given = 'Paul', family = 'Hoffman', email = 'phoffman@nygenome.org', role = c('aut', 'cre'), comment = c(ORCID = '0000-0002-7693-8957')),
@@ -18,11 +18,14 @@ License: GPL-3 | file LICENSE
1818
Encoding: UTF-8
1919
LazyData: true
2020
RoxygenNote: 6.1.1
21+
Depends:
22+
R (>= 3.5.0)
2123
Imports:
2224
cli,
2325
crayon,
26+
rappdirs,
2427
stats,
2528
utils
26-
Collate:
29+
Collate:
2730
'zzz.R'
2831
'seurat_data.R'

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export(AvailableData)
44
export(InstallData)
55
export(InstalledData)
6+
export(LoadData)
67
export(RemoveData)
78
export(UpdateData)
89
importFrom(cli,rule)
@@ -14,8 +15,10 @@ importFrom(crayon,col_nchar)
1415
importFrom(crayon,green)
1516
importFrom(crayon,red)
1617
importFrom(crayon,yellow)
18+
importFrom(rappdirs,user_data_dir)
1719
importFrom(stats,na.omit)
1820
importFrom(utils,available.packages)
21+
importFrom(utils,data)
1922
importFrom(utils,install.packages)
2023
importFrom(utils,packageVersion)
2124
importFrom(utils,remove.packages)

R/seurat_data.R

Lines changed: 107 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ NULL
1616
#'
1717
#' @export
1818
#'
19-
#' @seealso \code{\link{InstallData}} \code{\link{InstalledData}} \code{\link{RemoveData}} \code{\link{UpdateData}}
19+
#' @seealso \code{\link{InstallData}} \code{\link{InstalledData}}
20+
#' \code{\link{RemoveData}} \code{\link{UpdateData}}
21+
#'
22+
#' @examples
23+
#' AvailableData()
2024
#'
2125
AvailableData <- function() {
2226
UpdateManifest()
@@ -35,18 +39,30 @@ AvailableData <- function() {
3539
#'
3640
#' @export
3741
#'
38-
#' @seealso \code{\link{AvailableData}} \code{\link{InstalledData}} \code{\link{RemoveData}} \code{\link{UpdateData}}
42+
#' @seealso \code{\link{AvailableData}} \code{\link{InstalledData}}
43+
#' \code{\link{RemoveData}} \code{\link{UpdateData}}
44+
#'
45+
#' @examples
46+
#' \dontrun{
47+
#' InstallData('pbmc3k')
48+
#' }
3949
#'
4050
InstallData <- function(ds, force.reinstall = FALSE, ...) {
4151
UpdateManifest()
52+
if (pkg.env$source != 'remote') {
53+
stop(
54+
"No access to remote SeuratData repository, unable to install new datasets",
55+
call. = FALSE
56+
)
57+
}
4258
pkgs <- NameToPackage(ds = ds)
4359
if (!force.reinstall) {
4460
installed <- intersect(x = pkgs, y = rownames(x = InstalledData()))
4561
if (length(x = installed) > 0) {
4662
warning(
4763
"The following packages are already installed and will not be reinstalled: ",
4864
paste(
49-
gsub(pattern = '\\.SeuratData', replacement = '', x = installed),
65+
gsub(pattern = pkg.key, replacement = '', x = installed),
5066
collapse = ', '
5167
),
5268
call. = FALSE,
@@ -63,7 +79,12 @@ InstallData <- function(ds, force.reinstall = FALSE, ...) {
6379
for (p in pkgs2[pkgs2 %in% search()]) {
6480
detach(name = p, unload = TRUE, character.only = TRUE)
6581
}
66-
install.packages(pkgs = pkgs, repos = getOption(x = "SeuratData.repo.use"), type = 'source', ...)
82+
install.packages(
83+
pkgs = pkgs,
84+
repos = getOption(x = "SeuratData.repo.use"),
85+
type = 'source',
86+
...
87+
)
6788
for (pkg in pkgs) {
6889
attachNamespace(ns = pkg)
6990
pkg.env$attached <- c(pkg.env$attached, pkg)
@@ -86,13 +107,73 @@ InstallData <- function(ds, force.reinstall = FALSE, ...) {
86107
#'
87108
#' @export
88109
#'
89-
#' @seealso \code{\link{AvailableData}} \code{\link{InstallData}} \code{\link{RemoveData}} \code{\link{UpdateData}}
110+
#' @seealso \code{\link{AvailableData}} \code{\link{InstallData}}
111+
#' \code{\link{RemoveData}} \code{\link{UpdateData}}
112+
#'
113+
#' @examples
114+
#' InstalledData()
90115
#'
91116
InstalledData <- function() {
92117
dat <- AvailableData()
93118
return(dat[which(x = dat$Installed, ), , drop = FALSE])
94119
}
95120

121+
#' Modularly load a dataset
122+
#'
123+
#' @inheritParams LoadH5Seurat
124+
#' @param ds Optional name of dataset to load
125+
#' @param type How to load the \code{Seurat} object; choose from
126+
#' \describe{
127+
#' \item{info}{Information about the object and what's stored in it}
128+
#' \item{raw}{The raw form of the dataset, no other options are evaluated}
129+
#' \item{processed}{The proccessed data, modular loading avaible by setting other parameters}
130+
#' }
131+
#'
132+
#' @inherit LoadH5Seurat return
133+
#'
134+
#' @importFrom utils data
135+
#'
136+
#' @export
137+
#'
138+
#' @seealso \code{\link[utils]{data}}
139+
#'
140+
LoadData <- function(
141+
ds,
142+
type = c('info', 'raw', 'processed'),
143+
assays = NULL,
144+
reductions = NULL,
145+
graphs = NULL,
146+
verbose = TRUE
147+
) {
148+
.NotYetImplemented()
149+
installed <- InstalledData()
150+
if (!NameToPackage(ds = ds) %in% rownames(x = installed)) {
151+
stop("Cannot find dataset ", ds, call. = FALSE)
152+
}
153+
ds <- NameToPackage(ds = ds)
154+
type <- match.arg(arg = tolower(x = type), choices = c('info', 'raw', 'processed'))
155+
if (type == 'raw') {
156+
e <- new.env()
157+
ds <- gsub(pattern = '\\.SeuratData', replacement = '', x = ds)
158+
data(list = ds, envir = e)
159+
return(e[[ds]])
160+
}
161+
.NotYetImplemented()
162+
type <- match.arg(arg = type, choices = c('info', 'processed'))
163+
return(LoadH5Seurat(
164+
file = system.file(
165+
file.path('extdata', 'processed.h5Seurat'),
166+
package = ds,
167+
mustWork = TRUE
168+
),
169+
type = ifelse(test = type == 'processed', yes = 'object', no = type),
170+
assays = assays,
171+
reductions = reductions,
172+
graphs = graphs,
173+
verbose = verbose
174+
))
175+
}
176+
96177
#' Remove a dataset
97178
#'
98179
#' @inheritParams utils::remove.packages
@@ -102,7 +183,13 @@ InstalledData <- function() {
102183
#'
103184
#' @export
104185
#'
105-
#' @seealso \code{\link{AvailableData}} \code{\link{InstallData}} \code{\link{InstalledData}} \code{\link{UpdateData}}
186+
#' @seealso \code{\link{AvailableData}} \code{\link{InstallData}}
187+
#' \code{\link{InstalledData}} \code{\link{UpdateData}}
188+
#'
189+
#' @examples
190+
#' \dontrun{
191+
#' RemoveData('pbmc3k')
192+
#' }
106193
#'
107194
RemoveData <- function(ds, lib) {
108195
UpdateManifest()
@@ -125,9 +212,22 @@ RemoveData <- function(ds, lib) {
125212
#'
126213
#' @export
127214
#'
128-
#' @seealso \code{\link{AvailableData}} \code{\link{InstallData}} \code{\link{InstalledData}} \code{\link{RemoveData}}
215+
#' @seealso \code{\link{AvailableData}} \code{\link{InstallData}}
216+
#' \code{\link{InstalledData}} \code{\link{RemoveData}}
217+
#'
218+
#' @examples
219+
#' \dontrun{
220+
#' UpdateData(ask = FALSE)
221+
#' }
129222
#'
130223
UpdateData <- function(ask = TRUE, lib.loc = NULL) {
224+
UpdateManifest()
225+
if (pkg.env$source != 'remote') {
226+
stop(
227+
"No access to remote SeuratData repository, unable to update datasets",
228+
call. = FALSE
229+
)
230+
}
131231
update.packages(lib.loc = lib.loc, repos = getOption(x = "SeuratData.repo.use"), ask = ask, type = 'source')
132232
UpdateManifest()
133233
invisible(x = NULL)

0 commit comments

Comments
 (0)