[Bioperl-guts-l] bioperl-live/scripts/graphics render_msa.pl, NONE, 1.1

Albert Vilella avilella at dev.open-bio.org
Fri Oct 26 14:39:29 EDT 2007


Update of /home/repository/bioperl/bioperl-live/scripts/graphics
In directory dev.open-bio.org:/tmp/cvs-serv11701

Added Files:
	render_msa.pl 
Log Message:
render a svg of a multiple sequence alignment -- green boxes for matches/mismatches vs lines for gapped regions


--- NEW FILE: render_msa.pl ---
#!/usr/bin/perl
use strict;
use Bio::Graphics;
use Bio::AlignIO;
use Bio::SeqFeature::Generic;
use Getopt::Long;

my ($inputfile,$debug);

GetOptions(
	   'i|input|inputfile:s' => \$inputfile,
           'debug' => \$debug,
          );

my $aio = Bio::AlignIO->new(-file   => $inputfile,
                            -format => 'fasta') or die "parse failed";

my $aln = $aio->next_aln() or die "no alignment";

my $panel = Bio::Graphics::Panel->new(
    -image_class => 'SVG',
    -length    => $aln->length,
    -width     => 800,
    -pad_left  => 150,
    -pad_right => 10,
);

my $full_length = Bio::SeqFeature::Generic->new(
    -start        => 1,
    -end          => $aln->length,
    -display_name => 'fasta alignment',
);
$panel->add_track($full_length,
                  -glyph   => 'arrow',
                  -tick    => 2,
                  -fgcolor => 'black',
                  -double  => 1,
                  -label   => 1,
                 );
 
my $track = $panel->add_track(
                              -glyph       => 'segments',
                              -label       => 1,
                              -connector   => 'dashed',
                              -bgcolor     => 'green',
                              -label_position   => 'alignment_left',
                              -font2color  => 'red'
                             );
 
for my $seqobj ($aln->each_seq) {
    my $seq = $seqobj->seq;
    my @seqs;
    # get alignment positions for seqs
    my $feature = Bio::SeqFeature::Generic->new(
        -display_name => $seqobj->get_nse,
    );
    while ($seq =~ m{([^-]+)}g) {
        # zero-based coords, must adjust accordingly
        $feature->add_sub_SeqFeature(
        Bio::SeqFeature::Generic->new(-start => pos($seq)-length($1)+1,
                                      -end => pos($seq),
                                      -sequence => $1), 'EXPAND');

    }
    $track->add_feature($feature);
}

print $panel->svg;
1;#??




More information about the Bioperl-guts-l mailing list