annotate GRsetFromGEO/GRsetFromGEO.R @ 35:694382fd220a draft

Uploaded
author testtool
date Fri, 14 Apr 2017 14:16:46 -0400
parents 59a5237b72a3
children b3761b109ca9
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)
59a5237b72a3 Uploaded
testtool
parents:
diff changeset
2
59a5237b72a3 Uploaded
testtool
parents:
diff changeset
3 args <- commandArgs(trailingOnly = TRUE)
59a5237b72a3 Uploaded
testtool
parents:
diff changeset
4 GSE = args[1]
59a5237b72a3 Uploaded
testtool
parents:
diff changeset
5 output = args[2]
59a5237b72a3 Uploaded
testtool
parents:
diff changeset
6
35
694382fd220a Uploaded
testtool
parents: 34
diff changeset
7 function (GSE = NULL, path = NULL, array = "IlluminaHumanMethylation450k",
694382fd220a Uploaded
testtool
parents: 34
diff changeset
8 annotation = .default.450k.annotation, what = c("Beta", "M"),
694382fd220a Uploaded
testtool
parents: 34
diff changeset
9 mergeManifest = FALSE, i = 1)
694382fd220a Uploaded
testtool
parents: 34
diff changeset
10 {
694382fd220a Uploaded
testtool
parents: 34
diff changeset
11 what <- match.arg(what)
694382fd220a Uploaded
testtool
parents: 34
diff changeset
12 if (is.null(GSE) && is.null(path))
694382fd220a Uploaded
testtool
parents: 34
diff changeset
13 stop("Either GSE or path must be supplied.")
694382fd220a Uploaded
testtool
parents: 34
diff changeset
14 if (!is.null(GSE))
694382fd220a Uploaded
testtool
parents: 34
diff changeset
15 gset <- GEOquery::getGEO(GSE)
694382fd220a Uploaded
testtool
parents: 34
diff changeset
16 else gset <- GEOquery::getGEO(filename = file.path(path,
694382fd220a Uploaded
testtool
parents: 34
diff changeset
17 list.files(path, pattern = ".soft")))
694382fd220a Uploaded
testtool
parents: 34
diff changeset
18 if (length(gset) == 0)
694382fd220a Uploaded
testtool
parents: 34
diff changeset
19 stop("Empty list retrieved from GEO.")
694382fd220a Uploaded
testtool
parents: 34
diff changeset
20 if (length(gset) > 1) {
694382fd220a Uploaded
testtool
parents: 34
diff changeset
21 warning("More than one ExpressionSet found:\n", names(gset),
694382fd220a Uploaded
testtool
parents: 34
diff changeset
22 "\nUsing entry ", i)
694382fd220a Uploaded
testtool
parents: 34
diff changeset
23 gset <- gset[[i]]
694382fd220a Uploaded
testtool
parents: 34
diff changeset
24 }
694382fd220a Uploaded
testtool
parents: 34
diff changeset
25 else gset <- gset[[1]]
694382fd220a Uploaded
testtool
parents: 34
diff changeset
26 platform <- annotation(gset)
694382fd220a Uploaded
testtool
parents: 34
diff changeset
27 if (platform != "GPL13534")
694382fd220a Uploaded
testtool
parents: 34
diff changeset
28 warning(sprintf("%s is not the platform ID associated with IlluminaHumanMethylation450k. Should be GPL13534.",
694382fd220a Uploaded
testtool
parents: 34
diff changeset
29 platform))
694382fd220a Uploaded
testtool
parents: 34
diff changeset
30 if (what == "Beta" & (min(exprs(gset)[, 1], na.rm = TRUE) <
694382fd220a Uploaded
testtool
parents: 34
diff changeset
31 0 | max(exprs(gset)[, 1], na.rm = TRUE) > 1))
694382fd220a Uploaded
testtool
parents: 34
diff changeset
32 warning("Values outside [0,1] detected. 'what' argument should not be Beta.")
694382fd220a Uploaded
testtool
parents: 34
diff changeset
33 ann <- .getAnnotationString(c(array = array, annotation = annotation))
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))
694382fd220a Uploaded
testtool
parents: 34
diff changeset
36 object <- get(ann)
694382fd220a Uploaded
testtool
parents: 34
diff changeset
37 gr <- getLocations(object, mergeManifest = mergeManifest,
694382fd220a Uploaded
testtool
parents: 34
diff changeset
38 orderByLocation = TRUE)
694382fd220a Uploaded
testtool
parents: 34
diff changeset
39 locusNames <- names(gr)
694382fd220a Uploaded
testtool
parents: 34
diff changeset
40 sampleNames(gset) <- gset$title
694382fd220a Uploaded
testtool
parents: 34
diff changeset
41 common <- intersect(locusNames, fData(gset)$Name)
694382fd220a Uploaded
testtool
parents: 34
diff changeset
42 if (length(common) == 0)
694382fd220a Uploaded
testtool
parents: 34
diff changeset
43 stop("No rowname matches. 'rownames' need to match IlluminaHumanMethylation450k probe names.")
694382fd220a Uploaded
testtool
parents: 34
diff changeset
44 ind1 <- match(common, fData(gset)$Name)
694382fd220a Uploaded
testtool
parents: 34
diff changeset
45 ind2 <- match(common, locusNames)
694382fd220a Uploaded
testtool
parents: 34
diff changeset
46 preprocessing <- c(rg.norm = paste0("See GEO ", GSE, " for details"))
694382fd220a Uploaded
testtool
parents: 34
diff changeset
47 if (what == "Beta") {
694382fd220a Uploaded
testtool
parents: 34
diff changeset
48 out <- GenomicRatioSet(gr = gr[ind2, ], Beta = exprs(gset)[ind1,
694382fd220a Uploaded
testtool
parents: 34
diff changeset
49 , drop = FALSE], M = NULL, CN = NULL, pData = pData(gset),
694382fd220a Uploaded
testtool
parents: 34
diff changeset
50 annotation = c(array = array, annotation = annotation),
694382fd220a Uploaded
testtool
parents: 34
diff changeset
51 preprocessMethod = preprocessing)
694382fd220a Uploaded
testtool
parents: 34
diff changeset
52 }
694382fd220a Uploaded
testtool
parents: 34
diff changeset
53 else {
694382fd220a Uploaded
testtool
parents: 34
diff changeset
54 out <- GenomicRatioSet(gr = gr[ind2, ], Beta = NULL,
694382fd220a Uploaded
testtool
parents: 34
diff changeset
55 M = exprs(gset)[ind1, , drop = FALSE], CN = NULL,
694382fd220a Uploaded
testtool
parents: 34
diff changeset
56 pData = pData(gset), annotation = c(array = array,
694382fd220a Uploaded
testtool
parents: 34
diff changeset
57 annotation = annotation), preprocessMethod = preprocessing)
694382fd220a Uploaded
testtool
parents: 34
diff changeset
58 }
694382fd220a Uploaded
testtool
parents: 34
diff changeset
59 save(out,output)
694382fd220a Uploaded
testtool
parents: 34
diff changeset
60 }