diff diffbind.R @ 7:681dedc42aca draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/diffbind commit affbc59222cde9be21e91fa1f9194930a070b830
author iuc
date Sun, 28 Jan 2018 04:26:11 -0500
parents 9e9f85c20d99
children
line wrap: on
line diff
--- a/diffbind.R	Sat Oct 28 12:53:58 2017 -0400
+++ b/diffbind.R	Sun Jan 28 04:26:11 2018 -0500
@@ -3,7 +3,11 @@
 # we need that to not crash galaxy with an UTF8 error on German LC settings.
 Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
 
-library('getopt');
+suppressPackageStartupMessages({
+	library('getopt')
+	library('DiffBind')
+})
+
 options(stringAsfactors = FALSE, useFancyQuotes = FALSE)
 args <- commandArgs(trailingOnly = TRUE)
 
@@ -15,7 +19,9 @@
     'outfile' , 'o', 1, "character",
     'plots' , 'p', 2, "character",
     'infile' , 'i', 1, "character",
-    'format', 'f', 1, 'character'
+    'format', 'f', 1, "character",
+    'th', 't', 1, "double",
+    'bmatrix', 'b', 0, "logical"
 ), byrow=TRUE, ncol=4);
 
 opt = getopt(spec);
@@ -27,13 +33,10 @@
     q(status=1);
 }
 
-library('DiffBind')
-
 if ( !is.null(opt$plots) ) {
     pdf(opt$plots)
 }
 
-
 sample = dba(sampleSheet=opt$infile, peakFormat='bed')
 sample_count = dba.count(sample)
 sample_contrast = dba.contrast(sample_count, categories=DBA_CONDITION, minMembers=2)
@@ -44,6 +47,11 @@
 resSorted <- diff_bind[order(diff_bind$FDR),]
 write.table(as.data.frame(resSorted), file = opt$outfile, sep="\t", quote = FALSE, append=TRUE, row.names = FALSE, col.names = FALSE)
 
+# Output binding affinity scores
+if (!is.null(opt$bmatrix)) {
+    bmat <- dba.peakset(sample_count, bRetrieve=TRUE, DataType=DBA_DATA_FRAME)
+    write.table(as.data.frame(bmat), file="bmatrix.tab", sep="\t", quote=FALSE, row.names=FALSE, col.names=FALSE)
+}
 
 dev.off()
 sessionInfo()