/
plot_2d.pl
executable file
·159 lines (129 loc) · 3.59 KB
/
plot_2d.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env perl
use Image::Magick;
$file90 = shift;
$segs = shift;
$out_file = shift;
my $image_xx = 800;
my $image_yy = 600;
my $border = 20;
my $border2 = $border/2;
my $lab_margin = 30;
my $scale = 200/10;
my @seg_colors = qw//;
my @seg_sizes = qw/1 2 5 6 8 10 12 14 16 18 20/;
my $p = {
magick => Image::Magick->new(),
border => 2,
grid_color => "#eeeeee",
gif_file => $out_file,
height => $image_yy+$border+$lab_margin,
width => $image_xx+$border,
};
$p->{magick}->Set(size => "$p->{width}x$p->{height}");
$p->{magick}->Read('xc:white');
my @clstr_nos = ();
open(TMP, $file90) || die "Can not open file";
$readin = 0;
my $this_no = 0;
while(my $ll=<TMP>) {
if ($ll =~ /^>/ ) {
if ($readin) { $clstr_nos[$this_no]++; }
$this_no=0;
}
else {
$readin = 1; $this_no++;
}
}
close(TMP);
if ($readin) { $clstr_nos[$this_no]++; }
@segs = split(/,/, $segs);
@segs_no = ();
for ($i=0; $i<@segs; $i++) {
$seg = $segs[$i];
if ($seg =~ /-/) { ($b, $e) = split(/-/, $seg); }
else { $b= $e = $seg; }
$no1 = 0; for($j=$b; $j<=$e; $j++) { $no1+= $clstr_nos[$j]; }
print "$seg\t$no1\n";
$no2 = int($no1/$scale); $no2++ if ($no1 % $scale);
$segs_no[$i] = $no2;
}
my @covered = ();
my $xmin = $border2;
my $xmax = $image_xx+$border2;
my $ymin = $border2;
my $ymax = $image_yy+$border2;
$p->{magick}->Draw(primitive => 'line', points => "$xmin,$ymin,$xmax,$ymin");
$p->{magick}->Draw(primitive => 'line', points => "$xmin,$ymin,$xmin,$ymax");
$p->{magick}->Draw(primitive => 'line', points => "$xmax,$ymin,$xmax,$ymax");
$p->{magick}->Draw(primitive => 'line', points => "$xmin,$ymax,$xmax,$ymax");
my $no_segs = $#segs+1;
for ($i=$#segs; $i>=0; $i--) {
$size = $seg_sizes[$i]-1;
$c = "#000000";
$no2 = $segs_no[$i];
for ($j=0; $j<$no2; $j++) {
$x1 = rand($image_xx)+$border2; $x2 = $x1 + $size;
$y1 = rand($image_yy)+$border2; $y2 = $y1 + $size;
if ($x2 > $xmax) {$x2 = $xmax; $x1 = $x2-$size;}
if ($y2 > $ymax) {$y2 = $ymax; $y1 = $y2-$size;}
if ($size) {
$p->{magick}->Draw(primitive => 'Rectangle',
points => "$x1,$y1,$x2,$y2", fill => $c);
}
else {
$p->{magick}->Draw(primitive => 'point',
points => "$x1,$y1", fill => $c);
}
}
$x1 = $border2 + int($image_xx/$no_segs)*$i; $x2 = $x1 + $size;
$y1 = $ymax + int($lab_margin/2) - int($size/2); $y2 = $y1 + $size;
if ($size) {
$p->{magick}->Draw(primitive => 'Rectangle',
points => "$x1,$y1,$x2,$y2", fill => $c);
}
else {
$p->{magick}->Draw(primitive => 'point',
points => "$x1,$y1", fill => $c);
}
}
$p->{magick}->Write($p->{gif_file});
#build color index
my @colors = ();
for ($i=0; $i<$steps; $i++) {
$j = $i/$steps;
my ($r, $g, $b) = get_gradient_color_255_old($j);
my $c1 = uc(sprintf("#%2x%2x%2x",$r,$g,$b));
$c1 =~ s/ /0/g;
$colors[$i] = $c1;
}
# return color
sub get_gradient_color_255_old {
my $ratio = shift;
my ($r, $g, $b);
if ($ratio >= 0 and $ratio < 0.2 ) {
$r = 255;
$g = int( 1275*$ratio );
$b = 0;
}
elsif ($ratio >= 0.2 and $ratio < 0.4 ) {
$r = int ( 255 - 1275*($ratio-0.2) );
$g = 255;
$b = 0;
}
elsif ($ratio >= 0.4 and $ratio < 0.6 ) {
$r = 0;
$g = 255;
$b = int ( 1275 * ($ratio-0.4) );
}
elsif ($ratio >= 0.6 and $ratio < 0.8 ) {
$r = 0;
$g = int ( 255 - 1275*($ratio-0.6) );
$b = 255;
}
elsif ($ratio >= 0.8 and $ratio <= 1.0 ) {
$r = int ( 1275 *($ratio-0.8) );
$g = 0;
$b = 255;
}
return ($r,$g,$b);
}