| 1 | #!/usr/local/bin/perl | ||
| 2 | use strict; | ||
| 3 | use Bio::Graphics; | ||
| 4 | use Bio::AlignIO; | ||
| 5 | use Bio::SeqFeature::Generic; | ||
| 6 | use Bio::Tools::GuessSeqFormat; | ||
| 7 | use Getopt::Long; | ||
| 8 | |||
| 9 | my ($inputfile,$debug); | ||
| 10 | |||
| 11 | GetOptions( | ||
| 12 | 'i|input|inputfile:s' => \$inputfile, | ||
| 13 | 'debug' => \$debug, | ||
| 14 | ); | ||
| 15 | |||
| 16 | my $guessed_format = new Bio::Tools::GuessSeqFormat | ||
| 17 | (-file=>"$inputfile" | ||
| 18 | )->guess; | ||
| 19 | |||
| 20 | my $aio = Bio::AlignIO->new(-file => $inputfile, | ||
| 21 | -format => $guessed_format) or die "parse failed"; | ||
| 22 | |||
| 23 | my $aln = $aio->next_aln() or die "no alignment"; | ||
| 24 | |||
| 25 | my $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 | |||
| 33 | my $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 | |||
| 46 | my $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 | |||
| 55 | for 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 | |||
| 73 | print $panel->svg; | ||
| 74 | |||
| 75 |