Mercurial > repos > pavanvidem > diffbind
comparison diffbind.R @ 0:095c44c46032 draft
Uploaded
author | pavanvidem |
---|---|
date | Fri, 22 May 2015 08:15:25 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:095c44c46032 |
---|---|
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 library('DiffBind') | |
31 | |
32 if ( !is.null(opt$plots) ) { | |
33 pdf(opt$plots) | |
34 } | |
35 | |
36 | |
37 sample = dba(sampleSheet=opt$infile, peakFormat='bed') | |
38 sample_count = dba.count(sample) | |
39 sample_contrast = dba.contrast(sample_count, categories=DBA_CONDITION, minMembers=2) | |
40 sample_analyze = dba.analyze(sample_contrast) | |
41 diff_bind = dba.report(sample_analyze) | |
42 orvals = dba.plotHeatmap(sample_analyze, contrast=1, correlations=FALSE) | |
43 | |
44 resSorted <- diff_bind[order(diff_bind$FDR),] | |
45 write.table(as.data.frame(resSorted), file = opt$outfile, sep="\t", quote = FALSE, append=TRUE, row.names = FALSE, col.names = FALSE) | |
46 | |
47 | |
48 dev.off() | |
49 sessionInfo() |