blib/lib/Bio/Graphics/Glyph/redgreen_box.pm untested

filter: Statementstmt 0.0% 0 / 68 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 113 CC 13 SCAR 30.9
CC
13
Cov
0%
HSVtoRGB
56.0
draw
12.0
fgcolor
6.0
CRAP 22.0
1 package Bio::Graphics::Glyph::redgreen_box;
2  
3 use strict;
4 use base qw(Bio::Graphics::Glyph::generic);
5  
6 sub bgcolor {
7 my $self = shift;
8 $self->{force_bgcolor};
9 }
10  
11 sub fgcolor {
12 my $self = shift;
13 return $self->option('border') ? $self->SUPER::fgcolor : $self->{force_bgcolor};
14 }
15  
16 sub color_subparts { shift->option('color_subparts') }
17  
18 sub bump {
19 my $self = shift;
20 return 0 if $self->color_subparts;
21 return $self->SUPER::bump;
22 }
23  
24 sub draw {
25 my $self = shift;
26 my $val = $self->feature->score;
27  
28 # we're going to force all our parts to share the same colors
29 # unless otherwise requested
30 my @parts = $self->parts;
31 @parts = $self if !@parts && $self->level == 0;
32 unless ($self->color_subparts) {
33 my @rgb = map {int($_)} HSVtoRGB(120*(1-$val),1,255);
34 my $color = $self->panel->translate_color(@rgb);
35 $_->{force_bgcolor} = $color foreach @parts;
36 } else {
37 foreach (@parts) {
38 my $val = $_->feature->score;
39 my @rgb = map {int($_)} HSVtoRGB(120*(1-$val),1,255);
40 my $color = $self->panel->translate_color(@rgb);
41 $_->{force_bgcolor} = $color;
42 }
43 }
44  
45 $self->SUPER::draw(@_);
46 }
47  
48 sub HSVtoRGB ($$$) {
49 my ($h,$s,$v)=@_;
50 my ($r,$g,$b,$i,$f,$p,$q,$t);
51  
52 if( $s == 0 ) {
53 ## achromatic (grey)
54 return ($v,$v,$v);
55 }
56  
57 $h /= 60; ## sector 0 to 5
58 $i = int($h);
59 $f = $h - $i; ## factorial part of h
60 $p = $v * ( 1 - $s );
61 $q = $v * ( 1 - $s * $f );
62 $t = $v * ( 1 - $s * ( 1 - $f ) );
63
64 if($i<1) {
65 $r = $v;
66 $g = $t;
67 $b = $p;
68 } elsif($i<2){
69 $r = $q;
70 $g = $v;
71 $b = $p;
72 } elsif($i<3){
73 $r = $p;
74 $g = $v;
75 $b = $t;
76 } elsif($i<4){
77 $r = $p;
78 $g = $q;
79 $b = $v;
80 } elsif($i<5){
81 $r = $t;
82 $g = $p;
83 $b = $v;
84 } else {
85 $r = $v;
86 $g = $p;
87 $b = $q;
88 }
89 return ($r,$g,$b);
90 }
91  
92 sub mMin {
93 my $n=10000000000000;
94 map { $n=($n>$_) ? $_ : $n } @_;
95 return($n);
96 }
97  
98 sub mMax {
99 my $n=0;
100 map { $n=($n<$_) ? $_ : $n } @_;
101 return($n);
102 }
103  
104  
105 1;
106  
107 =head1 NAME
108  
109 Bio::Graphics::Glyph::redgreen_box - The "redgreen_box" glyph
110  
111 =head1 SYNOPSIS
112  
113 See L<Bio::Graphics::Panel> and L<Bio::Graphics::Glyph>.
114  
115 =head1 DESCRIPTION
116  
117 This glyph is similar to the graded_segments glyph except that it
118 generates a green-E<gt>red gradient suitable for use with microarray data.
119 A feature score of 0 is full green; a feature score of 1.0 is full
120 red; intermediate scores are shades of yellow.
121  
122 =head2 OPTIONS
123  
124 The following options are standard among all Glyphs. See
125 L<Bio::Graphics::Glyph> for a full explanation.
126  
127 Option Description Default
128 ------ ----------- -------
129  
130 -fgcolor Foreground color black
131  
132 -outlinecolor Synonym for -fgcolor
133  
134 -bgcolor Background color turquoise
135  
136 -fillcolor Synonym for -bgcolor
137  
138 -linewidth Line width 1
139  
140 -height Height of glyph 10
141  
142 -font Glyph font gdSmallFont
143  
144 -connector Connector type 0 (false)
145  
146 -connector_color
147 Connector color black
148  
149 -label Whether to draw a label 0 (false)
150  
151 -description Whether to draw a description 0 (false)
152  
153 -hilite Highlight color undef (no color)
154  
155 The following glyph-specific option is recognized:
156  
157 -border Draw a fgcolor border around 0 (false)
158 the box
159  
160 -color_subparts
161 Give each subpart a separate 0 (false)
162 color based on its score
163  
164 If the B<-color_subparts> option is true, then the glyph will
165 individually coloriz each of its subparts. In addition, internal
166 bumping of features will be turned off. This will produce an effect
167 similar to graded_segments.
168  
169 =head1 BUGS
170  
171 Please report them.
172  
173 =head1 SEE ALSO
174  
175 L<Bio::Graphics::Panel>,
176 L<Bio::Graphics::Glyph>,
177 L<Bio::Graphics::Glyph::arrow>,
178 L<Bio::Graphics::Glyph::cds>,
179 L<Bio::Graphics::Glyph::crossbox>,
180 L<Bio::Graphics::Glyph::diamond>,
181 L<Bio::Graphics::Glyph::dna>,
182 L<Bio::Graphics::Glyph::dot>,
183 L<Bio::Graphics::Glyph::ellipse>,
184 L<Bio::Graphics::Glyph::extending_arrow>,
185 L<Bio::Graphics::Glyph::generic>,
186 L<Bio::Graphics::Glyph::graded_segments>,
187 L<Bio::Graphics::Glyph::heterogeneous_segments>,
188 L<Bio::Graphics::Glyph::line>,
189 L<Bio::Graphics::Glyph::pinsertion>,
190 L<Bio::Graphics::Glyph::primers>,
191 L<Bio::Graphics::Glyph::rndrect>,
192 L<Bio::Graphics::Glyph::segments>,
193 L<Bio::Graphics::Glyph::ruler_arrow>,
194 L<Bio::Graphics::Glyph::toomany>,
195 L<Bio::Graphics::Glyph::transcript>,
196 L<Bio::Graphics::Glyph::transcript2>,
197 L<Bio::Graphics::Glyph::translation>,
198 L<Bio::Graphics::Glyph::triangle>,
199 L<Bio::DB::GFF>,
200 L<Bio::SeqI>,
201 L<Bio::SeqFeatureI>,
202 L<Bio::Das>,
203 L<GD>
204  
205 =head1 AUTHOR
206  
207 Lincoln Stein E<lt>lstein@cshl.orgE<gt>
208  
209 Copyright (c) 2001 Cold Spring Harbor Laboratory
210  
211 This library is free software; you can redistribute it and/or modify
212 it under the same terms as Perl itself. See DISCLAIMER.txt for
213 disclaimers of warranty.
214  
215 =cut