4 CXGN::Cview::Chromosome::Glyph - a class for drawing chromosome glyphs.
8 The chromosomes are represented as small glyphs that can be partially filled with a color to represent the state of a chromosome sequencing project, for example. This class inherits from L<CXGN::Cview::Chromosome>.
12 See also the documentation in L<CXGN::Cview>.
16 Lukas Mueller (lam87@cornell.edu)
26 use CXGN
::Cview
::Chromosome
;
29 package CXGN
::Cview
::Chromosome
::Glyph
;
31 use base qw
| CXGN
::Cview
::Chromosome
|;
36 Arguments: see L<CXGN::Cview::Chromosome>
42 my $self = $class->SUPER::new
(@_);
43 $self->set_outline_color(0,0,0);
44 $self->set_color(255, 255, 255);
45 $self->set_hilite_color(50, 255, 50);
47 $self->{curved_height
} = 8;
48 $self->set_track_colors( [ 0, 255, 0],
57 =head2 function set_fill_level()
60 Arguments: the track number and the fill level of the chromosome in %
61 (eg, 50, not 0.5, to represent 50%).
62 tracks: 0 for available and htgs3
63 1 for available and < htgs3
64 2 for complete, not submitted
67 Side effects: the chromosome will be displayed with % filled in.
68 For fill levels specified above 100, the fill level value
69 will be capped at 100. (Yay! nice problem to have!).
76 # set the percentage level to be displayed as finished in the chromosome. 50% would be 50, not 0.5
82 if ($level>100) { $level = 100; }
83 if (!defined($track)) { die "set_fill_level: Need a track"; }
84 $self->{fill_level
}->[$track] = $level;
90 return $self->{fill_level
}->[$track];
93 =head2 function set_bac_count()
96 Arguments: an integer reflecting the BACs sequenced.
97 is displayed below the glyph.
107 # set the number of bacs sequenced for that chromosome
110 $self->{bac_count
} = shift;
113 =head2 accessors get_track_colors(), set_track_colors()
115 Usage: $glyph->set_track_colors([255,255,0], [0,0,255]);
124 sub get_track_colors
{
126 return @
{$self->{track_colors
}};
130 sub set_track_colors
{
132 @
{$self->{track_colors
}}=@_;
135 =head2 get_track_color
137 Usage: my ($r, $g, $b) = $glyph->get_track_color($track1)
146 sub get_track_color
{
149 return $self->{track_colors
}->[$track];
152 =head2 function render()
155 Arguments: a GD image object.
157 Side effects: generates the image representing the glyph
164 # draw the chromosome
168 $self->_calculate_scaling_factor();
174 my $outline_color = $image -> colorResolve
($self->{outline_color
}->[0], $self->{outline_color
}->[1], $self->{outline_color
}->[2]);
175 my $hilite_color = $image -> colorResolve
($self->{hilite_color
}->[0], $self->{hilite_color
}->[1], $self->{hilite_color
}->[2]);
176 my $color = $image -> colorResolve
($self->{color
}->[0], $self->{color
}->[1], $self->{color
}->[2]);
178 my $halfwidth = $self ->{width
}/2;
180 $image -> line
($self->get_horizontal_offset() - $halfwidth, $self->get_vertical_offset() , $self->get_horizontal_offset()-$halfwidth, $self->get_vertical_offset()+$self->{height
}, $outline_color);
181 $image -> line
($self->get_horizontal_offset() + $halfwidth, $self->get_vertical_offset() , $self->get_horizontal_offset()+$halfwidth, $self->get_vertical_offset()+$self->{height
}, $outline_color);
182 $image -> arc
($self->get_horizontal_offset(), $self->get_vertical_offset(), $self->{width
}, $self->{curved_height
}, 180, 0, $outline_color);
183 $image -> arc
($self->get_horizontal_offset(), $self->get_vertical_offset()+$self->{height
}, $self->{width
}, $self->{curved_height
}, 0, 180, $outline_color);
184 $image -> fill
($self->get_horizontal_offset(), $self->get_vertical_offset(), $color);
186 my @track_color = ();
187 foreach my $track (0..(scalar($self->get_track_colors())-1)) {
189 #if ($track ==4) { die "TRACK=$track!!!!!"; }
190 my $colorRef = $self->get_track_color($track);
191 #print STDERR "TRACK COLOR: $colorRef->[0], $colorRef->[1], $colorRef->[2]\n";
192 $track_color[$track] = $image->colorResolve($colorRef->[0], $colorRef->[1], $colorRef->[2]);
195 my $start_level = $self->get_vertical_offset() + $self->mapunits2pixels(0);
196 foreach my $track (0..(scalar($self->get_track_colors())-1)) {
197 my $level = $self->get_vertical_offset() + $self->mapunits2pixels($self->get_fill_level($track));
198 #print STDERR "LEVEL: $level\n";
200 $image ->filledRectangle($self->get_horizontal_offset()-$halfwidth+1, $level,
201 $self->get_horizontal_offset()+$halfwidth-1, $start_level,
202 $track_color[$track]);
204 if ($self->get_fill_level($track) >= 99) {
205 $image->fill($self->get_horizontal_offset(), $self->get_vertical_offset()-2, $track_color[$track]);
207 $start_level = $level;
210 $image->fill($self->get_horizontal_offset(), $self->get_vertical_offset()+$self->mapunits2pixels(0)+1, $track_color[0]);
212 if ($self->{caption
}) {
213 my $bigfont = GD
::Font
->Large();
214 $image -> string
($bigfont, $self->get_horizontal_offset()- $bigfont->width() * length($self->{caption
})/2, $self->get_vertical_offset()-$bigfont->height()-$self->{curved_height}/2, "$self->{caption}", $outline_color);
216 my $percent_finished = $self->get_fill_level(2);
217 # my $percent_finished_caption = (sprintf "%3d", $self->get_fill_level(0)."\%"); #+$self->get_fill_level(1))."\%";
218 my $percent_finished_caption = (sprintf "%3d", $percent_finished)."\%";
219 $image -> string
($self->{font
}, $self->get_horizontal_offset()- $self->{font
}->width() * length($percent_finished_caption)/2, $self->get_vertical_offset() + $self->get_height()+$self->{curved_height
}, "$percent_finished_caption", $outline_color);
224 sub draw_chromosome
{
227 $self->render($image);
230 sub mapunits2pixels
{
232 my $mapunits = shift;
234 my $pixels = $self->get_height() * (100-$mapunits)/100;
235 #print STDERR "Mapunits2pixels: $mapunits are $pixels pixels\n";