1#!/usr/bin/perl 2use strict; 3use Bio::Graphics; 4use Bio::AlignIO; 5use Bio::SeqFeature::Generic; 6use Bio::Tools::GuessSeqFormat; 7use Getopt::Long; 8 9my ($inputfile,$debug); 10 11GetOptions( 12 'i|input|inputfile:s' => \$inputfile, 13 'debug' => \$debug, 14 ); 15 16my $guessed_format = new Bio::Tools::GuessSeqFormat 17 (-file=>"$inputfile" 18 )->guess; 19 20my $aio = Bio::AlignIO->new(-file => $inputfile, 21 -format => $guessed_format) or die "parse failed"; 22 23my $aln = $aio->next_aln() or die "no alignment"; 24 25my $panel = Bio::Graphics::Panel->new( 26 -image_class => 'SVG', 27 -length => $aln->length, 28 -width => 800, 29 -pad_left => 150, 30 -pad_right => 10, 31); 32 33my $full_length = Bio::SeqFeature::Generic->new( 34 -start => 1, 35 -end => $aln->length, 36 -display_name => 'fasta alignment', 37); 38$panel->add_track($full_length, 39 -glyph => 'arrow', 40 -tick => 2, 41 -fgcolor => 'black', 42 -double => 1, 43 -label => 1, 44 ); 45 46my $track = $panel->add_track( 47 -glyph => 'segments', 48 -label => 1, 49 -connector => 'dashed', 50 -bgcolor => 'green', 51 -label_position => 'alignment_left', 52 -font2color => 'red' 53 ); 54 55for my $seqobj ($aln->each_seq) { 56 my $seq = $seqobj->seq; 57 my @seqs; 58 # get alignment positions for seqs 59 my $feature = Bio::SeqFeature::Generic->new( 60 -display_name => $seqobj->get_nse, 61 ); 62 while ($seq =~ m{([^-]+)}g) { 63 # zero-based coords, must adjust accordingly 64 $feature->add_sub_SeqFeature( 65 Bio::SeqFeature::Generic->new(-start => pos($seq)-length($1)+1, 66 -end => pos($seq), 67 -sequence => $1), 'EXPAND'); 68 69 } 70 $track->add_feature($feature); 71} 72 73print $panel->svg; 74 75 76