Mercurial > repos > bgruening > diffbind
annotate diffbind.R @ 9:6171163112de draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
author | iuc |
---|---|
date | Sun, 28 Jan 2018 05:10:25 -0500 |
parents | |
children | d7725c5596ab |
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({ |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
7 library('getopt') |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
8 library('DiffBind') |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
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 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
|
12 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
|
13 |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
14 #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
|
15 #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
|
16 spec = matrix(c( |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
17 'verbose', 'v', 2, "integer", |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
18 'help' , 'h', 0, "logical", |
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", |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
20 'plots' , 'p', 2, "character", |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
21 'infile' , 'i', 1, "character", |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
22 'format', 'f', 1, "character", |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
23 'th', 't', 1, "double", |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
24 'bmatrix', 'b', 0, "logical" |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
25 ), 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
|
26 |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
27 opt = getopt(spec); |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
28 |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
29 # 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
|
30 # 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
|
31 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
|
32 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
|
33 q(status=1); |
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 |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
36 if ( !is.null(opt$plots) ) { |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
37 pdf(opt$plots) |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
38 } |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
39 |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
40 sample = dba(sampleSheet=opt$infile, peakFormat='bed') |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
41 sample_count = dba.count(sample) |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
42 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
|
43 sample_analyze = dba.analyze(sample_contrast) |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
44 diff_bind = dba.report(sample_analyze) |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
45 orvals = dba.plotHeatmap(sample_analyze, contrast=1, correlations=FALSE) |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
46 |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
47 resSorted <- diff_bind[order(diff_bind$FDR),] |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
48 write.table(as.data.frame(resSorted), file = opt$outfile, sep="\t", quote = FALSE, append=TRUE, row.names = FALSE, col.names = FALSE) |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
49 |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
50 # 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
|
51 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
|
52 bmat <- dba.peakset(sample_count, bRetrieve=TRUE, DataType=DBA_DATA_FRAME) |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
53 write.table(as.data.frame(bmat), file="bmatrix.tab", sep="\t", quote=FALSE, row.names=FALSE, col.names=FALSE) |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
54 } |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
55 |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
56 dev.off() |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
57 sessionInfo() |