Mercurial > repos > bgruening > diffbind
comparison test-data/out_rscript.txt @ 11:4c7ab9995f9e draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
author | iuc |
---|---|
date | Sat, 07 Apr 2018 15:45:41 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
10:d7725c5596ab | 11:4c7ab9995f9e |
---|---|
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 suppressPackageStartupMessages({ | |
7 library('getopt') | |
8 library('DiffBind') | |
9 library('rjson') | |
10 }) | |
11 | |
12 options(stringAsfactors = FALSE, useFancyQuotes = FALSE) | |
13 args <- commandArgs(trailingOnly = TRUE) | |
14 | |
15 #get options, using the spec as defined by the enclosed list. | |
16 #we read the options from the default: commandArgs(TRUE). | |
17 spec = matrix(c( | |
18 'infile' , 'i', 1, "character", | |
19 'outfile' , 'o', 1, "character", | |
20 'scorecol', 'n', 1, "integer", | |
21 'lowerbetter', 'l', 1, "logical", | |
22 'summits', 's', 1, "integer", | |
23 'th', 't', 1, "double", | |
24 'format', 'f', 1, "character", | |
25 'plots' , 'p', 2, "character", | |
26 'bmatrix', 'b', 0, "logical", | |
27 "rdaOpt", "r", 0, "logical", | |
28 'infoOpt' , 'a', 0, "logical", | |
29 'verbose', 'v', 2, "integer", | |
30 'help' , 'h', 0, "logical" | |
31 ), byrow=TRUE, ncol=4); | |
32 | |
33 opt = getopt(spec); | |
34 | |
35 # if help was asked for print a friendly message | |
36 # and exit with a non-zero error code | |
37 if ( !is.null(opt$help) ) { | |
38 cat(getopt(spec, usage=TRUE)); | |
39 q(status=1); | |
40 } | |
41 | |
42 parser <- newJSONParser() | |
43 parser$addData(opt$infile) | |
44 factorList <- parser$getObject() | |
45 filenamesIn <- unname(unlist(factorList[[1]][[2]])) | |
46 peaks <- filenamesIn[grepl("peaks.bed", filenamesIn)] | |
47 bams <- filenamesIn[grepl("bamreads.bam", filenamesIn)] | |
48 ctrls <- filenamesIn[grepl("bamcontrol.bam", filenamesIn)] | |
49 | |
50 # get the group and sample id from the peaks filenames | |
51 groups <- sapply(strsplit(peaks,"-"), `[`, 1) | |
52 samples <- sapply(strsplit(peaks,"-"), `[`, 2) | |
53 | |
54 if ( length(ctrls) != 0 ) { | |
55 sampleTable <- data.frame(SampleID=samples, | |
56 Condition=groups, | |
57 bamReads=bams, | |
58 bamControl=ctrls, | |
59 Peaks=peaks, | |
60 Tissue=samples, # using "Tissue" column to display ids as labels in PCA plot | |
61 stringsAsFactors=FALSE) | |
62 } else { | |
63 sampleTable <- data.frame(SampleID=samples, | |
64 Replicate=samples, | |
65 Condition=groups, | |
66 bamReads=bams, | |
67 Peaks=peaks, | |
68 Tissue=samples, | |
69 stringsAsFactors=FALSE) | |
70 } | |
71 | |
72 sample = dba(sampleSheet=sampleTable, peakFormat='bed', scoreCol=opt$scorecol, bLowerScoreBetter=opt$lowerbetter) | |
73 | |
74 if ( !is.null(opt$summits) ) { | |
75 sample_count = dba.count(sample, summits=opt$summits) | |
76 } else { | |
77 sample_count = dba.count(sample) | |
78 } | |
79 | |
80 sample_contrast = dba.contrast(sample_count, categories=DBA_CONDITION, minMembers=2) | |
81 sample_analyze = dba.analyze(sample_contrast) | |
82 diff_bind = dba.report(sample_analyze, th=opt$th) | |
83 | |
84 # Generate plots | |
85 if ( !is.null(opt$plots) ) { | |
86 pdf(opt$plots) | |
87 orvals = dba.plotHeatmap(sample_analyze, contrast=1, correlations=FALSE, cexCol=0.8, th=opt$th) | |
88 dba.plotPCA(sample_analyze, contrast=1, th=opt$th, label=DBA_TISSUE, labelSize=0.3) | |
89 dba.plotMA(sample_analyze, th=opt$th) | |
90 dba.plotVolcano(sample_analyze, th=opt$th) | |
91 dba.plotBox(sample_analyze, th=opt$th) | |
92 dev.off() | |
93 } | |
94 | |
95 # Output differential binding sites | |
96 resSorted <- diff_bind[order(diff_bind$FDR),] | |
97 write.table(as.data.frame(resSorted), file = opt$outfile, sep="\t", quote = FALSE, append=TRUE, row.names = FALSE) | |
98 | |
99 # Output binding affinity scores | |
100 if (!is.null(opt$bmatrix)) { | |
101 bmat <- dba.peakset(sample_count, bRetrieve=TRUE, DataType=DBA_DATA_FRAME) | |
102 write.table(as.data.frame(bmat), file="bmatrix.tab", sep="\t", quote=FALSE, row.names=FALSE) | |
103 } | |
104 | |
105 # Output RData file | |
106 if (!is.null(opt$rdaOpt)) { | |
107 save.image(file = "DiffBind_analysis.RData") | |
108 } | |
109 | |
110 # Output analysis info | |
111 if (!is.null(opt$infoOpt)) { | |
112 info <- "DiffBind_analysis_info.txt" | |
113 cat("dba.count Info\n\n", file=info, append = TRUE) | |
114 capture.output(sample, file=info, append=TRUE) | |
115 cat("\ndba.analyze Info\n\n", file=info, append = TRUE) | |
116 capture.output(sample_analyze, file=info, append=TRUE) | |
117 cat("\nSessionInfo\n\n", file=info, append = TRUE) | |
118 capture.output(sessionInfo(), file=info, append=TRUE) | |
119 } |