|
a |
|
b/R/downloadAndPrepareMetadata.R |
|
|
1 |
#' Download GEO metadata |
|
|
2 |
#' |
|
|
3 |
#' Function for downloading the metadata of a GEO dataset and prepare it for |
|
|
4 |
#' analysis. |
|
|
5 |
#' The function uses \code{getGEOSuppFiles} which downloads the data. The |
|
|
6 |
#' function then unzips the data files in the GEO series. |
|
|
7 |
#' |
|
|
8 |
#' @param geo_nbr The GEO ascession number. |
|
|
9 |
#' @param destdir The destination dir of the downloaded files. |
|
|
10 |
#' @param clean Should the strictly unnessesary files be deleted? |
|
|
11 |
#' @param verbose Signal the process. |
|
|
12 |
#' @return A \code{list} of \code{data.frame}s giving the clinical and metadata |
|
|
13 |
#' information for the GEO dataset. |
|
|
14 |
#' @note The function will overwrite existing files in the \code{destdir}. |
|
|
15 |
#' @author |
|
|
16 |
#' Anders Ellern Bilgrau, |
|
|
17 |
#' Steffen Falgreen Larsen |
|
|
18 |
#' @examples |
|
|
19 |
#' \dontrun{ |
|
|
20 |
#' print(DLBCL_overview) |
|
|
21 |
#' geo_nbr <- DLBCL_overview[6,1] |
|
|
22 |
#' downloadAndPrepareMetadata(geo_nbr = geo_nbr, destdir = getwd()) |
|
|
23 |
#' } |
|
|
24 |
#' @importFrom GEOquery getGEO |
|
|
25 |
#' @importFrom Biobase pData |
|
|
26 |
#' @keywords internal |
|
|
27 |
#' @export |
|
|
28 |
downloadAndPrepareMetadata <- function(geo_nbr, |
|
|
29 |
destdir = getwd(), |
|
|
30 |
clean = FALSE, |
|
|
31 |
verbose = TRUE) { |
|
|
32 |
if (verbose) message("Preparing ", geo_nbr, " metadata") |
|
|
33 |
|
|
|
34 |
# Download data if not already downloaded |
|
|
35 |
if (verbose) message("Downloading files...") |
|
|
36 |
dl_dir <- file.path(destdir, geo_nbr) |
|
|
37 |
dir.create(dl_dir, showWarnings = FALSE, recursive = TRUE) |
|
|
38 |
dl <- getGEO(GEO = geo_nbr, destdir = dl_dir, |
|
|
39 |
GSEMatrix = TRUE, getGPL = FALSE) |
|
|
40 |
|
|
|
41 |
# Extract pheno data |
|
|
42 |
if (!is.list(dl)) { |
|
|
43 |
|
|
|
44 |
pd <- pData(dl) |
|
|
45 |
|
|
|
46 |
} else { |
|
|
47 |
|
|
|
48 |
pd <- lapply(dl, pData) |
|
|
49 |
|
|
|
50 |
# Merge the dataframes (if multiple) |
|
|
51 |
merge2 <- function(x, y) { |
|
|
52 |
merge(x, y, all = TRUE, sort = FALSE) |
|
|
53 |
} |
|
|
54 |
pd <- Reduce(merge2, pd) |
|
|
55 |
|
|
|
56 |
} |
|
|
57 |
|
|
|
58 |
# Set class |
|
|
59 |
class(pd) <- c(geo_nbr, class(pd)) |
|
|
60 |
|
|
|
61 |
# Clean-up if wanted |
|
|
62 |
if (clean) { |
|
|
63 |
if (verbose) message("Removing unnessary files...") |
|
|
64 |
file.remove(file.path(destdir, geo_nbr, names(dl))) |
|
|
65 |
} |
|
|
66 |
|
|
|
67 |
if (verbose) message("Done.") |
|
|
68 |
return(invisible(pd)) |
|
|
69 |
} |
|
|
70 |
|