annotate deseq2.R @ 31:9a882d108833 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
author iuc
date Tue, 18 Jul 2023 14:58:52 +0000
parents 8fe98f7094de
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
1 #!/usr/bin/env Rscript
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
2
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
3 # A command-line interface to DESeq2 for use with Galaxy
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
4 # written by Bjoern Gruening and modified by Michael Love 2016.03.30
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
5 #
14
d0c39b5e78cf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 12
diff changeset
6 # This argument is required:
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
7 #
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
8 # 'factors' a JSON list object from Galaxy
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
9 #
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
10 # the output file has columns:
15
9a616afdbda5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 83eb5b2665d87c02b270596f8175499e69061032
iuc
parents: 14
diff changeset
11 #
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
12 # baseMean (mean normalized count)
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
13 # log2FoldChange (by default a moderated LFC estimate)
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
14 # lfcSE (the standard error)
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
15 # stat (the Wald statistic)
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
16 # pvalue (p-value from comparison of Wald statistic to a standard Normal)
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
17 # padj (adjusted p-value, Benjamini Hochberg correction on genes which pass the mean count filter)
15
9a616afdbda5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 83eb5b2665d87c02b270596f8175499e69061032
iuc
parents: 14
diff changeset
18 #
14
d0c39b5e78cf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 12
diff changeset
19 # the first variable in 'factors' will be the primary factor.
d0c39b5e78cf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 12
diff changeset
20 # the levels of the primary factor are used in the order of appearance in factors.
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
21 #
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
22 # by default, levels in the order A,B,C produces a single comparison of B vs A, to a single file 'outfile'
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
23 #
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
24 # for the 'many_contrasts' flag, levels in the order A,B,C produces comparisons C vs A, B vs A, C vs B,
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
25 # to a number of files using the 'outfile' prefix: 'outfile.condition_C_vs_A' etc.
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
26 # all plots will still be sent to a single PDF, named by the arg 'plots', with extra pages.
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
27 #
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
28 # fit_type is an integer valued argument, with the options from ?estimateDisperions
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
29 # 1 "parametric"
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
30 # 2 "local"
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
31 # 3 "mean"
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
32
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
33 # setup R error handling to go to stderr
30
8fe98f7094de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 6868b66f73ddbe947986d1a20b546873cbd515a9
iuc
parents: 29
diff changeset
34 options(show.error.messages = FALSE, error = function() {
8fe98f7094de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 6868b66f73ddbe947986d1a20b546873cbd515a9
iuc
parents: 29
diff changeset
35 cat(geterrmessage(), file = stderr())
8fe98f7094de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 6868b66f73ddbe947986d1a20b546873cbd515a9
iuc
parents: 29
diff changeset
36 q("no", 1, FALSE)
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
37 })
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
38
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
39 library("getopt")
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
40 library("tools")
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
41 options(stringAsFactors = FALSE, useFancyQuotes = FALSE)
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
42 args <- commandArgs(trailingOnly = TRUE)
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
43
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
44 # get options, using the spec as defined by the enclosed list.
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
45 # we read the options from the default: commandArgs(TRUE).
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
46 spec <- matrix(c(
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
47 "quiet", "q", 0, "logical",
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
48 "help", "h", 0, "logical",
21
a6fc9228e1a0 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 05bc13637dc9f8e523bc72844ff6eb0794f98ad3
iuc
parents: 19
diff changeset
49 "cores", "s", 0, "integer",
a6fc9228e1a0 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 05bc13637dc9f8e523bc72844ff6eb0794f98ad3
iuc
parents: 19
diff changeset
50 "batch_factors", "w", 1, "character",
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
51 "outfile", "o", 1, "character",
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
52 "countsfile", "n", 1, "character",
29
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
53 "sizefactorsfile", "F", 1, "character",
18
3bf1b3ec1ddf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 448dccb0c02aba00d8301247b0f0f406ab3d4fa2
iuc
parents: 17
diff changeset
54 "rlogfile", "r", 1, "character",
3bf1b3ec1ddf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 448dccb0c02aba00d8301247b0f0f406ab3d4fa2
iuc
parents: 17
diff changeset
55 "vstfile", "v", 1, "character",
15
9a616afdbda5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 83eb5b2665d87c02b270596f8175499e69061032
iuc
parents: 14
diff changeset
56 "header", "H", 0, "logical",
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
57 "factors", "f", 1, "character",
12
bd06df00180a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 11
diff changeset
58 "files_to_labels", "l", 1, "character",
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
59 "plots", "p", 1, "character",
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
60 "tximport", "i", 0, "logical",
11
25204a860b79 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 0a56599c36b4968095ec5a3cb589f94fb139466c
iuc
parents: 9
diff changeset
61 "txtype", "y", 1, "character",
19
c56e0689e46e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 5b6dc96c6e14582d5bb1dc213ac8d26dc7b2829e
iuc
parents: 18
diff changeset
62 "tx2gene", "x", 1, "character", # a space-sep tx-to-gene map or GTF/GFF3 file
18
3bf1b3ec1ddf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 448dccb0c02aba00d8301247b0f0f406ab3d4fa2
iuc
parents: 17
diff changeset
63 "esf", "e", 1, "character",
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
64 "fit_type", "t", 1, "integer",
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
65 "many_contrasts", "m", 0, "logical",
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
66 "outlier_replace_off", "a", 0, "logical",
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
67 "outlier_filter_off", "b", 0, "logical",
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
68 "auto_mean_filter_off", "c", 0, "logical",
31
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
69 "use_beta_priors", "d", 0, "logical",
30
8fe98f7094de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 6868b66f73ddbe947986d1a20b546873cbd515a9
iuc
parents: 29
diff changeset
70 "alpha_ma", "A", 1, "numeric",
8fe98f7094de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 6868b66f73ddbe947986d1a20b546873cbd515a9
iuc
parents: 29
diff changeset
71 "prefilter", "P", 0, "logical",
8fe98f7094de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 6868b66f73ddbe947986d1a20b546873cbd515a9
iuc
parents: 29
diff changeset
72 "prefilter_value", "V", 1, "numeric"
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
73 ), byrow = TRUE, ncol = 4)
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
74 opt <- getopt(spec)
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
75
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
76 # if help was asked for print a friendly message
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
77 # and exit with a non-zero error code
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
78 if (!is.null(opt$help)) {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
79 cat(getopt(spec, usage = TRUE))
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
80 q(status = 1)
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
81 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
82
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
83 # enforce the following required arguments
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
84 if (is.null(opt$outfile)) {
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
85 cat("'outfile' is required\n")
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
86 q(status = 1)
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
87 }
14
d0c39b5e78cf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 12
diff changeset
88 if (is.null(opt$factors)) {
d0c39b5e78cf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 12
diff changeset
89 cat("'factors' is required\n")
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
90 q(status = 1)
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
91 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
92
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
93 verbose <- is.null(opt$quiet)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
94
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
95 source_local <- function(fname) {
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
96 argv <- commandArgs(trailingOnly = FALSE)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
97 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
98 source(paste(base_dir, fname, sep = "/"))
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
99 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
100
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
101 source_local("get_deseq_dataset.R")
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
102
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
103 suppressPackageStartupMessages({
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
104 library("DESeq2")
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
105 library("RColorBrewer")
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
106 library("gplots")
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
107 })
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
108
21
a6fc9228e1a0 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 05bc13637dc9f8e523bc72844ff6eb0794f98ad3
iuc
parents: 19
diff changeset
109 if (opt$cores > 1) {
a6fc9228e1a0 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 05bc13637dc9f8e523bc72844ff6eb0794f98ad3
iuc
parents: 19
diff changeset
110 library("BiocParallel")
a6fc9228e1a0 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 05bc13637dc9f8e523bc72844ff6eb0794f98ad3
iuc
parents: 19
diff changeset
111 register(MulticoreParam(opt$cores))
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
112 parallel <- TRUE
21
a6fc9228e1a0 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 05bc13637dc9f8e523bc72844ff6eb0794f98ad3
iuc
parents: 19
diff changeset
113 } else {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
114 parallel <- FALSE
21
a6fc9228e1a0 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 05bc13637dc9f8e523bc72844ff6eb0794f98ad3
iuc
parents: 19
diff changeset
115 }
a6fc9228e1a0 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 05bc13637dc9f8e523bc72844ff6eb0794f98ad3
iuc
parents: 19
diff changeset
116
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
117 # build or read sample table
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
118
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
119 trim <- function(x) gsub("^\\s+|\\s+$", "", x)
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
120
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
121 # switch on if 'factors' was provided:
14
d0c39b5e78cf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 12
diff changeset
122 library("rjson")
d0c39b5e78cf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 12
diff changeset
123 parser <- newJSONParser()
d0c39b5e78cf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 12
diff changeset
124 parser$addData(opt$factors)
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
125 factor_list <- parser$getObject()
14
d0c39b5e78cf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 12
diff changeset
126 filenames_to_labels <- fromJSON(opt$files_to_labels)
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
127 factors <- sapply(factor_list, function(x) x[[1]])
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
128 primary_factor <- factors[1]
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
129 filenames_in <- unname(unlist(factor_list[[1]][[2]]))
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
130 labs <- unname(unlist(filenames_to_labels[basename(filenames_in)]))
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
131 sample_table <- data.frame(
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
132 sample = basename(filenames_in),
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
133 filename = filenames_in,
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
134 row.names = filenames_in,
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
135 stringsAsFactors = FALSE
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
136 )
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
137 for (factor in factor_list) {
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
138 factor_name <- trim(factor[[1]])
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
139 sample_table[[factor_name]] <- character(nrow(sample_table))
14
d0c39b5e78cf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 12
diff changeset
140 lvls <- sapply(factor[[2]], function(x) names(x))
d0c39b5e78cf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 12
diff changeset
141 for (i in seq_along(factor[[2]])) {
d0c39b5e78cf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 12
diff changeset
142 files <- factor[[2]][[i]][[1]]
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
143 sample_table[files, factor_name] <- trim(lvls[i])
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
144 }
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
145 sample_table[[factor_name]] <- factor(sample_table[[factor_name]], levels = lvls)
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
146 }
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
147 rownames(sample_table) <- labs
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
148
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
149 design_formula <- as.formula(paste("~", paste(rev(factors), collapse = " + ")))
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
150
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
151 # these are plots which are made once for each analysis
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
152 generate_generic_plots <- function(dds, factors) {
12
bd06df00180a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 11
diff changeset
153 library("ggplot2")
bd06df00180a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 11
diff changeset
154 library("ggrepel")
bd06df00180a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 11
diff changeset
155 library("pheatmap")
bd06df00180a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 11
diff changeset
156
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
157 rld <- rlog(dds)
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
158 p <- plotPCA(rld, intgroup = rev(factors))
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
159 print(p + geom_text_repel(aes_string(x = "PC1", y = "PC2", label = factor(colnames(dds))), size = 3) + geom_point())
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
160 dat <- assay(rld)
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
161 dists_rl <- dist(t(dat))
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
162 mat <- as.matrix(dists_rl)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
163 colors <- colorRampPalette(rev(brewer.pal(9, "Blues")))(255)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
164 pheatmap(
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
165 mat,
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
166 clustering_distance_rows = dists_rl,
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
167 clustering_distance_cols = dists_rl,
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
168 col = colors,
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
169 main = "Sample-to-sample distances"
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
170 )
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
171 plotDispEsts(dds, main = "Dispersion estimates")
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
172 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
173
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
174 # these are plots which can be made for each comparison, e.g.
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
175 # once for C vs A and once for B vs A
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
176 generate_specific_plots <- function(res, threshold, title_suffix) {
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
177 use <- res$baseMean > threshold
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
178 if (sum(!use) == 0) {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
179 h <- hist(res$pvalue, breaks = 0:50 / 50, plot = FALSE)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
180 barplot(
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
181 height = h$counts,
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
182 col = "powderblue",
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
183 space = 0,
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
184 xlab = "p-values",
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
185 ylab = "frequency",
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
186 main = paste("Histogram of p-values for", title_suffix)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
187 )
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
188 text(x = c(0, length(h$counts)), y = 0, label = paste(c(0, 1)), adj = c(0.5, 1.7), xpd = NA)
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
189 } else {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
190 h1 <- hist(res$pvalue[!use], breaks = 0:50 / 50, plot = FALSE)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
191 h2 <- hist(res$pvalue[use], breaks = 0:50 / 50, plot = FALSE)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
192 colori <- c("filtered (low count)" = "khaki", "not filtered" = "powderblue")
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
193 barplot(
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
194 height = rbind(h1$counts, h2$counts),
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
195 beside = FALSE,
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
196 col = colori,
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
197 space = 0,
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
198 xlab = "p-values",
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
199 ylab = "frequency",
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
200 main = paste("Histogram of p-values for", title_suffix)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
201 )
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
202 text(x = c(0, length(h1$counts)), y = 0, label = paste(c(0, 1)), adj = c(0.5, 1.7), xpd = NA)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
203 legend("topright", fill = rev(colori), legend = rev(names(colori)), bg = "white")
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
204 }
27
d027d1f4984e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit c8e7020d39d581d7374a13cf94c64998a6481e05"
iuc
parents: 25
diff changeset
205 plotMA(res, main = paste("MA-plot for", title_suffix), ylim = range(res$log2FoldChange, na.rm = TRUE), alpha = opt$alpha_ma)
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
206 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
207
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
208 if (verbose) {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
209 cat(paste("primary factor:", primary_factor, "\n"))
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
210 if (length(factors) > 1) {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
211 cat(paste("other factors in design:", paste(factors[-length(factors)], collapse = ","), "\n"))
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
212 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
213 cat("\n---------------------\n")
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
214 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
215
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
216 dds <- get_deseq_dataset(sample_table, header = opt$header, design_formula = design_formula, tximport = opt$tximport, txtype = opt$txtype, tx2gene = opt$tx2gene)
31
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
217
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
218 # use/estimate size factors with the chosen method
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
219 if (!is.null(opt$esf)) {
31
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
220 if (opt$esf %in% list("ratio", "poscounts", "iterate")) {
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
221 cat("Calculating size factors de novo\n")
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
222 dds <- estimateSizeFactors(dds, type = opt$esf)
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
223 } else {
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
224 sf_table <- read.table(opt$esf)
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
225 # Sort the provided size factors just in case the order differs from the input file order.
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
226 merged_table <- merge(sample_table, sf_table, by.x = 0, by.y = 1, sort = FALSE)
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
227 sf_values <- as.numeric(unlist(merged_table[5]))
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
228 "sizeFactors"(dds) <- sf_values
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
229
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
230 cat("Using user-provided size factors:\n")
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
231 print(sf_values)
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
232 }
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
233 } else {
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
234 cat("No size factor was used\n")
18
3bf1b3ec1ddf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 448dccb0c02aba00d8301247b0f0f406ab3d4fa2
iuc
parents: 17
diff changeset
235 }
29
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
236
31
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
237
29
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
238 # estimate size factors for each sample
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
239 # - https://support.bioconductor.org/p/97676/
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
240 if (!is.null(opt$sizefactorsfile)) {
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
241 nm <- assays(dds)[["avgTxLength"]]
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
242 if (!is.null(nm)) {
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
243 ## Recommended: takes into account tximport data
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
244 cat("\nsize factors for samples: taking tximport data into account\n")
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
245 size_factors <- estimateSizeFactorsForMatrix(counts(dds) / nm)
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
246 } else {
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
247 norm_factors <- normalizationFactors(dds)
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
248 if (!is.null(norm_factors)) {
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
249 ## In practice, gives same results as above.
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
250 cat("\nsize factors for samples: no tximport data, using derived normalization factors\n")
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
251 size_factors <- estimateSizeFactorsForMatrix(norm_factors)
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
252 } else {
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
253 ## If we have no other information, estimate from raw.
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
254 cat("\nsize factors for samples: no tximport data, no normalization factors, estimating from raw data\n")
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
255 size_factors <- estimateSizeFactorsForMatrix(counts(dds))
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
256 }
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
257 }
30
8fe98f7094de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 6868b66f73ddbe947986d1a20b546873cbd515a9
iuc
parents: 29
diff changeset
258 write.table(size_factors, file = opt$sizefactorsfile, sep = "\t", col.names = FALSE, quote = FALSE)
29
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
259 }
cd9874cb9019 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit cbeb1c4c436be04323bd9a809a6393d00b168d07"
iuc
parents: 27
diff changeset
260
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
261 apply_batch_factors <- function(dds, batch_factors) {
17
d9e5cadc7f0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents: 16
diff changeset
262 rownames(batch_factors) <- batch_factors$identifier
d9e5cadc7f0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents: 16
diff changeset
263 batch_factors <- subset(batch_factors, select = -c(identifier, condition))
d9e5cadc7f0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents: 16
diff changeset
264 dds_samples <- colnames(dds)
d9e5cadc7f0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents: 16
diff changeset
265 batch_samples <- rownames(batch_factors)
d9e5cadc7f0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents: 16
diff changeset
266 if (!setequal(batch_samples, dds_samples)) {
d9e5cadc7f0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents: 16
diff changeset
267 stop("Batch factor names don't correspond to input sample names, check input files")
d9e5cadc7f0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents: 16
diff changeset
268 }
d9e5cadc7f0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents: 16
diff changeset
269 dds_data <- colData(dds)
d9e5cadc7f0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents: 16
diff changeset
270 # Merge dds_data with batch_factors using indexes, which are sample names
d9e5cadc7f0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents: 16
diff changeset
271 # Set sort to False, which maintains the order in dds_data
30
8fe98f7094de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 6868b66f73ddbe947986d1a20b546873cbd515a9
iuc
parents: 29
diff changeset
272 reordered_batch <- merge(dds_data, batch_factors, by.x = 0, by.y = 0, sort = FALSE)
17
d9e5cadc7f0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents: 16
diff changeset
273 batch_factors <- reordered_batch[, ncol(dds_data):ncol(reordered_batch)]
d9e5cadc7f0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents: 16
diff changeset
274 for (factor in colnames(batch_factors)) {
d9e5cadc7f0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents: 16
diff changeset
275 dds[[factor]] <- batch_factors[[factor]]
d9e5cadc7f0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents: 16
diff changeset
276 }
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
277 colnames(dds) <- reordered_batch[, 1]
17
d9e5cadc7f0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents: 16
diff changeset
278 return(dds)
d9e5cadc7f0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents: 16
diff changeset
279 }
15
9a616afdbda5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 83eb5b2665d87c02b270596f8175499e69061032
iuc
parents: 14
diff changeset
280
17
d9e5cadc7f0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents: 16
diff changeset
281 if (!is.null(opt$batch_factors)) {
30
8fe98f7094de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 6868b66f73ddbe947986d1a20b546873cbd515a9
iuc
parents: 29
diff changeset
282 batch_factors <- read.table(opt$batch_factors, sep = "\t", header = TRUE)
17
d9e5cadc7f0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit b95582cea8320d5488056a9576474f79cec53be8
iuc
parents: 16
diff changeset
283 dds <- apply_batch_factors(dds = dds, batch_factors = batch_factors)
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
284 batch_design <- colnames(batch_factors)[-c(1, 2)]
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
285 design_formula <- as.formula(paste("~", paste(c(batch_design, rev(factors)), collapse = " + ")))
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
286 design(dds) <- design_formula
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
287 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
288
15
9a616afdbda5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 83eb5b2665d87c02b270596f8175499e69061032
iuc
parents: 14
diff changeset
289 if (verbose) {
9a616afdbda5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 83eb5b2665d87c02b270596f8175499e69061032
iuc
parents: 14
diff changeset
290 cat("DESeq2 run information\n\n")
9a616afdbda5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 83eb5b2665d87c02b270596f8175499e69061032
iuc
parents: 14
diff changeset
291 cat("sample table:\n")
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
292 print(sample_table[, -c(1:2), drop = FALSE])
15
9a616afdbda5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 83eb5b2665d87c02b270596f8175499e69061032
iuc
parents: 14
diff changeset
293 cat("\ndesign formula:\n")
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
294 print(design_formula)
15
9a616afdbda5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 83eb5b2665d87c02b270596f8175499e69061032
iuc
parents: 14
diff changeset
295 cat("\n\n")
9a616afdbda5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 83eb5b2665d87c02b270596f8175499e69061032
iuc
parents: 14
diff changeset
296 cat(paste(ncol(dds), "samples with counts over", nrow(dds), "genes\n"))
9a616afdbda5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 83eb5b2665d87c02b270596f8175499e69061032
iuc
parents: 14
diff changeset
297 }
9a616afdbda5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 83eb5b2665d87c02b270596f8175499e69061032
iuc
parents: 14
diff changeset
298
30
8fe98f7094de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 6868b66f73ddbe947986d1a20b546873cbd515a9
iuc
parents: 29
diff changeset
299 # minimal pre-filtering
8fe98f7094de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 6868b66f73ddbe947986d1a20b546873cbd515a9
iuc
parents: 29
diff changeset
300 if (!is.null(opt$prefilter)) {
8fe98f7094de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 6868b66f73ddbe947986d1a20b546873cbd515a9
iuc
parents: 29
diff changeset
301 keep <- rowSums(counts(dds)) >= opt$prefilter_value
8fe98f7094de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 6868b66f73ddbe947986d1a20b546873cbd515a9
iuc
parents: 29
diff changeset
302 dds <- dds[keep, ]
8fe98f7094de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 6868b66f73ddbe947986d1a20b546873cbd515a9
iuc
parents: 29
diff changeset
303 }
8fe98f7094de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 6868b66f73ddbe947986d1a20b546873cbd515a9
iuc
parents: 29
diff changeset
304
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
305 # optional outlier behavior
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
306 if (is.null(opt$outlier_replace_off)) {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
307 min_rep <- 7
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
308 } else {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
309 min_rep <- Inf
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
310 if (verbose) cat("outlier replacement off\n")
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
311 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
312 if (is.null(opt$outlier_filter_off)) {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
313 cooks_cutoff <- TRUE
15
9a616afdbda5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 83eb5b2665d87c02b270596f8175499e69061032
iuc
parents: 14
diff changeset
314 } else {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
315 cooks_cutoff <- FALSE
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
316 if (verbose) cat("outlier filtering off\n")
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
317 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
318
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
319 # optional automatic mean filtering
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
320 if (is.null(opt$auto_mean_filter_off)) {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
321 independent_filtering <- TRUE
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
322 } else {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
323 independent_filtering <- FALSE
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
324 if (verbose) cat("automatic filtering on the mean off\n")
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
325 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
326
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
327 # shrinkage of LFCs
31
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
328 if (is.null(opt$use_beta_priors)) {
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
329 beta_prior <- FALSE
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
330 if (verbose)
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
331 cat("Applied default - beta prior off\n")
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
332 } else {
31
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
333 beta_prior <- opt$use_beta_priors
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
334 }
31
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
335 sprintf("use_beta_prior is set to %s", beta_prior)
9a882d108833 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 469558ddf5bc6249874fe5826637fd6ee81588cf
iuc
parents: 30
diff changeset
336
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
337
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
338 # dispersion fit type
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
339 if (is.null(opt$fit_type)) {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
340 fit_type <- "parametric"
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
341 } else {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
342 fit_type <- c("parametric", "local", "mean")[opt$fit_type]
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
343 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
344
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
345 if (verbose) cat(paste("using disperion fit type:", fit_type, "\n"))
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
346
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
347 # run the analysis
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
348 dds <- DESeq(dds, fitType = fit_type, betaPrior = beta_prior, minReplicatesForReplace = min_rep, parallel = parallel)
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
349
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
350 # create the generic plots and leave the device open
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
351 if (!is.null(opt$plots)) {
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
352 if (verbose) cat("creating plots\n")
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
353 pdf(opt$plots)
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
354 generate_generic_plots(dds, factors)
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
355 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
356
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
357 n <- nlevels(colData(dds)[[primary_factor]])
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
358 all_levels <- levels(colData(dds)[[primary_factor]])
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
359
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
360 if (!is.null(opt$countsfile)) {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
361 normalized_counts <- counts(dds, normalized = TRUE)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
362 write.table(normalized_counts, file = opt$countsfile, sep = "\t", col.names = NA, quote = FALSE)
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
363 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
364
18
3bf1b3ec1ddf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 448dccb0c02aba00d8301247b0f0f406ab3d4fa2
iuc
parents: 17
diff changeset
365 if (!is.null(opt$rlogfile)) {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
366 rlog_normalized <- rlogTransformation(dds)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
367 rlog_normalized_mat <- assay(rlog_normalized)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
368 write.table(rlog_normalized_mat, file = opt$rlogfile, sep = "\t", col.names = NA, quote = FALSE)
18
3bf1b3ec1ddf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 448dccb0c02aba00d8301247b0f0f406ab3d4fa2
iuc
parents: 17
diff changeset
369 }
3bf1b3ec1ddf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 448dccb0c02aba00d8301247b0f0f406ab3d4fa2
iuc
parents: 17
diff changeset
370
3bf1b3ec1ddf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 448dccb0c02aba00d8301247b0f0f406ab3d4fa2
iuc
parents: 17
diff changeset
371 if (!is.null(opt$vstfile)) {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
372 vst_normalized <- varianceStabilizingTransformation(dds)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
373 vst_normalized_mat <- assay(vst_normalized)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
374 write.table(vst_normalized_mat, file = opt$vstfile, sep = "\t", col.names = NA, quote = FALSE)
18
3bf1b3ec1ddf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 448dccb0c02aba00d8301247b0f0f406ab3d4fa2
iuc
parents: 17
diff changeset
375 }
3bf1b3ec1ddf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 448dccb0c02aba00d8301247b0f0f406ab3d4fa2
iuc
parents: 17
diff changeset
376
3bf1b3ec1ddf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 448dccb0c02aba00d8301247b0f0f406ab3d4fa2
iuc
parents: 17
diff changeset
377
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
378 if (is.null(opt$many_contrasts)) {
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
379 # only contrast the first and second level of the primary factor
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
380 ref <- all_levels[1]
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
381 lvl <- all_levels[2]
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
382 res <- results(
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
383 dds,
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
384 contrast = c(primary_factor, lvl, ref),
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
385 cooksCutoff = cooks_cutoff,
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
386 independentFiltering = independent_filtering
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
387 )
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
388 if (verbose) {
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
389 cat("summary of results\n")
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
390 cat(paste0(primary_factor, ": ", lvl, " vs ", ref, "\n"))
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
391 print(summary(res))
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
392 }
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
393 res_sorted <- res[order(res$padj), ]
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
394 out_df <- as.data.frame(res_sorted)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
395 out_df$geneID <- rownames(out_df) # nolint
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
396 out_df <- out_df[, c("geneID", "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
397 filename <- opt$outfile
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
398 write.table(out_df, file = filename, sep = "\t", quote = FALSE, row.names = FALSE, col.names = FALSE)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
399 if (independent_filtering) {
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
400 threshold <- unname(attr(res, "filterThreshold"))
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
401 } else {
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
402 threshold <- 0
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
403 }
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
404 title_suffix <- paste0(primary_factor, ": ", lvl, " vs ", ref)
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
405 if (!is.null(opt$plots)) {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
406 generate_specific_plots(res, threshold, title_suffix)
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
407 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
408 } else {
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
409 # rotate through the possible contrasts of the primary factor
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
410 # write out a sorted table of results with the contrast as a suffix
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
411 # add contrast specific plots to the device
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
412 for (i in seq_len(n - 1)) {
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
413 ref <- all_levels[i]
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
414 contrast_levels <- all_levels[(i + 1):n]
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
415 for (lvl in contrast_levels) {
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
416 res <- results(
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
417 dds,
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
418 contrast = c(primary_factor, lvl, ref),
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
419 cooksCutoff = cooks_cutoff,
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
420 independentFiltering = independent_filtering
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
421 )
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
422 res_sorted <- res[order(res$padj), ]
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
423 out_df <- as.data.frame(res_sorted)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
424 out_df$geneID <- rownames(out_df) # nolint
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
425 out_df <- out_df[, c("geneID", "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
426 filename <- paste0(primary_factor, "_", lvl, "_vs_", ref)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
427 write.table(out_df, file = filename, sep = "\t", quote = FALSE, row.names = FALSE, col.names = FALSE)
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
428 if (independent_filtering) {
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
429 threshold <- unname(attr(res, "filterThreshold"))
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
430 } else {
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
431 threshold <- 0
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
432 }
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
433 title_suffix <- paste0(primary_factor, ": ", lvl, " vs ", ref)
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
434 if (!is.null(opt$plots)) {
25
de44f8eff84a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 9eb6d07510ccf27d6499172d62c81661078ec57b"
iuc
parents: 24
diff changeset
435 generate_specific_plots(res, threshold, title_suffix)
6
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
436 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
437 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
438 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
439 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
440
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
441 # close the plot device
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
442 if (!is.null(opt$plots)) {
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
443 cat("closing plot device\n")
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
444 dev.off()
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
445 }
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
446
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
447 cat("Session information:\n\n")
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
448
4939397c4706 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 3bc8d91ee546682ef8e9303bd1044bb14cf21b07
iuc
parents:
diff changeset
449 sessionInfo()