Bio-Align-Graphics

 view release on metacpan or  search on metacpan

lib/Bio/Align/Graphics.pm  view on Meta::CPAN

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#
#Produces:  An image file
#
#Revision History:
#09/01/2006 - WDM - Introduction of "wrap" flag, allowing alignment to be
#                   wrapped at a set base and stacked vertically
#                   Addition of internal members y_num and y_size for tracking
#                   of number of vertical panels and size of panels,
#                   respectively
#
#09/06/2006 - WDM - Introduction of "p_legend" flag, for printing of an optional
#                   colored legend when protein coloring is selected
#
#09/24/2008 - WDM - Test file created for the module
#
#03/01/2009 - YH -  Introduction of "show_nonsynonymous" flag which enables
#                   highlighting of nonsynonymous mutations in nucleotide
#                   alignments. Addition of internal members codon_table and
#                   missense_pos for translating codons -> amino acids and for
#                   keeping track of missense mutation positions respectively.
#
#03/05/2009 - YH  - Swapped names of subroutines x_label and y_label to match

lib/Bio/Align/Graphics.pm  view on Meta::CPAN

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
font => defined($options{font}) ? $FONT_TABLE{$options{font}} : $FONT_TABLE{2},
x_label => defined($options{x_label}) ? $options{x_label} : 1,
y_label => defined($options{y_label}) ? $options{y_label} : 1,
 
#Colors
bg_color => $options{bg_color} || 'white',
fg_color => $options{font_color} || 'black',
x_label_color => $options{x_label_color} || 'blue',
y_label_color => $options{y_label_color} || 'red',
p_color => $options{p_color} || undef,
p_legend => $options{p_legend} || undef,
p_color_table => undef,
                 
#Sequence Defaults
reference => $options{reference} || undef,
reference_id => $options{reference_id} || undef,
match_char => $options{match_char} || ".",
block_size => defined($options{block_size}) ? $options{block_size} : 10,
block_space => defined ($options{block_space}) ? ($options{block_space} * ($options{font} ? $FONT_TABLE{$options{font}}->width : $FONT_TABLE{2}->width)) : ( ($options{font} ? ($FONT_TABLE{$options{font}}->width * 2 ) : ($FONT_TABLE{2}->width * 2)) )...
wrap => $options{wrap} || 80,
show_nonsynonymous => $options{show_nonsynonymous} || undef, # If turned on, will highlight nonsynonymous (missense) mutations. Valid only for nucleotide alignments

lib/Bio/Align/Graphics.pm  view on Meta::CPAN

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
        $self->{seq_start_y} = ($self->{pad_top} + length($self->{seq_length_aa}) + $self->{y_label_space}) * $self->{y_char_size};
        $self->{width} = $self->{seq_start_x} + ((( $self->{wrap} / $self->{block_size}) + 1) * $self->{block_space}) + ( ($self->{wrap} + $self->{pad_right}) * ($self->{x_char_size} + 1.2) ) + ( ($self->{seq_length} / 3) * 2); # Needed to add this for widt...
}else
{
        $self->{seq_start_y} = ($self->{pad_top} + length($self->{seq_length}) + $self->{y_label_space}) * $self->{y_char_size};
        $self->{width} = $self->{seq_start_x} + ((( $self->{wrap} / $self->{block_size}) + 1) * $self->{block_space}) + ($self->{wrap} + $self->{pad_right}) * $self->{x_char_size};
}
 
$self->{footer_start} = $self->{seq_start_y} + $self->{y_size} * $self->{y_num};
 
if(defined($self->{p_color}) && defined($self->{p_legend}) && $self->{p_legend}){
$self->{height} = $self->{seq_start_y} + $self->{footer_size} + $self->{y_size} * $self->{y_num};
}else{
 $self->{height} = $self->{seq_start_y} + $self->{y_size} * $self->{y_num};
}
$self->{image} = GD::Simple->new($self->{width},$self->{height});
$self->{image}->alphaBlending(1);
$self->{image}->saveAlpha(1);
$self->{image}->bgcolor($self->{bg_color});
$self->{image}->fgcolor($self->{fg_color});
$self->{image}->rectangle(0,0,$self->{width}-1, $self->{height} - 1);

