comparison diffbind.R @ 0:18090d836604 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit f970dcbe9d0e4c3714b1db74c404ea34223cf8ed
author iuc
date Tue, 20 Mar 2018 04:51:01 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:18090d836604
1 ## Setup R error handling to go to stderr
2 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
3 # we need that to not crash galaxy with an UTF8 error on German LC settings.
4 Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
5
6 suppressPackageStartupMessages({
7 library('getopt')
8 library('DiffBind')
9 })
10
11 options(stringAsfactors = FALSE, useFancyQuotes = FALSE)
12 args <- commandArgs(trailingOnly = TRUE)
13
14 #get options, using the spec as defined by the enclosed list.
15 #we read the options from the default: commandArgs(TRUE).
16 spec = matrix(c(
17 'verbose', 'v', 2, "integer",
18 'help' , 'h', 0, "logical",
19 'outfile' , 'o', 1, "character",
20 'plots' , 'p', 2, "character",
21 'infile' , 'i', 1, "character",
22 'format', 'f', 1, "character",
23 'th', 't', 1, "double",
24 'bmatrix', 'b', 0, "logical",
25 "rdaOpt", "r", 0, "logical"
26 ), byrow=TRUE, ncol=4);
27
28 opt = getopt(spec);
29
30 # if help was asked for print a friendly message
31 # and exit with a non-zero error code
32 if ( !is.null(opt$help) ) {
33 cat(getopt(spec, usage=TRUE));
34 q(status=1);
35 }
36
37 if ( !is.null(opt$plots) ) {
38 pdf(opt$plots)
39 }
40
41 sample = dba(sampleSheet=opt$infile, peakFormat='bed')
42 sample_count = dba.count(sample)
43 sample_contrast = dba.contrast(sample_count, categories=DBA_CONDITION, minMembers=2)
44 sample_analyze = dba.analyze(sample_contrast)
45 diff_bind = dba.report(sample_analyze)
46 orvals = dba.plotHeatmap(sample_analyze, contrast=1, correlations=FALSE)
47 dev.off()
48
49 resSorted <- diff_bind[order(diff_bind$FDR),]
50 write.table(as.data.frame(resSorted), file = opt$outfile, sep="\t", quote = FALSE, append=TRUE, row.names = FALSE, col.names = FALSE)
51
52 # Output binding affinity scores
53 if (!is.null(opt$bmatrix)) {
54 bmat <- dba.peakset(sample_count, bRetrieve=TRUE, DataType=DBA_DATA_FRAME)
55 write.table(as.data.frame(bmat), file="bmatrix.tab", sep="\t", quote=FALSE, row.names=FALSE, col.names=FALSE)
56 }
57
58 ## Output RData file
59
60 if (!is.null(opt$rdaOpt)) {
61 save.image(file = "DiffBind_analysis.RData")
62 }
63
64 sessionInfo()