Mercurial > repos > bgruening > diffbind
annotate diffbind.R @ 20:11cd8b1ae397 draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/diffbind commit affbc59222cde9be21e91fa1f9194930a070b830
| author | iuc |
|---|---|
| date | Sun, 28 Jan 2018 04:25:49 -0500 |
| parents | a8dc71379df0 |
| children |
| rev | line source |
|---|---|
| 0 | 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 | |
|
20
11cd8b1ae397
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/diffbind commit affbc59222cde9be21e91fa1f9194930a070b830
iuc
parents:
11
diff
changeset
|
6 suppressPackageStartupMessages({ |
|
11cd8b1ae397
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/diffbind commit affbc59222cde9be21e91fa1f9194930a070b830
iuc
parents:
11
diff
changeset
|
7 library('getopt') |
|
11cd8b1ae397
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/diffbind commit affbc59222cde9be21e91fa1f9194930a070b830
iuc
parents:
11
diff
changeset
|
8 library('DiffBind') |
|
11cd8b1ae397
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/diffbind commit affbc59222cde9be21e91fa1f9194930a070b830
iuc
parents:
11
diff
changeset
|
9 }) |
|
11cd8b1ae397
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/diffbind commit affbc59222cde9be21e91fa1f9194930a070b830
iuc
parents:
11
diff
changeset
|
10 |
| 0 | 11 options(stringAsfactors = FALSE, useFancyQuotes = FALSE) |
| 12 args <- commandArgs(trailingOnly = TRUE) | |
| 13 | |
| 14 #get options, using the spec as defined by the enclosed list. | |
| 15 #we read the options from the default: commandArgs(TRUE). | |
| 16 spec = matrix(c( | |
| 7 | 17 'verbose', 'v', 2, "integer", |
| 18 'help' , 'h', 0, "logical", | |
| 19 'outfile' , 'o', 1, "character", | |
| 20 'plots' , 'p', 2, "character", | |
| 21 'infile' , 'i', 1, "character", | |
|
20
11cd8b1ae397
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/diffbind commit affbc59222cde9be21e91fa1f9194930a070b830
iuc
parents:
11
diff
changeset
|
22 'format', 'f', 1, "character", |
|
11cd8b1ae397
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/diffbind commit affbc59222cde9be21e91fa1f9194930a070b830
iuc
parents:
11
diff
changeset
|
23 'th', 't', 1, "double", |
|
11cd8b1ae397
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/diffbind commit affbc59222cde9be21e91fa1f9194930a070b830
iuc
parents:
11
diff
changeset
|
24 'bmatrix', 'b', 0, "logical" |
| 0 | 25 ), byrow=TRUE, ncol=4); |
| 7 | 26 |
| 0 | 27 opt = getopt(spec); |
| 28 | |
| 29 # if help was asked for print a friendly message | |
| 30 # and exit with a non-zero error code | |
| 31 if ( !is.null(opt$help) ) { | |
| 9 | 32 cat(getopt(spec, usage=TRUE)); |
| 33 q(status=1); | |
| 0 | 34 } |
| 35 | |
| 36 if ( !is.null(opt$plots) ) { | |
| 9 | 37 pdf(opt$plots) |
| 0 | 38 } |
| 39 | |
| 9 | 40 sample = dba(sampleSheet=opt$infile, peakFormat='bed') |
| 0 | 41 sample_count = dba.count(sample) |
| 10 | 42 sample_contrast = dba.contrast(sample_count, categories=DBA_CONDITION, minMembers=2) |
| 0 | 43 sample_analyze = dba.analyze(sample_contrast) |
| 44 diff_bind = dba.report(sample_analyze) | |
| 10 | 45 orvals = dba.plotHeatmap(sample_analyze, contrast=1, correlations=FALSE) |
| 0 | 46 |
| 10 | 47 resSorted <- diff_bind[order(diff_bind$FDR),] |
| 48 write.table(as.data.frame(resSorted), file = opt$outfile, sep="\t", quote = FALSE, append=TRUE, row.names = FALSE, col.names = FALSE) | |
| 49 | |
|
20
11cd8b1ae397
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/diffbind commit affbc59222cde9be21e91fa1f9194930a070b830
iuc
parents:
11
diff
changeset
|
50 # Output binding affinity scores |
|
11cd8b1ae397
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/diffbind commit affbc59222cde9be21e91fa1f9194930a070b830
iuc
parents:
11
diff
changeset
|
51 if (!is.null(opt$bmatrix)) { |
|
11cd8b1ae397
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/diffbind commit affbc59222cde9be21e91fa1f9194930a070b830
iuc
parents:
11
diff
changeset
|
52 bmat <- dba.peakset(sample_count, bRetrieve=TRUE, DataType=DBA_DATA_FRAME) |
|
11cd8b1ae397
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/diffbind commit affbc59222cde9be21e91fa1f9194930a070b830
iuc
parents:
11
diff
changeset
|
53 write.table(as.data.frame(bmat), file="bmatrix.tab", sep="\t", quote=FALSE, row.names=FALSE, col.names=FALSE) |
|
11cd8b1ae397
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/diffbind commit affbc59222cde9be21e91fa1f9194930a070b830
iuc
parents:
11
diff
changeset
|
54 } |
| 0 | 55 |
| 56 dev.off() | |
| 57 sessionInfo() |
