1 package CXGN
::Cview
::MapImage
;
5 CXGN::Cview::MapImage - an interface for Cview map images.
9 Inherits from L<CXGN::Cview::ImageI>.
13 Lukas Mueller (lam87@cornell.edu)
25 use CXGN
::Cview
::ImageI
;
27 use base qw
/ CXGN::Cview::ImageI /;
31 =head2 function MapImage::new()
33 MapImage -> new(map name, map_width [pixels], map_height [pixels])
35 Creates a new map object.
42 my $width = shift; # the image width in pixels
43 my $height = shift; # the image height in pixels
45 my $self = $class->SUPER::new
();
46 GD
::Image
->trueColor(1);
47 my $image = GD
::Image
->new($width, $height);
48 # $image || die "Can't generate image...";
49 $self->set_image($image); # make it truecolor (the last argument =1)
50 $self->{chromosomes
} = ();
51 $self->{chr_links
} = ();
52 $self->set_width($width);
53 $self->set_height($height);
54 $self->set_name($map_name);
62 =head2 function render()
64 $map -> render() # takes no parameters
66 renders the map on the internal image.
72 # the first color allocated is the background color.
73 $self->{white
} = $self->get_image()->colorResolve(255,255,255);
74 $self->get_image()->filledRectangle(0,0 ,$self->{width
}, $self->{height
}, $self->{white
});
77 foreach my $c (@
{$self->{chromosomes
}}) {
79 $c -> draw_chromosome
($self->get_image());
81 foreach my $l (@
{$self->{chr_links
}}) {
82 $l -> render
($self->get_image());
84 foreach my $r (@
{$self->{rulers
}}) {
85 $r -> render
($self->get_image());
87 foreach my $p (@
{$self->{physical
}}) {
88 $p -> render
($self->get_image());
90 foreach my $o (@
{$self->{image_objects
}}) {
91 $o -> render
($self->get_image());
94 foreach my $c (@
{$self->{chromosomes
}}) {
96 $c -> render_markers
($self->get_image());
102 =head2 function render_png()
104 $map->render_png(); # no parameters
106 renders the image as a png to STDOUT.
113 print $self->get_image()->png();
116 =head2 function render_png_string()
118 renders the png and returns it as a string.
124 sub render_png_string
{
127 return $self->get_image()->png();
130 =head2 function render_png_file()
132 $map->render_png_file ($filepath)
134 render the image as a png saving the image at $filepath.
138 sub render_png_file
{
139 my ($self, $filename) = @_;
140 $self->_render_to_file($filename,'png');
143 =head2 function render_jpg()
147 renders the image as a jpg to STDOUT.
155 print $self->get_image()->jpeg();
158 =head2 function render_jpg_file()
160 $map->render_jpg_file(filepath)
162 renders the image as a jpg file at filepath
166 sub render_jpg_file
{
167 my ($self, $filename) = @_;
168 $self->_render_to_file($filename,'jpeg');
172 sub render_gif_file
{
173 my ($self, $filename) = @_;
174 $self->_render_to_file($filename,'gif');
177 sub _render_to_file
{
178 my ($self, $filename, $format) = @_;
180 open (my $fh, ">", $filename) || die "Can't open $filename for writing!!! Check write permission in dest directory. : $!";
181 print $fh $self->get_image()->$format();
185 =head2 function get_image_map()
187 $string = $map->get_image_map()
189 Get the image map as a string. Calls get_image_map for all the objects contained
196 my $map_name = shift;
197 #print STDERR "get_image_map map\n";
198 #as of 1/6/07, must use both NAME and ID to have both Mozilla and IE conformance, although standard xhtml uses ID only -- Evan
199 my $imagemap = "<map name=\"$map_name\" id=\"$map_name\">";
200 foreach my $c (@
{$self->{chromosomes
}}) {
201 #print STDERR "getting the chromosome image maps...\n";
202 $imagemap .= $c -> get_image_map
();
204 foreach my $p (@
{$self->{physical
}}) {
205 $imagemap .= $p -> get_image_map
();
208 #in xhtml 1.0+, a <map> must have child nodes, so if it doesn't, don't print it -- Evan, 1/6/07
209 if(scalar(@
{$self->{chromosomes
}}) > 0 or scalar(@
{$self->{physical
}}) > 0)
211 return $imagemap."</map>";
219 =head2 function add_chromosome()
221 $map->add_chromosome($chromosome_object)
223 adds the chromosome object to the map. Obviously works also for subclasses of
224 chromosomes such as physical and IL.
228 sub add_image_object
{
231 push @
{$self->{image_objects
}}, $object;
236 my $chromosome = shift;
238 push @
{$self->{chromosomes
}}, $chromosome;
241 sub get_chromosomes
{
243 return @
{$self->{chromosomes
}};
246 =head2 function add_chr_link()
248 $map->add_chr_link($chr_link)
250 adds the chromosome linking object $chr_link to the map.
256 my $chr_link = shift;
257 push @
{$self->{chr_links
}}, $chr_link;
260 =head2 function add_ruler()
262 $map->add_ruler($ruler)
264 adds the ruler $ruler to the map.
271 push @
{$self->{rulers
}}, $ruler;
274 =head2 function add_physical()
276 $map->add_physical($physical)
278 adds the physical map $physical to the map.
280 Note: The physical object has to be populated both in terms of marker
281 positions and physical map.
287 my $physical = shift;
288 push @
{$self->{physical
}}, $physical;