Mercurial > repos > bgruening > diffbind
comparison 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 |
comparison
equal
deleted
inserted
replaced
12:fa56d93f7980 | 13:1de83981d43c |
---|---|
92 dev.off() | 92 dev.off() |
93 } | 93 } |
94 | 94 |
95 # Output differential binding sites | 95 # Output differential binding sites |
96 resSorted <- diff_bind[order(diff_bind$FDR),] | 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) | 97 # Convert from GRanges (1-based) to 0-based format (adapted from https://www.biostars.org/p/89341/) |
98 if (opt$format == "bed") { | |
99 resSorted <- data.frame(Chrom=seqnames(resSorted), | |
100 Start=start(resSorted) - 1, | |
101 End=end(resSorted), | |
102 Name=rep("DiffBind", length(resSorted)), | |
103 Score=rep("0", length(resSorted)), | |
104 Strand=gsub("\\*", ".", strand(resSorted))) | |
105 } else if (opt$format == "interval") { | |
106 # Output as interval | |
107 df <- as.data.frame(resSorted) | |
108 extrainfo <- NULL | |
109 for (i in 1:nrow(df)) { | |
110 extrainfo[i] <- paste0(c(df$width[i], df[i, 6:ncol(df)]), collapse="|") | |
111 } | |
112 resSorted <- data.frame(Chrom=seqnames(resSorted), | |
113 Start=start(resSorted) - 1, | |
114 End=end(resSorted), | |
115 Name=rep("DiffBind", length(resSorted)), | |
116 Score=rep("0", length(resSorted)), | |
117 Strand=gsub("\\*", ".", strand(resSorted)), | |
118 Comment=extrainfo) | |
119 } else { | |
120 # Output as 0-based tabular | |
121 resSorted <- data.frame(Chrom=seqnames(resSorted), | |
122 Start=start(resSorted) - 1, | |
123 End=end(resSorted), | |
124 Name=rep("DiffBind", length(resSorted)), | |
125 Score=rep("0", length(resSorted)), | |
126 Strand=gsub("\\*", ".", strand(resSorted)), | |
127 mcols(resSorted)) | |
128 } | |
129 write.table(resSorted, file = opt$outfile, sep="\t", quote = FALSE, append=TRUE, row.names = FALSE) | |
98 | 130 |
99 # Output binding affinity scores | 131 # Output binding affinity scores |
100 if (!is.null(opt$bmatrix)) { | 132 if (!is.null(opt$bmatrix)) { |
101 bmat <- dba.peakset(sample_count, bRetrieve=TRUE, DataType=DBA_DATA_FRAME) | 133 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) | 134 # Output as 0-based tabular |
135 bmat <- data.frame(Chrom=bmat[, 1], | |
136 Start=bmat[, 2] - 1, | |
137 End=bmat[, 3], | |
138 bmat[, 4:ncol(bmat)]) | |
139 write.table(bmat, file="bmatrix.tab", sep="\t", quote=FALSE, row.names=FALSE) | |
103 } | 140 } |
104 | 141 |
105 # Output RData file | 142 # Output RData file |
106 if (!is.null(opt$rdaOpt)) { | 143 if (!is.null(opt$rdaOpt)) { |
107 save.image(file = "DiffBind_analysis.RData") | 144 save.image(file = "DiffBind_analysis.RData") |