Mercurial > repos > bgruening > diffbind
comparison diffbind.R @ 0:7faaf4a5e4e1 draft
Uploaded
author | bgruening |
---|---|
date | Thu, 16 Jan 2014 04:15:09 -0500 |
parents | |
children | 9e9f85c20d99 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7faaf4a5e4e1 |
---|---|
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 | |
34 if ( !is.null(opt$plots) ) { | |
35 pdf(opt$plots) | |
36 } | |
37 | |
38 | |
39 sample = dba(sampleSheet=opt$infile, peakFormat='bed') | |
40 sample_count = dba.count(sample) | |
41 sample_contrast = dba.contrast(sample_count, categories=DBA_CONDITION, minMembers=2) | |
42 sample_analyze = dba.analyze(sample_contrast) | |
43 diff_bind = dba.report(sample_analyze) | |
44 orvals = dba.plotHeatmap(sample_analyze, contrast=1, correlations=FALSE) | |
45 | |
46 resSorted <- diff_bind[order(diff_bind$FDR),] | |
47 write.table(as.data.frame(resSorted), file = opt$outfile, sep="\t", quote = FALSE, append=TRUE, row.names = FALSE, col.names = FALSE) | |
48 | |
49 | |
50 dev.off() | |
51 sessionInfo() |