changeset 0:fff88b734caf draft

Uploaded
author dereeper
date Tue, 10 Aug 2021 19:27:51 +0000
parents
children 3b78dc3c36df
files boxplots.pl boxplots.xml calc.r
diffstat 3 files changed, 129 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/boxplots.pl	Tue Aug 10 19:27:51 2021 +0000
@@ -0,0 +1,99 @@
+#!/usr/bin/perl
+
+use strict;
+use File::Basename;
+my $dirname = dirname(__FILE__);
+
+my $in = $ARGV[0];
+my $yaxis = $ARGV[1];
+my $output = $ARGV[2];
+
+open(H,">$output");
+print H qq~
+<script src="https://code.highcharts.com/highcharts.js"></script>
+<script src="https://code.highcharts.com/highcharts-more.js"></script>
+<script src="https://code.highcharts.com/modules/exporting.js"></script>
+<script src="https://code.highcharts.com/modules/export-data.js"></script>
+<script src="https://code.highcharts.com/modules/accessibility.js"></script>
+
+<figure class="highcharts-figure">
+    <div id="container"></div>
+</figure>~;
+
+
+my %hash;
+open(F,$in);
+my $first = <F>;
+$first =~s/\n//g;$first =~s/\r//g;
+my %level;
+my $order = "";
+my @headers = split(/\t/,$first);
+while(<F>){
+	my $line = $_;
+	$line =~s/\n//g;$line =~s/\r//g;
+	my @infos = split(/\t/,$line);
+	my $cat = $infos[0];
+	for (my $i = 1; $i <= $#infos; $i++){
+		$hash{$cat}{$headers[$i]}.= $infos[$i]."\n";
+		if ($order !~/$headers[$i]/){
+			$order .= $headers[$i]."|";
+		}
+		$level{$headers[$i]}=1;
+	}
+}
+close(F);
+
+my @categories = split(/\|/,$order);
+
+my $categories = "\"".join("\",\"",@categories)."\"";
+my %series;
+foreach my $cat(keys(%hash)){
+	my $refhash = $hash{$cat};
+	my %subhash = %$refhash;
+	foreach my $header(@categories){
+		my $values = $hash{$cat}{$header};
+		open(F,">inforcalc");print F $values;close(F);
+		my $cmd = `Rscript $dirname/calc.r <inforcalc`;
+		unlink("infocalc");
+		my ($min,$max,$quantile1,$quantile2,$quantile3,$quantile4,$quantile5) = split(";",$cmd);	
+		$series{$cat} .= " [$min,$quantile2,$quantile3,$quantile4,$max],\n";
+	}
+}
+
+my $javascript = qq~
+<script type='text/javascript'>
+Highcharts.chart('container', {
+
+    chart: {
+        type: 'boxplot'
+    },
+    legend: {
+        enabled: true
+    },
+    title: {
+        text: ''
+    },
+    xAxis: {
+        categories: [$categories]
+    },
+    yAxis: {
+        title: {
+            text: '$yaxis'
+        }
+    },
+
+    series: [
+    ~;
+foreach my $cat(keys(%hash)){
+	$javascript .= "{name: '$cat',\n";
+	my $values = $series{$cat};
+	chop($values);chop($values);
+	$javascript .= "data: [ $values ] },\n";
+}
+chop($javascript);chop($javascript);
+$javascript .= "]\n });\n";
+$javascript .= "</script>";
+print H $javascript;
+close(H);
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/boxplots.xml	Tue Aug 10 19:27:51 2021 +0000
@@ -0,0 +1,25 @@
+<tool id="boxplots" name="Interactive boxplots" version="1.0">
+  <description>using Highcharts library</description>
+  <command>perl ${__tool_directory__}/boxplots.pl $input $y_axis $output </command>
+
+ 
+  <inputs>
+	  <param format="tabular" name="input" type="data" label="input tabular file"/>
+	  <param name="y_axis" type="text" label="Y axis" value="y_axis_name"/>
+ </inputs>
+
+ <outputs>  
+	 <data format="html" name="output" label="HTML output"/>
+
+</outputs>
+<help><![CDATA[
+You should provide a tabular file that looks like:
+
+::
+
+    	A	B	C
+    category1	1;3;5	4;5;7	9;3
+    category2	5;3;5	5;5;6	10;2
+
+    ]]></help>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calc.r	Tue Aug 10 19:27:51 2021 +0000
@@ -0,0 +1,5 @@
+#!/usr/bin/Rscript
+d<-scan("stdin", quiet=TRUE)
+#d <- c(d)
+#1.4, 5.66, 7.13, 9.21)
+cat(min(d), max(d), quantile(d), sep=";")