Mercurial > repos > iuc > ruvseq
annotate ruvseq.R @ 4:3a083c78896e draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 30117fce22f3771c9c0c13e70c3ad14b694de6e2
author | iuc |
---|---|
date | Fri, 21 Apr 2023 14:09:17 +0000 |
parents | fed9d0350d72 |
children |
rev | line source |
---|---|
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
1 # setup R error handling to go to stderr |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
2 library("getopt") |
4
3a083c78896e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 30117fce22f3771c9c0c13e70c3ad14b694de6e2
iuc
parents:
2
diff
changeset
|
3 options(show.error.messages = FALSE, error = function() { |
3a083c78896e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 30117fce22f3771c9c0c13e70c3ad14b694de6e2
iuc
parents:
2
diff
changeset
|
4 cat(geterrmessage(), file = stderr()) |
3a083c78896e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 30117fce22f3771c9c0c13e70c3ad14b694de6e2
iuc
parents:
2
diff
changeset
|
5 q("no", 1, FALSE) |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
6 }) |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
7 options(stringAsFactors = FALSE, useFancyQuotes = FALSE) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
8 |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
9 setup_cmdline_options <- function() { |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
10 args <- commandArgs(trailingOnly = TRUE) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
11 spec <- matrix(c( |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
12 "help", "h", 0, "logical", |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
13 "alpha", "a", 1, "double", |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
14 "min_mean_count", "min_c", 1, "double", |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
15 "min_k", "min_k", 1, "double", |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
16 "max_k", "max_k", 1, "double", |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
17 "sample_json", "s", 1, "character", |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
18 "plots", "p", 1, "character", |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
19 "header", "H", 0, "logical", |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
20 "txtype", "y", 1, "character", |
4
3a083c78896e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 30117fce22f3771c9c0c13e70c3ad14b694de6e2
iuc
parents:
2
diff
changeset
|
21 "tx2gene", "x", 1, "character", # a space-sep tx-to-gene map or GTF file (auto detect .gtf/.GTF) |
3a083c78896e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 30117fce22f3771c9c0c13e70c3ad14b694de6e2
iuc
parents:
2
diff
changeset
|
22 "ruv_ncounts", "ruv_ncounts", 0, "logical"), |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
23 byrow = TRUE, ncol = 4) |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
24 |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
25 opt <- getopt(spec) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
26 # if help was asked for print a friendly message |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
27 # and exit with a non-zero error code |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
28 if (!is.null(opt$help)) { |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
29 cat(getopt(spec, usage = TRUE)) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
30 q(status = 1) |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
31 } else { |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
32 load_libraries() |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
33 } |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
34 return(opt) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
35 } |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
36 |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
37 load_libraries <- function() { |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
38 # Allows displaying help without waiting for libraries to load |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
39 library("tools") |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
40 library("jsonlite") |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
41 library("reshape2") |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
42 library("RUVSeq") |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
43 library("RColorBrewer") |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
44 library("tximport") |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
45 library("DESeq2") |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
46 library("ggrepel") |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
47 } |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
48 |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
49 source_local <- function(fname) { |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
50 argv <- commandArgs(trailingOnly = FALSE) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
51 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
52 source(paste(base_dir, fname, sep = "/")) |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
53 } |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
54 |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
55 # Source get_deseq_dataset.R for getting deseq dataset from htseq/featurecounts/tximport |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
56 source_local("get_deseq_dataset.R") |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
57 |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
58 # RUVseq function definitions |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
59 |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
60 plot_pca_rle <- function(set, title) { |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
61 x <- pData(set)[, 1] |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
62 colors <- brewer.pal(3, "Set2") |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
63 label <- paste0(" for ", title) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
64 plotRLE(set, outline = FALSE, ylim = c(-4, 4), col = colors[x]) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
65 title(main = paste0("RLE", label)) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
66 plotPCA(set, col = colors[x], cex = 1.2) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
67 title(main = paste0("PCA", label)) |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
68 } |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
69 |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
70 plot_factors_of_unwanted_var <- function(set, method, k) { |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
71 pd <- pData(set) |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
72 pd["sample"] <- row.names(pd) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
73 colnames(pd)[1] <- "condition" |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
74 d <- melt(pd, id.vars = c("sample", "condition")) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
75 d["x"] <- 1 # There is no information on the X, so we just fake it to be able to do a scatterplot |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
76 print(ggplot(d, aes(x = x, y = value, color = condition, label = sample)) + |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
77 geom_point() + |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
78 ggtitle(paste0("Factors of unwanted variation for method: ", method, ", k=", k)) + |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
79 facet_wrap(~ variable, scales = "free_x") + |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
80 geom_text_repel() + |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
81 theme(axis.title.x = element_blank(), |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
82 axis.text.x = element_blank(), |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
83 axis.ticks.x = element_blank(), |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
84 plot.title = element_text(hjust = 0.5)) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
85 ) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
86 } |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
87 |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
88 create_seq_expression_set <- function(dds, min_mean_count) { |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
89 count_values <- counts(dds) |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
90 print(paste0("feature count before filtering :", nrow(count_values), "\n")) |
1
c24765926774
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 9ed3d83cc447ee897af867362bf1dd67af8a11c2
iuc
parents:
0
diff
changeset
|
91 print(paste0("Filtering features which mean expression is less or eq. than ", min_mean_count, " counts\n")) |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
92 filter <- apply(count_values, 1, function(x) mean(x) > min_mean_count) |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
93 filtered <- count_values[filter, ] |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
94 print(paste0("feature count after filtering :", nrow(filtered), "\n")) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
95 set <- newSeqExpressionSet(as.matrix(filtered), |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
96 phenoData = data.frame(colData(dds)$condition, row.names = colnames(filtered))) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
97 plot_pca_rle(set = set, title = "raw data") |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
98 set <- betweenLaneNormalization(set, which = "upper") |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
99 plot_pca_rle(set = set, title = "upper quartile normalized") |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
100 return(set) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
101 } |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
102 |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
103 get_empirical_control_genes <- function(set, cutoff_p) { |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
104 x <- pData(set)[, 1] |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
105 design <- model.matrix(~x, data = pData(set)) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
106 y <- DGEList(counts = counts(set), group = x) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
107 y <- calcNormFactors(y, method = "upperquartile") |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
108 y <- estimateGLMCommonDisp(y, design) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
109 y <- estimateGLMTagwiseDisp(y, design) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
110 fit <- glmFit(y, design) |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
111 lrt <- glmLRT(fit, coef = 2) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
112 top <- topTags(lrt, n = nrow(set))$table |
1
c24765926774
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 9ed3d83cc447ee897af867362bf1dd67af8a11c2
iuc
parents:
0
diff
changeset
|
113 top_rows <- rownames(top)[which(top$PValue < cutoff_p)] |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
114 empirical <- rownames(set)[which(!(rownames(set) %in% top_rows))] |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
115 return(empirical) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
116 } |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
117 |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
118 ruv_control_gene_method <- function(set, k, control_genes = "empirical", cutoff_p = 0.2) { |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
119 if (control_genes == "empirical") { |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
120 control_genes <- get_empirical_control_genes(set, cutoff_p = cutoff_p) |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
121 } |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
122 set <- RUVg(set, control_genes, k = k) |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
123 plot_pca_rle(set, paste0("RUVg with empirical control genes, k=", k)) |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
124 plot_factors_of_unwanted_var(set, method = "RUVg with empirical control genes", k = k) |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
125 return(set) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
126 } |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
127 |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
128 ruv_residual_method <- function(set, k) { |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
129 genes <- rownames(counts(set)) |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
130 x <- pData(set)[, 1] |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
131 # Initial edger residuals |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
132 design <- model.matrix(~x, data = pData(set)) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
133 y <- DGEList(counts = counts(set), group = x) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
134 y <- calcNormFactors(y, method = "upperquartile") |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
135 y <- estimateGLMCommonDisp(y, design) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
136 y <- estimateGLMTagwiseDisp(y, design) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
137 fit <- glmFit(y, design) |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
138 res <- residuals(fit, type = "deviance") |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
139 set <- RUVr(set, genes, k = k, res) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
140 plot_pca_rle(set = set, title = paste0("RUVr using residuals, k=", k)) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
141 plot_factors_of_unwanted_var(set, method = "RUVr using residuals", k = k) |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
142 return(set) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
143 } |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
144 |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
145 ruv_replicate_method <- function(set, k) { |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
146 genes <- rownames(counts(set)) |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
147 x <- pData(set)[, 1] |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
148 differences <- makeGroups(x) |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
149 set <- RUVs(set, genes, k = k, differences) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
150 plot_pca_rle(set, paste0("RUVs with replicate samples, k=", k)) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
151 plot_factors_of_unwanted_var(set, method = "RUVs using replicates", k = k) |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
152 return(set) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
153 } |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
154 |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
155 opt <- setup_cmdline_options() |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
156 alpha <- opt$alpha |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
157 min_k <- opt$min_k |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
158 max_k <- opt$max_k |
1
c24765926774
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 9ed3d83cc447ee897af867362bf1dd67af8a11c2
iuc
parents:
0
diff
changeset
|
159 min_c <- opt$min_mean_count |
4
3a083c78896e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 30117fce22f3771c9c0c13e70c3ad14b694de6e2
iuc
parents:
2
diff
changeset
|
160 ruv_ncounts <- ifelse(is.null(opt$ruv_ncounts), FALSE, TRUE) |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
161 sample_json <- fromJSON(opt$sample_json) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
162 sample_paths <- sample_json$path |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
163 sample_names <- sample_json$label |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
164 condition <- as.factor(sample_json$condition) |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
165 sample_table <- data.frame(samplename = sample_names, filename = sample_paths, condition = condition) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
166 rownames(sample_table) <- sample_names |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
167 |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
168 dds <- get_deseq_dataset(sample_table, header = opt$header, design_formula = ~ condition, tximport = opt$txtype, txtype = opt$txtype, tx2gene = opt$tx2gene) |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
169 if (!is.null(opt$plots)) { |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
170 pdf(opt$plots) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
171 } |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
172 |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
173 # Run through the ruvseq variants |
1
c24765926774
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 9ed3d83cc447ee897af867362bf1dd67af8a11c2
iuc
parents:
0
diff
changeset
|
174 set <- create_seq_expression_set(dds, min_mean_count = min_c) |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
175 result <- list(no_correction = set) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
176 for (k in seq(min_k, max_k)) { |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
177 result[[paste0("residual_method_k", k)]] <- ruv_residual_method(set, k = k) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
178 result[[paste0("replicate_method_k", k)]] <- ruv_replicate_method(set, k = k) |
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
179 result[[paste0("control_method_k", k)]] <- ruv_control_gene_method(set, k = k, cutoff_p = 0.5) |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
180 } |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
181 |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
182 for (name in names(result)) { |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
183 if (!startsWith(name, "no_correction")) { |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
184 set <- result[[name]] |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
185 unwanted_variation <- pData(set) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
186 df <- data.frame(identifier = rownames(unwanted_variation)) |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
187 df <- cbind(df, unwanted_variation) |
2
fed9d0350d72
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 4daa375d022673d2437d609b1865b78c64b04415"
iuc
parents:
1
diff
changeset
|
188 colnames(df)[2] <- "condition" |
4
3a083c78896e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 30117fce22f3771c9c0c13e70c3ad14b694de6e2
iuc
parents:
2
diff
changeset
|
189 write.table(df, file = paste0("uv_batch_effects_", name, ".tabular"), sep = "\t", quote = FALSE, row.names = FALSE) |
3a083c78896e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 30117fce22f3771c9c0c13e70c3ad14b694de6e2
iuc
parents:
2
diff
changeset
|
190 if (ruv_ncounts) { |
3a083c78896e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 30117fce22f3771c9c0c13e70c3ad14b694de6e2
iuc
parents:
2
diff
changeset
|
191 ruvnorm_counts <- normCounts(set) |
3a083c78896e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 30117fce22f3771c9c0c13e70c3ad14b694de6e2
iuc
parents:
2
diff
changeset
|
192 ruvnorm_df <- data.frame(geneID = rownames(ruvnorm_counts), ruvnorm_counts) |
3a083c78896e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 30117fce22f3771c9c0c13e70c3ad14b694de6e2
iuc
parents:
2
diff
changeset
|
193 write.table(ruvnorm_df, file = paste0("ruv_norm_counts_", name, ".tabular"), sep = "\t", quote = FALSE, row.names = FALSE) |
3a083c78896e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 30117fce22f3771c9c0c13e70c3ad14b694de6e2
iuc
parents:
2
diff
changeset
|
194 } |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
195 } |
4
3a083c78896e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 30117fce22f3771c9c0c13e70c3ad14b694de6e2
iuc
parents:
2
diff
changeset
|
196 |
0
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
197 } |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
198 |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
199 # close the plot device |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
200 if (!is.null(opt$plots)) { |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
201 cat("closing plot device\n") |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
202 dev.off() |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
203 } |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
204 |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
205 cat("Session information:\n\n") |
61dffb20b6f9
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents:
diff
changeset
|
206 sessionInfo() |