comparison boxplots.pl @ 0:fff88b734caf draft

Uploaded
author dereeper
date Tue, 10 Aug 2021 19:27:51 +0000
parents
children 2920630b4d02
comparison
equal deleted inserted replaced
-1:000000000000 0:fff88b734caf
1 #!/usr/bin/perl
2
3 use strict;
4 use File::Basename;
5 my $dirname = dirname(__FILE__);
6
7 my $in = $ARGV[0];
8 my $yaxis = $ARGV[1];
9 my $output = $ARGV[2];
10
11 open(H,">$output");
12 print H qq~
13 <script src="https://code.highcharts.com/highcharts.js"></script>
14 <script src="https://code.highcharts.com/highcharts-more.js"></script>
15 <script src="https://code.highcharts.com/modules/exporting.js"></script>
16 <script src="https://code.highcharts.com/modules/export-data.js"></script>
17 <script src="https://code.highcharts.com/modules/accessibility.js"></script>
18
19 <figure class="highcharts-figure">
20 <div id="container"></div>
21 </figure>~;
22
23
24 my %hash;
25 open(F,$in);
26 my $first = <F>;
27 $first =~s/\n//g;$first =~s/\r//g;
28 my %level;
29 my $order = "";
30 my @headers = split(/\t/,$first);
31 while(<F>){
32 my $line = $_;
33 $line =~s/\n//g;$line =~s/\r//g;
34 my @infos = split(/\t/,$line);
35 my $cat = $infos[0];
36 for (my $i = 1; $i <= $#infos; $i++){
37 $hash{$cat}{$headers[$i]}.= $infos[$i]."\n";
38 if ($order !~/$headers[$i]/){
39 $order .= $headers[$i]."|";
40 }
41 $level{$headers[$i]}=1;
42 }
43 }
44 close(F);
45
46 my @categories = split(/\|/,$order);
47
48 my $categories = "\"".join("\",\"",@categories)."\"";
49 my %series;
50 foreach my $cat(keys(%hash)){
51 my $refhash = $hash{$cat};
52 my %subhash = %$refhash;
53 foreach my $header(@categories){
54 my $values = $hash{$cat}{$header};
55 open(F,">inforcalc");print F $values;close(F);
56 my $cmd = `Rscript $dirname/calc.r <inforcalc`;
57 unlink("infocalc");
58 my ($min,$max,$quantile1,$quantile2,$quantile3,$quantile4,$quantile5) = split(";",$cmd);
59 $series{$cat} .= " [$min,$quantile2,$quantile3,$quantile4,$max],\n";
60 }
61 }
62
63 my $javascript = qq~
64 <script type='text/javascript'>
65 Highcharts.chart('container', {
66
67 chart: {
68 type: 'boxplot'
69 },
70 legend: {
71 enabled: true
72 },
73 title: {
74 text: ''
75 },
76 xAxis: {
77 categories: [$categories]
78 },
79 yAxis: {
80 title: {
81 text: '$yaxis'
82 }
83 },
84
85 series: [
86 ~;
87 foreach my $cat(keys(%hash)){
88 $javascript .= "{name: '$cat',\n";
89 my $values = $series{$cat};
90 chop($values);chop($values);
91 $javascript .= "data: [ $values ] },\n";
92 }
93 chop($javascript);chop($javascript);
94 $javascript .= "]\n });\n";
95 $javascript .= "</script>";
96 print H $javascript;
97 close(H);
98
99