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
|
37
|
24 array = "IlluminaHumanMethylation450k"
|
|
25 annotation = default.450k.annotation
|
|
26 what = c("Beta", "M")
|
|
27 mergeManifest = FALSE
|
|
28 i = 1
|
|
29
|
|
30 gset <- getGEO(GSE)
|
|
31 gset <- gset[[1]]
|
|
32
|
|
33 platform <- annotation(gset)
|
|
34
|
|
35 ann <- getAnnotationString(c(array = array, annotation = annotation))
|
|
36 if (!require(ann, character.only = TRUE))
|
|
37 stop(sprintf("cannot load annotation package %s", ann))
|
|
38
|
|
39 object <- get(ann)
|
|
40
|
|
41 gr <- getLocations(object, mergeManifest = mergeManifest,
|
|
42 orderByLocation = TRUE)
|
|
43 locusNames <- names(gr)
|
|
44 sampleNames(gset) <- gset$title
|
|
45 common <- intersect(locusNames, fData(gset)$Name)
|
|
46 if (length(common) == 0) {
|
|
47 stop("No rowname matches. 'rownames' need to match IlluminaHumanMethylation450k probe names.")
|
|
48 ind1 <- match(common, fData(gset)$Name)
|
|
49 ind2 <- match(common, locusNames)
|
|
50 preprocessing <- c(rg.norm = paste0("See GEO ", GSE, " for details"))
|
|
51 if (what == "Beta") {
|
|
52 out <- GenomicRatioSet(gr = gr[ind2, ], Beta = exprs(gset)[ind1,
|
|
53 , drop = FALSE], M = NULL, CN = NULL, pData = pData(gset),
|
|
54 annotation = c(array = array, annotation = annotation),
|
|
55 preprocessMethod = preprocessing)
|
35
|
56 }
|
37
|
57 else {
|
|
58 out <- GenomicRatioSet(gr = gr[ind2, ], Beta = NULL,
|
|
59 M = exprs(gset)[ind1, , drop = FALSE], CN = NULL,
|
|
60 pData = pData(gset), annotation = c(array = array,
|
|
61 annotation = annotation), preprocessMethod = preprocessing)
|
|
62 }
|
|
63 return(out)
|
35
|
64 }
|
37
|
65 save(out,file = output)
|
|
66
|
|
67
|