forked from NCIP/pathway-interaction-database
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Coloring.pm
executable file
·71 lines (55 loc) · 1.6 KB
/
Coloring.pm
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
# Copyright SRA International
#
# Distributed under the OSI-approved BSD 3-Clause License.
# See http://ncip.github.com/pathway-interaction-database/LICENSE.txt for details.
package Coloring;
require Exporter;
@ISA = qw(Exporter);
#@EXPORT = qw(
# CreateIsA
# CreateLabelSort
#);
use strict;
######################################################################
sub new {
my ($self, $breaks, $color_scale) = @_;
## my ($self, $neutral_lo, $neutral_hi,
## $breaks, $color_scale, $neutral) = @_;
my $x = {};
# $x->{neutral_lo} = $neutral_lo;
# $x->{neutral_hi} = $neutral_hi;
$x->{breaks} = $breaks;
$x->{color_scale} = $color_scale;
# $x->{neutral} = $neutral;
return bless $x;
}
######################################################################
sub ColorScale {
my ($self) = @_;
return $self->{color_scale};
}
######################################################################
sub NumericBreaks {
my ($self) = @_;
return $self->{breaks};
}
######################################################################
sub Value2Color {
my ($self, $v) = @_;
my @color_scale = @{ $self->{color_scale} };
my @breaks = @{ $self->{breaks} };
# my $neutral = $self->{neutral};
# my $neutral_lo = $self->{neutral_lo};
# my $neutral_hi = $self->{neutral_hi};
# if (($v <= $neutral_hi) && ($v >= $neutral_lo)) {
# return $neutral;
# }
for (my $i = 0; $i < @breaks; $i++) {
if ($v <= $breaks[$i]) {
return $color_scale[$i];
}
}
return $color_scale[$#color_scale];
}
######################################################################
1;