|
a |
|
b/R/requireBrainarray.R |
|
|
1 |
#' Installs brainarray CDF and probe information packages |
|
|
2 |
#' |
|
|
3 |
#' This package downloads, installs, and/or loads the brainarray CDF and probe |
|
|
4 |
#' enviroments from the Brainarray website. |
|
|
5 |
#' |
|
|
6 |
#' @param array_type A character of length 1 giving the giving the name of the' |
|
|
7 |
#' array. (Preferably as returned by \code{affyio::read.celfile.header}) |
|
|
8 |
#' @param custom_cdf A charcter giving the annotation type. |
|
|
9 |
#' @param version A character of length 1 giving the version to download. |
|
|
10 |
#' @return Invisibly returns a list of the locations of the saved files. |
|
|
11 |
#' @author |
|
|
12 |
#' Steffen Falgreen, |
|
|
13 |
#' Anders Ellern Bilgrau |
|
|
14 |
#' @seealso \code{\link{tempdir}}, \code{\link{install.packages}} |
|
|
15 |
#' @references |
|
|
16 |
#' See \url{http://brainarray.mbni.med.umich.edu}. |
|
|
17 |
#' @examples |
|
|
18 |
#' tmp.path <- requireBrainarray("hgu133a", custom_cdf = "enst", |
|
|
19 |
#' version = "18.0.0") |
|
|
20 |
#' print(tmp.path) |
|
|
21 |
#' tmp.path2 <- requireBrainarray("hgu133a", custom_cdf = "enst") |
|
|
22 |
#' print(tmp.path2) |
|
|
23 |
#' @import AnnotationDbi |
|
|
24 |
#' @export |
|
|
25 |
requireBrainarray <- function(array_type, |
|
|
26 |
custom_cdf = "enst", |
|
|
27 |
version = getLatestVersion()) { |
|
|
28 |
output <- list() |
|
|
29 |
brain_dat <- output[["brain_dat"]] <- |
|
|
30 |
readBrainarrayTable(custom_cdf = custom_cdf, version = version) |
|
|
31 |
|
|
|
32 |
base_url <- attributes(brain_dat)$base_url |
|
|
33 |
if (getSubversion(version) >= 19) { |
|
|
34 |
base_url <- paste0("http://mbni.org/customcdf/", version, "/", |
|
|
35 |
tolower(custom_cdf)) |
|
|
36 |
} |
|
|
37 |
|
|
|
38 |
pkgs <- getBrainarrayPackages(brain_dat, array_type = array_type) |
|
|
39 |
|
|
|
40 |
for (pkg in pkgs) { |
|
|
41 |
loaded <- suppressWarnings(require(pkg, character.only = TRUE)) |
|
|
42 |
if (!loaded || packageVersion(pkg) != version) { |
|
|
43 |
if (loaded) { |
|
|
44 |
message("Installed package version is not ", version, |
|
|
45 |
". Overwriting installed package.", sep = "") |
|
|
46 |
} |
|
|
47 |
file.pkg <- paste0(pkg, "_", version, ".tar.gz") |
|
|
48 |
|
|
|
49 |
# Construct url and download package |
|
|
50 |
pkg_url <- file.path(paste0(base_url, ".download"), file.pkg) |
|
|
51 |
pkg_dest <- output[[pkg]] <- file.path(tempdir(), file.pkg) |
|
|
52 |
download.file(url = pkg_url, destfile = pkg_dest) |
|
|
53 |
|
|
|
54 |
# Install and load package |
|
|
55 |
install.packages(pkgs = pkg_dest, repos = NULL, type = "source") |
|
|
56 |
require(pkg, character.only = TRUE) |
|
|
57 |
} |
|
|
58 |
} |
|
|
59 |
|
|
|
60 |
return(invisible(output)) |
|
|
61 |
} |