Mercurial > repos > bgruening > diffbind
annotate diffbind.R @ 13:1de83981d43c draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
author | iuc |
---|---|
date | Wed, 30 May 2018 12:25:42 -0400 |
parents | 4c7ab9995f9e |
children | 194e3f2c1d86 |
rev | line source |
---|---|
9
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
1 ## Setup R error handling to go to stderr |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
2 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } ) |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
3 # we need that to not crash galaxy with an UTF8 error on German LC settings. |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
4 Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
5 |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
6 suppressPackageStartupMessages({ |
11
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
7 library('getopt') |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
8 library('DiffBind') |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
9 library('rjson') |
9
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
10 }) |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
11 |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
12 options(stringAsfactors = FALSE, useFancyQuotes = FALSE) |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
13 args <- commandArgs(trailingOnly = TRUE) |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
14 |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
15 #get options, using the spec as defined by the enclosed list. |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
16 #we read the options from the default: commandArgs(TRUE). |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
17 spec = matrix(c( |
11
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
18 'infile' , 'i', 1, "character", |
9
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
19 'outfile' , 'o', 1, "character", |
11
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
20 'scorecol', 'n', 1, "integer", |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
21 'lowerbetter', 'l', 1, "logical", |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
22 'summits', 's', 1, "integer", |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
23 'th', 't', 1, "double", |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
24 'format', 'f', 1, "character", |
9
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
25 'plots' , 'p', 2, "character", |
10
d7725c5596ab
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit f970dcbe9d0e4c3714b1db74c404ea34223cf8ed
iuc
parents:
9
diff
changeset
|
26 'bmatrix', 'b', 0, "logical", |
11
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
27 "rdaOpt", "r", 0, "logical", |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
28 'infoOpt' , 'a', 0, "logical", |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
29 'verbose', 'v', 2, "integer", |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
30 'help' , 'h', 0, "logical" |
9
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
31 ), byrow=TRUE, ncol=4); |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
32 |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
33 opt = getopt(spec); |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
34 |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
35 # if help was asked for print a friendly message |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
36 # and exit with a non-zero error code |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
37 if ( !is.null(opt$help) ) { |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
38 cat(getopt(spec, usage=TRUE)); |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
39 q(status=1); |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
40 } |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
41 |
11
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
42 parser <- newJSONParser() |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
43 parser$addData(opt$infile) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
44 factorList <- parser$getObject() |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
45 filenamesIn <- unname(unlist(factorList[[1]][[2]])) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
46 peaks <- filenamesIn[grepl("peaks.bed", filenamesIn)] |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
47 bams <- filenamesIn[grepl("bamreads.bam", filenamesIn)] |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
48 ctrls <- filenamesIn[grepl("bamcontrol.bam", filenamesIn)] |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
49 |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
50 # get the group and sample id from the peaks filenames |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
51 groups <- sapply(strsplit(peaks,"-"), `[`, 1) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
52 samples <- sapply(strsplit(peaks,"-"), `[`, 2) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
53 |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
54 if ( length(ctrls) != 0 ) { |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
55 sampleTable <- data.frame(SampleID=samples, |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
56 Condition=groups, |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
57 bamReads=bams, |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
58 bamControl=ctrls, |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
59 Peaks=peaks, |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
60 Tissue=samples, # using "Tissue" column to display ids as labels in PCA plot |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
61 stringsAsFactors=FALSE) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
62 } else { |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
63 sampleTable <- data.frame(SampleID=samples, |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
64 Replicate=samples, |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
65 Condition=groups, |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
66 bamReads=bams, |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
67 Peaks=peaks, |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
68 Tissue=samples, |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
69 stringsAsFactors=FALSE) |
9
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
70 } |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
71 |
11
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
72 sample = dba(sampleSheet=sampleTable, peakFormat='bed', scoreCol=opt$scorecol, bLowerScoreBetter=opt$lowerbetter) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
73 |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
74 if ( !is.null(opt$summits) ) { |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
75 sample_count = dba.count(sample, summits=opt$summits) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
76 } else { |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
77 sample_count = dba.count(sample) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
78 } |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
79 |
9
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
80 sample_contrast = dba.contrast(sample_count, categories=DBA_CONDITION, minMembers=2) |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
81 sample_analyze = dba.analyze(sample_contrast) |
11
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
82 diff_bind = dba.report(sample_analyze, th=opt$th) |
9
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
83 |
11
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
84 # Generate plots |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
85 if ( !is.null(opt$plots) ) { |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
86 pdf(opt$plots) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
87 orvals = dba.plotHeatmap(sample_analyze, contrast=1, correlations=FALSE, cexCol=0.8, th=opt$th) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
88 dba.plotPCA(sample_analyze, contrast=1, th=opt$th, label=DBA_TISSUE, labelSize=0.3) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
89 dba.plotMA(sample_analyze, th=opt$th) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
90 dba.plotVolcano(sample_analyze, th=opt$th) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
91 dba.plotBox(sample_analyze, th=opt$th) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
92 dev.off() |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
93 } |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
94 |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
95 # Output differential binding sites |
9
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
96 resSorted <- diff_bind[order(diff_bind$FDR),] |
13
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
97 # Convert from GRanges (1-based) to 0-based format (adapted from https://www.biostars.org/p/89341/) |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
98 if (opt$format == "bed") { |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
99 resSorted <- data.frame(Chrom=seqnames(resSorted), |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
100 Start=start(resSorted) - 1, |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
101 End=end(resSorted), |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
102 Name=rep("DiffBind", length(resSorted)), |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
103 Score=rep("0", length(resSorted)), |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
104 Strand=gsub("\\*", ".", strand(resSorted))) |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
105 } else if (opt$format == "interval") { |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
106 # Output as interval |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
107 df <- as.data.frame(resSorted) |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
108 extrainfo <- NULL |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
109 for (i in 1:nrow(df)) { |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
110 extrainfo[i] <- paste0(c(df$width[i], df[i, 6:ncol(df)]), collapse="|") |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
111 } |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
112 resSorted <- data.frame(Chrom=seqnames(resSorted), |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
113 Start=start(resSorted) - 1, |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
114 End=end(resSorted), |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
115 Name=rep("DiffBind", length(resSorted)), |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
116 Score=rep("0", length(resSorted)), |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
117 Strand=gsub("\\*", ".", strand(resSorted)), |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
118 Comment=extrainfo) |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
119 } else { |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
120 # Output as 0-based tabular |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
121 resSorted <- data.frame(Chrom=seqnames(resSorted), |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
122 Start=start(resSorted) - 1, |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
123 End=end(resSorted), |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
124 Name=rep("DiffBind", length(resSorted)), |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
125 Score=rep("0", length(resSorted)), |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
126 Strand=gsub("\\*", ".", strand(resSorted)), |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
127 mcols(resSorted)) |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
128 } |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
129 write.table(resSorted, file = opt$outfile, sep="\t", quote = FALSE, append=TRUE, row.names = FALSE) |
9
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
130 |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
131 # Output binding affinity scores |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
132 if (!is.null(opt$bmatrix)) { |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
133 bmat <- dba.peakset(sample_count, bRetrieve=TRUE, DataType=DBA_DATA_FRAME) |
13
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
134 # Output as 0-based tabular |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
135 bmat <- data.frame(Chrom=bmat[, 1], |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
136 Start=bmat[, 2] - 1, |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
137 End=bmat[, 3], |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
138 bmat[, 4:ncol(bmat)]) |
1de83981d43c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 13485bed6a57ec4a34cab4ec6bb8b36d219e3610
iuc
parents:
11
diff
changeset
|
139 write.table(bmat, file="bmatrix.tab", sep="\t", quote=FALSE, row.names=FALSE) |
9
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
140 } |
6171163112de
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit 9de99de5fb4c62f889814ea43b8800ce8d28eb83
iuc
parents:
diff
changeset
|
141 |
11
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
142 # Output RData file |
10
d7725c5596ab
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit f970dcbe9d0e4c3714b1db74c404ea34223cf8ed
iuc
parents:
9
diff
changeset
|
143 if (!is.null(opt$rdaOpt)) { |
d7725c5596ab
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit f970dcbe9d0e4c3714b1db74c404ea34223cf8ed
iuc
parents:
9
diff
changeset
|
144 save.image(file = "DiffBind_analysis.RData") |
d7725c5596ab
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit f970dcbe9d0e4c3714b1db74c404ea34223cf8ed
iuc
parents:
9
diff
changeset
|
145 } |
d7725c5596ab
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit f970dcbe9d0e4c3714b1db74c404ea34223cf8ed
iuc
parents:
9
diff
changeset
|
146 |
11
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
147 # Output analysis info |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
148 if (!is.null(opt$infoOpt)) { |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
149 info <- "DiffBind_analysis_info.txt" |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
150 cat("dba.count Info\n\n", file=info, append = TRUE) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
151 capture.output(sample, file=info, append=TRUE) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
152 cat("\ndba.analyze Info\n\n", file=info, append = TRUE) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
153 capture.output(sample_analyze, file=info, append=TRUE) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
154 cat("\nSessionInfo\n\n", file=info, append = TRUE) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
155 capture.output(sessionInfo(), file=info, append=TRUE) |
4c7ab9995f9e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/diffbind commit cc4c1c4131518b9cbf986a1f252767ff73ca938e
iuc
parents:
10
diff
changeset
|
156 } |