annotate GRsetFromGEO/GRsetFromGEO.R @ 40:234e990e8e1d draft

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