annotate diffbind.R @ 0:7faaf4a5e4e1 draft

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