3
# file: embl2picture.pl
4
# This is code example 6 in the Graphics-HOWTO
5
# Author: Lincoln Stein
8
use lib "$ENV{HOME}/projects/bioperl-live";
12
use constant USAGE =><<END;
14
Render a GenBank/EMBL entry into drawable form.
15
Return as a GIF or PNG image on standard output.
17
File must be in embl, genbank, or another SeqIO-
18
recognized format. Only the first entry will be
22
embl2picture.pl factor7.embl | display -
26
my $file = shift or die USAGE;
27
my $io = Bio::SeqIO->new(-file=>$file) or die USAGE;
28
my $seq = $io->next_seq or die USAGE;
29
my $wholeseq = Bio::SeqFeature::Generic->new(-start=>1,-end=>$seq->length,
30
-display_name=>$seq->display_name);
32
my @features = $seq->all_SeqFeatures;
34
# sort features by their primary tags
36
for my $f (@features) {
37
my $tag = $f->primary_tag;
38
push @{$sorted_features{$tag}},$f;
41
my $panel = Bio::Graphics::Panel->new(
42
-length => $seq->length,
43
-key_style => 'between',
48
$panel->add_track($wholeseq,
54
$panel->add_track($wholeseq,
61
if ($sorted_features{CDS}) {
62
$panel->add_track($sorted_features{CDS},
63
-glyph => 'transcript2',
70
-label => \&gene_label,
71
-description=> \&gene_description,
73
delete $sorted_features{'CDS'};
76
if ($sorted_features{tRNA}) {
77
$panel->add_track($sorted_features{tRNA},
78
-glyph => 'transcript2',
85
-label => \&gene_label,
87
delete $sorted_features{tRNA};
91
my @colors = qw(cyan orange blue purple green chartreuse magenta yellow aqua);
93
for my $tag (sort keys %sorted_features) {
94
my $features = $sorted_features{$tag};
95
$panel->add_track($features,
97
-bgcolor => $colors[$idx++ % @colors],
103
-description => \&generic_description
113
foreach (qw(product gene)) {
114
next unless $feature->has_tag($_);
115
@notes = $feature->each_tag_value($_);
121
sub gene_description {
125
next unless $feature->has_tag($_);
126
@notes = $feature->each_tag_value($_);
129
return unless @notes;
130
substr($notes[0],30) = '...' if length $notes[0] > 30;
134
sub generic_description {
137
foreach ($feature->all_tags) {
138
my @values = $feature->each_tag_value($_);
139
$description .= $_ eq 'note' ? "@values" : "$_=@values; ";
141
$description =~ s/; $//; # get rid of last