[Bioperl-l] rendering the 5' & 3' UTR in a graphic

Mgavi Brathwaite lsbrath at gmail.com
Thu Aug 27 19:04:36 UTC 2009


Hello,

I am able to render all of the features except the 5' & 3' UTR. This is how
the features part of the Genbank file looks:

 FEATURES             Location/Qualifiers
     source          1..185000
                     /note="locus_tag=Nbl1"
                     /organism="Mus musculus"
     gene            142646..153328
                     /note="locus_tag=Nbl1"
                     /gene="ENSMUSG00000041120"
                     /note="neuroblastoma, suppression of tumorigenicity 1
                     [Source:MGI;Acc:MGI:104591]"
     5'UTR             142646..150000
                     /note="Nbl1"
     mRNA            join(142646..142794,149973..150167,150269..150380,
                     152019..153328)
                     /gene="ENSMUSG00000041120"
                     /note="transcript_id=ENSMUST00000042844"
     CDS             join(150001..150167,150269..150380,152019..152276)
                     /db_xref="CCDS:CCDS18839.1"
                     /db_xref="MGI:Nbl1"
                     /db_xref="Vega_mouse_transcript:OTTMUST00000022949"
                     /protein_id="ENSMUSP00000045608"
                     /gene="ENSMUSG00000041120"
                     /note="transcript_id=ENSMUST00000042844"
     misc_feature    150001..152276
                     /note="deletion"
     3'UTR             152277..153328
                     /gene="Nbl1"
ORIGIN      -
        1 GACCAGAGCC ACTCGCTAGG AGTCACACCG AGCCTGGGGG TCCGAAGGGA ACAGCATCAA

He is the code:

# file: embl2picture.pl
# This is code example 6 in the Graphics-HOWTO
# Author: Lincoln Stein

use strict;
#use lib "$ENV{HOME}/projects/bioperl-live";
use Bio::Graphics;
use Bio::SeqIO;

use constant USAGE =><<END;
Usage: $0 <file>
   Render a GenBank/EMBL entry into drawable form.
   Return as a GIF or PNG image on standard output.

   File must be in embl, genbank, or another SeqIO-
   recognized format.  Only the first entry will be
   rendered.

Example to try:
   embl2picture.pl factor7.embl | display -

END

my $file = shift                       or die USAGE;
my $io = Bio::SeqIO->new(-file=>$file) or die USAGE;
my $seq = $io->next_seq                or die USAGE;
my $wholeseq = Bio::SeqFeature::Generic->new(
                                             -start        => 1,
                                             -end          => $seq->length,
                                             -display_name =>
$seq->display_name
                                            );
# script reads the features from the sequence object by calling
all_SeqFeatures()
my @features = $seq->all_SeqFeatures;

# sorts each feature by its primary tag into a hash
# of array references named %sorted_features
my %sorted_features;
my %want = map {$_ =>1} qw/source CDS gene utr5prime utr3prime mRNA
misc_feature/;
for my $f (@features) {
  #get cds, primer_bind, and genes features only
  my $tag = $f->primary_tag;
  # create a hash of $f keys and $tag values
  #push @{$sorted_features{$tag}},$f if ($tag =~
/CDS|gene|mRNA|source|misc_feature|5'UTR|3'UTR/);
  push @{$sorted_features{$tag}},$f if ($want{$tag});
}
# we create the Bio::Graphics::Panel object.
# As in previous examples, we specify the width of the image,
# as well as some extra white space to pad out the left and right
borders.
my $panel = Bio::Graphics::Panel->new(
                                      -length    => $seq->length,
                                      -key_style => 'between',
                                      -width     => 400,
                                      -pad_left  => 10,
                                      -pad_right => 10,
                                      );
# We now add two tracks, one for the scale
# and the other for the sequence as a whole.
$panel->add_track($wholeseq,
                  -glyph  => 'arrow',
                  -bump   => 0,
                  -double => 1,
                  -tick   => 2,
                  -bgcolor => 'blue',
                  -label   => 1,
                 );
=cut
$panel->add_track($wholeseq,
                  -glyph   => 'generic',
                  -bgcolor => 'blue',
                  -label   => 1,
                 );