lib/Bio/Align/Graphics.pm  view on Meta::CPAN

250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
}elsif  ( defined($self->{show_nonsynonymous}) )
 {
        $self->{codon_table} = Bio::Tools::CodonTable->new();
        $self->{missense_pos} = {};
#       print STDERR "You are using option show_nonsynonymous. Option works best if wrap value is a multiple of 4.\n"
 }
 
if(defined($self->{p_color}) && $self->{seq_format} eq "protein")
{
$self->_draw_colored_sequences();
        if(defined($self->{p_legend}) && $self->{p_legend})
        {
         $self->_draw_legend();
        }
}elsif(defined($self->{p_color}) && ($self->{seq_format} ne "protein"))
 {
  die "draw:Option p_color only works with Protein alignments!\n";
 }else
  {
   $self->_draw_sequences();
  }
 
if(defined($self->{dm_label_start}))

lib/Bio/Align/Graphics.pm  view on Meta::CPAN

793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
         }
          
          
         $block_total += $block_num;
        }
$block_total = 0;
        }
}
}
 
sub _draw_legend{
 
my $self = shift;
my $title_font = $FONT_TABLE{3};
my @l_order = ("Negatively Charged", "Positively Charged", "Hydrophobic", "Aromatic", "Found in Loops", "Large Polar Acids");
my %legend = ("Negatively Charged" => ["D" , "E"] , "Positively Charged" => ["K", "R"] , "Hydrophobic" => ["A","F","I","L","M","V","W","Y"] ,
                "Aromatic" => ["F", "H", "W", "Y"] , "Found in Loops" => ["D", "G", "P", "S", "T"] , "Large Polar Acids" => ["H", "K", "N", "Q", "R"]);
 
my $x1 = 2;
my $x2 = 42;
 
my $colors = $self->{p_color_table};
 
my $y_start = $self->{footer_start};
my $label = "Protein Color Legend";
$self->{image}->bgcolor($self->{bg_color});

lib/Bio/Align/Graphics.pm  view on Meta::CPAN

828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
foreach my $c_label (@l_order)
{
 
if( ($count % 2) == 0)
{
 
$self->{image}->moveTo( $x2 $self->{x_char_size}, $y_start + ( ($count - 1) * $self->{y_char_size}));
$self->{image}->font($self->{font});
$self->{image}->string($c_label);
        my $i = 0;
        foreach my $chars(@{$legend{$c_label}})
        {
         $self->{image}->bgcolor($$colors{$chars});
         $self->{image}->fgcolor($$colors{$chars});
         $self->{image}->rectangle( ($x2 + 20 + $i) * $self->{x_char_size}, $y_start + ( ($count - 2) * $self->{y_char_size}), ($x2 + 20 + $i + 1) * $self->{x_char_size}, $y_start + ( ($count -1) * $self->{y_char_size}));
         $self->{image}->bgcolor($self->{bg_color});
         $self->{image}->fgcolor($self->{fg_color});
         $i++;
        }
 
}else
 {
  $self->{image}->moveTo($x1 * $self->{x_char_size} , $y_start + ($count * $self->{y_char_size}));
  $self->{image}->font($self->{font});
  $self->{image}->string($c_label);
        my $i = 0;
        foreach my $chars(@{$legend{$c_label}})
        {
         $self->{image}->bgcolor($$colors{$chars});
         $self->{image}->fgcolor($$colors{$chars});
         $self->{image}->rectangle( ($x1 + 20 + $i) * $self->{x_char_size}, $y_start + ( ($count - 1) * $self->{y_char_size}), ($x1 + 20 + $i + 1) * $self->{x_char_size}, $y_start + ( ($count) * $self->{y_char_size}));
         $self->{image}->bgcolor($self->{bg_color});
         $self->{image}->fgcolor($self->{fg_color});
         $i++;
        }
 }



( run in 0.939 second using v1.01-cache-2.11-cpan-49f99fa48dc )