|
NAMEBio::Graphics::Glyph - Base class for Bio::Graphics::Glyph objectsSYNOPSISSee Bio::Graphics::Panel.DESCRIPTIONBio::Graphics::Glyph is the base class for all glyph objects. Each glyph is a wrapper around an Bio:SeqFeatureI object, knows how to render itself on an Bio::Graphics::Panel, and has a variety of configuration variables.End developers will not ordinarily work directly with Bio::Graphics::Glyph objects, but with Bio::Graphics::Glyph::generic and its subclasses. Similarly, most glyph developers will want to subclass from Bio::Graphics::Glyph::generic because the latter provides labeling and arrow-drawing facilities. METHODSThis section describes the class and object methods for Bio::Graphics::Glyph.CONSTRUCTORSBio::Graphics::Glyph objects are constructed automatically by an Bio::Graphics::Glyph::Factory, and are not usually created by end-developer code.
OBJECT METHODSOnce a glyph is created, it responds to a large number of methods. In this section, these methods are grouped into related categories.Retrieving glyph context:
Retrieving glyph options:
Setting an option:
Retrieving information about the sequence:
Retrieving formatting information:
These methods are called by Bio::Graphics::Track during the layout process:
These methods are intended to be overridden in subclasses:
These methods are useful utility routines:
OPTIONSThe following options are standard among all Glyphs. See individual glyph pages for more options.Also try out the glyph_help.pl script, which attempts to document each glyph's shared and specific options and provides an interface for graphically inspecting the effect of different options. Option Description Default ------ ----------- ------- -fgcolor Foreground color black -bgcolor Background color turquoise -fillcolor Synonym for -bgcolor -linewidth Line width 1 -height Height of glyph 10 -font Glyph font gdSmallFont -connector Connector type undef (false) -connector_color Connector color black -strand_arrow Whether to indicate undef (false) strandedness -stranded Whether to indicate undef (false) strandedness (same as above)) -label Whether to draw a label undef (false) -description Whether to draw a description undef (false) -no_subparts Set to true to prevent undef (false) drawing of the subparts of a feature. -ignore_sub_part Give the types/methods of undef subparts to ignore (as a space delimited list). -maxdepth Specifies the maximum number undef (unlimited) child-generations to decend when getting subfeatures -sort_order Specify layout sort order "default" -always_sort Sort even when bumping is off undef (false) -bump_limit Maximum number of levels to bump undef (unlimited) -hilite Highlight color undef (no color) -link, -title, -target These options are used when creating imagemaps for display on the web. See L<Bio::Graphics::Panel/"Creating Imagemaps">. For glyphs that consist of multiple segments, the -connector option controls what's drawn between the segments. The default is undef (no connector). Options include: "hat" an upward-angling conector "solid" a straight horizontal connector "quill" a decorated line with small arrows indicating strandedness (like the UCSC Genome Browser uses) "dashed" a horizontal dashed line. "crossed" a straight horizontal connector with an "X" on it (Can be used when segments are not yet validated by some internal experiments...) The -connector_color option controls the color of the connector, if any. The label is printed above the glyph. You may pass an anonymous subroutine to -label, in which case the subroutine will be invoked with the feature as its single argument and is expected to return the string to use as the label. If you provide the numeric value "1" to -label, the label will be read off the feature's seqname(), info() and primary_tag() methods will be called until a suitable name is found. To create a label with the text "1", pass the string "1 ". (A 1 followed by a space). The description is printed below the glyph. You may pass an anonymous subroutine to -description, in which case the subroutine will be invoked with the feature as its single argument and is expected to return the string to use as the description. If you provide the numeric value "1" to -description, the description will be read off the feature's source_tag() method. To create a description with the text "1", pass the string "1 ". (A 1 followed by a space). In the case of ACEDB Ace::Sequence feature objects, the feature's info(), Brief_identification() and Locus() methods will be called to create a suitable description. The -strand_arrow option, if true, requests that the glyph indicate which strand it is on, usually by drawing an arrowhead. Not all glyphs will respond to this request. For historical reasons, -stranded is a synonym for this option. Multisegmented features will draw an arrowhead on each component unless you specify a value of "ends" to -strand_arrow, in which case only the rightmost component (for + strand features) or the leftmost component (for - strand features) will have arrowheads. sort_order: By default, features are drawn with a layout based only on the position of the feature, assuring a maximal "packing" of the glyphs when bumped. In some cases, however, it makes sense to display the glyphs sorted by score or some other comparison, e.g. such that more "important" features are nearer the top of the display, stacked above less important features. The -sort_order option allows a few different built-in values for changing the default sort order (which is by "left" position): "low_score" (or "high_score") will cause features to be sorted from lowest to highest score (or vice versa). "left" (or "default") and "right" values will cause features to be sorted by their position in the sequence. "longest" (or "shortest") will cause the longest (or shortest) features to be sorted first, and "strand" will cause the features to be sorted by strand: "+1" (forward) then "0" (unknown, or NA) then "-1" (reverse). Finally, "name" will sort by the display_name of the features. In all cases, the "left" position will be used to break any ties. To break ties using another field, options may be strung together using a "|" character; e.g. "strand|low_score|right" would cause the features to be sorted first by strand, then score (lowest to highest), then by "right" position in the sequence. Finally, a subroutine coderef with a $$ prototype can be provided. It will receive two glyph as arguments and should return -1, 0 or 1 (see Perl's sort() function for more information). For example, to sort a set of database search hits by bits (stored in the features' "score" fields), scaled by the log of the alignment length (with "start" position breaking any ties): sort_order = sub ($$) { my ($glyph1,$glyph2) = @_; my $a = $glyph1->feature; my $b = $glyph2->feature; ( $b->score/log($b->length) <=> $a->score/log($a->length) ) || ( $a->start <=> $b->start ) } It is important to remember to use the $$ prototype as shown in the example. Otherwise Bio::Graphics will quit with an exception. The arguments are subclasses of Bio::Graphics::Glyph, not the features themselves. While glyphs implement some, but not all, of the feature methods, to be safe call the two glyphs' feature() methods in order to convert them into the actual features. The '-always_sort' option, if true, will sort features even if bumping is turned off. This is useful if you would like overlapping features to stack in a particular order. Features towards the end of the list will overlay those towards the beginning of the sort order. The -hilite option draws a colored box behind each feature using the indicated color. Typically you will pass it a code ref that returns a color name. For example: -hilite => sub { my $name = shift->display_name; return 'yellow' if $name =~ /XYZ/ } The -no_subparts option will prevent the glyph from searching its feature for subfeatures. This may enhance performance if you know in advance that none of your features contain subfeatures. SUBCLASSING Bio::Graphics::GlyphBy convention, subclasses are all lower-case. Begin each subclass with a preamble like this one:package Bio::Graphics::Glyph::crossbox; use strict; use base qw(Bio::Graphics::Glyph); Then override the methods you need to. Typically, just the draw() method will need to be overridden. However, if you need additional room in the glyph, you may override calculate_height(), calculate_left() and calculate_right(). Do not directly override height(), left() and right(), as their purpose is to cache the values returned by their calculating cousins in order to avoid time-consuming recalculation. A simple draw() method looks like this: sub draw { my $self = shift; $self->SUPER::draw(@_); my $gd = shift; # and draw a cross through the box my ($x1,$y1,$x2,$y2) = $self->calculate_boundaries(@_); my $fg = $self->fgcolor; $gd->line($x1,$y1,$x2,$y2,$fg); $gd->line($x1,$y2,$x2,$y1,$fg); } This subclass draws a simple box with two lines criss-crossed through it. We first call our inherited draw() method to generate the filled box and label. We then call calculate_boundaries() to return the coordinates of the glyph, disregarding any extra space taken by labels. We call fgcolor() to return the desired foreground color, and then call $gd->line() twice to generate the criss-cross. For more complex draw() methods, see Bio::Graphics::Glyph::transcript and Bio::Graphics::Glyph::segments. Please avoid using a specific image class (via "use GD" for example) within your glyph package. Instead, rely on the image package passed to the draw() method. This approach allows for future expansion of supported image classes without requiring glyph redesign. If you need access to the specific image classes such as Polygon, Image, or Font, generate them like such: sub draw { my $self = shift; my $image_class = shift; my $polygon_package = $self->polygon_package->new() ... } BUGSPlease report them.SEE ALSOBio::DB::GFF::Feature, Ace::Sequence, Bio::Graphics::Panel, Bio::Graphics::Track, Bio::Graphics::Glyph::Factory, Bio::Graphics::Glyph::alignment, Bio::Graphics::Glyph::anchored_arrow, Bio::Graphics::Glyph::arrow, Bio::Graphics::Glyph::box, Bio::Graphics::Glyph::broken_line, Bio::Graphics::Glyph::cds, Bio::Graphics::Glyph::christmas_arrow, Bio::Graphics::Glyph::crossbox, Bio::Graphics::Glyph::dashed_line, Bio::Graphics::Glyph::diamond, Bio::Graphics::Glyph::dna, Bio::Graphics::Glyph::dot, Bio::Graphics::Glyph::dumbbell, Bio::Graphics::Glyph::ellipse, Bio::Graphics::Glyph::ex, Bio::Graphics::Glyph::extending_arrow, Bio::Graphics::Glyph::flag, Bio::Graphics::Glyph::gene, Bio::Graphics::Glyph::generic, Bio::Graphics::Glyph::graded_segments, Bio::Graphics::Glyph::group, Bio::Graphics::Glyph::heterogeneous_segments, Bio::Graphics::Glyph::image, Bio::Graphics::Glyph::lightning, Bio::Graphics::Glyph::line, Bio::Graphics::Glyph::merge_parts, Bio::Graphics::Glyph::merged_alignment, Bio::Graphics::Glyph::minmax, Bio::Graphics::Glyph::oval, Bio::Graphics::Glyph::pentagram, Bio::Graphics::Glyph::pinsertion, Bio::Graphics::Glyph::primers, Bio::Graphics::Glyph::processed_transcript, Bio::Graphics::Glyph::protein, Bio::Graphics::Glyph::ragged_ends, Bio::Graphics::Glyph::redgreen_box, Bio::Graphics::Glyph::redgreen_segment, Bio::Graphics::Glyph::repeating_shape, Bio::Graphics::Glyph::rndrect, Bio::Graphics::Glyph::ruler_arrow, Bio::Graphics::Glyph::saw_teeth, Bio::Graphics::Glyph::segmented_keyglyph, Bio::Graphics::Glyph::segments, Bio::Graphics::Glyph::so_transcript, Bio::Graphics::Glyph::span, Bio::Graphics::Glyph::splice_site, Bio::Graphics::Glyph::stackedplot, Bio::Graphics::Glyph::ternary_plot, Bio::Graphics::Glyph::text_in_box, Bio::Graphics::Glyph::three_letters, Bio::Graphics::Glyph::tic_tac_toe, Bio::Graphics::Glyph::toomany, Bio::Graphics::Glyph::track, Bio::Graphics::Glyph::transcript, Bio::Graphics::Glyph::transcript2, Bio::Graphics::Glyph::translation, Bio::Graphics::Glyph::triangle, Bio::Graphics::Glyph::two_bolts, Bio::Graphics::Glyph::wave, Bio::Graphics::Glyph::weighted_arrow, Bio::Graphics::Glyph::whiskerplot, Bio::Graphics::Glyph::xyplotAUTHORLincoln Stein <lstein@cshl.org>Copyright (c) 2001 Cold Spring Harbor Laboratory This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See DISCLAIMER.txt for disclaimers of warranty.
Visit the GSP FreeBSD Man Page Interface. |