annotate diffbind.R @ 18:f907216064f6 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
author iuc
date Mon, 08 Jul 2024 18:31:51 +0000
parents 2605cbdaa7d8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
1 ## Setup R error handling to go to stderr
18
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
2 options(show.error.messages = F, error = function() {
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
3 cat(geterrmessage(), file = stderr())
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
4 q("no", 1, F)
16
163688bb8f73 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents: 15
diff changeset
5 })
9
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
6 # we need that to not crash galaxy with an UTF8 error on German LC settings.
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
7 Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
8
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
9 suppressPackageStartupMessages({
18
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
10 library("getopt")
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
11 library("DiffBind")
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
12 library("rjson")
9
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
13 })
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
14
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
15 options(stringAsfactors = FALSE, useFancyQuotes = FALSE)
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
16 args <- commandArgs(trailingOnly = TRUE)
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
17
18
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
18 # get options, using the spec as defined by the enclosed list.
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
19 # we read the options from the default: commandArgs(TRUE).
16
163688bb8f73 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents: 15
diff changeset
20 spec <- matrix(c(
18
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
21 "infile", "i", 1, "character",
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
22 "outfile", "o", 1, "character",
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
23 "method", "m", 1, "character",
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
24 "scorecol", "n", 1, "integer",
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
25 "lowerbetter", "l", 1, "logical",
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
26 "summits", "s", 1, "integer",
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
27 "th", "t", 1, "double",
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
28 "minoverlap", "O", 1, "integer",
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
29 "use_blacklist", "B", 0, "logical",
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
30 "format", "f", 1, "character",
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
31 "plots", "p", 2, "character",
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
32 "bmatrix", "b", 0, "logical",
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
33 "rdaOpt", "r", 0, "logical",
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
34 "infoOpt", "a", 0, "logical",
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
35 "verbose", "v", 2, "integer",
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
36 "help", "h", 0, "logical"
17
2605cbdaa7d8 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents: 16
diff changeset
37 ), byrow = TRUE, ncol = 4)
9
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
38
17
2605cbdaa7d8 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents: 16
diff changeset
39 opt <- getopt(spec)
9
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
40 # if help was asked for print a friendly message
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
41 # and exit with a non-zero error code
16
163688bb8f73 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents: 15
diff changeset
42 if (!is.null(opt$help)) {
18
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
43 cat(getopt(spec, usage = TRUE))
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
44 q(status = 1)
9
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
45 }
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
46
11
4c7ab9995f9e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents: 10
diff changeset
47 parser <- newJSONParser()
4c7ab9995f9e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents: 10
diff changeset
48 parser$addData(opt$infile)
16
163688bb8f73 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents: 15
diff changeset
49 factor_list <- parser$getObject()
163688bb8f73 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents: 15
diff changeset
50 filenames_in <- unname(unlist(factor_list[[1]][[2]]))
163688bb8f73 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents: 15
diff changeset
51 peaks <- filenames_in[grepl("peaks.bed", filenames_in)]
163688bb8f73 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents: 15
diff changeset
52 bams <- filenames_in[grepl("bamreads.bam", filenames_in)]
163688bb8f73 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents: 15
diff changeset
53 ctrls <- filenames_in[grepl("bamcontrol.bam", filenames_in)]
11
4c7ab9995f9e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents: 10
diff changeset
54
4c7ab9995f9e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents: 10
diff changeset
55 # get the group and sample id from the peaks filenames
16
163688bb8f73 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents: 15
diff changeset
56 groups <- sapply(strsplit(peaks, "-"), `[`, 1)
163688bb8f73 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents: 15
diff changeset
57 samples <- sapply(strsplit(peaks, "-"), `[`, 2)
11
4c7ab9995f9e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents: 10
diff changeset
58
16
163688bb8f73 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents: 15
diff changeset
59 if (length(ctrls) != 0) {
18
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
60 sample_table <- data.frame(
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
61 SampleID = samples,
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
62 Condition = groups,
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
63 bamReads = bams,
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
64 bamControl = ctrls,
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
65 Peaks = peaks,
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
66 Tissue = samples
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
67 ) # using "Tissue" column to display ids as labels in PCA plot
11
4c7ab9995f9e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents: 10
diff changeset
68 } else {
18
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
69 sample_table <- data.frame(
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
70 SampleID = samples,
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
71 Replicate = samples,
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
72 Condition = groups,
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
73 bamReads = bams,
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
74 Peaks = peaks,
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
75 Tissue = samples
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
76 )
9
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
77 }
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
78
18
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
79 sample <- dba(sampleSheet = sample_table, peakFormat = "bed", scoreCol = opt$scorecol, bLowerScoreBetter = opt$lowerbetter, minOverlap = opt$minoverlap)
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
80
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
81 if (!is.null(opt$use_blacklist)) {
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
82 sample <- dba.blacklist(sample, blacklist = TRUE)
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
83 }
11
4c7ab9995f9e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents: 10
diff changeset
84
16
163688bb8f73 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents: 15
diff changeset
85 if (!is.null(opt$summits)) {
18
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
86 sample_count <- dba.count(sample, summits = opt$summits)
11
4c7ab9995f9e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents: 10
diff changeset
87 } else {
18
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
88 sample_count <- dba.count(sample)
11
4c7ab9995f9e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents: 10
diff changeset
89 }
4c7ab9995f9e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents: 10
diff changeset
90
16
163688bb8f73 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents: 15
diff changeset
91 sample_contrast <- dba.contrast(sample_count, categories = DBA_CONDITION, minMembers = 2)
18
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
92
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
93 if (opt$method == "DBA_DESEQ2") {
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
94 method <- DBA_DESEQ2
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
95 } else if (opt$method == "DBA_EDGER") {
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
96 method <- DBA_EDGER
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
97 }
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
98
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
99 sample_analyze <- dba.analyze(sample_contrast, method = method, bBlacklist = FALSE, bGreylist = FALSE)
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
100
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
101 diff_bind <- dba.report(sample_analyze, th = opt$th, method = method)
9
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
102
11
4c7ab9995f9e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents: 10
diff changeset
103 # Generate plots
16
163688bb8f73 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents: 15
diff changeset
104 if (!is.null(opt$plots)) {
18
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
105 pdf(opt$plots)
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
106 orvals <- dba.plotHeatmap(sample_analyze, contrast = 1, correlations = FALSE, cexCol = 0.8, th = opt$th, method = method)
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
107 dba.plotPCA(sample_analyze, contrast = 1, th = opt$th, label = DBA_TISSUE, labelSize = 0.3, method = method)
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
108 dba.plotMA(sample_analyze, th = opt$th, method = method)
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
109 dba.plotVolcano(sample_analyze, th = opt$th, method = method)
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
110 dba.plotBox(sample_analyze, th = opt$th, method = method)
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
111 dev.off()
11
4c7ab9995f9e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents: 10
diff changeset
112 }
4c7ab9995f9e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents: 10
diff changeset
113
4c7ab9995f9e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents: 10
diff changeset
114 # Output differential binding sites
16
163688bb8f73 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents: 15
diff changeset
115 res_sorted <- diff_bind[order(diff_bind$FDR), ]
13
1de83981d43c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents: 11
diff changeset
116 # Convert from GRanges (1-based) to 0-based format (adapted from https://www.biostars.org/p/89341/)
1de83981d43c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents: 11
diff changeset
117 if (opt$format == "bed") {
18
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
118 res_sorted <- data.frame(
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
119 Chrom = seqnames(res_sorted),
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
120 Start = start(res_sorted) - 1,
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
121 End = end(res_sorted),
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
122 Name = rep("DiffBind", length(res_sorted)),
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
123 Score = rep("0", length(res_sorted)),
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
124 Strand = gsub("\\*", ".", strand(res_sorted))
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
125 )
13
1de83981d43c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents: 11
diff changeset
126 } else if (opt$format == "interval") {
18
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
127 # Output as interval
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
128 df <- as.data.frame(res_sorted)
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
129 extrainfo <- NULL
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
130 for (i in seq_len(nrow(df))) {
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
131 extrainfo[i] <- paste0(c(df$width[i], df[i, 6:ncol(df)]), collapse = "|")
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
132 }
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
133 res_sorted <- data.frame(
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
134 Chrom = seqnames(res_sorted),
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
135 Start = start(res_sorted) - 1,
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
136 End = end(res_sorted),
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
137 Name = rep("DiffBind", length(res_sorted)),
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
138 Score = rep("0", length(res_sorted)),
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
139 Strand = gsub("\\*", ".", strand(res_sorted)),
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
140 Comment = extrainfo
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
141 )
13
1de83981d43c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents: 11
diff changeset
142 } else {
18
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
143 # Output as 0-based tabular
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
144 res_sorted <- data.frame(
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
145 Chrom = seqnames(res_sorted),
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
146 Start = start(res_sorted) - 1,
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
147 End = end(res_sorted),
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
148 Name = rep("DiffBind", length(res_sorted)),
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
149 Score = rep("0", length(res_sorted)),
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
150 Strand = gsub("\\*", ".", strand(res_sorted)),
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
151 mcols(res_sorted)
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
152 )
13
1de83981d43c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents: 11
diff changeset
153 }
16
163688bb8f73 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents: 15
diff changeset
154 write.table(res_sorted, file = opt$outfile, sep = "\t", quote = FALSE, row.names = FALSE)
9
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
155
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
156 # Output binding affinity scores
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
157 if (!is.null(opt$bmatrix)) {
18
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
158 bmat <- dba.peakset(sample_count, bRetrieve = TRUE, DataType = DBA_DATA_FRAME, minOverlap = opt$minoverlap)
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
159 # Output as 0-based tabular
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
160 bmat <- data.frame(
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
161 Chrom = bmat[, 1],
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
162 Start = bmat[, 2] - 1,
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
163 End = bmat[, 3],
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
164 bmat[, 4:ncol(bmat)]
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
165 )
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
166 write.table(bmat, file = "bmatrix.tab", sep = "\t", quote = FALSE, row.names = FALSE)
9
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
167 }
6171163112de planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff changeset
168
11
4c7ab9995f9e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents: 10
diff changeset
169 # Output RData file
10
d7725c5596ab planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit f970dcbe9d0e4c3714b1db74c404ea34223cf8ed
iuc
parents: 9
diff changeset
170 if (!is.null(opt$rdaOpt)) {
18
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
171 save.image(file = "DiffBind_analysis.RData")
10
d7725c5596ab planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit f970dcbe9d0e4c3714b1db74c404ea34223cf8ed
iuc
parents: 9
diff changeset
172 }
d7725c5596ab planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit f970dcbe9d0e4c3714b1db74c404ea34223cf8ed
iuc
parents: 9
diff changeset
173
11
4c7ab9995f9e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents: 10
diff changeset
174 # Output analysis info
4c7ab9995f9e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents: 10
diff changeset
175 if (!is.null(opt$infoOpt)) {
18
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
176 info <- "DiffBind_analysis_info.txt"
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
177 cat("dba.count Info\n\n", file = info, append = TRUE)
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
178 capture.output(sample, file = info, append = TRUE)
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
179 cat("\ndba.analyze Info\n\n", file = info, append = TRUE)
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
180 capture.output(sample_analyze, file = info, append = TRUE)
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
181 cat("\nSessionInfo\n\n", file = info, append = TRUE)
f907216064f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit fd148a124034b44d0d61db3eec32ff991d8c152c
iuc
parents: 17
diff changeset
182 capture.output(sessionInfo(), file = info, append = TRUE)
16
163688bb8f73 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents: 15
diff changeset
183 }