annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
1 ## Setup R error handling to go to stderr
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
2 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
3 # we need that to not crash galaxy with an UTF8 error on German LC settings.
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
4 Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
5
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
6 library('getopt');
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
7 options(stringAsfactors = FALSE, useFancyQuotes = FALSE)
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
8 args <- commandArgs(trailingOnly = TRUE)
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
9
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
10 #get options, using the spec as defined by the enclosed list.
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
11 #we read the options from the default: commandArgs(TRUE).
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
12 spec = matrix(c(
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
13 'verbose', 'v', 2, "integer",
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
14 'help' , 'h', 0, "logical",
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
15 'outfile' , 'o', 1, "character",
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
16 'plots' , 'p', 2, "character",
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
17 'infile' , 'i', 1, "character",
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
18 'format', 'f', 1, 'character'
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
19 ), byrow=TRUE, ncol=4);
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
20
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
21 opt = getopt(spec);
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
22
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
23 # if help was asked for print a friendly message
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
24 # and exit with a non-zero error code
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
25 if ( !is.null(opt$help) ) {
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
26 cat(getopt(spec, usage=TRUE));
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
27 q(status=1);
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
28 }
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
29
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
30
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
31 library('DiffBind')
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
32 # used to save to BED, GFF or WIG format
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
33 library('rtracklayer')
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
34
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
35 if ( !is.null(opt$plots) ) {
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
36 pdf(opt$plots)
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
37 }
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
38
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
39
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
40 sample = dba(sampleSheet=opt$infile, peakFormat='bed')
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
41 sample_count = dba.count(sample)
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
42 sample_contrast = dba.contrast(sample_count, categories=DBA_CONDITION)
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
43 sample_analyze = dba.analyze(sample_contrast)
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
44 diff_bind = dba.report(sample_analyze)
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
45
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
46
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
47 export(diff_bind, opt$outfile, format=opt$format)
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
48
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
49 dev.off()
c0f5b2133506 initial commit for DiffBind
bjoern-gruening
parents:
diff changeset
50 sessionInfo()