Bio::G...:Glyph(3pm)
okay bestie, this is the manual page for Bio::G...:Glyph(3pm) from User Contributed Perl Documentation. Part 1, so no sign-off β just vibes, facts, and zero skipped details. β¨
π NAME π
Bio::Graphics::Glyph β Base class for Bio::Graphics::Glyph objects
πΈ SYNOPSIS πΈ
See Bio::Graphics::Panel.
π¦ DESCRIPTION π¦
Okay so Bio::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. Slay. β¨
π METHODS π
This section describes the class and object methods for Bio::Graphics::Glyph.
π§Έ CONSTRUCTORS π§Έ
Bio::Graphics::Glyph objects are constructed automatically by an Bio::Graphics::Glyph::Factory, and are not usually created by end-developer code. No cap.
$glyph = Bio::Graphics::Glyph->new(-feature=>$feature,-factory=>$factory)
Given a sequence feature, creates an Bio::Graphics::Glyph object to display it. The -feature argument points to the Bio:SeqFeatureI object to display, and -factory indicates an Bio::Graphics::Glyph::Factory object from which the glyph will fetch all its run-time configuration information. Factories are created and manipulated by the Bio::Graphics::Panel object.
A standard set of options are recognized. See OPTIONS.
π« OBJECT METHODS π«
Once a glyph is created, it responds to a large number of methods. In this section, these methods are grouped into related categories. Main character energy, honestly. π
π Retrieving glyph context:
$factory = $glyph->factoryβ Get theBio::Graphics::Glyph::Factoryassociated with this object. This cannot be changed once it is set. Periodt.$panel = $glyph->panelβ Get theBio::Graphics::Panelassociated with this object. This cannot be changed once it is set.$feature = $glyph->featureβ Get the sequence feature associated with this object. This cannot be changed once it is set.$feature = $glyph->parent_feature()β Within callbacks only, theparent_feature()method returns the parent of the current feature, if there is one. Called with a numeric argument, ascends the parentage tree:parent_feature(1)will return the parent,parent_feature(2)will return the grandparent, etc. If there is no parent, returnsundef.$feature = $glyph->add_feature(@features)β Add the list of features to the glyph, creating subparts. This is most common done with the track glyph returned byBio::Graphics::Panel->add_track().
If the Bio::Graphics::Panel was initialized with -feature_limit set to a non-zero value, then calls to a track glyph's add_feature() method will maintain a count of features added to the track. Once the feature count exceeds the value set in -feature_limit, additional features will displace existing ones in a way that effects a uniform sampling of the total feature set. This is useful to protect against excessively large tracks. The total number of features added can be retrieved by calling the glyph's feature_count() method.
$feature = $glyph->add_group(@features)β This is similar toadd_feature(), but the list of features is treated as a group and can be configured as a set.$glyph->finishedβ When you are finished with a glyph, you can call itsfinished()method in order to break cycles that would otherwise cause memory leaks.finished()is typically only used by thePanelobject.
bestie, ignoring finished() is how you get memory leaks. It's giving haunted house. π
$subglyph = $glyph->make_subglyph($level,@sub_features)β This method is called to create subglyphs from a list of subfeatures. The$levelindicates the current level of the glyph (top-level glyphs are level 0, subglyphs are level 1, etc).
Ordinarily this method simply calls $self->factory->make_subglyph($level,@sub_features). Override it in subclasses to create subglyphs of a particular type. For example:
sub make_subglyph {
my $self = shift;
my $level = shift;
my $factory = $self->factory;
$factory->make_glyph($factory,'arrow',@_);
}
$count = $glyph->feature_count()β Return the number of features added to this glyph viaadd_feature().$flag = $glyph->features_clipped()β If the panel was initialized with-feature_limitset to a non-zero value, then calls toadd_features()will limit the number of glyphs to the indicated value. If this value was exceeded, thenfeatures_clipped()will return true.
π¨ Retrieving glyph options:
$fgcolor = $glyph->fgcolor$bgcolor = $glyph->bgcolor$fontcolor = $glyph->fontcolor$fontcolor = $glyph->font2color$fillcolor = $glyph->fillcolor
These methods return the configured foreground, background, font, alternative font, and fill colors for the glyph in the form of a GD::Image color index. π¨
$color = $glyph->tkcolorβ This method returns a color to be used to flood-fill the entire glyph before drawing (currently used by the"track"glyph). π($left,$top,$right,$bottom) = $glyph->bounds($dx,$dy)β Given the topleft coordinates of the glyph, return the bounding box of its contents, exclusive of padding. This is typically called by thedraw()anddraw_component()methods to recover the position of the glyph.($left,$top,$right,$bottom) = $glyph->calculate_boundaries($dx,$dy)β An alias forbounds(), used by some glyphs for compatibility with older versions of this module.$width = $glyph->width([$newwidth])β Return the width of the glyph, not including left or right padding. This is ordinarily set internally based on the size of the feature and the scale of the panel.$width = $glyph->layout_widthβ Returns the width of the glyph including left and right padding.$width = $glyph->heightβ Returns the height of the glyph, not including the top or bottom padding. This is calculated from the"height"option and cannot be changed.$font = $glyph->fontβ Return the font for the glyph.$option = $glyph->option($option)β Return the value of the indicated option.$index = $glyph->color($option_name)β Given an option name that corresponds to a color (e.g.'fgcolor') look up the option and translate it into a GD color index.$index = $glyph->translate_color($color)β Given a symbolic or#RRGGBB-form color name, returns its GD index.$level = $glyph->levelβ The"level"is the nesting level of the glyph. Groups are level -1, top level glyphs are level 0, subparts (e.g. exons) are level 1 and so forth.@parts = $glyph->partsβ For glyphs that can contain subparts (e.g. the segments glyph), this method will return the list of subglyphs it contains. Subglyphs are created automatically by thenew()method and are created subject to the maximum recursion depth specified by themaxdepth()method and/or the-maxdepthoption.
βοΈ Setting an option:
$glyph->configure(-name=>$value)β You may change a glyph option after it is created usingset_option(). This is most commonly used to configure track glyphs.
𧬠Retrieving information about the sequence:
$start = $glyph->start$end = $glyph->end
These methods return the start and end of the glyph in base pair units.
$offset = $glyph->offsetβ Returns the offset of the segment (the base pair at the far left of the image).$length = $glyph->lengthβ Returns the length of the sequence segment.
π Retrieving formatting information:
$top = $glyph->top$left = $glyph->left$bottom = $glyph->bottom$right = $glyph->right
These methods return the top, left, bottom and right of the glyph in pixel coordinates.
$height = $glyph->heightβ Returns the height of the glyph. This may be somewhat larger or smaller than the height suggested by theGlyphFactory, depending on the type of the glyph.$scale = $glyph->scaleβ Get the scale for the glyph in pixels/bp.$height = $glyph->labelheightβ Return the height of the label, if any.$label = $glyph->labelβ Return a human-readable label for the glyph.
These methods are called by Bio::Graphics::Track during the layout process:
$glyph->move($dx,$dy)β Move the glyph in pixel coordinates by the indicated delta-x and delta-y values.($x1,$y1,$x2,$y2) = $glyph->boxβ Return the current position of the glyph.
These methods are intended to be overridden in subclasses:
$glyph->calculate_heightβ Calculate the height of the glyph.$glyph->calculate_leftβ Calculate the left side of the glyph.$glyph->calculate_rightβ Calculate the right side of the glyph.$glyph->draw($gd,$left,$top)β Optionally offset the glyph by the indicated amount and draw it onto theGD::Imageobject.$glyph->draw_label($gd,$left,$top)β Draw the label for the glyph onto the providedGD::Imageobject, optionally offsetting by the amounts indicated in$leftand$right.$glyph->maxdepth()β This returns the maximum number of levels of feature subparts that the glyph will recurse through. For example, returning 0 indicates that the glyph will only draw the top-level feature. Returning 1 indicates that it will only draw the top-level feature and one level of subfeatures. Returning 2 will descend down two levels. Overriding this method will speed up rendering by avoiding creating of a bunch of subglyphs that will never be drawn.
The default behavior is to return undef (unlimited levels of descent) unless the -maxdepth option is passed, in which case this number is returned.
Note that Bio::Graphics::Glyph::generic overrides maxdepth() to return 0, meaning no descent into subparts will be performed.
These methods are useful utility routines:
@pixels = $glyph->map_pt(@bases);β Map the list of base position, given in base pair units, into pixels, using the current scale and glyph position. This method will accept a single base position or an array.$glyph->filled_box($gd,$x1,$y1,$x2,$y2)β Draw a filled rectangle with the appropriate foreground and fill colors, and pen width onto theGD::Imageobject given by$gd, using the provided rectangle coordinates.$glyph->filled_oval($gd,$x1,$y1,$x2,$y2)β As above, but draws an oval inscribed on the rectangle.$glyph->exceeds_depthβ Returns true if descending into another level of subfeatures will exceed the value returned bymaxdepth().
β¨ OPTIONS β¨
okay bestie, these options are the standard ones every Glyph gets π β like the shared starter pack. For extra options, go peek at the individual glyph pages, mmkay?
also!! there's a lil script called glyph_help.pl that literally tries to document each glyph's shared and specific options, and gives you a whole interface to graphically inspect what different options actually do. iconic of it tbh π
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">.
π the connector tea
so when a glyph is made of multiple segments, the -connector option decides what gets drawn between them. default is undef, which means no connector at all, sorry. but you got options, bestie:
"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...)
and -connector_color sets the color of that connector, if there is one. slay π
π·οΈ labels & descriptions
the label gets printed above the glyph. you can hand -label an anonymous subroutine, and it'll get called with the feature as its single argument β you're expected to return the string to use as the label. π
if you give -label the numeric value 1, the label gets read off the feature's seqname(), and info() and primary_tag() methods get called until a suitable name turns up. and heads up: if you want a label that literally says "1", pass the string "1 " β that's a 1 followed by a space, okay? π
the description prints below the glyph. same deal β pass -description an anonymous subroutine and it gets the feature as its single argument, expected to return the string for the description. if you hand -description the numeric value 1, the description is read off the feature's source_tag() method. and again, to get a description that just says "1", pass the string "1 " (one, then a space). β¨
and for ACEDB Ace::Sequence feature objects specifically? the feature's info(), Brief_identification() and Locus() methods get called to build a suitable description. π
β‘οΈ strand_arrow
-strand_arrow, if it's true, asks the glyph to show which strand it's on β usually by drawing an arrowhead. but ngl, not every glyph will respond to this request, so don't be shocked. for historical reasons, -stranded is a synonym for this option (yes, the manpage really did just say "same as above))." we love legacy code π«Ά).
for multisegmented features: an arrowhead gets drawn on each component β unless you give -strand_arrow a value of "ends". in that case only the rightmost component gets arrowheads (for + strand features), or only the leftmost component (for - strand features). periodt.
π sort_order
by default, features get drawn with a layout based purely on position, which assures maximal "packing" of the glyphs when bumped. but sometimes you wanna sort by score or some other comparison instead β like when more "important" features should sit nearer the top, stacked above the less important ones. π
-sort_order gives you a few built-in values to shake up the default sort order (which is by "left" position):
"low_score"(or"high_score") β sorts features from lowest to highest score, or vice versa"left"(or"default") and"right"β sorts features by their position in the sequence"longest"(or"shortest") β sorts the longest (or shortest) features first"strand"β sorts by strand:"+1"(forward), then"0"(unknown, or NA), then"-1"(reverse)"name"β sorts by thedisplay_nameof the features
in all cases, the "left" position breaks any ties. and if you wanna break ties with a different field, you can string options together with a "|" character β like "strand|low_score|right", which sorts first by strand, then score (lowest to highest), then by "right" position in the sequence. cute, right? π¦
finally, you can hand it a subroutine coderef with a $$ prototype. it receives two glyphs as arguments and should return -1, 0 or 1 (check Perl's sort() function if you need the deets). 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 )
}
π¨ bestie, listen: it is important to remember to use the $$ prototype exactly as shown in the example. otherwise Bio::Graphics will quit with an exception. no cap.
the arguments are subclasses of Bio::Graphics::Glyph, not the features themselves. glyphs implement some β but not all β of the feature methods, so to be safe, call the two glyphs' feature() methods to convert them into the actual features. π§
π always_sort
-always_sort, if true, sorts features even if bumping is turned off. this is useful when you want 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 way that works... lowkey important. π
ποΈ hilite
-hilite draws a colored box behind each feature using the color you indicate. typically you pass it a code ref that returns a color name. like so:
-hilite => sub { my $name = shift->display_name;
return 'yellow' if $name =~ /XYZ/ }
π« no_subparts
-no_subparts stops the glyph from searching its feature for subfeatures. this may boost performance if you already know none of your features contain subfeatures. efficiency queen behavior π
πΈ SUBCLASSING Bio::Graphics::Glyph πΈ
by convention, subclasses are all lower-case. start 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 actually need. typically, just the draw() method needs overriding. but if you need extra room in the glyph, you can override calculate_height(), calculate_left() and calculate_right(). and bestie, do NOT directly override height(), left() and right() β their whole job is caching the values returned by their calculating cousins so you don't do time-consuming recalculation over and over. respect the cache π
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. then we call calculate_boundaries() to get the coordinates of the glyph, ignoring any extra space taken up by labels. we call fgcolor() to get the desired foreground color, and then call $gd->line() twice to generate the criss-cross. chef's kiss π
for more complex draw() methods, go look at Bio::Graphics::Glyph::transcript and Bio::Graphics::Glyph::segments. π
alsooo, please avoid using a specific image class (like via use GD) inside your glyph package. instead, rely on the image package passed to the draw() method. this approach lets supported image classes expand in the future without you having to redesign your glyph. if you need access to specific image classes like Polygon, Image, or Font, generate them like this:
sub draw {
my $self = shift;
my $image_class = shift;
my $polygon_package = $self->polygon_package->new()
...
}
π BUGS π
Please report them.
(that's it. that's the whole section. short king energy fr fr π)
π SEE ALSO π
okay bestie, here's the whole squad π this is the extended universe, the group chat, the entire guest list. go read these when you're done here, no cap:
Bio::DB::GFF::FeatureAce::SequenceBio::Graphics::PanelBio::Graphics::TrackBio::Graphics::Glyph::FactoryBio::Graphics::Glyph::alignmentBio::Graphics::Glyph::anchored_arrowBio::Graphics::Glyph::arrowBio::Graphics::Glyph::boxBio::Graphics::Glyph::broken_lineBio::Graphics::Glyph::cdsBio::Graphics::Glyph::christmas_arrowBio::Graphics::Glyph::crossboxBio::Graphics::Glyph::dashed_lineBio::Graphics::Glyph::diamondBio::Graphics::Glyph::dnaBio::Graphics::Glyph::dotBio::Graphics::Glyph::dumbbellBio::Graphics::Glyph::ellipseBio::Graphics::Glyph::exBio::Graphics::Glyph::extending_arrowBio::Graphics::Glyph::flagBio::Graphics::Glyph::geneBio::Graphics::Glyph::genericBio::Graphics::Glyph::graded_segmentsBio::Graphics::Glyph::groupBio::Graphics::Glyph::heterogeneous_segmentsBio::Graphics::Glyph::imageBio::Graphics::Glyph::lightningBio::Graphics::Glyph::lineBio::Graphics::Glyph::merge_partsBio::Graphics::Glyph::merged_alignmentBio::Graphics::Glyph::minmaxBio::Graphics::Glyph::ovalBio::Graphics::Glyph::pentagramBio::Graphics::Glyph::pinsertionBio::Graphics::Glyph::primersBio::Graphics::Glyph::processed_transcriptBio::Graphics::Glyph::proteinBio::Graphics::Glyph::ragged_endsBio::Graphics::Glyph::redgreen_boxBio::Graphics::Glyph::redgreen_segmentBio::Graphics::Glyph::repeating_shapeBio::Graphics::Glyph::rndrectBio::Graphics::Glyph::ruler_arrowBio::Graphics::Glyph::saw_teethBio::Graphics::Glyph::segmented_keyglyphBio::Graphics::Glyph::segmentsBio::Graphics::Glyph::so_transcriptBio::Graphics::Glyph::spanBio::Graphics::Glyph::splice_siteBio::Graphics::Glyph::stackedplotBio::Graphics::Glyph::ternary_plotBio::Graphics::Glyph::text_in_boxBio::Graphics::Glyph::three_lettersBio::Graphics::Glyph::tic_tac_toeBio::Graphics::Glyph::toomanyBio::Graphics::Glyph::trackBio::Graphics::Glyph::transcriptBio::Graphics::Glyph::transcript2Bio::Graphics::Glyph::translationBio::Graphics::Glyph::triangleBio::Graphics::Glyph::two_boltsBio::Graphics::Glyph::waveBio::Graphics::Glyph::weighted_arrowBio::Graphics::Glyph::whiskerplotBio::Graphics::Glyph::xyplot
like. SIXTY-SEVEN of them. it's giving glyph multiverse π¦ every single one is its own little main character and i am obsessed. iykyk π
π AUTHOR π
Lincoln Stein β the literal icon, the blueprint, the moment π
Lincoln Stein <lstein@cshl.org>
Copyright (c) 2001 Cold Spring Harbor Laboratory
and the legal bit, because we respect the paperwork bestie πβ¨:
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.
translation: free software, same terms as Perl itself, and if you wanna know about warranties, DISCLAIMER.txt is right there waiting for you π«Ά
and that's the whole page, bestie!! πΈ this was the User Contributed Perl Documentation version of Bio::G...:Glyph(3pm), running on perl v5.30.0 and dated 2019-11-25 β so if you're reading this from the future, hi, hope the syntax still hits πβ¨ go forth and subclass responsibly, mwah π
π¦ where this page comes from
- debian bookworm: libbio-graphics-perl 2.40-6 Β· Perl
- debian trixie: libbio-graphics-perl 2.40-6 Β· Perl
- ubuntu jammy: libbio-graphics-perl 2.40-6 Β· Perl
- ubuntu noble: libbio-graphics-perl 2.40-6 Β· Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms