comparison diffbind.R @ 0:c0f5b2133506 draft default tip

initial commit for DiffBind
author bjoern-gruening
date Tue, 14 Jan 2014 18:12:02 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c0f5b2133506
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 library('getopt');
7 options(stringAsfactors = FALSE, useFancyQuotes = FALSE)
8 args <- commandArgs(trailingOnly = TRUE)
9
10 #get options, using the spec as defined by the enclosed list.
11 #we read the options from the default: commandArgs(TRUE).
12 spec = matrix(c(
13 'verbose', 'v', 2, "integer",
14 'help' , 'h', 0, "logical",
15 'outfile' , 'o', 1, "character",
16 'plots' , 'p', 2, "character",
17 'infile' , 'i', 1, "character",
18 'format', 'f', 1, 'character'
19 ), byrow=TRUE, ncol=4);
20
21 opt = getopt(spec);
22
23 # if help was asked for print a friendly message
24 # and exit with a non-zero error code
25 if ( !is.null(opt$help) ) {
26 cat(getopt(spec, usage=TRUE));
27 q(status=1);
28 }
29
30
31 library('DiffBind')
32 # used to save to BED, GFF or WIG format
33 library('rtracklayer')
34
35 if ( !is.null(opt$plots) ) {
36 pdf(opt$plots)
37 }
38
39
40 sample = dba(sampleSheet=opt$infile, peakFormat='bed')
41 sample_count = dba.count(sample)
42 sample_contrast = dba.contrast(sample_count, categories=DBA_CONDITION)
43 sample_analyze = dba.analyze(sample_contrast)
44 diff_bind = dba.report(sample_analyze)
45
46
47 export(diff_bind, opt$outfile, format=opt$format)
48
49 dev.off()
50 sessionInfo()