3 CXGN::Cview::MapOverviews - classes to display different kinds of map overviews.
7 my $overview = CXGN::MapOverview::Generic->new(
8 CXGN::Cview::Map::SGN::Genetic->new($dbh, 9), $args_ref
10 $overview->hilite_markers(@marker_names);
11 $overview->render_map();
12 $overview->get_image_html();
17 CXGN::Cview::MapOverviews contains a number of classes designed to display map overview images (chromosomes aligned horizontally) for a given map. The base class is an abstract class called CXGN::Cview::MapOverviews and it depends on CXGN::Cview classes for drawing the chromosomes. The subclasses derived from this class are
23 CXGN::Cview::MapOverviews::Generic, which displays a generic overview for maps of type "genetic", "fish" or "physical" - or any other map that has an appropriate CXGN::Cview::Map object implemented.
27 CXGN::Cview::MapOverviews::ProjectStats displays a map showing the progress of the sequencing project. It also uses CXGN::People, to get the BAC statistics associated to the different chromosomes.
31 =head2 Caching implementation
33 The caching is implemented using CXGN::Tools::WebImageCache, which implements caching on the file system level. Each subclass of MapOverviews can implement its own get_cache_key() function, which should should be set to a distinct key for each map. MapOverviews::Generic concatenates the map_version_id, the hilited markers, and the package name. For more information, see L<CXGN::Tools::WebImageCache>.
35 =head2 Resetting the cache
37 The cache can be reset by deleting the contents of the caching directory. The default value is set using CXGN::VHost properties basepath, tempfiles_subdir and the string "cview", which resolves to "/data/local/website/sgn/documents/tempfiles/cview/" on the current production systems (as of Dec 2006). The class also takes a $reset_cache parameter in the constructor, which will be passed to the CXGN::Tools::WebImageCache constructor. A true value will cause the cache to be considered as expired.
41 Lukas Mueller (lam87@cornell.edu)
42 John Binns (zombieite@gmail.com)
46 package CXGN
::Cview
::MapOverviews
;
53 use CXGN
::Tools
::WebImageCache
;
55 use CXGN
::Cview
::Chromosome
;
56 use CXGN
::Cview
::Chromosome
::PachyteneIdiogram
;
57 use CXGN
::Cview
::Chromosome
::Glyph
;
58 use CXGN
::Cview
::MapImage
;
59 use CXGN
::Cview
::Marker
;
60 use CXGN
::Cview
::Marker
::RangeMarker
;
61 use CXGN
::Cview
::Ruler
;
62 use CXGN
::Cview
::Chromosome
::Physical
;
63 use CXGN
::Cview
::Label
;
64 use CXGN
::Cview
::Map
::Tools
;
66 use CXGN
::Cview
::MapOverviews
::Generic
;
67 use CXGN
::Cview
::MapOverviews
::Physical
;
68 use CXGN
::Cview
::MapOverviews
::ProjectStats
;
69 use CXGN
::Cview
::MapOverviews
::Individual
;
71 =head1 CXGN::Cview::MapOverviews
73 This class implements an abstract interface for drawing map overview images.
77 use CXGN
::DB
::Connection
;
79 use base
qw( CXGN::DB::Connection );
81 # an abstract class from which other overviews inherit.
85 Synopsis: Constructor for MapOverview object
86 Example: my $map_overview = CXGN::Cview::MapOverviews::Generic
87 ->new( $map_object, $args_ref );
88 Arguments: usually a subclass of CXGN::Cview::Map
90 the $args_ref can have the following keys (* means required)
91 force forces recalculation of the image
92 basepath* the basepath to use for tempfile storage
93 tempfiles_subdir* the subdir, after the basepath, where
94 the tempfiles are stored
95 dbh* a database handle
97 Returns: a CXGN::Cview::MapOverview object
108 my $self = bless {}, $class;
110 $self->_set_force($args->{force
});
112 # define some default values
114 ####@{$self->{c_len}} = (0, 163, 140, 170, 130, 120, 100, 110, 90, 115, 90, 100, 120);
116 $self->set_horizontal_spacing(50);
120 my $cache = CXGN
::Tools
::WebImageCache
->new();
122 $cache->set_force($args->{force
});
123 $cache->set_basedir($args->{basepath
});
124 $cache->set_temp_dir($args->{tempfiles_subdir
});
126 $self->set_cache($cache);
127 $self->set_image_width(700);
128 $self->set_image_height(200);
133 =head2 accessors set_map(), get_map()
135 Synopsis: $overview->get_map();
137 Returns: gets the map object.
138 Side effects: the corresponding map will be represented
154 =head2 function set_horizontal_spacing()
156 Synopsis: $overview->set_horizontal_spacing(60)
157 Arguments: the horizontal spacing in pixels
159 Side effects: Defines the spacing between the chromosome glyphs
160 in the overview image. If this is not set, the
166 sub set_horizontal_spacing
{
168 $self->{horizontal_spacing
} = shift;
171 =head2 function get_horizontal_spacing()
173 Synopsis: $my_spacing = $overview->get_horizontal_spacing()
174 Arguments: None (accessor)
175 Returns: the number of pixels between the chromosome glyphs.
181 sub get_horizontal_spacing
{
183 return $self->{horizontal_spacing
};
186 =head2 function render_map()
188 Synopsis: $overview->render_map()
191 Side effects: renders the map and sets two properties (see below).
192 Description: this function needs to be implemented in subclasses
193 to draw the desired map. The calculated map should be
194 stored directly using the cache functions
195 (see CXGN::Tools::WebImageCache) (essentially, using the
196 functions set_image_data() and set_image_map_data() ).
198 The subclassed function should call SUPER::render_map(),
199 such that the key can be properly set.
211 =head2 function get_file_png()
213 Synopsis: $overview->get_file_png($path)
214 Arguments: a fully qualified path of the file
218 Description: saves the image into the specified file
227 $self->{map_image
}->render_png_file($path);
230 =head2 function get_image_map()
232 Synopsis: my $html_image_map = $overview->get_image_map();
234 Returns: an html image map, defining the links on the image
237 Status: DEPRECATED! USE get_image_html INSTEAD!
243 my $map_name = shift;
245 my $map_file = ($self->get_temp_file())[1].".map";
247 if (!$self->has_cache()) {
248 open (my $FILE, ">", $map_file) ||
249 die "Can't open map file $map_file: $!";
250 print $FILE $self->{image_map
};
254 open (my $FILE, "<", $map_file) ||
255 die "Can't open map file! $map_file";
256 my @FILE = (<$FILE>);
258 $self->{image_map
} = join "\n", @FILE;
260 return $self->{image_map
};
264 =head2 function set_image_map()
266 Synopsis: $overview->set_image_map();
267 Arguments: a string representing the html image map for
268 the overview image (essentially, the appropriate
269 <map> tag that goes with the overview image).
271 Side effects: this will be used directly to print the <map> tag
278 $self->{image_map
}=shift;
281 =head2 function get_image_html()
285 Returns: a string representing the image for an html page,
286 including image tag and image map
294 return $self->get_cache()->get_image_html();
296 # return '<img src="'.($self->get_file_png())[0].'" usemap="#overview" border="0" />'."<br />\n". $self->get_image_map("overview");
299 =head2 accessors get_marker_count(), set_marker_count()
301 Synopsis: my $count = $map->get_marker_count($chr)
302 Arguments: a chromosome name
303 Returns: the number of markers on that chromosome
305 Description: needs to be implemented in a subclass.
310 sub get_marker_count
{
313 sub set_marker_count
{
316 =head2 accessors set_map_image(), get_map_image()
318 Property: the image object (GD::Image)
320 Description: this image object is used for drawing the image
326 return $self->{map_image
};
331 $self->{map_image
}=shift;
334 =head2 function hilite_marker()
336 Synopsis: $overview->hilite_marker("TG280");
337 Arguments: a marker name (string)
339 Side effects: causes the marker to be highlighted on the overview
346 my $marker_name = shift;
347 if (!exists($self->{hilite_markers
})) { @
{$self->{hilite_markers
}}=(); }
348 push @
{$self->{hilite_markers
}}, $marker_name;
351 sub get_hilite_markers
{
353 if (!exists($self->{hilite_markers
})) { @
{$self->{hilite_markers
}}=(); }
354 return @
{$self->{hilite_markers
}};
357 sub add_marker_not_found
{
361 # prevent these not initialized errors...
363 if (!exists($self->{markers_not_found
})) { %{$self->{markers_not_found
}}=(); }
364 ${$self->{markers_not_found
}}{$marker}=1;
367 # return the markers that were not found for hiliting on the overview diagram
368 # Note: render_map has to be called before calling this function.
370 sub get_markers_not_found
{
372 if (!$self->{markers_not_found
}) { %{$self->{markers_not_found
}}=(); }
373 return ( map ($_, (keys(%{$self->{markers_not_found
}}))));
391 $self->get_map()->set_map_items(@map_items);
395 =head2 accessors set_chr_height(), get_chr_height()
397 Property: the height of the chromosome in pixels.
398 This is currently only used for the Project
399 Stats overview, in which chromosome don\'t
400 have a 'natural' height.
408 return $self->{chr_height
};
413 $self->{chr_height
}=shift;
416 =head2 accessors set_image_height(), get_image_height()
418 Property: The height of the image in pixels.
425 sub get_image_height
{
427 return $self->{image_height
};
430 sub set_image_height
{
432 $self->{image_height
}=shift;
435 =head2 accessors set_image_width(), get_image_width()
437 Property: the width of the entire image in pixels.
446 sub get_image_width
{
448 return $self->{image_width
};
451 sub set_image_width
{
453 $self->{image_width
}=shift;
458 # accessors _set_force, _get_force
460 # if set to true, forces the re-calculation of the image and stats.
464 return $self->{force
};
469 $self->{force
}=shift;
472 =head2 accessors set_cache(), get_cache()
474 Property: a CXGN::Tools::WebImageCache object
477 Description: see CXGN::Tools::WebImageCache
483 return $self->{cache
};
488 $self->{cache
}=shift;
491 =head2 get_chromosomes(), set_chromosomes()
493 Usage: my @c = $map->get_chromosomes();
494 Desc: returns (sets) a list of Cview chromosome objects for
495 this map, in the same order as get_chromosome_names().
501 sub get_chromosomes
{
503 return $self->{chromosomes
};
507 sub set_chromosomes
{
509 $self->{chromosomes
}=shift;
513 =head2 accessors set_chromosome_count, get_chromosome_count
524 sub get_chromosome_count
{
526 return $self->{chromosome_count
};
529 sub set_chromosome_count
{
531 $self->{chromosome_count
}=shift;
535 =head2 function get_cache_key()
537 Usage: $map->get_cache_key()
538 Desc: needs to be implemented in subclass and return
539 a cache key for the current map
546 die "get_cache_key is abstract. Please implement in subclass.";