annotate GRsetFromGEO/GRsetFromGEO.R @ 49:dc5539530e3a draft

Uploaded
author testtool
date Mon, 24 Apr 2017 11:47:32 -0400
parents 660897ee0d12
children 7aeee7c02c4d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42
4987433afb56 Uploaded
testtool
parents: 40
diff changeset
1 require("GEOquery", quietly = TRUE)
34
59a5237b72a3 Uploaded
testtool
parents:
diff changeset
2 require("minfi", quietly = TRUE)
36
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
3 require("FDb.InfiniumMethylation.hg19", quietly = TRUE)
34
59a5237b72a3 Uploaded
testtool
parents:
diff changeset
4
43
660897ee0d12 Uploaded
testtool
parents: 42
diff changeset
5 options(warn = -1)
660897ee0d12 Uploaded
testtool
parents: 42
diff changeset
6 options("download.file.method"="wget")
660897ee0d12 Uploaded
testtool
parents: 42
diff changeset
7
34
59a5237b72a3 Uploaded
testtool
parents:
diff changeset
8 args <- commandArgs(trailingOnly = TRUE)
59a5237b72a3 Uploaded
testtool
parents:
diff changeset
9 GSE = args[1]
59a5237b72a3 Uploaded
testtool
parents:
diff changeset
10 output = args[2]
59a5237b72a3 Uploaded
testtool
parents:
diff changeset
11
36
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
12 getAnnotationString <- function(annotation) {
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
13 if(length(annotation) == 1)
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
14 return(sprintf("%sanno", annotation))
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
15 if(all(c("array", "annotation") %in% names(annotation)))
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
16 return(sprintf("%sanno.%s", annotation["array"], annotation["annotation"]))
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
17 stop("unable to get the annotation string for this object")
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
18 }
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
19
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
20 default.450k.annotation <- "ilmn12.hg19"
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
21
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
22
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
23
37
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
24 array = "IlluminaHumanMethylation450k"
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
25 annotation = default.450k.annotation
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
26 what = c("Beta", "M")
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
27 mergeManifest = FALSE
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
28 i = 1
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
29
43
660897ee0d12 Uploaded
testtool
parents: 42
diff changeset
30 gset <- getGEO(GSE)
660897ee0d12 Uploaded
testtool
parents: 42
diff changeset
31
660897ee0d12 Uploaded
testtool
parents: 42
diff changeset
32 if (is.null(GSE)) {
660897ee0d12 Uploaded
testtool
parents: 42
diff changeset
33 stop("Must specify GSE")
660897ee0d12 Uploaded
testtool
parents: 42
diff changeset
34 } else {
660897ee0d12 Uploaded
testtool
parents: 42
diff changeset
35 options(download.file.method.GEOquery = "wget")}
660897ee0d12 Uploaded
testtool
parents: 42
diff changeset
36
37
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
37 gset <- gset[[1]]
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
38
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
39 platform <- annotation(gset)
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
40
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
41 ann <- getAnnotationString(c(array = array, annotation = annotation))
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
42 if (!require(ann, character.only = TRUE))
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
43 stop(sprintf("cannot load annotation package %s", ann))
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
44
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
45 object <- get(ann)
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
46
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
47 gr <- getLocations(object, mergeManifest = mergeManifest,
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
48 orderByLocation = TRUE)
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
49 locusNames <- names(gr)
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
50 sampleNames(gset) <- gset$title
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
51 common <- intersect(locusNames, fData(gset)$Name)
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
52 if (length(common) == 0) {
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
53 stop("No rowname matches. 'rownames' need to match IlluminaHumanMethylation450k probe names.")
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
54 ind1 <- match(common, fData(gset)$Name)
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
55 ind2 <- match(common, locusNames)
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
56 preprocessing <- c(rg.norm = paste0("See GEO ", GSE, " for details"))
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
57 if (what == "Beta") {
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
58 out <- GenomicRatioSet(gr = gr[ind2, ], Beta = exprs(gset)[ind1,
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
59 , drop = FALSE], M = NULL, CN = NULL, pData = pData(gset),
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
60 annotation = c(array = array, annotation = annotation),
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
61 preprocessMethod = preprocessing)
35
694382fd220a Uploaded
testtool
parents: 34
diff changeset
62 }
37
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
63 else {
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
64 out <- GenomicRatioSet(gr = gr[ind2, ], Beta = NULL,
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
65 M = exprs(gset)[ind1, , drop = FALSE], CN = NULL,
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
66 pData = pData(gset), annotation = c(array = array,
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
67 annotation = annotation), preprocessMethod = preprocessing)
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
68 }
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
69 return(out)
35
694382fd220a Uploaded
testtool
parents: 34
diff changeset
70 }
37
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
71 save(out,file = output)
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
72
c982fdb0e27d Uploaded
testtool
parents: 36
diff changeset
73