annotate GRsetFromGEO/GRsetFromGEO.R @ 36:b3761b109ca9 draft

Uploaded
author testtool
date Mon, 24 Apr 2017 08:50:59 -0400
parents 694382fd220a
children c982fdb0e27d
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("BiocGenerics", quietly = TRUE)
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
3 require("data.table", quietly = TRUE)
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
4 require("GEOquery", quietly = TRUE)
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
5 require("rtracklayer", quietly = TRUE)
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
6 require("FDb.InfiniumMethylation.hg19", quietly = TRUE)
34
59a5237b72a3 Uploaded
testtool
parents:
diff changeset
7
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
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
24 function (GSE = GSE, array = "IlluminaHumanMethylation450k", annotation = default.450k.annotation,
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
25 what = c("Beta", "M"), mergeManifest = FALSE, i = 1){
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
26
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
27
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
28 gset <- getGEO(GSE)
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
29 gset <- gset[[1]]
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
30
35
694382fd220a Uploaded
testtool
parents: 34
diff changeset
31 platform <- annotation(gset)
36
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
32
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
33 ann <- getAnnotationString(c(array = array, annotation = annotation))
35
694382fd220a Uploaded
testtool
parents: 34
diff changeset
34 if (!require(ann, character.only = TRUE))
694382fd220a Uploaded
testtool
parents: 34
diff changeset
35 stop(sprintf("cannot load annotation package %s", ann))
36
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
36
35
694382fd220a Uploaded
testtool
parents: 34
diff changeset
37 object <- get(ann)
36
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
38
35
694382fd220a Uploaded
testtool
parents: 34
diff changeset
39 gr <- getLocations(object, mergeManifest = mergeManifest,
694382fd220a Uploaded
testtool
parents: 34
diff changeset
40 orderByLocation = TRUE)
694382fd220a Uploaded
testtool
parents: 34
diff changeset
41 locusNames <- names(gr)
694382fd220a Uploaded
testtool
parents: 34
diff changeset
42 sampleNames(gset) <- gset$title
694382fd220a Uploaded
testtool
parents: 34
diff changeset
43 common <- intersect(locusNames, fData(gset)$Name)
36
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
44 if (length(common) == 0) {
35
694382fd220a Uploaded
testtool
parents: 34
diff changeset
45 stop("No rowname matches. 'rownames' need to match IlluminaHumanMethylation450k probe names.")
36
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
46 ind1 <- match(common, fData(gset)$Name)
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
47 ind2 <- match(common, locusNames)
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
48 preprocessing <- c(rg.norm = paste0("See GEO ", GSE, " for details"))
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
49 if (what == "Beta") {
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
50 out <- GenomicRatioSet(gr = gr[ind2, ], Beta = exprs(gset)[ind1,
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
51 , drop = FALSE], M = NULL, CN = NULL, pData = pData(gset),
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
52 annotation = c(array = array, annotation = annotation),
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
53 preprocessMethod = preprocessing)
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
54 }
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
55 else {
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
56 out <- GenomicRatioSet(gr = gr[ind2, ], Beta = NULL,
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
57 M = exprs(gset)[ind1, , drop = FALSE], CN = NULL,
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
58 pData = pData(gset), annotation = c(array = array,
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
59 annotation = annotation), preprocessMethod = preprocessing)
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
60 }
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
61 return(out)
35
694382fd220a Uploaded
testtool
parents: 34
diff changeset
62 }
36
b3761b109ca9 Uploaded
testtool
parents: 35
diff changeset
63 save(out,file = output)
35
694382fd220a Uploaded
testtool
parents: 34
diff changeset
64 }