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