render()render_png()render_png_file()
cview.pm - a collection of objects to draw chromosomes.
my $dbh = DBI -> connect("dbi:mysql:host=localhost;database=sgn", "web_usr", "tomato");
my $map = map_image -> new($dbh, 500, 600);
my $chr1 = chromosome -> new(1,550,100,20); cview_sql::fetch_chromosome($dbh, $chr1, 1,1); $chr1 -> set_labels_left(); $chr1 -> set_display_marker_offset(); $chr1-> set_hilite(50, 100); $map->add_chromosome($chr1);
my @m1 = $chr1 -> get_markers();
for (my $i=0; $i<@m1; $i++) {
#$m1[$i]->hide();
$m1[$i]->hide_label();
if ($i % 5 ==0) {
$m1[$i]->hilite(); $m1[$i]->show_label();
}
}
# adding a ruler # my $ruler = ruler -> new (200, 20, 550, 0, $chr1->get_chromosome_length()); $ruler -> set_labels_right(); $map -> add_ruler($ruler);
# adding a physical map # my $physical = physical -> new(1, 550, 300, 20); cview_sql::fetch_chromosome($dbh, $physical, 1, 1); cview_sql::fetch_physical($dbh, $physical, 1, 1); $map -> add_physical($physical);
# rendering the image # $map -> render_jpg();
Lukas Mueller lam97@cornell.edu
The cview package defines several objects: 1) A map_image object that is like a canvas to draw other objects on 2) A chromosome object that contains chromosome information, such as markers and links between chromosomes 3) A marker object that contains the marker information 4) A chr_link object that stores information about markers that are linked on different chromosomes 5) A ruler object that draws a ruler 6) A physical object, which inherits from chromosome and draws a physical map. 7) A IL object, which inherits from chromosome, and draws an IL map.
These objects can be placed on the map_image at will and will know how to render themselves.
=cut
package map_image;
map_image -> new(map name, map_width [pixels], map_height [pixels])
Creates a new map object.
render()$map -> render() # takes no parameters
renders the map on the internal image.
render_png()$map->render_png(); # no parameters
renders the image as a png to STDOUT.
render_png_file()
$map->render_png_file ($filepath)
render the image as a png saving the image at $filepath.
$map->render_jpg()
renders the image as a jpg to STDOUT.
$map->render_jpg_file(filepath)
renders the image as a jpg file at filepath
$string = $map->get_image_map()
Get the image map as a string. Calls get_image_map for all the objects contained in the map_image.
$map->add_chromosome($chromosome_object)
adds the chromosome object to the map. Obviously works also for subclasses of chromosomes such as physical and IL.
$map->add_chr_link($chr_link)
adds the chromosome linking object $chr_link to the map.
$map->add_ruler($ruler)
adds the ruler $ruler to the map.
$map->add_physical($physical)
adds the physical map $physical to the map.
Note: The physical object has to be populated both in terms of marker positions and physical map.
my $c = chromosome -> new( chr number, height in pixels, horizontal offset, vertical offset, [start cM], [end cM])
Creates a new chromosome object. The horizontal offset denotes the offset of the chromosome mid-line. The vertical offset defines the upper end of the chromosome. Note that some renditions of the chromosome will add round edges on the top and on the bottom, so that the rounded top position will be smaller than the vertical offset.
Optionally, start_cM and end_cM can be supplied, which will set the start and end in cM for a chromosome section. The chromosome will be rendered as a section, i.e, the ends will be flat instead of rounded.
$chr->set_height($height)
Sets the height of the chromosome in pixels. Recalculates all the scaling information.
$height = $chr ->get_height()
Gets the height of the chromosome in pixels.
sets the length in map units [cM].
This can also be automatically determined if not set manually, to the offset of the marker with the highest map unit value.
gets the length of the chromosome in map units.
$chr->set_section($start_in_map_units, $end_in_map_units);
Defines the chromosome as a section. The section starts at the start coordinate in map units, and ends at the end coordinate in map units. Chromosomes that are sections are rendered differently than full chromosomes. The section will be rendered so that it fills the entire height of the chromosome as defined with new or set_height, and the top edge will be drawn at the horizontal and vertical offset defined in the new call or with set_horizonatal_offset and set_vertical_offset.
$flag = $chr->is_section()
Returns true if the chromosome $chr is a section.
$chr->set_hilite(start_coord, end_coord)
Highlights the region of the chromosome between start_coord and end_coord with the hilite_color (which can be set with set_hilite_color, see below).
$chr->set_hilite($red_channel, $green_channel, $blue_channel)
Sets the hilite color for chromosome highlighting. Three values between 0 and 255 are required for defining red, green and blue channels. The default color is yellow (255, 255,0)
Sets the chromosome fill color. Three values between 0 and 255 are required for defining red, green and blue channels. The default color is 200, 100, 100, which is a light red.
Sets the chromosome outline color. Three values between 0 and 255 are required for defining red, green and blue channels. The default color is 0,0,0, which is black.
Sets the url for the hyperlink for the chromosome if it is clicked.
Sets the width of the chromosome in pixels
Sets the caption of the chromosome. The caption will be drawn centered on the top of the chromosome. Usually, the chromosome number should be displayed.
Causes the labels to be displayed on the left side of the chromosome.
Causes the labels to be displayed on the right side of the chromosome.
Causes the labels not to be displayed for the whole chromosome.
Causes the marker offsets to be displayed on the opposite side of the labels.
$chr-> render($image);
This function is called to render the chromosome and recursively calls all the rendering functions of the objects it contains. The image parameter is an GD image object. Usually, you should not have to call this function, but the map_image object calls this function for you if you render a map.
Gets the image map for the chromosome and all contained objects within chromosome. This is normally called by the map_image object.
$chr->add_marker($m);
Adds the marker object $m to the chromosome.
=cut
sub add_marker {
my $self = shift;
my $m = shift;
push @{$self->{markers}}, $m;
}
my @m = $chr -> get_markers();
Gets all the markers in the chromosome as an array.
my $pixels = $chr->get_cM_pixels($cM_pos);
Gets the number of pixels the cM value corresponds to. Note that you have to add the vertical chromosome offset (get_vertical_offset) to this number the get the actual image coordinates.
my $cM = $chr->get_pixels_cM($pixels);
Gets the number of cM that the number of $pixels correspond to. Note that you have to substract the vertical chromosome offset (get_vertical_offset) from the pixels this number the get the correct number of cM.
Returns the vertical offset of the chromosome. Defines the upper limit of the chromosome. Certain chromosome renditions will add a round edge on the top that will extend the chromomsome beyond that value.
$chr->draw_chromosome($image, $type);
Draws the chromosome on $image. Image is a GD image. The default chromosome rendering is as a 'sausage' type chromosome. A line model is available by supplying the type parameter ``line''. This is usually called by the map_image object.
my $m -> new ($chr, $marker_id, $marker_name, $marker_type, $confidence, $order_in_loc, $location_subscript, $cM_offset, $loc_type, $loc_order);
Creates a new marker. The $chr is the chromosome object the marker belongs to. The marker_id has to be a unique id for the marker.
set_color()Sets the color of the marker (more specifically, the line of the marker on the chromosome). Three numbers between 0 and 255 for red, green and blue channels are required. Default color is black.
Sets the hilite color. Default is yellow. Three numbers between 0 and 255 for red, green and blue channels are required.
Sets the color of the line connecting the label with the marker. Default is black. Three numbers between 0 and 255 for red, green and blue channels are required.
Sets the color of the offset scale text, if enabled.
Gets the complete name of the marker including the suffix.
get_marker_name()gets the marker name, excluding the suffix.
gets the unique id associated with the marker.
sets the url that this marker links to.
Hilites the marker in the hilite color (default is yellow).
Hides the marker completely from the chromosome.
Unhides the marker.
Returns true if marker is hidden.
Hides the label of the marker only. The marker 'tick' is still being drawn.
Unhides the label if it was previously hidden. Otherwise has no effect.
Returns true if the lable is not hidden.
get_image_map()Returns the image map for this label as a string. Usually the chromosome object calls this function.
render()
$marker -> render($image);
Renders the map on a GD image object. The chromosome object usually calls this function to render the entire chromosome.
returns true if the marker is visible, meaning it is not hidden and it lies not outside the chromosome section, if defined.
get_offset()Returns the offset of the marker in map units (cM).