... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
Package: MultiAssayExperimentData |
2 | 2 |
Title: Exposes and makes available data from web resources such as cBioPortal |
3 |
-Version: 0.99.33 |
|
3 |
+Version: 0.99.34 |
|
4 | 4 |
Authors@R: c(person("Levi", "Waldron", email = "[email protected]", |
5 | 5 |
role = "aut"), |
6 | 6 |
person("Marcel", "Ramos", email = "[email protected]", |
... | ... |
@@ -27,6 +27,6 @@ BugReports: https://github.com/waldronlab/MultiAssayExperimentData/issues |
27 | 27 |
RoxygenNote: 6.0.1 |
28 | 28 |
Collate: |
29 | 29 |
'MultiAssayExperimentData-pkg.R' |
30 |
+ 'cache.R' |
|
30 | 31 |
'utils.R' |
31 | 32 |
'importcBioPortal.R' |
32 |
- 'removeCache.R' |
8 | 10 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,78 @@ |
1 |
+#' @name cBio_cache |
|
2 |
+#' |
|
3 |
+#' @title Manage cache / download directories for study data |
|
4 |
+#' |
|
5 |
+#' @description Managing data downloads is important to save disk space and |
|
6 |
+#' re-downloading data files. This can be done effortlessly via the integrated |
|
7 |
+#' BiocFileCache system. |
|
8 |
+#' |
|
9 |
+#' @section setCache: |
|
10 |
+#' Specify the directory location of the data cache. By default, it will |
|
11 |
+#' got to the user's home directory and project directory as specified by |
|
12 |
+#' \link{user_cache_dir} |
|
13 |
+#' |
|
14 |
+#' @section removeCache: |
|
15 |
+#' Some files may become corrupt when downloading, this function allows |
|
16 |
+#' the user to delete the tarball associated with a `cancer_study_id`` |
|
17 |
+#' |
|
18 |
+#' @param cancer_study_id A single string from `studiesTable` associated |
|
19 |
+#' with a study tarball |
|
20 |
+#' @param directory The file location where the cache is located. Once set |
|
21 |
+#' future downloads will go to this folder. |
|
22 |
+#' |
|
23 |
+#' @md |
|
24 |
+#' |
|
25 |
+#' @export |
|
26 |
+removeCache <- function(cancer_study_id) { |
|
27 |
+ bfc <- .get_cache(TRUE) |
|
28 |
+ rid <- bfcquery(bfc, cancer_study_id, "rname")$rid |
|
29 |
+ if (length(rid)) { |
|
30 |
+ bfcremove(bfc, rid) |
|
31 |
+ message("Cache record: ", cancer_study_id, ".tar.gz removed") |
|
32 |
+ } else |
|
33 |
+ message("No record found: ", cancer_study_id, ".tar.gz") |
|
34 |
+} |
|
35 |
+ |
|
36 |
+#' @rdname cBio_cache |
|
37 |
+#' @export |
|
38 |
+setCache <- |
|
39 |
+function(directory = rappdirs::user_cache_dir("MultiAssayExperimentData"), |
|
40 |
+ verbose = TRUE, |
|
41 |
+ ask = interactive()) |
|
42 |
+{ |
|
43 |
+ create_path <- function(directory) { |
|
44 |
+ dir.create(directory, recursive = TRUE, showWarnings = FALSE) |
|
45 |
+ } |
|
46 |
+ |
|
47 |
+ stopifnot(is.character(directory), |
|
48 |
+ isSingleString(directory), !is.na(directory)) |
|
49 |
+ |
|
50 |
+ if (!ask) |
|
51 |
+ create_path(directory) |
|
52 |
+ else { |
|
53 |
+ qtxt <- sprintf( |
|
54 |
+ "Create MultiAssayExperimentData cache at \n %s? [y/n]: ", |
|
55 |
+ directory |
|
56 |
+ ) |
|
57 |
+ answer <- .getAnswer(qtxt, allowed = c("y", "Y", "n", "N")) |
|
58 |
+ if ("n" == answer) |
|
59 |
+ stop("'cBio_cache' directory will not be created") |
|
60 |
+ } |
|
61 |
+ create_path(directory) |
|
62 |
+ options("cBio_cache" = directory) |
|
63 |
+ |
|
64 |
+ if (verbose) |
|
65 |
+ message("MultiAssayExperimentData cache directory set to: ", |
|
66 |
+ directory) |
|
67 |
+ invisible(directory) |
|
68 |
+} |
|
69 |
+ |
|
70 |
+#' @rdname cBio_cache |
|
71 |
+#' @export |
|
72 |
+cBio_cache <- function() { |
|
73 |
+ cache_dir <- getOption("cBio_cache", setCache(verbose = FALSE)) |
|
74 |
+ if (!dir.exists(cache_dir)) |
|
75 |
+ setCache(cache_dir) |
|
76 |
+ |
|
77 |
+ return(cache_dir) |
|
78 |
+} |
0 | 79 |
deleted file mode 100644 |
... | ... |
@@ -1,20 +0,0 @@ |
1 |
-#' Delete downloaded study tarballs from cache |
|
2 |
-#' |
|
3 |
-#' Some files may become corrupt when downloading, this function allows |
|
4 |
-#' the user to delete the tarball associated with a `cancer_study_id`` |
|
5 |
-#' |
|
6 |
-#' @param cancer_study_id A single string from `studiesTable` associated |
|
7 |
-#' with a study tarball |
|
8 |
-#' |
|
9 |
-#' @md |
|
10 |
-#' |
|
11 |
-#' @export |
|
12 |
-removeCache <- function(cancer_study_id) { |
|
13 |
- bfc <- .get_cache(TRUE) |
|
14 |
- rid <- bfcquery(bfc, cancer_study_id, "rname")$rid |
|
15 |
- if (length(rid)) { |
|
16 |
- bfcremove(bfc, rid) |
|
17 |
- message("Cache record: ", cancer_study_id, ".tar.gz removed") |
|
18 |
- } else |
|
19 |
- message("No record found: ", cancer_study_id, ".tar.gz") |
|
20 |
-} |
... | ... |
@@ -120,3 +120,18 @@ |
120 | 120 |
samp <- RTCGAToolbox:::.findCol(coldat, "SAMPLE_ID") |
121 | 121 |
length(pt) && length(samp) |
122 | 122 |
} |
123 |
+ |
|
124 |
+.getAnswer <- function(msg, allowed) |
|
125 |
+{ |
|
126 |
+ if (interactive()) { |
|
127 |
+ repeat { |
|
128 |
+ cat(msg) |
|
129 |
+ answer <- readLines(n = 1) |
|
130 |
+ if (answer %in% allowed) |
|
131 |
+ break |
|
132 |
+ } |
|
133 |
+ tolower(answer) |
|
134 |
+ } else { |
|
135 |
+ "n" |
|
136 |
+ } |
|
137 |
+} |
123 | 138 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,41 @@ |
1 |
+% Generated by roxygen2: do not edit by hand |
|
2 |
+% Please edit documentation in R/cache.R |
|
3 |
+\name{cBio_cache} |
|
4 |
+\alias{cBio_cache} |
|
5 |
+\alias{removeCache} |
|
6 |
+\alias{setCache} |
|
7 |
+\alias{cBio_cache} |
|
8 |
+\title{Manage cache / download directories for study data} |
|
9 |
+\usage{ |
|
10 |
+removeCache(cancer_study_id) |
|
11 |
+ |
|
12 |
+setCache(directory = rappdirs::user_cache_dir("MultiAssayExperimentData"), |
|
13 |
+ verbose = TRUE, ask = interactive()) |
|
14 |
+ |
|
15 |
+cBio_cache() |
|
16 |
+} |
|
17 |
+\arguments{ |
|
18 |
+\item{cancer_study_id}{A single string from \code{studiesTable} associated |
|
19 |
+with a study tarball} |
|
20 |
+ |
|
21 |
+\item{directory}{The file location where the cache is located. Once set |
|
22 |
+future downloads will go to this folder.} |
|
23 |
+} |
|
24 |
+\description{ |
|
25 |
+Managing data downloads is important to save disk space and |
|
26 |
+re-downloading data files. This can be done effortlessly via the integrated |
|
27 |
+BiocFileCache system. |
|
28 |
+} |
|
29 |
+\section{setCache}{ |
|
30 |
+ |
|
31 |
+Specify the directory location of the data cache. By default, it will |
|
32 |
+got to the user's home directory and project directory as specified by |
|
33 |
+\link{user_cache_dir} |
|
34 |
+} |
|
35 |
+ |
|
36 |
+\section{removeCache}{ |
|
37 |
+ |
|
38 |
+Some files may become corrupt when downloading, this function allows |
|
39 |
+the user to delete the tarball associated with a `cancer_study_id`` |
|
40 |
+} |
|
41 |
+ |
0 | 42 |
deleted file mode 100644 |
... | ... |
@@ -1,16 +0,0 @@ |
1 |
-% Generated by roxygen2: do not edit by hand |
|
2 |
-% Please edit documentation in R/removeCache.R |
|
3 |
-\name{removeCache} |
|
4 |
-\alias{removeCache} |
|
5 |
-\title{Delete downloaded study tarballs from cache} |
|
6 |
-\usage{ |
|
7 |
-removeCache(cancer_study_id) |
|
8 |
-} |
|
9 |
-\arguments{ |
|
10 |
-\item{cancer_study_id}{A single string from \code{studiesTable} associated |
|
11 |
-with a study tarball} |
|
12 |
-} |
|
13 |
-\description{ |
|
14 |
-Some files may become corrupt when downloading, this function allows |
|
15 |
-the user to delete the tarball associated with a `cancer_study_id`` |
|
16 |
-} |