[Bioperl-l] Graphics Panel

Kevin Brown Kevin.M.Brown at asu.edu
Mon Jan 8 17:47:12 UTC 2007


I'm trying to create an image showing the alignment of CDS's to a
chromosome in a genbank file that I retrieved from ncbi.  The base code
that I'm using came directly from the howto
(http://www.bioperl.org/wiki/HOWTO:Graphics).  Since the chromosome is
fairly long (3Mbp in length) I'm trying to split the drawing up into
sections and I'm running into some issues.  The first issue is that no
matter what I do with the -description option, I can't get the locus tag
of the gene to show up properly.  Instead I always get the description
of what the gene does.  I have verified that "locus_tag" does contain
the information I'm after (BMA0001, BMA0002, etc...).  The other issue
is that even though I'm feeding  the add_track method a new array for
each division, only the first section even shows the genes in a track.

Below are two of the scripts that I use to retrieve the genbank files
and parse them.  Attached is an example output with the issues I've
tried to describe.  This is with BioPerl 1.5.2_100 retrieved from CPAN
today.

This retrieves the genbank files for the organism that I'm mucking
around with.

#!/use/bin/perl -w
use strict;

use Bio::DB::GenBank;
use Bio::SeqIO;

my $gb = new Bio::DB::GenBank;
my @ids = ('NC_006348');

foreach my $id (@ids) {
	my $entry = $gb->get_Seq_by_id($id);
	my $out = Bio::SeqIO->new(-file=>">$id.gb", -format=>'genbank');
	$out->write_seq($entry);
}


This script is for creating the image from the above genbank file.

# This script generates a PNG picture of a 10K region containing a
# set of red features and a set of blue features. Call it like this:
#         red_and_blue.pl > redblue.png
# you can now view the picture with your favorite image application
# This script parses a GenBank or EMBL file named on the command
# line and produces a PNG rendering of it.  Call it like this:
# biographics.pl NC_006348.gb NC_006348.png 10

use strict;
use Bio::Graphics;
use Bio::SeqIO;

my $file = shift                       or die "provide a sequence file
as the argument\n";
my $output = shift or die "provide an output file for the image\n";
my $division = shift || 3;
 my $io = Bio::SeqIO->new(-file=>$file) or die "could not create
Bio::SeqIO";
 my $seq = $io->next_seq                or die "could not find a
sequence in the file";

open my $out, ">$output" or die "could not open $output for writing\n";

 my @features = $seq->all_SeqFeatures;

 # sort features by their primary tags
 my %sorted_features;
 for my $f (@features) {
   my $tag = $f->primary_tag;
   if ($tag eq 'CDS') {
     push
@{$sorted_features{int($f->start()/$seq->length()*$division)}},$f;
   }
 }
foreach my $key (keys %sorted_features) {
	print $key ."\t".@{$sorted_features{$key}}."\n";
}

my $wholeseq =
Bio::SeqFeature::Generic->new(-start=>1,-end=>$seq->length);

my $panel = Bio::Graphics::Panel->new(
				      -length    =>
$seq->length/$division,
 				      -key_style => 'between',
 				      -width     => 15000,
 				      -pad_left  => 10,
 				      -pad_right => 10,
 				      );
for (my $i = 0; $i<$division;$i++) {

$panel->add_track($wholeseq,
 		  -glyph => 'arrow',
 		  -bump => 0,
 		  -double=>1,
 		  -tick => 2,
		  -start => 1+$i*int($seq->length()/$division),
		  -end => ($i+1)*int($seq->length()/$division),
		);

 $panel->add_track($wholeseq,
 		  -glyph  => 'generic',
 		  -bgcolor => 'blue',
 		  -label  => 1,
		  -offset => $i*int($seq->length()/$division),
                  -start => 1+$i*int($seq->length()/$division),
                  -end => ($i+1)*int($seq->length()/$division),
 		 );

 # general case
   $panel->add_track(\@{$sorted_features{$i}},
 		    -glyph    =>  'generic',
 		    -bgcolor  =>  sub {
				my $feature = shift;
				my $idx;
				my @colors = qw(cyan orange blue purple
green chartreuse magenta yellow aqua);
				if ($feature->strand >= 0) {
					$idx = ($feature->start() - 1) %
3;
				}
				else {
        				$idx = ($feature->end() - 1) % 3
+ 3;
   				}
				$colors[$idx];},
 		    -fgcolor  => 'black',
 		    -font2color => 'red',
 		    -bump     => +1,
 		    -height   => 8,
 		    -description    => \&generic_description,
                    -offset => 1+$i*int($seq->length()/$division),
                    #-end => ($i+1)*int($seq->length()/$division),
 		   );
}
 print $out $panel->png;
 exit 0;

sub generic_description {
  my $feature = shift;
  my $description = $feature->get_tag_values("locus_tag");
  return "$description";
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: NC_006348.png
Type: image/png
Size: 125121 bytes
Desc: NC_006348.png
URL: <http://lists.open-bio.org/pipermail/bioperl-l/attachments/20070108/41ea62ca/attachment-0004.png>


More information about the Bioperl-l mailing list