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";
14 bp_embl2picture.pl - Render a Genbank/EMBL sequence file graphically as a png image
18 % bp_embl2picture.pl factor7.embl | display -
22 Render a GenBank/EMBL entry into drawable form. Return as a GIF or
23 PNG image on standard output.
25 The file must be in embl, genbank, or another SeqIO- recognized format.
26 Only the first entry will be rendered.
30 L<Bio::Graphics>, the BioGraphics HOWTO.
34 Lincoln Stein, lstein@cshl.edu
36 Copyright (c) 2004 Cold Spring Harbor Laboratory
38 This library is free software; you can redistribute it and/or modify
39 it under the same terms as Perl itself. See DISCLAIMER.txt for
40 disclaimers of warranty.
44 use constant USAGE
=><<END;
46 Render a GenBank/EMBL entry into drawable form.
47 Return as a GIF or PNG image on standard output.
49 File must be in embl, genbank, or another SeqIO-
50 recognized format. Only the first entry will be
54 embl2picture.pl factor7.embl | display -
58 my $file = shift or die USAGE
;
59 my $io = Bio
::SeqIO
->new(-file
=>$file) or die USAGE
;
60 my $seq = $io->next_seq or die USAGE
;
61 my $wholeseq = Bio
::SeqFeature
::Generic
->new(-start
=>1,-end
=>$seq->length,
62 -display_name
=>$seq->display_name);
64 my @features = $seq->all_SeqFeatures;
66 # sort features by their primary tags
68 for my $f (@features) {
69 my $tag = $f->primary_tag;
70 push @
{$sorted_features{$tag}},$f;
73 my $panel = Bio
::Graphics
::Panel
->new(
74 -length => $seq->length,
75 -key_style
=> 'between',
80 $panel->add_track($wholeseq,
86 $panel->add_track($wholeseq,
93 if ($sorted_features{CDS
}) {
94 $panel->add_track($sorted_features{CDS
},
95 -glyph
=> 'transcript2',
102 -label
=> \
&gene_label
,
103 -description
=> \
&gene_description
,
105 delete $sorted_features{'CDS'};
108 if ($sorted_features{tRNA
}) {
109 $panel->add_track($sorted_features{tRNA
},
110 -glyph
=> 'transcript2',
113 -font2color
=> 'red',
117 -label
=> \
&gene_label
,
119 delete $sorted_features{tRNA
};
123 my @colors = qw(cyan orange blue purple green chartreuse magenta yellow aqua);
125 for my $tag (sort keys %sorted_features) {
126 my $features = $sorted_features{$tag};
127 $panel->add_track($features,
129 -bgcolor
=> $colors[$idx++ % @colors],
131 -font2color
=> 'red',
135 -description
=> \
&generic_description
145 foreach (qw(product gene)) {
146 next unless $feature->has_tag($_);
147 @notes = $feature->each_tag_value($_);
153 sub gene_description
{
157 next unless $feature->has_tag($_);
158 @notes = $feature->each_tag_value($_);
161 return unless @notes;
162 substr($notes[0],30) = '...' if length $notes[0] > 30;
166 sub generic_description
{
169 foreach ($feature->all_tags) {
170 my @values = $feature->each_tag_value($_);
171 $description .= $_ eq 'note' ?
"@values" : "$_=@values; ";
173 $description =~ s/; $//; # get rid of last