Mercurial > repos > drosofff > msp_sr_readmap_and_size_histograms
changeset 12:2fc0d4756048 draft
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit e27d18d58ae095e7fad4b08b04370857a1d37964-dirty
author | mvdbeek |
---|---|
date | Tue, 02 Feb 2016 14:53:10 -0500 |
parents | edd57052f0bb |
children | 355940295e76 |
files | readmap.xml |
diffstat | 1 files changed, 123 insertions(+), 128 deletions(-) [+] |
line wrap: on
line diff
--- a/readmap.xml Tue Feb 02 12:57:04 2016 -0500 +++ b/readmap.xml Tue Feb 02 14:53:10 2016 -0500 @@ -1,4 +1,4 @@ -<tool id="Readmap" name="Generate readmap and histograms from alignment files" version="1.1.0"> +<tool id="Readmap" name="Generate readmap and histograms from alignment files" version="1.1.1"> <description>from sRbowtie aligment</description> <requirements> <requirement type="package" version="0.12.7">bowtie</requirement> @@ -77,151 +77,146 @@ <param name="maxquery" type="integer" size="3" value="28" label="Max size of query small RNAs" help="'28' = 28 nucleotides"/> <param name="title" type="text" size="15" value= "Readmaps and size distributions" label="Main Titles"/> <param name="xlabel" type="text" size="15" value="Coordinates/read size" label="x axis label"/> - <param name="yrange" type="integer" size="6" value="0" label="y axis range for readmap tool" help="leave at 0 for autoscaling"/> <param name="ylabel" type="text" size="15" value="Number of reads" label="y axis label"/> + <param name="yrange" type="integer" size="3" value="0" label="y axis range for readmaps. 0 means auto-scaling."/> <param name="rows_per_page" type="text" size="9" value="8" label="How many items to display per page?"> <validator type="in_range" min="6" max="20" message="Select between 6 and 20 rows, as the readability will suffer otherwise."/> </param> </inputs> <configfiles> - <configfile name="plotCode"><![CDATA[ + <configfile name="plotCode"> ## Setup R error handling to go to stderr - options( show.error.messages=F, - error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } ) - library(RColorBrewer) - library(lattice) - library(latticeExtra) - library(grid) - library(gridExtra) - - ## data frames implementation + options( show.error.messages=F, + error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } ) + library(RColorBrewer) + library(lattice) + library(latticeExtra) + library(grid) + library(gridExtra) + + ## data frames implementation - rm=read.delim("${readmap_dataframe}", header=T, row.names=NULL) - n_samples=length(unique(rm\$sample)) - genes=unique(levels(rm\$gene)) - per_gene_readmap=lapply(genes, function(x) subset(rm, gene==x)) ####### ? - n_genes=length(per_gene_readmap) + rm=read.delim("${readmap_dataframe}", header=T, row.names=NULL) + n_samples=length(unique(rm\$sample)) + genes=unique(levels(rm\$gene)) + per_gene_readmap=lapply(genes, function(x) subset(rm, gene==x)) ####### ? + n_genes=length(per_gene_readmap) + + size=read.delim("${size_distribution_dataframe}", header=T, row.names=NULL) + per_gene_size=lapply(genes, function(x) subset(size, gene==x)) ###### ? - size=read.delim("${size_distribution_dataframe}", header=T, row.names=NULL) - per_gene_size=lapply(genes, function(x) subset(size, gene==x)) ###### ? - - ## end of data frames implementation - - ## functions + ## end of data frames implementation + + ## functions + + plot_readmap=function(df, ...) { + combineLimits(xyplot(count~coord|factor(sample, levels=unique(sample))+reorder(gene, count, function(x) -sum(abs(x))), + data=df, + type='h', + scales= list(relation="free", x=list(rot=0, cex=0.7, axs="i", tck=0.5), y=list(tick.number=4, rot=90, cex=0.7)), + xlab=NULL, main=NULL, ylab=NULL, + as.table=T, + origin = 0, + horizontal=FALSE, + group=polarity, + col=c("red","blue"), + par.strip.text = list(cex=0.7), + ...)) + } - plot_readmap=function(df, ...) { - combineLimits(xyplot(count~coord|factor(sample, levels=unique(sample))+reorder(gene, count, function(x) -sum(abs(x))), - data=df, - type='h', - scales= list(relation="free", x=list(rot=0, cex=0.7, axs="i", tck=0.5), y=list(tick.number=4, rot=90, cex=0.7)), - xlab=NULL, main=NULL, ylab=NULL, - as.table=T, - origin = 0, - horizontal=FALSE, - group=polarity, - col=c("red","blue"), - par.strip.text = list(cex=0.7), - ...)) - } + plot_size_distribution= function(df, ...) { + smR.prepanel=function(x,y,...){; yscale=c(-max(abs(y)), max(abs(y)));list(ylim=yscale);} + bc= barchart(count~as.factor(size)|factor(sample, levels=unique(sample))+gene, data = df, origin = 0, + horizontal=FALSE, + group=polarity, + stack=TRUE, + col=c('red', 'blue'), + cex=0.75, + scales=list(y=list(tick.number=4, rot=90, relation="free", cex=0.7), x=list(cex=0.7) ), + prepanel=smR.prepanel, + xlab = NULL, + ylab = NULL, + main = NULL, + as.table=TRUE, + newpage = T, + par.strip.text = list(cex=0.7), + ...) + combineLimits(bc) + } + + ## end of functions + + ## function parameters' + + par.settings.readmap=list(layout.heights=list(top.padding=0, bottom.padding=-2.5), strip.background = list(col=c("lightblue","lightgreen")) ) + par.settings.size=list(layout.heights=list(top.padding=-1, bottom.padding=-2.5), strip.background = list(col=c("lightblue","lightgreen")) ) + par.settings.combination.readmap=list(layout.heights=list(top.padding=0, bottom.padding=-3), strip.background=list(col=c("lightblue","lightgreen")) ) + par.settings.combination.size=list(layout.heights=list(top.padding=-2, bottom.padding=-0.5), strip.background=list(col=c("lightblue", "lightgreen")) ) - plot_size_distribution= function(df, ...) { - smR.prepanel=function(x,y,...){; yscale=c(-max(abs(y)), max(abs(y)));list(ylim=yscale);} - bc= barchart(count~as.factor(size)|factor(sample, levels=unique(sample))+gene, data = df, origin = 0, - horizontal=FALSE, - group=polarity, - stack=TRUE, - col=c('red', 'blue'), - cex=0.75, - scales=list(y=list(tick.number=4, rot=90, relation="free", cex=0.7), x=list(cex=0.7) ), - prepanel=smR.prepanel, - xlab = NULL, - ylab = NULL, - main = NULL, - as.table=TRUE, - newpage = T, - par.strip.text = list(cex=0.7), - ...) - combineLimits(bc) - } + ## end of function parameters' + + ## GRAPHS + + if (n_genes > 7) {page_height_simple = 11.69; page_height_combi=11.69; rows_per_page=${rows_per_page}; extrarow=0 } else { + rows_per_page= 8; page_height_simple = 11.69; page_height_combi=11.69; extrarow=0 } + ## rows_per_page= 8; page_height_simple = 11.69/7*n_genes; page_height_combi=11.69/9*(n_genes*2); extrarow=0 } + ## rows_per_page= n_genes; page_height_simple = 11.69/n_genes/4; page_height_combi=11.69/(n_genes*2); extrarow=1 } + if (n_samples > 4) {page_width = 8.2677*n_samples/4} else {page_width = 8.2677*n_samples/3} # to test - ## end of functions - - ## function parameters' - - par.settings.readmap=list(layout.heights=list(top.padding=0, bottom.padding=-2.5), strip.background = list(col=c("lightblue","lightgreen")) ) - par.settings.size=list(layout.heights=list(top.padding=-1, bottom.padding=-2.5), strip.background = list(col=c("lightblue","lightgreen")) ) - par.settings.combination.readmap=list(layout.heights=list(top.padding=0, bottom.padding=-3), strip.background=list(col=c("lightblue","lightgreen")) ) - par.settings.combination.size=list(layout.heights=list(top.padding=-2, bottom.padding=-0.5), strip.background=list(col=c("lightblue", "lightgreen")) ) - - ## end of function parameters' - - ## GRAPHS - - if (n_genes > 7) {page_height_simple = 11.69; page_height_combi=11.69; rows_per_page=${rows_per_page}; extrarow=0 } else { - rows_per_page= 8; page_height_simple = 11.69; page_height_combi=11.69; extrarow=0 } - ## rows_per_page= 8; page_height_simple = 11.69/7*n_genes; page_height_combi=11.69/9*(n_genes*2); extrarow=0 } - ## rows_per_page= n_genes; page_height_simple = 11.69/n_genes/4; page_height_combi=11.69/(n_genes*2); extrarow=1 } - if (n_samples > 4) {page_width = 8.2677*n_samples/4} else {page_width = 8.2677*n_samples/3} # to test + pdf(file="${readmap_PDF}", paper="special", height=page_height_simple, width=page_width) + for (i in seq(1,n_genes,rows_per_page)) { + start=i + end=i+rows_per_page-1 + if (end>n_genes) {end=n_genes} + readmap_plot.list=lapply(per_gene_readmap[start:end], function(x) plot_readmap(x, par.settings=par.settings.readmap)) + args.list=c(readmap_plot.list, list(nrow=rows_per_page, ncol=1, + main=textGrob("Read Maps (nucleotide coordinates)", gp=gpar(cex=1), just="top"), + left=textGrob("${ylabel}", gp=gpar(cex=1), vjust=1, rot=90) + #sub=textGrob("readmap coordinates", gp=gpar(cex=.75), just="bottom") + ) + ) + do.call(grid.arrange, args.list) + } + devname=dev.off() - } + pdf(file="${size_PDF}", paper="special", height=page_height_simple, width=page_width) + for (i in seq(1,n_genes,rows_per_page)) { + start=i + end=i+rows_per_page-1 + if (end>n_genes) {end=n_genes} + plot.list=lapply(per_gene_size[start:end], function(x) plot_size_distribution(x, par.settings=par.settings.size) ) + args.list=c(plot.list, list(nrow=rows_per_page, ncol=1, + main=textGrob("Size distributions (in nucleotides)", gp=gpar(cex=1), just="top"), + left=textGrob("${ylabel}", gp=gpar(cex=1), vjust=1, rot=90) + #sub="readsize in nucleotides" + ) + ) + do.call(grid.arrange, args.list) + } + devname=dev.off() - pdf(file="${readmap_PDF}", paper="special", height=page_height_simple, width=page_width) - for (i in seq(1,n_genes,rows_per_page)) { - start=i - end=i+rows_per_page-1 - if (end>n_genes) {end=n_genes} - if ("${yrange}" != 0) { - readmap_plot.list=lapply(per_gene_readmap[start:end], function(x) plot_readmap(x, par.settings=par.settings.readmap)) - } else { - readmap_plot.list=lapply(per_gene_readmap[start:end], function(x) plot_readmap(x, ylim=c(-"{$yrange}", "{$yrange}"), par.settings=par.settings.readmap)) + pdf(file="${combi_PDF}", paper="special", height=page_height_combi, width=page_width) + for (i in seq(1,n_genes,rows_per_page/2)) { + start=i + end=i+rows_per_page/2-1 + if (end>n_genes) {end=n_genes} + if ("${yrange}" != 0) {readmap_plot.list=lapply(per_gene_readmap[start:end], function(x) plot_readmap(x, par.settings=par.settings.readmap)) } else { + readmap_plot.list=lapply(per_gene_readmap[start:end], function(x) plot_readmap(x, ylim=c(-"{$yrange}", "{$yrange}"), par.settings=par.settings.readmap)) } + size_plot.list=lapply(per_gene_size[start:end], function(x) plot_size_distribution(x, strip=FALSE, par.settings=par.settings.combination.size)) + plot.list=rbind(read_plot.list, size_plot.list ) + args.list=c(plot.list, list(nrow=rows_per_page + extrarow, ncol=1, + main=textGrob("${title}", gp=gpar(cex=1), just="top"), + left=textGrob("${ylabel}", gp=gpar(cex=1), vjust=1, rot=90), + sub=textGrob("${xlabel}", gp=gpar(cex=1), just="bottom") + ) + ) + do.call(grid.arrange, args.list) } - args.list=c(readmap_plot.list, list(nrow=rows_per_page, ncol=1, - main=textGrob("Read Maps (nucleotide coordinates)", gp=gpar(cex=1), just="top"), - left=textGrob("${ylabel}", gp=gpar(cex=1), vjust=1, rot=90) - #sub=textGrob("readmap coordinates", gp=gpar(cex=.75), just="bottom") - ) - ) - do.call(grid.arrange, args.list) - } - devname=dev.off() + devname=dev.off() - pdf(file="${size_PDF}", paper="special", height=page_height_simple, width=page_width) - for (i in seq(1,n_genes,rows_per_page)) { - start=i - end=i+rows_per_page-1 - if (end>n_genes) {end=n_genes} - plot.list=lapply(per_gene_size[start:end], function(x) plot_size_distribution(x, par.settings=par.settings.size) ) - args.list=c(plot.list, list(nrow=rows_per_page, ncol=1, - main=textGrob("Size distributions (in nucleotides)", gp=gpar(cex=1), just="top"), - left=textGrob("${ylabel}", gp=gpar(cex=1), vjust=1, rot=90) - #sub="readsize in nucleotides" - ) - ) - do.call(grid.arrange, args.list) - } - devname=dev.off() - - pdf(file="${combi_PDF}", paper="special", height=page_height_combi, width=page_width) - for (i in seq(1,n_genes,rows_per_page/2)) { - start=i - end=i+rows_per_page/2-1 - if (end>n_genes) {end=n_genes} - read_plot.list=lapply(per_gene_readmap[start:end], function(x) plot_readmap(x, par.settings=par.settings.combination.readmap)) - size_plot.list=lapply(per_gene_size[start:end], function(x) plot_size_distribution(x, strip=FALSE, par.settings=par.settings.combination.size)) - plot.list=rbind(read_plot.list, size_plot.list ) - args.list=c(plot.list, list(nrow=rows_per_page + extrarow, ncol=1, - main=textGrob("${title}", gp=gpar(cex=1), just="top"), - left=textGrob("${ylabel}", gp=gpar(cex=1), vjust=1, rot=90), - sub=textGrob("${xlabel}", gp=gpar(cex=1), just="bottom") - ) - ) - do.call(grid.arrange, args.list) - } - devname=dev.off() - - ]]></configfile> + </configfile> </configfiles> <outputs>