Adding a DNA track

From BioPerl
Jump to: navigation, search

The hack

I thought this was helpful, since the only DNA track example documentation I could find was in the POD of bioperl-live (not on search.cpan.org yet). Thoughts? --Jhannah 02:48, 13 May 2008 (UTC)

The script

use strict;
use Bio::Graphics;
use Bio::SeqFeature::Generic;
 
# ------------------------
# Configure these...      ( name start end )
my @stuff = qw( 
   thing1  2  6
   thing2 14 10
   thing3 12 16
   thing4 18 22
);
my $seq = 'ACGGTCGATCGATCGATCGATCGTACGATCG';
# ------------------------
 
my $panel = Bio::Graphics::Panel->new(
   -length => length($seq),         # bp
   -width  => length($seq) * 7,     # pixels
);
 
# Add the arrow at the top.
my $full_length = Bio::SeqFeature::Generic->new(
   -start => 1,
   -end   => length($seq),
);
$panel->add_track($full_length,
   -glyph     => 'arrow',
   -tick      => 2,
   -fgcolor   => 'black',
   -northeast => 1,
);
 
# Data track...
my $track = $panel->add_track(
   -glyph    => 'generic',
   -stranded => 1,
   -label    => 1,
);
 
# Add each feature to the data track.
while (@stuff) {
   my ($name, $start, $end) = splice @stuff, 0, 3;
   my $feature = Bio::SeqFeature::Generic->new(
      -strand       => $start < $end ? 1 : -1,
      -display_name => $name,
      -start        => $start,
      -end          => $end,
   );
   $track->add_feature($feature);
}
 
# Add the DNA track to the bottom.
my $dna = Bio::PrimarySeq->new( -seq => $seq );
my $feature = Bio::SeqFeature::Generic->new( -start => 1, -end => length($seq) );
$feature->attach_seq($dna);
$panel->add_track( $feature, -glyph => 'dna' );
 
# Send to a .png file.
print $panel->png;

Output:

Bio Graphics Glyph dna.png

to the #top

Personal tools
Namespaces
Variants
Actions
Main Links
documentation
community
development
Toolbox