annotate boxplots.pl @ 2:2920630b4d02 draft

Uploaded
author dereeper
date Wed, 11 Aug 2021 15:53:11 +0000
parents fff88b734caf
children
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 = $_;
2
2920630b4d02 Uploaded
dereeper
parents: 0
diff changeset
33 $line =~s/\n//g;$line =~s/\r//g;$line =~s/\"//g;
0
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};
2
2920630b4d02 Uploaded
dereeper
parents: 0
diff changeset
55 $values =~s/;/\n/g;
2920630b4d02 Uploaded
dereeper
parents: 0
diff changeset
56 if ($values =~/\d+/){
2920630b4d02 Uploaded
dereeper
parents: 0
diff changeset
57 open(F,">inforcalc");print F $values;close(F);
2920630b4d02 Uploaded
dereeper
parents: 0
diff changeset
58 my $cmd = `Rscript $dirname/calc.r <inforcalc`;
2920630b4d02 Uploaded
dereeper
parents: 0
diff changeset
59 unlink("infocalc");
2920630b4d02 Uploaded
dereeper
parents: 0
diff changeset
60 my ($min,$max,$quantile1,$quantile2,$quantile3,$quantile4,$quantile5) = split(";",$cmd);
2920630b4d02 Uploaded
dereeper
parents: 0
diff changeset
61 $series{$cat} .= " [$min,$quantile2,$quantile3,$quantile4,$max],\n";
2920630b4d02 Uploaded
dereeper
parents: 0
diff changeset
62 }
2920630b4d02 Uploaded
dereeper
parents: 0
diff changeset
63 else{
2920630b4d02 Uploaded
dereeper
parents: 0
diff changeset
64 $series{$cat} .= " [0,0,0,0,0],\n";
2920630b4d02 Uploaded
dereeper
parents: 0
diff changeset
65 }
0
fff88b734caf Uploaded
dereeper
parents:
diff changeset
66 }
fff88b734caf Uploaded
dereeper
parents:
diff changeset
67 }
fff88b734caf Uploaded
dereeper
parents:
diff changeset
68
fff88b734caf Uploaded
dereeper
parents:
diff changeset
69 my $javascript = qq~
fff88b734caf Uploaded
dereeper
parents:
diff changeset
70 <script type='text/javascript'>
fff88b734caf Uploaded
dereeper
parents:
diff changeset
71 Highcharts.chart('container', {
fff88b734caf Uploaded
dereeper
parents:
diff changeset
72
fff88b734caf Uploaded
dereeper
parents:
diff changeset
73 chart: {
fff88b734caf Uploaded
dereeper
parents:
diff changeset
74 type: 'boxplot'
fff88b734caf Uploaded
dereeper
parents:
diff changeset
75 },
fff88b734caf Uploaded
dereeper
parents:
diff changeset
76 legend: {
fff88b734caf Uploaded
dereeper
parents:
diff changeset
77 enabled: true
fff88b734caf Uploaded
dereeper
parents:
diff changeset
78 },
fff88b734caf Uploaded
dereeper
parents:
diff changeset
79 title: {
fff88b734caf Uploaded
dereeper
parents:
diff changeset
80 text: ''
fff88b734caf Uploaded
dereeper
parents:
diff changeset
81 },
fff88b734caf Uploaded
dereeper
parents:
diff changeset
82 xAxis: {
fff88b734caf Uploaded
dereeper
parents:
diff changeset
83 categories: [$categories]
fff88b734caf Uploaded
dereeper
parents:
diff changeset
84 },
fff88b734caf Uploaded
dereeper
parents:
diff changeset
85 yAxis: {
fff88b734caf Uploaded
dereeper
parents:
diff changeset
86 title: {
fff88b734caf Uploaded
dereeper
parents:
diff changeset
87 text: '$yaxis'
fff88b734caf Uploaded
dereeper
parents:
diff changeset
88 }
fff88b734caf Uploaded
dereeper
parents:
diff changeset
89 },
fff88b734caf Uploaded
dereeper
parents:
diff changeset
90
fff88b734caf Uploaded
dereeper
parents:
diff changeset
91 series: [
fff88b734caf Uploaded
dereeper
parents:
diff changeset
92 ~;
fff88b734caf Uploaded
dereeper
parents:
diff changeset
93 foreach my $cat(keys(%hash)){
fff88b734caf Uploaded
dereeper
parents:
diff changeset
94 $javascript .= "{name: '$cat',\n";
fff88b734caf Uploaded
dereeper
parents:
diff changeset
95 my $values = $series{$cat};
fff88b734caf Uploaded
dereeper
parents:
diff changeset
96 chop($values);chop($values);
fff88b734caf Uploaded
dereeper
parents:
diff changeset
97 $javascript .= "data: [ $values ] },\n";
fff88b734caf Uploaded
dereeper
parents:
diff changeset
98 }
fff88b734caf Uploaded
dereeper
parents:
diff changeset
99 chop($javascript);chop($javascript);
fff88b734caf Uploaded
dereeper
parents:
diff changeset
100 $javascript .= "]\n });\n";
fff88b734caf Uploaded
dereeper
parents:
diff changeset
101 $javascript .= "</script>";
fff88b734caf Uploaded
dereeper
parents:
diff changeset
102 print H $javascript;
fff88b734caf Uploaded
dereeper
parents:
diff changeset
103 close(H);
fff88b734caf Uploaded
dereeper
parents:
diff changeset
104
fff88b734caf Uploaded
dereeper
parents:
diff changeset
105