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