Bio::Graphics::Glyph
cds
Summary
Bio::Graphics::Glyph::cds - The "cds" glyph
Package variables
Globals (from "use vars" definitions)
$VERSION = '1.02'
Included modules
Inherit
Synopsis
Description
This glyph draws features that are associated with a protein coding
region. At high magnifications, draws a series of boxes that are
color-coded to indicate the frame in which the translation occurs. At
low magnifications, draws the amino acid sequence of the resulting
protein. Amino acids that are created by a splice are optionally
shown in a distinctive color.
The following options are standard among all Glyphs. See
Bio::Graphics::Glyph for a full explanation.
Option Description Default
------ ----------- -------
-fgcolor Foreground color black
-outlinecolor Synonym for -fgcolor
-bgcolor Background color turquoise
-fillcolor Synonym for -bgcolor
-linewidth Line width 1
-height Height of glyph 10
-font Glyph font gdSmallFont
-connector Connector type 0 (false)
-connector_color
Connector color black
-label Whether to draw a label 0 (false)
-description Whether to draw a description 0 (false)
-strand_arrow Whether to indicate 0 (false)
strandedness
In addition, the alignment glyph recognizes the following
glyph-specific options:
Option Description Default
------ ----------- -------
-frame0f Color for first (+) frame background color
-frame1f Color for second (+) frame background color
-frame2f Color for third (+) frame background color
-frame0r Color for first (-) frame background color
-frame1r Color for second (-) frame background color
-frame2r Color for third (-) frame background color
-gridcolor Color for the "staff" lightslategray
Methods
| connector | No description | Code |
| description | No description | Code |
| draw | No description | Code |
| draw_component | No description | Code |
| make_key_feature | No description | Code |
| bump | No description | Code |
Methods description
None available.
Methods code
sub description
{ my $self = shift;
return if $self->level;
return $self->SUPER::description;
}; } |
sub draw
{ my $self = shift;
my ($gd,$left,$top) = @_;
my @parts = $self->parts;
@parts = $self if !@parts && $self->level == 0;
return $self->SUPER::draw(@_) unless @parts;
my $fits = $self->protein_fits;
if (!$fits) {
my ($x1,$y1,$x2,$y2) = $self->bounds($left,$top);
my $height = ($y2-$y1)/3; my $grid = $self->gridcolor;
for (0..2) {
my $offset = $y1+$height*$_+1;
$gd->line($x1,$offset,$x2,$offset,$grid);
}
}
$self->{cds_part2color} ||= {};
my $fill = $self->bgcolor;
my $strand = $self->feature->strand;
@parts = map { $_->[0] }
sort { $b->[1] <=> $a->[1] }
map { [$_, $_->left ] } @parts if $strand < 0;
my $translate_table = Bio::Tools::CodonTable->new;
for (my $i=0; $i < @parts; $i++) {
my $part = $parts[$i];
my $feature = $part->feature;
my $pos = $strand > 0 ? $feature->start : $feature->end;
my $phase = eval {$feature->phase} || 0;
my ($frame,$offset) = frame_and_offset($pos,
$feature->strand,
-$phase);
my $suffix = $strand < 0 ? 'r' : 'f';
my $key = "frame$frame$suffix";
$self->{cds_frame2color}{$key} ||= $self->color($key) || $fill;
$part->{cds_partcolor} = $self->{cds_frame2color}{$key};
$part->{cds_frame} = $frame;
$part->{cds_offset} = $offset;
next unless $fits;
my $protein = $part->feature->translate(undef,undef,$phase)->seq;
$part->{cds_translation} = $protein;
BLOCK: {
length $protein >= $feature->length/3 and last BLOCK; ($feature->length - $phase) % 3 == 0 and last BLOCK;
my $next_part = $parts[$i+1]
or do {
$part->{cds_splice_residue} = '?';
last BLOCK; };
my $next_feature = $next_part->feature or last BLOCK;
my $next_phase = eval {$next_feature->phase} or last BLOCK;
my $splice_codon = '';
my $left_of_splice = substr($feature->seq,-$next_phase,$next_phase);
my $right_of_splice = substr($next_feature->seq,0,3-$next_phase);
$splice_codon = $left_of_splice . $right_of_splice;
length $splice_codon == 3 or last BLOCK;
my $amino_acid = $translate_table->translate($splice_codon);
$part->{cds_splice_residue} = $amino_acid;
}
}
$self->Bio::Graphics::Glyph::generic::draw($gd,$left,$top);} |
sub draw_component
{ my $self = shift;
my $gd = shift;
my ($x1,$y1,$x2,$y2) = $self->bounds(@_);
my $color = $self->{cds_partcolor};
my $feature = $self->feature;
my $frame = $self->{cds_frame};
unless ($self->protein_fits) {
my $height = ($y2-$y1)/3; my $offset = $y1 + $height*$frame;
$gd->filledRectangle($x1,$offset,$x2,$offset+2,$color);
return;
}
my $font = $self->font;
my $pixels_per_residue = $self->pixels_per_residue;
my $strand = $feature->strand;
my $start = $self->map_no_trunc($feature->start + $self->{cds_offset});
my $stop = $self->map_no_trunc($feature->end + $self->{cds_offset});
my @residues = split '',$self->{cds_translation};
push @residues,$self->{cds_splice_residue} if $self->{cds_splice_residue};
for (my $i=0;$i<@residues;$i++) {
my $x = $strand > 0 ? $start + $i * $pixels_per_residue
: $stop - $i * $pixels_per_residue;
next unless ($x >= $x1 && $x <= $x2);
$gd->char($font,$x+1,$y1,$residues[$i],$color);
}} |
sub make_key_feature
{ my $self = shift;
my @gatc = qw(g a t c);
my $offset = $self->panel->offset;
my $scale = 1/$self->scale; # base pairs/pixel
my $start = $offset;
my $stop = $offset + 100 * $scale;
my $seq = join('',map{$gatc[rand 4]} (1..1500));
my $feature =
Bio::Graphics::Feature->new(-start=> $start,
-end => $stop,
-seq => $seq,
-name => $self->option('key'),
-strand=> +1,
);
$feature->add_segment(Bio::Graphics::Feature->new(
-start=> $start,
-end => $start + ($stop - $start)/2, -seq => $seq, -name => $self->option('key'), -strand=> +1, ), Bio::Graphics::Feature->new( -start=> $start + ($stop - $start)/2+1,
-end => $stop,
-seq => $seq,
-name => $self->option('key'),
-phase=> 1,
-strand=> +1,
));
$feature;} |
sub bump
{ my $self = shift;
return $self->SUPER::bump(@_) if $self->all_callbacks;
return 0; } |
General documentation
| SUGGESTED STANZA FOR GENOME BROWSER | Top |
Using the "coding" aggregator, this produces a nice gbrowse display.
[CDS]
feature = coding
glyph = cds
frame0f = cadetblue
frame1f = blue
frame2f = darkblue
frame0r = darkred
frame1r = red
frame2r = crimson
description = 0
height = 13
label = CDS frame
key = CDS
citation = This track shows CDS reading frames.
Please report them.
Bio::Graphics::Panel,
Bio::Graphics::Glyph,
Bio::Graphics::Glyph::arrow,
Bio::Graphics::Glyph::cds,
Bio::Graphics::Glyph::crossbox,
Bio::Graphics::Glyph::diamond,
Bio::Graphics::Glyph::dna,
Bio::Graphics::Glyph::dot,
Bio::Graphics::Glyph::ellipse,
Bio::Graphics::Glyph::extending_arrow,
Bio::Graphics::Glyph::generic,
Bio::Graphics::Glyph::graded_segments,
Bio::Graphics::Glyph::heterogeneous_segments,
Bio::Graphics::Glyph::line,
Bio::Graphics::Glyph::pinsertion,
Bio::Graphics::Glyph::primers,
Bio::Graphics::Glyph::rndrect,
Bio::Graphics::Glyph::segments,
Bio::Graphics::Glyph::ruler_arrow,
Bio::Graphics::Glyph::toomany,
Bio::Graphics::Glyph::transcript,
Bio::Graphics::Glyph::transcript2,
Bio::Graphics::Glyph::translation,
Bio::Graphics::Glyph::triangle,
Bio::DB::GFF,
Bio::SeqI,
Bio::SeqFeatureI,
Bio::Das,
GD
Lincoln 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.