annotate boxplots.pl @ 0:fff88b734caf draft

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