Mercurial > repos > greg > ks_distribution
changeset 9:214e2710c51e draft
Uploaded
author | greg |
---|---|
date | Fri, 23 Jun 2017 14:12:59 -0400 |
parents | 1650842a90ba |
children | 95ea500c158e |
files | ks_distribution.R ks_distribution.xml macros.xml |
diffstat | 3 files changed, 89 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/ks_distribution.R Thu Jun 08 10:32:44 2017 -0400 +++ b/ks_distribution.R Fri Jun 23 14:12:59 2017 -0400 @@ -5,22 +5,15 @@ option_list <- list( make_option(c("-c", "--components_input"), action="store", dest="components_input", help="Ks significant components input dataset"), make_option(c("-k", "--kaks_input"), action="store", dest="kaks_input", help="KaKs analysis input dataset"), - make_option(c("-o", "--output"), action="store", dest="output", help="Output dataset") + make_option(c("-n", "--num_comp"), action="store", dest="num_comp", type="integer", help="Number of significant components in the Ks distribution"), + make_option(c("-o", "--output"), action="store", dest="output", help="Output dataset"), + make_option(c("-r", "--colors"), action="store", default=NA, help="List of component colors"), ) parser <- OptionParser(usage="%prog [options] file", option_list=option_list) args <- parse_args(parser, positional_arguments=TRUE) opt <- args$options - -get_num_components = function(components_data) -{ - # Get the max of the number_comp column. - number_comp = components_data[, 3] - num_components <- max(number_comp, na.rm=TRUE) - return(num_components) -} - get_pi_mu_var = function(components_data, num_components) { # FixMe: enhance this to generically handle any integer value for num_components. @@ -64,7 +57,7 @@ return(results) } -plot_ks<-function(kaks_input, output, pi, mu, var) +plot_ks<-function(kaks_input, num_components, colors, output, pi, mu, var) { # Start PDF device driver to save charts to output. pdf(file=output, bg="white") @@ -89,7 +82,51 @@ barplot(nc, space=0.25, offset=0, width=0.04, xlim=c(0, max_ks), ylim=c(0, ymax), col="lightpink1", border="lightpink3") # Add x-axis. axis(1) - color <- c('red', 'yellow','green','black','blue', 'darkorange' ) + if(is.na(colors) + { + color <- c('red', 'yellow', 'green', 'black', 'blue', 'darkorange') + } + else + { + # Handle specified colors for components. + cStr <- unlist(colors) + color <- c() + items <- strsplit(cStr, ",") + for (item in items) { + color <- c(color, item) + } + num_colors_specified = length(color) + if num_colors_specified < num_components: + { + for (i in num_colors_specified:num_components) + { + if !(any(color=='red') + { + color <- c(color, 'red') + } + else if !(any(color=='yellow') + { + color <- c(color, 'yellow') + } + else if !(any(color=='green') + { + color <- c(color, 'green') + } + else if !(any(color=='black') + { + color <- c(color, 'black') + } + else if !(any(color=='blue') + { + color <- c(color, 'blue') + } + else + { + color <- c(color, 'darkorange') + } + } + } + } for (i in 1:length(mu)) { lines(vx, g[,i] * h, lwd=2, col=color[i]) @@ -117,8 +154,7 @@ # Read in the components data. components_data <- read.delim(opt$components_input, header=TRUE) -# Get the number of components. -num_components <- get_num_components(components_data) +num_components <- opt$num_comp # Set pi, mu, var. items <- get_pi_mu_var(components_data, num_components) @@ -160,4 +196,4 @@ } # Plot the output. -plot_ks(opt$kaks_input, opt$output, pi, mu, var) +plot_ks(opt$kaks_input, num_components, opt$colors, opt$output, pi, mu, var)
--- a/ks_distribution.xml Thu Jun 08 10:32:44 2017 -0400 +++ b/ks_distribution.xml Fri Jun 23 14:12:59 2017 -0400 @@ -1,18 +1,41 @@ -<tool id="ks_distribution" name="KsDistribution" version="1.0.0"> +<tool id="ks_distribution" name="KsDistribution" version="1.0.1"> <description>plots the distribution of synonymous substitution (Ks) rates and fits significant component(s)</description> <macros> <import>macros.xml</import> </macros> <expand macro="requirements_ks_distribution" /> <command detect_errors="exit_code"><![CDATA[ +import json Rscript $__tool_directory__/ks_distribution.R -k '$input' -c '$components' +-n $input.num_components -o '$output' +#if str($choose_colors_cond.choose_colors) == 'yes': + #set ccs = list() + #for $i in $choose_colors_cond.colors: + $ccs.append($i.color) + #end for + -r '#echo json.dumps(ccs)#' +#end if ]]></command> <inputs> <param name="input" format="tabular" type="data" label="KaKsAnalysis tabular file" /> - <param name="components" format="tabular" type="data" label="Significant components" /> + <param name="components" format="ptkscmp" type="data" label="Significant components" /> + <conditional name="choose_colors_cond"> + <param name="choose_colors" type="select" label="Choose colors for significant components"> + <option value="no" selected="true">No</option> + <option value="yes">Yes</option> + </param> + <when value="no" /> + <when value="yes"> + <repeat name="colors" title="Component colors" min="1"> + <param name="color" type="select" label="Color"> + <expand macro="color_selector" /> + </param> + </repeat> + </when> + </conditional> </inputs> <outputs> <data name="output" format="pdf"/> @@ -20,7 +43,7 @@ <tests> <test> <param name="input" value="kaks_input1.tabular" ftype="tabular" /> - <param name="components" value="components.tabular" ftype="tabular" /> + <param name="components" value="components.ptkscmp" ftype="ptkscmp" /> <output name="output" file="output.pdf" ftype="pdf" compare="contains" /> </test> </tests> @@ -37,6 +60,9 @@ * **Synonymous substitution rates** - estimated synonymous substitution (Ks) rates output file produced by the KaKsAnalysis tool selected from your history. * **Synonymous components** - estimated significant component(s) output file produced by the KaKsAnalysis tool selected from your history. + * **Choose colors for significant components** - select 'Yes' to specify component colors or 'No' for colors chosen randlomly. + + * **Component colors** - select a color from the palette for each component (colors will be chosen randomly for unspecified components). </help> <citations> <expand macro="citation1" />
--- a/macros.xml Thu Jun 08 10:32:44 2017 -0400 +++ b/macros.xml Fri Jun 23 14:12:59 2017 -0400 @@ -3,7 +3,7 @@ <token name="@WRAPPER_VERSION@">1.0</token> <xml name="requirements_assembly_post_processor"> <requirements> - <requirement type="package" version="1.0.0">plant_tribes_assembly_post_processor</requirement> + <requirement type="package" version="1.0.1">plant_tribes_assembly_post_processor</requirement> </requirements> </xml> <xml name="requirements_gene_family_aligner"> @@ -117,6 +117,14 @@ </when> </conditional> </xml> + <xml name="color_selector"> + <option value="255,0,0" selected="True">red</option> + <option value="0,255,0">green</option> + <option value="0,0,255">blue</option> + <option value="255,255,0">yellow</option> + <option value="255,140,0">dark orange</option> + <option value="0,0,0">black</option> + </xml> <xml name="citation1"> <citation type="bibtex"> @misc{None,