annotate diffbind.R @ 16:163688bb8f73 draft

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