=cut
# Locate primary tag of "CDS" and create a track using a glyph
# at creation time. After we handle this special case, we remove
# the CDS feature type from the %sorted_features associative array.
if ($sorted_features{CDS}) {
  $panel->add_track($sorted_features{CDS},
                    -glyph       => 'transcript2',
                    -bgcolor     => 'orange',
                    -fgcolor     => 'black',
                    -font2color  => 'red',
                    -key         => 'CDS',
                    -bump        =>  +1,
                    -height      =>  12,
                    -label       => \&gene_label,
                    -description => \&gene_description,
                   );
  delete $sorted_features{'CDS'};
}

# Locate primary tag of "mRNA" and create a track using a glyph
# at creation time. After we handle this special case, we remove
# the mRNA feature type from the %sorted_features associative array.

if ($sorted_features{mRNA}) {
  $panel->add_track($sorted_features{mRNA},
                    -glyph       => 'transcript2',
                    -bgcolor     => 'red',
                    -fgcolor     => 'black',
                    -font2color  => 'red',
                    -key         => 'mRNA',
                    -bump        =>  +1,
                    -height      =>  12,
                    -label       => \&gene_label,
                    -description => \&gene_description,
                   );
  delete $sorted_features{'mRNA'};
}
#=cut
# Locate primary tag of "5'UTR" and create a track using a glyph
# at creation time. After we handle this special case, we remove
# the 5'UTR feature type from the %sorted_features associative array.
if ($sorted_features{utr5prime}) {
  $panel->add_track($sorted_features{utr5prime},
                    -glyph       => 'transcript2',
                    -bgcolor     => '',
                    -fgcolor     => 'black',
                    -font2color  => 'red',
                    -key         => 'utr5prime',
                    -bump        =>  +1,
                    -height      =>  12,
                    -label       => \&gene_label,
                    -description => \&gene_description,
                   );
  delete $sorted_features{utr5prime};
}
=cut
# Locate primary tag of "3'UTR" and create a track using a glyph
# at creation time. After we handle this special case, we remove
# the 3'UTR feature type from the %sorted_features associative array.
if ($sorted_features{3\'UTR}) {
  $panel->add_track($sorted_features{'3\'UTR'},
                    -glyph       => 'transcript2',
                    -bgcolor     => '',
                    -fgcolor     => 'black',
                    -font2color  => 'red',
                    -key         => '3\'UTR',
                    -bump        =>  +1,
                    -height      =>  12,
                    -label       => \&gene_label,
                    -description => \&gene_description,
                   );
  delete $sorted_features{'3\'UTR'};
}
=cut
# general case
# Create a track for each feature type. In order to distinguish the tracks
by color,
# we initialize an array of 9 color names and simply cycle through them
my @colors = qw(cyan orange blue purple green chartreuse magenta yellow
aqua);
my $idx    = 0;
for my $tag (sort keys %sorted_features) {
  my $features = $sorted_features{$tag};
  $panel->add_track($features,
                    -glyph       =>  'generic',
                    -bgcolor     =>  $colors[$idx++ % @colors],
                    -fgcolor     => 'black',
                    -font2color  => 'red',
                    -key         => "${tag}s",
                    -bump        => +1,
                    -height      => 8,
                    # -description option to point to a subroutine
                    # that will generate more informative description
strings.
                    -description => \&generic_description,
                   );
}
binmode(STDOUT);
print $panel->png;
exit 0;

sub gene_label {
  my $feature = shift;
  my @notes;
  foreach (qw(product gene)) {
    @notes = eval {$feature->get_tag_values($_)};
    last;
  }
  $notes[0];
}

sub gene_description {
  my $feature = shift;
  my @notes;
  foreach (qw(note)) {
    # Notice that we place calls to get_tag_values() inside eval{} blocks
    # in order to avoid having an exception raised if the feature does not
    # have a tag with the desired value.
    @notes = eval{$feature->get_tag_values($_)};
    last;
  }
  return unless @notes;
  substr($notes[0],30) = '...' if length $notes[0] > 30;
  $notes[0];
}

sub generic_description {
  my $feature = shift;
  my $description;
  foreach ($feature->get_all_tags) {
    my @values = $feature->get_tag_values($_);
   $description .= $_ eq 'note' ? "@values" : "$_=@values; ";
  }
  $description =~ s/; $//; # get rid of last
  $description;
}

sub fp_utr{
    my $five_prime_utr = '5\'UTR';
    return $five_prime_utr;
}


This is  how the image currently looks:



Any ideas why I am unable to render the 5' & 3' UTR  features?



More information about the Bioperl-l mailing list