annotate GRsetFromGEO/GRsetFromGEO.R @ 37:c982fdb0e27d draft

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