annotate deseq2.R @ 26:47267a044ef1 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
author iuc
date Thu, 12 Apr 2018 17:29:07 -0400
parents 1a34aec44d60
children dc6bc19f05ab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
1 #!/usr/bin/env Rscript
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
2
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
3 # A command-line interface to DESeq2 for use with Galaxy
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
4 # written by Bjoern Gruening and modified by Michael Love 2016.03.30
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
5 #
26
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
6 # This argument is required:
17
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
7 #
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
8 # 'factors' a JSON list object from Galaxy
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
9 #
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
10 # the output file has columns:
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
11 #
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
12 # baseMean (mean normalized count)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
13 # log2FoldChange (by default a moderated LFC estimate)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
14 # lfcSE (the standard error)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
15 # stat (the Wald statistic)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
16 # pvalue (p-value from comparison of Wald statistic to a standard Normal)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
17 # padj (adjusted p-value, Benjamini Hochberg correction on genes which pass the mean count filter)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
18 #
26
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
19 # the first variable in 'factors' will be the primary factor.
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
20 # the levels of the primary factor are used in the order of appearance in factors.
17
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
21 #
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
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'
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
23 #
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
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,
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
25 # to a number of files using the 'outfile' prefix: 'outfile.condition_C_vs_A' etc.
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
26 # all plots will still be sent to a single PDF, named by the arg 'plots', with extra pages.
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
27 #
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
28 # fit_type is an integer valued argument, with the options from ?estimateDisperions
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
29 # 1 "parametric"
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
30 # 2 "local"
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
31 # 3 "mean"
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
32
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
33 # setup R error handling to go to stderr
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
34 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
35
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
36 # we need that to not crash galaxy with an UTF8 error on German LC settings.
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
37 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
38
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
39 library("getopt")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
40 library("tools")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
41 options(stringAsFactors = FALSE, useFancyQuotes = FALSE)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
42 args <- commandArgs(trailingOnly = TRUE)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
43
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
44 # get options, using the spec as defined by the enclosed list.
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
45 # we read the options from the default: commandArgs(TRUE).
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
46 spec <- matrix(c(
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
47 "quiet", "q", 0, "logical",
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
48 "help", "h", 0, "logical",
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
49 "outfile", "o", 1, "character",
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
50 "countsfile", "n", 1, "character",
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
51 "factors", "f", 1, "character",
24
1a34aec44d60 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 23
diff changeset
52 "files_to_labels", "l", 1, "character",
17
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
53 "plots" , "p", 1, "character",
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
54 "tximport", "i", 0, "logical",
23
d1241c2b81a7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 0a56599c36b4968095ec5a3cb589f94fb139466c
iuc
parents: 21
diff changeset
55 "txtype", "y", 1, "character",
17
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
56 "tx2gene", "x", 1, "character", # a space-sep tx-to-gene map or GTF file (auto detect .gtf/.GTF)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
57 "fit_type", "t", 1, "integer",
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
58 "many_contrasts", "m", 0, "logical",
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
59 "outlier_replace_off" , "a", 0, "logical",
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
60 "outlier_filter_off" , "b", 0, "logical",
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
61 "auto_mean_filter_off", "c", 0, "logical",
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
62 "beta_prior_off", "d", 0, "logical"),
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
63 byrow=TRUE, ncol=4)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
64 opt <- getopt(spec)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
65
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
66 # if help was asked for print a friendly message
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
67 # and exit with a non-zero error code
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
68 if (!is.null(opt$help)) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
69 cat(getopt(spec, usage=TRUE))
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
70 q(status=1)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
71 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
72
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
73 # enforce the following required arguments
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
74 if (is.null(opt$outfile)) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
75 cat("'outfile' is required\n")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
76 q(status=1)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
77 }
26
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
78 if (is.null(opt$factors)) {
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
79 cat("'factors' is required\n")
17
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
80 q(status=1)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
81 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
82
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
83 verbose <- if (is.null(opt$quiet)) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
84 TRUE
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
85 } else {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
86 FALSE
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
87 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
88
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
89 if (!is.null(opt$tximport)) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
90 if (is.null(opt$tx2gene)) stop("A transcript-to-gene map or a GTF file is required for tximport")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
91 if (tolower(file_ext(opt$tx2gene)) == "gtf") {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
92 gtfFile <- opt$tx2gene
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
93 } else {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
94 gtfFile <- NULL
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
95 tx2gene <- read.table(opt$tx2gene, header=FALSE)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
96 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
97 useTXI <- TRUE
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
98 } else {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
99 useTXI <- FALSE
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
100 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
101
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
102 suppressPackageStartupMessages({
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
103 library("DESeq2")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
104 library("RColorBrewer")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
105 library("gplots")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
106 })
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
107
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
108 # build or read sample table
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
109
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
110 trim <- function (x) gsub("^\\s+|\\s+$", "", x)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
111
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
112 # switch on if 'factors' was provided:
26
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
113 library("rjson")
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
114 parser <- newJSONParser()
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
115 parser$addData(opt$factors)
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
116 factorList <- parser$getObject()
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
117 filenames_to_labels <- fromJSON(opt$files_to_labels)
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
118 factors <- sapply(factorList, function(x) x[[1]])
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
119 primaryFactor <- factors[1]
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
120 filenamesIn <- unname(unlist(factorList[[1]][[2]]))
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
121 labs = unname(unlist(filenames_to_labels[basename(filenamesIn)]))
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
122 sampleTable <- data.frame(sample=basename(filenamesIn),
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
123 filename=filenamesIn,
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
124 row.names=filenamesIn,
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
125 stringsAsFactors=FALSE)
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
126 for (factor in factorList) {
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
127 factorName <- trim(factor[[1]])
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
128 sampleTable[[factorName]] <- character(nrow(sampleTable))
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
129 lvls <- sapply(factor[[2]], function(x) names(x))
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
130 for (i in seq_along(factor[[2]])) {
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
131 files <- factor[[2]][[i]][[1]]
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
132 sampleTable[files,factorName] <- trim(lvls[i])
17
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
133 }
26
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
134 sampleTable[[factorName]] <- factor(sampleTable[[factorName]], levels=lvls)
17
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
135 }
26
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
136 rownames(sampleTable) <- labs
17
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
137
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
138 primaryFactor <- factors[1]
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
139 designFormula <- as.formula(paste("~", paste(rev(factors), collapse=" + ")))
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
140
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
141 if (verbose) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
142 cat("DESeq2 run information\n\n")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
143 cat("sample table:\n")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
144 print(sampleTable[,-c(1:2),drop=FALSE])
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
145 cat("\ndesign formula:\n")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
146 print(designFormula)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
147 cat("\n\n")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
148 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
149
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
150 # these are plots which are made once for each analysis
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
151 generateGenericPlots <- function(dds, factors) {
24
1a34aec44d60 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 23
diff changeset
152 library("ggplot2")
1a34aec44d60 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 23
diff changeset
153 library("ggrepel")
1a34aec44d60 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 23
diff changeset
154 library("pheatmap")
1a34aec44d60 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 23
diff changeset
155
17
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
156 rld <- rlog(dds)
24
1a34aec44d60 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 23
diff changeset
157 p <- plotPCA(rld, intgroup=rev(factors))
1a34aec44d60 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 23
diff changeset
158 print(p + geom_text_repel(aes_string(x = "PC1", y = "PC2", label = factor(colnames(dds))), size=3) + geom_point())
17
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
159 dat <- assay(rld)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
160 distsRL <- dist(t(dat))
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
161 mat <- as.matrix(distsRL)
24
1a34aec44d60 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 23
diff changeset
162 colors <- colorRampPalette( rev(brewer.pal(9, "Blues")) )(255)
1a34aec44d60 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 23
diff changeset
163 pheatmap(mat,
1a34aec44d60 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 23
diff changeset
164 clustering_distance_rows=distsRL,
1a34aec44d60 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 23
diff changeset
165 clustering_distance_cols=distsRL,
1a34aec44d60 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 23
diff changeset
166 col=colors,
1a34aec44d60 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 23
diff changeset
167 main="Sample-to-sample distances")
17
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
168 plotDispEsts(dds, main="Dispersion estimates")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
169 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
170
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
171 # these are plots which can be made for each comparison, e.g.
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
172 # once for C vs A and once for B vs A
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
173 generateSpecificPlots <- function(res, threshold, title_suffix) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
174 use <- res$baseMean > threshold
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
175 if (sum(!use) == 0) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
176 h <- hist(res$pvalue, breaks=0:50/50, plot=FALSE)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
177 barplot(height = h$counts,
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
178 col = "powderblue", space = 0, xlab="p-values", ylab="frequency",
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
179 main=paste("Histogram of p-values for",title_suffix))
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
180 text(x = c(0, length(h$counts)), y = 0, label=paste(c(0,1)), adj=c(0.5,1.7), xpd=NA)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
181 } else {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
182 h1 <- hist(res$pvalue[!use], breaks=0:50/50, plot=FALSE)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
183 h2 <- hist(res$pvalue[use], breaks=0:50/50, plot=FALSE)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
184 colori <- c("filtered (low count)"="khaki", "not filtered"="powderblue")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
185 barplot(height = rbind(h1$counts, h2$counts), beside = FALSE,
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
186 col = colori, space = 0, xlab="p-values", ylab="frequency",
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
187 main=paste("Histogram of p-values for",title_suffix))
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
188 text(x = c(0, length(h1$counts)), y = 0, label=paste(c(0,1)), adj=c(0.5,1.7), xpd=NA)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
189 legend("topright", fill=rev(colori), legend=rev(names(colori)), bg="white")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
190 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
191 plotMA(res, main= paste("MA-plot for",title_suffix), ylim=range(res$log2FoldChange, na.rm=TRUE))
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
192 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
193
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
194 if (verbose) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
195 cat(paste("primary factor:",primaryFactor,"\n"))
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
196 if (length(factors) > 1) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
197 cat(paste("other factors in design:",paste(factors[-length(factors)],collapse=","),"\n"))
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
198 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
199 cat("\n---------------------\n")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
200 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
201
26
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
202 # For JSON input from Galaxy, path is absolute
47267a044ef1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit e811a7887db870f4f94f620f52bce656c8d5ba23
iuc
parents: 24
diff changeset
203 dir <- ""
17
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
204
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
205 if (!useTXI) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
206 # construct the object from HTSeq files
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
207 dds <- DESeqDataSetFromHTSeqCount(sampleTable = sampleTable,
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
208 directory = dir,
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
209 design = designFormula)
24
1a34aec44d60 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 23
diff changeset
210 labs <- unname(unlist(filenames_to_labels[colnames(dds)]))
1a34aec44d60 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 23
diff changeset
211 colnames(dds) <- labs
17
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
212 } else {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
213 # construct the object using tximport
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
214 # first need to make the tx2gene table
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
215 # this takes ~2-3 minutes using Bioconductor functions
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
216 if (!is.null(gtfFile)) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
217 suppressPackageStartupMessages({
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
218 library("GenomicFeatures")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
219 })
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
220 txdb <- makeTxDbFromGFF(gtfFile, format="gtf")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
221 k <- keys(txdb, keytype = "GENEID")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
222 df <- select(txdb, keys = k, keytype = "GENEID", columns = "TXNAME")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
223 tx2gene <- df[, 2:1] # tx ID, then gene ID
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
224 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
225 library("tximport")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
226 txiFiles <- as.character(sampleTable[,2])
24
1a34aec44d60 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 23
diff changeset
227 labs <- unname(unlist(filenames_to_labels[sampleTable[,1]]))
1a34aec44d60 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 62e9101c1e7b8467e395f31ccbd9321de01a6418
iuc
parents: 23
diff changeset
228 names(txiFiles) <- labs
23
d1241c2b81a7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 0a56599c36b4968095ec5a3cb589f94fb139466c
iuc
parents: 21
diff changeset
229 txi <- tximport(txiFiles, type=opt$txtype, tx2gene=tx2gene)
17
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
230 dds <- DESeqDataSetFromTximport(txi,
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
231 sampleTable[,3:ncol(sampleTable),drop=FALSE],
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
232 designFormula)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
233 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
234
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
235 if (verbose) cat(paste(ncol(dds), "samples with counts over", nrow(dds), "genes\n"))
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
236 # optional outlier behavior
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
237 if (is.null(opt$outlier_replace_off)) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
238 minRep <- 7
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
239 } else {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
240 minRep <- Inf
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
241 if (verbose) cat("outlier replacement off\n")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
242 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
243 if (is.null(opt$outlier_filter_off)) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
244 cooksCutoff <- TRUE
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
245 } else {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
246 cooksCutoff <- FALSE
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
247 if (verbose) cat("outlier filtering off\n")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
248 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
249
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
250 # optional automatic mean filtering
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
251 if (is.null(opt$auto_mean_filter_off)) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
252 independentFiltering <- TRUE
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
253 } else {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
254 independentFiltering <- FALSE
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
255 if (verbose) cat("automatic filtering on the mean off\n")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
256 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
257
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
258 # shrinkage of LFCs
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
259 if (is.null(opt$beta_prior_off)) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
260 betaPrior <- TRUE
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
261 } else {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
262 betaPrior <- FALSE
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
263 if (verbose) cat("beta prior off\n")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
264 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
265
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
266 # dispersion fit type
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
267 if (is.null(opt$fit_type)) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
268 fitType <- "parametric"
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
269 } else {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
270 fitType <- c("parametric","local","mean")[opt$fit_type]
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
271 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
272
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
273 if (verbose) cat(paste("using disperion fit type:",fitType,"\n"))
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
274
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
275 # run the analysis
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
276 dds <- DESeq(dds, fitType=fitType, betaPrior=betaPrior, minReplicatesForReplace=minRep)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
277
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
278 # create the generic plots and leave the device open
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
279 if (!is.null(opt$plots)) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
280 if (verbose) cat("creating plots\n")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
281 pdf(opt$plots)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
282 generateGenericPlots(dds, factors)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
283 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
284
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
285 n <- nlevels(colData(dds)[[primaryFactor]])
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
286 allLevels <- levels(colData(dds)[[primaryFactor]])
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
287
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
288 if (!is.null(opt$countsfile)) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
289 normalizedCounts<-counts(dds,normalized=TRUE)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
290 write.table(normalizedCounts, file=opt$countsfile, sep="\t", col.names=NA, quote=FALSE)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
291 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
292
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
293 if (is.null(opt$many_contrasts)) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
294 # only contrast the first and second level of the primary factor
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
295 ref <- allLevels[1]
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
296 lvl <- allLevels[2]
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
297 res <- results(dds, contrast=c(primaryFactor, lvl, ref),
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
298 cooksCutoff=cooksCutoff,
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
299 independentFiltering=independentFiltering)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
300 if (verbose) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
301 cat("summary of results\n")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
302 cat(paste0(primaryFactor,": ",lvl," vs ",ref,"\n"))
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
303 print(summary(res))
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
304 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
305 resSorted <- res[order(res$padj),]
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
306 outDF <- as.data.frame(resSorted)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
307 outDF$geneID <- rownames(outDF)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
308 outDF <- outDF[,c("geneID", "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
309 filename <- opt$outfile
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
310 write.table(outDF, file=filename, sep="\t", quote=FALSE, row.names=FALSE, col.names=FALSE)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
311 if (independentFiltering) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
312 threshold <- unname(attr(res, "filterThreshold"))
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
313 } else {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
314 threshold <- 0
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
315 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
316 title_suffix <- paste0(primaryFactor,": ",lvl," vs ",ref)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
317 if (!is.null(opt$plots)) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
318 generateSpecificPlots(res, threshold, title_suffix)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
319 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
320 } else {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
321 # rotate through the possible contrasts of the primary factor
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
322 # write out a sorted table of results with the contrast as a suffix
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
323 # add contrast specific plots to the device
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
324 for (i in seq_len(n-1)) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
325 ref <- allLevels[i]
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
326 contrastLevels <- allLevels[(i+1):n]
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
327 for (lvl in contrastLevels) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
328 res <- results(dds, contrast=c(primaryFactor, lvl, ref),
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
329 cooksCutoff=cooksCutoff,
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
330 independentFiltering=independentFiltering)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
331 resSorted <- res[order(res$padj),]
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
332 outDF <- as.data.frame(resSorted)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
333 outDF$geneID <- rownames(outDF)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
334 outDF <- outDF[,c("geneID", "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
335 filename <- paste0(opt$outfile,".",primaryFactor,"_",lvl,"_vs_",ref)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
336 write.table(outDF, file=filename, sep="\t", quote=FALSE, row.names=FALSE, col.names=FALSE)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
337 if (independentFiltering) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
338 threshold <- unname(attr(res, "filterThreshold"))
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
339 } else {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
340 threshold <- 0
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
341 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
342 title_suffix <- paste0(primaryFactor,": ",lvl," vs ",ref)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
343 if (!is.null(opt$plots)) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
344 generateSpecificPlots(res, threshold, title_suffix)
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
345 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
346 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
347 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
348 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
349
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
350 # close the plot device
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
351 if (!is.null(opt$plots)) {
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
352 cat("closing plot device\n")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
353 dev.off()
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
354 }
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
355
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
356 cat("Session information:\n\n")
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
357
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
358 sessionInfo()
24930eeff731 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/deseq2 commit 23559e873291b04840f186edb0b4b85e76359e05
iuc
parents:
diff changeset
359