Mercurial > repos > bgruening > diffbind
annotate diffbind.R @ 17:2605cbdaa7d8 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
author | iuc |
---|---|
date | Fri, 15 Dec 2023 19:39:14 +0000 |
parents | 163688bb8f73 |
children | f907216064f6 |
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 |
17
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
2 options(show.error.messages = FALSE, error = function() { |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
3 cat(geterrmessage(), file = stderr()) |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
4 q("no", 1, FALSE) |
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({ |
17
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
10 library("getopt") |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
11 library("DiffBind") |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
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 |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
18 #get options, using the spec as defined by the enclosed list. |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
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( |
17
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
21 "infile", "i", 1, "character", |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
22 "outfile", "o", 1, "character", |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
23 "scorecol", "n", 1, "integer", |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
24 "lowerbetter", "l", 1, "logical", |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
25 "summits", "s", 1, "integer", |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
26 "th", "t", 1, "double", |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
27 "format", "f", 1, "character", |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
28 "plots", "p", 2, "character", |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
29 "bmatrix", "b", 0, "logical", |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
30 "rdaOpt", "r", 0, "logical", |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
31 "infoOpt", "a", 0, "logical", |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
32 "verbose", "v", 2, "integer", |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
33 "help", "h", 0, "logical" |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
34 ), 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
|
35 |
17
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
36 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
|
37 |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
38 # 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
|
39 # 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
|
40 if (!is.null(opt$help)) { |
17
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
41 cat(getopt(spec, usage = TRUE)) |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
42 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
|
43 } |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
44 |
11
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
45 parser <- newJSONParser() |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
53 # 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
|
54 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
|
55 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
|
56 |
16
163688bb8f73
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents:
15
diff
changeset
|
57 if (length(ctrls) != 0) { |
17
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
58 sample_table <- data.frame( |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
59 SampleID = samples, |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
60 Condition = groups, |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
61 bamReads = bams, |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
62 bamControl = ctrls, |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
63 Peaks = peaks, |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
64 Tissue = samples |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
65 ) # 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
|
66 } else { |
17
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
67 sample_table <- data.frame( |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
68 SampleID = samples, |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
69 Replicate = samples, |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
70 Condition = groups, |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
71 bamReads = bams, |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
72 Peaks = peaks, |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
73 Tissue = samples |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
74 ) |
9
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
75 } |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
76 |
16
163688bb8f73
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents:
15
diff
changeset
|
77 sample <- dba(sampleSheet = sample_table, peakFormat = "bed", scoreCol = opt$scorecol, bLowerScoreBetter = opt$lowerbetter) |
11
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
78 |
16
163688bb8f73
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents:
15
diff
changeset
|
79 if (!is.null(opt$summits)) { |
17
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
80 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
|
81 } else { |
17
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
82 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
|
83 } |
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 sample_contrast <- dba.contrast(sample_count, categories = DBA_CONDITION, minMembers = 2) |
163688bb8f73
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents:
15
diff
changeset
|
86 sample_analyze <- dba.analyze(sample_contrast) |
163688bb8f73
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents:
15
diff
changeset
|
87 diff_bind <- dba.report(sample_analyze, th = opt$th) |
9
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
88 |
11
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
89 # 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
|
90 if (!is.null(opt$plots)) { |
17
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
91 pdf(opt$plots) |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
92 orvals <- dba.plotHeatmap(sample_analyze, contrast = 1, correlations = FALSE, cexCol = 0.8, th = opt$th) |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
93 dba.plotPCA(sample_analyze, contrast = 1, th = opt$th, label = DBA_TISSUE, labelSize = 0.3) |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
94 dba.plotMA(sample_analyze, th = opt$th) |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
95 dba.plotVolcano(sample_analyze, th = opt$th) |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
96 dba.plotBox(sample_analyze, th = opt$th) |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
97 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
|
98 } |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
99 |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
100 # 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
|
101 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
|
102 # 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
|
103 if (opt$format == "bed") { |
17
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
104 res_sorted <- data.frame( |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
105 Chrom = seqnames(res_sorted), |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
106 Start = start(res_sorted) - 1, |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
107 End = end(res_sorted), |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
108 Name = rep("DiffBind", length(res_sorted)), |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
109 Score = rep("0", length(res_sorted)), |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
110 Strand = gsub("\\*", ".", strand(res_sorted)) |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
111 ) |
13
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
112 } else if (opt$format == "interval") { |
17
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
113 # Output as interval |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
114 df <- as.data.frame(res_sorted) |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
115 extrainfo <- NULL |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
116 for (i in seq_len(nrow(df))) { |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
117 extrainfo[i] <- paste0(c(df$width[i], df[i, 6:ncol(df)]), collapse = "|") |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
118 } |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
119 res_sorted <- data.frame( |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
120 Chrom = seqnames(res_sorted), |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
121 Start = start(res_sorted) - 1, |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
122 End = end(res_sorted), |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
123 Name = rep("DiffBind", length(res_sorted)), |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
124 Score = rep("0", length(res_sorted)), |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
125 Strand = gsub("\\*", ".", strand(res_sorted)), |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
126 Comment = extrainfo |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
127 ) |
13
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
128 } else { |
17
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
129 # Output as 0-based tabular |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
130 res_sorted <- data.frame( |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
131 Chrom = seqnames(res_sorted), |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
132 Start = start(res_sorted) - 1, |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
133 End = end(res_sorted), |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
134 Name = rep("DiffBind", length(res_sorted)), |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
135 Score = rep("0", length(res_sorted)), |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
136 Strand = gsub("\\*", ".", strand(res_sorted)), |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
137 mcols(res_sorted) |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
138 ) |
13
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
139 } |
16
163688bb8f73
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 77828512472bf9815bdda725a58a2321f7803661"
iuc
parents:
15
diff
changeset
|
140 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
|
141 |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
142 # 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
|
143 if (!is.null(opt$bmatrix)) { |
17
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
144 bmat <- dba.peakset(sample_count, bRetrieve = TRUE, DataType = DBA_DATA_FRAME) |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
145 # Output as 0-based tabular |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
146 bmat <- data.frame( |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
147 Chrom = bmat[, 1], |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
148 Start = bmat[, 2] - 1, |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
149 End = bmat[, 3], |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
150 bmat[, 4:ncol(bmat)] |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
151 ) |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
152 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
|
153 } |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
154 |
11
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
155 # 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
|
156 if (!is.null(opt$rdaOpt)) { |
17
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
157 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
|
158 } |
d7725c5596ab
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit f970dcbe9d0e4c3714b1db74c404ea34223cf8ed
iuc
parents:
9
diff
changeset
|
159 |
11
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
160 # 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
|
161 if (!is.null(opt$infoOpt)) { |
17
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
162 info <- "DiffBind_analysis_info.txt" |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
163 cat("dba.count Info\n\n", file = info, append = TRUE) |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
164 capture.output(sample, file = info, append = TRUE) |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
165 cat("\ndba.analyze Info\n\n", file = info, append = TRUE) |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
166 capture.output(sample_analyze, file = info, append = TRUE) |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
167 cat("\nSessionInfo\n\n", file = info, append = TRUE) |
2605cbdaa7d8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 3da34ac6e5b18fd5deacaf31b757aca6bae82251
iuc
parents:
16
diff
changeset
|
168 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
|
169 } |