34
|
1 require("minfi", quietly = TRUE)
|
36
|
2 require("BiocGenerics", quietly = TRUE)
|
|
3 require("data.table", quietly = TRUE)
|
|
4 require("GEOquery", quietly = TRUE)
|
|
5 require("rtracklayer", quietly = TRUE)
|
|
6 require("FDb.InfiniumMethylation.hg19", quietly = TRUE)
|
34
|
7
|
|
8 args <- commandArgs(trailingOnly = TRUE)
|
|
9 GSE = args[1]
|
|
10 output = args[2]
|
|
11
|
36
|
12 getAnnotationString <- function(annotation) {
|
|
13 if(length(annotation) == 1)
|
|
14 return(sprintf("%sanno", annotation))
|
|
15 if(all(c("array", "annotation") %in% names(annotation)))
|
|
16 return(sprintf("%sanno.%s", annotation["array"], annotation["annotation"]))
|
|
17 stop("unable to get the annotation string for this object")
|
|
18 }
|
|
19
|
|
20 default.450k.annotation <- "ilmn12.hg19"
|
|
21
|
|
22
|
|
23
|
|
24 function (GSE = GSE, array = "IlluminaHumanMethylation450k", annotation = default.450k.annotation,
|
|
25 what = c("Beta", "M"), mergeManifest = FALSE, i = 1){
|
|
26
|
|
27
|
|
28 gset <- getGEO(GSE)
|
|
29 gset <- gset[[1]]
|
|
30
|
35
|
31 platform <- annotation(gset)
|
36
|
32
|
|
33 ann <- getAnnotationString(c(array = array, annotation = annotation))
|
35
|
34 if (!require(ann, character.only = TRUE))
|
|
35 stop(sprintf("cannot load annotation package %s", ann))
|
36
|
36
|
35
|
37 object <- get(ann)
|
36
|
38
|
35
|
39 gr <- getLocations(object, mergeManifest = mergeManifest,
|
|
40 orderByLocation = TRUE)
|
|
41 locusNames <- names(gr)
|
|
42 sampleNames(gset) <- gset$title
|
|
43 common <- intersect(locusNames, fData(gset)$Name)
|
36
|
44 if (length(common) == 0) {
|
35
|
45 stop("No rowname matches. 'rownames' need to match IlluminaHumanMethylation450k probe names.")
|
36
|
46 ind1 <- match(common, fData(gset)$Name)
|
|
47 ind2 <- match(common, locusNames)
|
|
48 preprocessing <- c(rg.norm = paste0("See GEO ", GSE, " for details"))
|
|
49 if (what == "Beta") {
|
|
50 out <- GenomicRatioSet(gr = gr[ind2, ], Beta = exprs(gset)[ind1,
|
|
51 , drop = FALSE], M = NULL, CN = NULL, pData = pData(gset),
|
|
52 annotation = c(array = array, annotation = annotation),
|
|
53 preprocessMethod = preprocessing)
|
|
54 }
|
|
55 else {
|
|
56 out <- GenomicRatioSet(gr = gr[ind2, ], Beta = NULL,
|
|
57 M = exprs(gset)[ind1, , drop = FALSE], CN = NULL,
|
|
58 pData = pData(gset), annotation = c(array = array,
|
|
59 annotation = annotation), preprocessMethod = preprocessing)
|
|
60 }
|
|
61 return(out)
|
35
|
62 }
|
36
|
63 save(out,file = output)
|
35
|
64 }
|