| 1 | # BioPerl module for Bio::Draw::Pictogram | ||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||
| 3 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||
| 5 | # Cared for by Shawn Hoon <shawnh@fugu-sg.org> | ||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||
| 7 | # Copyright Shawn Hoon | ||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||
| 9 | # You may distribute this module under the same terms as perl itself | ||||||||||||||||||||||
| 10 | |||||||||||||||||||||||
| 11 | # POD documentation - main docs before the code | ||||||||||||||||||||||
| 12 | |||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||
| 14 | |||||||||||||||||||||||
| 15 | Bio::Draw::Pictogram - generate SVG output of Pictogram display for consensus motifs | ||||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||||||||||
| 18 | |||||||||||||||||||||||
| 19 | use Bio::Draw::Pictogram; | ||||||||||||||||||||||
| 20 | use Bio::SeqIO; | ||||||||||||||||||||||
| 21 | |||||||||||||||||||||||
| 22 | my $sio = Bio::SeqIO->new(-file=>$ARGV[0],-format=>'fasta'); | ||||||||||||||||||||||
| 23 | my @seq; | ||||||||||||||||||||||
| 24 | while(my $seq = $sio->next_seq){ | ||||||||||||||||||||||
| 25 | push @seq, $seq; | ||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||
| 27 | |||||||||||||||||||||||
| 28 | my $picto = Bio::Draw::Pictogram->new(-width=>"800", | ||||||||||||||||||||||
| 29 | -height=>"500", | ||||||||||||||||||||||
| 30 | -fontsize=>"60", | ||||||||||||||||||||||
| 31 | -plot_bits=>1, | ||||||||||||||||||||||
| 32 | -background=>{ | ||||||||||||||||||||||
| 33 | 'A'=>0.25, | ||||||||||||||||||||||
| 34 | 'C'=>0.18, | ||||||||||||||||||||||
| 35 | 'T'=>0.32, | ||||||||||||||||||||||
| 36 | 'G'=>0.25}, | ||||||||||||||||||||||
| 37 | -color=>{'A'=>'red', | ||||||||||||||||||||||
| 38 | 'G'=>'blue', | ||||||||||||||||||||||
| 39 | 'C'=>'green', | ||||||||||||||||||||||
| 40 | 'T'=>'magenta'}); | ||||||||||||||||||||||
| 41 | |||||||||||||||||||||||
| 42 | my $svg = $picto->make_svg(\@seq); | ||||||||||||||||||||||
| 43 | |||||||||||||||||||||||
| 44 | print $svg->xmlify."\n"; | ||||||||||||||||||||||
| 45 | |||||||||||||||||||||||
| 46 | #Support for Bio::Matrix::PSM::SiteMatrix now included | ||||||||||||||||||||||
| 47 | |||||||||||||||||||||||
| 48 | use Bio::Matrix::PSM::IO; | ||||||||||||||||||||||
| 49 | |||||||||||||||||||||||
| 50 | my $picto = Bio::Draw::Pictogram->new(-width=>"800", | ||||||||||||||||||||||
| 51 | -height=>"500", | ||||||||||||||||||||||
| 52 | -fontsize=>"60", | ||||||||||||||||||||||
| 53 | -plot_bits=>1, | ||||||||||||||||||||||
| 54 | -background=>{ | ||||||||||||||||||||||
| 55 | 'A'=>0.25, | ||||||||||||||||||||||
| 56 | 'C'=>0.18, | ||||||||||||||||||||||
| 57 | 'T'=>0.32, | ||||||||||||||||||||||
| 58 | 'G'=>0.25}, | ||||||||||||||||||||||
| 59 | -color=>{'A'=>'red', | ||||||||||||||||||||||
| 60 | 'G'=>'blue', | ||||||||||||||||||||||
| 61 | 'C'=>'green', | ||||||||||||||||||||||
| 62 | 'T'=>'magenta'}); | ||||||||||||||||||||||
| 63 | |||||||||||||||||||||||
| 64 | my $psm = $psmIO->next_psm; | ||||||||||||||||||||||
| 65 | my $svg = $picto->make_svg($psm); | ||||||||||||||||||||||
| 66 | print $svg->xmlify; | ||||||||||||||||||||||
| 67 | |||||||||||||||||||||||
| 68 | =head1 DESCRIPTION | ||||||||||||||||||||||
| 69 | |||||||||||||||||||||||
| 70 | A module for generating SVG output of Pictogram display for consensus | ||||||||||||||||||||||
| 71 | motifs. This method of representation was describe by Burge and | ||||||||||||||||||||||
| 72 | colleagues: (Burge, C.B.,Tuschl, T., Sharp, P.A. in The RNA world II, | ||||||||||||||||||||||
| 73 | 525-560, CSHL press, 1999) | ||||||||||||||||||||||
| 74 | |||||||||||||||||||||||
| 75 | This is a simple module that takes in an array of sequences (assuming | ||||||||||||||||||||||
| 76 | equal lengths) and calculates relative base frequencies where the | ||||||||||||||||||||||
| 77 | height of each letter reflects the frequency of each nucleotide at a | ||||||||||||||||||||||
| 78 | given position. It can also plot the information content at each | ||||||||||||||||||||||
| 79 | position scaled by the background frequencies of each nucleotide. | ||||||||||||||||||||||
| 80 | |||||||||||||||||||||||
| 81 | It requires the SVG-2.26 or later module by Ronan Oger available at | ||||||||||||||||||||||
| 82 | http://www.cpan.org | ||||||||||||||||||||||
| 83 | |||||||||||||||||||||||
| 84 | Recommended viewing of the SVG is the plugin available at Adobe: | ||||||||||||||||||||||
| 85 | http://www.adobe.com/svg | ||||||||||||||||||||||
| 86 | |||||||||||||||||||||||
| 87 | =head1 FEEDBACK | ||||||||||||||||||||||
| 88 | |||||||||||||||||||||||
| 89 | |||||||||||||||||||||||
| 90 | =head2 Mailing Lists | ||||||||||||||||||||||
| 91 | |||||||||||||||||||||||
| 92 | User feedback is an integral part of the evolution of this and other | ||||||||||||||||||||||
| 93 | Bioperl modules. Send your comments and suggestions preferably to one | ||||||||||||||||||||||
| 94 | of the Bioperl mailing lists. Your participation is much appreciated. | ||||||||||||||||||||||
| 95 | |||||||||||||||||||||||
| 96 | bioperl-l@bioperl.org - General discussion | ||||||||||||||||||||||
| 97 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||||||||||||||
| 98 | |||||||||||||||||||||||
| 99 | =head2 Support | ||||||||||||||||||||||
| 100 | |||||||||||||||||||||||
| 101 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||
| 102 | |||||||||||||||||||||||
| 103 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||
| 104 | |||||||||||||||||||||||
| 105 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||
| 106 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||
| 107 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||
| 108 | with code and data examples if at all possible. | ||||||||||||||||||||||
| 109 | |||||||||||||||||||||||
| 110 | =head2 Reporting Bugs | ||||||||||||||||||||||
| 111 | |||||||||||||||||||||||
| 112 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||||||||||
| 113 | the bugs and their resolution. Bug reports can be submitted via the | ||||||||||||||||||||||
| 114 | web: | ||||||||||||||||||||||
| 115 | |||||||||||||||||||||||
| 116 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||||||||||
| 117 | |||||||||||||||||||||||
| 118 | =head1 AUTHOR - Shawn Hoon | ||||||||||||||||||||||
| 119 | |||||||||||||||||||||||
| 120 | Email shawnh@fugu-sg.org | ||||||||||||||||||||||
| 121 | |||||||||||||||||||||||
| 122 | =head1 APPENDIX | ||||||||||||||||||||||
| 123 | |||||||||||||||||||||||
| 124 | The rest of the documentation details each of the object | ||||||||||||||||||||||
| 125 | methods. Internal methods are usually preceded with a "_". | ||||||||||||||||||||||
| 126 | |||||||||||||||||||||||
| 127 | =cut | ||||||||||||||||||||||
| 128 | |||||||||||||||||||||||
| 129 | package Bio::Draw::Pictogram; | ||||||||||||||||||||||
| 130 | 2 | $Bio::Draw::Pictogram::VERSION = '1.7.3'; | |||||||||||||||||||||
| 131 | 2 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 132 | 2 | ▶ | use SVG 2.26; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 133 | 2 | ▶ | use Bio::SeqIO; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 134 | 2 | ▶ | use base qw(Bio::Root::Root); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 135 | |||||||||||||||||||||||
| 136 | 2 | ▶ | use constant MAXBITS => 2; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 137 | |||||||||||||||||||||||
| 138 | =head2 new | ||||||||||||||||||||||
| 139 | |||||||||||||||||||||||
| 140 | Title : new | ||||||||||||||||||||||
| 141 | Usage : my $picto = Bio::Draw::Pictogram->new(-width=>"800", | ||||||||||||||||||||||
| 142 | -height=>"500", | ||||||||||||||||||||||
| 143 | -fontsize=>"60", | ||||||||||||||||||||||
| 144 | -plot_bits=>1, | ||||||||||||||||||||||
| 145 | -background=>{ | ||||||||||||||||||||||
| 146 | 'A'=>0.25, | ||||||||||||||||||||||
| 147 | 'C'=>0.18, | ||||||||||||||||||||||
| 148 | 'T'=>0.32, | ||||||||||||||||||||||
| 149 | 'G'=>0.25}, | ||||||||||||||||||||||
| 150 | -color=>{'A'=>'red', | ||||||||||||||||||||||
| 151 | 'G'=>'blue', | ||||||||||||||||||||||
| 152 | 'C'=>'green', | ||||||||||||||||||||||
| 153 | 'T'=>'magenta'}); | ||||||||||||||||||||||
| 154 | Function: Constructor for Pictogram Object | ||||||||||||||||||||||
| 155 | Returns : L<Bio::Draw::Pictogram> | ||||||||||||||||||||||
| 156 | |||||||||||||||||||||||
| 157 | =cut | ||||||||||||||||||||||
| 158 | |||||||||||||||||||||||
| 159 | 2 | ▶ | sub new { | ||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=22.9
Pod
documented
| |||||||||||||||||||||||
| 160 | 2 | my ($caller,@args) = @_; | |||||||||||||||||||||
| 161 | 2 | my $self = $caller->SUPER::new(@args); | |||||||||||||||||||||
| 162 | 2 | my ($width,$height,$fontsize,$color,$background,$bit,$normalize) = $self->_rearrange([qw(WIDTH HEIGHT FONTSIZE COLOR BACKGROUND PLOT_BITS NORMALIZE)],@args); | |||||||||||||||||||||
| 163 | 2 | ▶ | $width||=800; | ||||||||||||||||||||
|
Condition50%1/2
$width ||= 800
MC/DC0%0/1
$width ||= 800
$width
Truth table50%1/2
A
A= $width
| |||||||||||||||||||||||
| 164 | 2 | ▶ | $height||=600; | ||||||||||||||||||||
|
Condition50%1/2
$height ||= 600
MC/DC0%0/1
$height ||= 600
$height
Truth table50%1/2
A
A= $height
| |||||||||||||||||||||||
| 165 | 2 | my $svg = SVG->new(width=>$width,height=>$height); | |||||||||||||||||||||
| 166 | 2 | $self->svg_obj($svg); | |||||||||||||||||||||
| 167 | 2 | ▶ | $fontsize ||= 80; | ||||||||||||||||||||
|
Condition50%1/2
$fontsize ||= 80
MC/DC0%0/1
$fontsize ||= 80
$fontsize
Truth table50%1/2
A
A= $fontsize
| |||||||||||||||||||||||
| 168 | 2 | ▶ | $self->fontsize($fontsize) if $fontsize; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 169 | 2 | ▶ | $color = $color || {'T'=>'black','C'=>'blue','G'=>'green','A'=>'red'}; | ||||||||||||||||||||
|
Condition50%1/2
$color || {'T', 'black', 'C', 'blue', 'G', 'green', 'A', 'red'}
MC/DC0%0/1
$color || {'T', 'black', 'C', 'blue', 'G', 'green', 'A', 'red'}
$color
Truth table50%1/2
A
A= $color
| |||||||||||||||||||||||
| 170 | 2 | $self->color($color); | |||||||||||||||||||||
| 171 | 2 | ▶ | $background = $background || {'T'=>0.25,'C'=>0.25,'G'=>0.25,'A'=>0.25}; | ||||||||||||||||||||
|
Condition50%1/2
$background || {'T', 0.25, 'C', 0.25, 'G', 0.25, 'A', 0.25}
MC/DC0%0/1
$background || {'T', 0.25, 'C', 0.25, 'G', 0.25, 'A', 0.25}
$background
Truth table50%1/2
A
A= $background
| |||||||||||||||||||||||
| 172 | 2 | $self->background($background); | |||||||||||||||||||||
| 173 | 2 | ▶ | $self->plot_bits($bit) if $bit; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 174 | 2 | ▶ | $self->normalize($normalize) if $normalize; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 175 | |||||||||||||||||||||||
| 176 | 2 | return $self; | |||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||
| 178 | |||||||||||||||||||||||
| 179 | =head2 make_svg | ||||||||||||||||||||||
| 180 | |||||||||||||||||||||||
| 181 | Title : make_svg | ||||||||||||||||||||||
| 182 | Usage : $picto->make_svg(); | ||||||||||||||||||||||
| 183 | Function: make the SVG object | ||||||||||||||||||||||
| 184 | Returns : L<SVG> | ||||||||||||||||||||||
| 185 | Arguments: A fasta file or array ref of L<Bio::Seq> objects or a L<Bio::Matrix::PSM::SiteMatrixI> | ||||||||||||||||||||||
| 186 | |||||||||||||||||||||||
| 187 | =cut | ||||||||||||||||||||||
| 188 | |||||||||||||||||||||||
| 189 | 2 | ▶ | sub make_svg { | ||||||||||||||||||||
|
Subroutine
make_svg: called CC=15 SCAR=27.6
Pod
documented
| |||||||||||||||||||||||
| 190 | 2 | my ($self,$input) = @_; | |||||||||||||||||||||
| 191 | 2 | my $fontsize = $self->fontsize; | |||||||||||||||||||||
| 192 | 2 | my $size = $fontsize * 0.75; | |||||||||||||||||||||
| 193 | 2 | my $width= $size; | |||||||||||||||||||||
| 194 | 2 | my $height= $size+40; | |||||||||||||||||||||
| 195 | 2 | my $color = $self->color; | |||||||||||||||||||||
| 196 | |||||||||||||||||||||||
| 197 | #starting x coordinate for pictogram | ||||||||||||||||||||||
| 198 | 2 | my $x = 45+$size/2; | |||||||||||||||||||||
| 199 | 2 | my $pos_y = $size * 2; | |||||||||||||||||||||
| 200 | 2 | my $bit_y = $pos_y+40; | |||||||||||||||||||||
| 201 | 2 | my @pwm; | |||||||||||||||||||||
| 202 | |||||||||||||||||||||||
| 203 | 2 | my $bp = 1; | |||||||||||||||||||||
| 204 | |||||||||||||||||||||||
| 205 | #input can be file or array ref of sequences | ||||||||||||||||||||||
| 206 | 2 | ▶ | if(ref($input) eq 'ARRAY'){ | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 207 | 1 | @pwm = @{$self->_make_pwm($input)}; | |||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||
| 209 | ▶ | elsif(ref($input) && $input->isa("Bio::Matrix::PSM::SiteMatrixI")){ | |||||||||||||||||||||
|
Condition33%1/3
ref $input and $input->isa("Bio::Matrix::PSM::SiteMatrixI")
MC/DC0%0/2
ref $input and $input->isa("Bio::Matrix::PSM::SiteMatrixI")
ref $input
$input->isa("Bio::Matrix::PSM::SiteMatrixI")
Truth table33%1/3
A and B
A= ref $inputB= $input->isa("Bio::Matrix::PSM::SiteMatrixI")
| |||||||||||||||||||||||
| 210 | 1 | @pwm = $self->_make_pwm_from_site_matrix($input); | |||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||
| 212 | else { | ||||||||||||||||||||||
| 213 | 0 | my $sio = Bio::SeqIO->new(-file=>$input,-format=>"fasta"); | |||||||||||||||||||||
| 214 | 0 | my @seq; | |||||||||||||||||||||
| 215 | 0 | ▶ | while (my $seq = $sio->next_seq){ | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 216 | 0 | push @seq, $seq; | |||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||
| 218 | 0 | @pwm = @{$self->_make_pwm(\@seq)}; | |||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||
| 220 | |||||||||||||||||||||||
| 221 | |||||||||||||||||||||||
| 222 | 2 | my $svg = $self->svg_obj; | |||||||||||||||||||||
| 223 | 2 | my $seq_length = scalar(@pwm + 1) * $width + $x + $x; | |||||||||||||||||||||
| 224 | 2 | my $seq_grp; | |||||||||||||||||||||
| 225 | |||||||||||||||||||||||
| 226 | #scale the svg if length greater than svg width | ||||||||||||||||||||||
| 227 | 2 | ▶ | if($seq_length > $svg->{-document}->{'width'}){ | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 228 | 1 | my $ratio = $svg->{-document}->{'width'}/($seq_length); | |||||||||||||||||||||
| 229 | 1 | $seq_grp = $svg->group(transform=>"scale($ratio,1)"); | |||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||
| 231 | else { | ||||||||||||||||||||||
| 232 | 1 | $seq_grp= $svg->group(); | |||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||
| 234 | |||||||||||||||||||||||
| 235 | #do the drawing, each set is a base position | ||||||||||||||||||||||
| 236 | 2 | foreach my $set(@pwm){ | |||||||||||||||||||||
| 237 | 34 | my ($A,$C,$G,$T,$bits) = @$set; | |||||||||||||||||||||
| 238 | 34 | my @array; | |||||||||||||||||||||
| 239 | 34 | push @array, ['a',($A)]; | |||||||||||||||||||||
| 240 | 34 | push @array, ['g',($G)]; | |||||||||||||||||||||
| 241 | 34 | push @array, ['c',($C)]; | |||||||||||||||||||||
| 242 | 34 | push @array, ['t',($T)]; | |||||||||||||||||||||
| 243 | 34 | @array = sort {$b->[1]<=>$a->[1]}@array; | |||||||||||||||||||||
| 244 | 34 | my $count = 1; | |||||||||||||||||||||
| 245 | 34 | my $pos_group = $seq_grp->group(id=>"bp $bp"); | |||||||||||||||||||||
| 246 | 34 | my $prev_size; | |||||||||||||||||||||
| 247 | my $y_trans; | ||||||||||||||||||||||
| 248 | |||||||||||||||||||||||
| 249 | #draw each letter at each position | ||||||||||||||||||||||
| 250 | 34 | foreach my $letter(@array){ | |||||||||||||||||||||
| 251 | 136 | my $scale; | |||||||||||||||||||||
| 252 | 136 | ▶ | if($self->normalize){ | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 253 | 100 | $scale = $letter->[1]; | |||||||||||||||||||||
| 254 | } else { | ||||||||||||||||||||||
| 255 | 36 | $scale = $letter->[1] * ($bits / MAXBITS); | |||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||
| 257 | |||||||||||||||||||||||
| 258 | 136 | ▶ | if($count == 1){ | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 259 | 34 | ▶ | if($self->normalize){ | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 260 | 25 | $y_trans = 0; | |||||||||||||||||||||
| 261 | } else { | ||||||||||||||||||||||
| 262 | 9 | $y_trans = (1 - ($bits / MAXBITS)) * $size; | |||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||
| 265 | else { | ||||||||||||||||||||||
| 266 | 102 | $y_trans += $prev_size; | |||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||
| 268 | $pos_group->text('id'=> uc($letter->[0]).$bp,height=>$height, | ||||||||||||||||||||||
| 269 | 'width'=>$width,x=>$x,y=>$size, | ||||||||||||||||||||||
| 270 | 'transform'=>"translate(0,$y_trans),scale(1,$scale)", | ||||||||||||||||||||||
| 271 | 'style'=>{"font-size"=>$fontsize, | ||||||||||||||||||||||
| 272 | 'text-anchor'=>'middle', | ||||||||||||||||||||||
| 273 | 'font-family'=>'Verdana', | ||||||||||||||||||||||
| 274 | 136 | ▶ | 'fill'=>$color->{uc $letter->[0]}})->cdata(uc $letter->[0]) if $scale > 0; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 275 | |||||||||||||||||||||||
| 276 | 136 | $prev_size = $scale * $size; | |||||||||||||||||||||
| 277 | 136 | $count++; | |||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||
| 279 | #plot the bit if required | ||||||||||||||||||||||
| 280 | 34 | ▶ | if($self->plot_bits){ | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 281 | 34 | $seq_grp->text('x'=>$x, | |||||||||||||||||||||
| 282 | 'y'=>$bit_y, | ||||||||||||||||||||||
| 283 | 'style'=>{"font-size"=>'10', | ||||||||||||||||||||||
| 284 | 'text-anchor'=>'middle', | ||||||||||||||||||||||
| 285 | 'font-family'=>'Verdana', | ||||||||||||||||||||||
| 286 | 'fill'=>'black'})->cdata($bits); | ||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||
| 288 | 34 | $bp++; | |||||||||||||||||||||
| 289 | 34 | $x+=$width; | |||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||
| 291 | |||||||||||||||||||||||
| 292 | #plot the tags | ||||||||||||||||||||||
| 293 | 2 | ▶ | $seq_grp->text(x=>int($width/2),y=>$bit_y,style=>{"font-size"=>'10','text-anchor'=>'middle','font-family'=>'Verdana','fill'=>'black'})->cdata("Bits:") if $self->plot_bits; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 294 | |||||||||||||||||||||||
| 295 | 2 | $seq_grp->text(x=>int($width/2),y=>$pos_y,style=>{"font-size"=>'10','text-anchor'=>'middle','font-family'=>'Verdana','fill'=>'black'})->cdata("Position:"); | |||||||||||||||||||||
| 296 | |||||||||||||||||||||||
| 297 | #plot the base positions | ||||||||||||||||||||||
| 298 | 2 | $x = 45+$size/2-int($width/2); | |||||||||||||||||||||
| 299 | 2 | foreach my $nbr(1..($bp-1)){ | |||||||||||||||||||||
| 300 | 34 | $seq_grp->text(x=>$x+int($width/2),y=>$pos_y,style=>{"font-size"=>'10','text-anchor'=>'left','font-family'=>'Verdana','fill'=>'black'})->cdata($nbr); | |||||||||||||||||||||
| 301 | 34 | $x+=$width; | |||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||
| 303 | |||||||||||||||||||||||
| 304 | |||||||||||||||||||||||
| 305 | # $seq_grp->transform("scale(2,2)"); | ||||||||||||||||||||||
| 306 | |||||||||||||||||||||||
| 307 | 2 | return $self->svg_obj($svg); | |||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||
| 309 | |||||||||||||||||||||||
| 310 | 1 | ▶ | sub _make_pwm_from_site_matrix{ | ||||||||||||||||||||
|
Subroutine
_make_pwm_from_site_matrix: called CC=2 SCAR=6.9
| |||||||||||||||||||||||
| 311 | 1 | my ($self,$matrix) = @_; | |||||||||||||||||||||
| 312 | 1 | my $bgd = $self->background; | |||||||||||||||||||||
| 313 | 1 | my @pwm; | |||||||||||||||||||||
| 314 | 1 | my $consensus = $matrix->consensus; | |||||||||||||||||||||
| 315 | 1 | foreach my $i(1..length($consensus)){ | |||||||||||||||||||||
| 316 | 25 | my %base = $matrix->next_pos; | |||||||||||||||||||||
| 317 | 25 | my $bits; | |||||||||||||||||||||
| 318 | 25 | $bits+=($base{pA} * log2($base{pA}/$bgd->{'A'})); | |||||||||||||||||||||
| 319 | 25 | $bits+=($base{pC} * log2($base{pC}/$bgd->{'C'})); | |||||||||||||||||||||
| 320 | 25 | $bits+=($base{pG} * log2($base{pG}/$bgd->{'G'})); | |||||||||||||||||||||
| 321 | 25 | $bits+=($base{pT} * log2($base{pT}/$bgd->{'T'})); | |||||||||||||||||||||
| 322 | 25 | push @pwm, [$base{pA},$base{pC},$base{pG},$base{pT},abs(sprintf("%.3f",$bits))]; | |||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||
| 324 | 1 | return @pwm; | |||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||
| 326 | |||||||||||||||||||||||
| 327 | 1 | ▶ | sub _make_pwm { | ||||||||||||||||||||
|
Subroutine
_make_pwm: called CC=16 SCAR=27.7
| |||||||||||||||||||||||
| 328 | 1 | my ($self,$input) = @_; | |||||||||||||||||||||
| 329 | 1 | my $count = 1; | |||||||||||||||||||||
| 330 | 1 | my %hash; | |||||||||||||||||||||
| 331 | 1 | my $bgd = $self->background; | |||||||||||||||||||||
| 332 | #sum up the frequencies at each base pair | ||||||||||||||||||||||
| 333 | 1 | foreach my $seq(@$input){ | |||||||||||||||||||||
| 334 | 14 | my $string = $seq->seq; | |||||||||||||||||||||
| 335 | 14 | $string = uc $string; | |||||||||||||||||||||
| 336 | 14 | my @motif = split('',$string); | |||||||||||||||||||||
| 337 | 14 | my $pos = 1; | |||||||||||||||||||||
| 338 | 14 | foreach my $t(@motif){ | |||||||||||||||||||||
| 339 | 126 | $hash{$pos}{$t}++; | |||||||||||||||||||||
| 340 | 126 | $pos++; | |||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||
| 342 | 14 | $count++; | |||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||
| 344 | |||||||||||||||||||||||
| 345 | #calculate relative freq | ||||||||||||||||||||||
| 346 | 1 | my @pwm; | |||||||||||||||||||||
| 347 | |||||||||||||||||||||||
| 348 | #decrement last count | ||||||||||||||||||||||
| 349 | 1 | $count--; | |||||||||||||||||||||
| 350 | 1 | foreach my $pos(sort{$a<=>$b} keys %hash){ | |||||||||||||||||||||
| 351 | 9 | my @array; | |||||||||||||||||||||
| 352 | 9 | ▶ | push @array,($hash{$pos}{'A'}||0)/$count; | ||||||||||||||||||||
|
Condition100%2/2
$hash{$pos}{'A'} || 0
MC/DC100%1/1
$hash{$pos}{'A'} || 0
$hash{$pos}{'A'}
Truth table100%2/2
A
A= $hash{$pos}{'A'}
| |||||||||||||||||||||||
| 353 | 9 | ▶ | push @array,($hash{$pos}{'C'}||0)/$count; | ||||||||||||||||||||
|
Condition100%2/2
$hash{$pos}{'C'} || 0
MC/DC100%1/1
$hash{$pos}{'C'} || 0
$hash{$pos}{'C'}
Truth table100%2/2
A
A= $hash{$pos}{'C'}
| |||||||||||||||||||||||
| 354 | 9 | ▶ | push @array,($hash{$pos}{'G'}||0)/$count; | ||||||||||||||||||||
|
Condition100%2/2
$hash{$pos}{'G'} || 0
MC/DC100%1/1
$hash{$pos}{'G'} || 0
$hash{$pos}{'G'}
Truth table100%2/2
A
A= $hash{$pos}{'G'}
| |||||||||||||||||||||||
| 355 | 9 | ▶ | push @array,($hash{$pos}{'T'}||0)/$count; | ||||||||||||||||||||
|
Condition100%2/2
$hash{$pos}{'T'} || 0
MC/DC100%1/1
$hash{$pos}{'T'} || 0
$hash{$pos}{'T'}
Truth table100%2/2
A
A= $hash{$pos}{'T'}
| |||||||||||||||||||||||
| 356 | |||||||||||||||||||||||
| 357 | #calculate bits | ||||||||||||||||||||||
| 358 | # relative entropy (RelEnt) or Kullback-Liebler distance | ||||||||||||||||||||||
| 359 | # relent = sum fk * log2(fk/gk) where fk is frequency of nucleotide k and | ||||||||||||||||||||||
| 360 | # gk the background frequency of nucleotide k | ||||||||||||||||||||||
| 361 | |||||||||||||||||||||||
| 362 | 9 | my $bits; | |||||||||||||||||||||
| 363 | 9 | ▶ | $bits+=(($hash{$pos}{'A'}||0) / $count) * log2((($hash{$pos}{'A'}||0)/$count) / ($bgd->{'A'})); | ||||||||||||||||||||
|
Condition100%4/4
$hash{$pos}{'A'} || 0
$hash{$pos}{'A'} || 0
MC/DC100%1/1
$hash{$pos}{'A'} || 0
$hash{$pos}{'A'}
MC/DC100%1/1
$hash{$pos}{'A'} || 0
$hash{$pos}{'A'}
Truth table100%2/2
A
A= $hash{$pos}{'A'}
Truth table100%2/2
A
A= $hash{$pos}{'A'}
| |||||||||||||||||||||||
| 364 | 9 | ▶ | $bits+=(($hash{$pos}{'C'}||0) / $count) * log2((($hash{$pos}{'C'}||0)/$count) / ($bgd->{'C'})); | ||||||||||||||||||||
|
Condition100%4/4
$hash{$pos}{'C'} || 0
$hash{$pos}{'C'} || 0
MC/DC100%1/1
$hash{$pos}{'C'} || 0
$hash{$pos}{'C'}
MC/DC100%1/1
$hash{$pos}{'C'} || 0
$hash{$pos}{'C'}
Truth table100%2/2
A
A= $hash{$pos}{'C'}
Truth table100%2/2
A
A= $hash{$pos}{'C'}
| |||||||||||||||||||||||
| 365 | 9 | ▶ | $bits+=(($hash{$pos}{'G'}||0) / $count) * log2((($hash{$pos}{'G'}||0)/$count) / ($bgd->{'G'})); | ||||||||||||||||||||
|
Condition100%4/4
$hash{$pos}{'G'} || 0
$hash{$pos}{'G'} || 0
MC/DC100%1/1
$hash{$pos}{'G'} || 0
$hash{$pos}{'G'}
MC/DC100%1/1
$hash{$pos}{'G'} || 0
$hash{$pos}{'G'}
Truth table100%2/2
A
A= $hash{$pos}{'G'}
Truth table100%2/2
A
A= $hash{$pos}{'G'}
| |||||||||||||||||||||||
| 366 | 9 | ▶ | $bits+=(($hash{$pos}{'T'}||0) / $count) * log2((($hash{$pos}{'T'}||0)/$count) / ($bgd->{'T'})); | ||||||||||||||||||||
|
Condition100%4/4
$hash{$pos}{'T'} || 0
$hash{$pos}{'T'} || 0
MC/DC100%1/1
$hash{$pos}{'T'} || 0
$hash{$pos}{'T'}
MC/DC100%1/1
$hash{$pos}{'T'} || 0
$hash{$pos}{'T'}
Truth table100%2/2
A
A= $hash{$pos}{'T'}
Truth table100%2/2
A
A= $hash{$pos}{'T'}
| |||||||||||||||||||||||
| 367 | 9 | push @array, abs(sprintf("%.3f",$bits)); | |||||||||||||||||||||
| 368 | |||||||||||||||||||||||
| 369 | 9 | push @pwm,\@array; | |||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||
| 371 | 1 | return $self->pwm(\@pwm); | |||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||
| 373 | |||||||||||||||||||||||
| 374 | |||||||||||||||||||||||
| 375 | ###various get/sets | ||||||||||||||||||||||
| 376 | |||||||||||||||||||||||
| 377 | =head2 fontsize | ||||||||||||||||||||||
| 378 | |||||||||||||||||||||||
| 379 | Title : fontsize | ||||||||||||||||||||||
| 380 | Usage : $picto->fontsize(); | ||||||||||||||||||||||
| 381 | Function: get/set for fontsize | ||||||||||||||||||||||
| 382 | Returns : int | ||||||||||||||||||||||
| 383 | Arguments: int | ||||||||||||||||||||||
| 384 | |||||||||||||||||||||||
| 385 | =cut | ||||||||||||||||||||||
| 386 | |||||||||||||||||||||||
| 387 | 4 | ▶ | sub fontsize { | ||||||||||||||||||||
|
Subroutine
fontsize: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 388 | 4 | my ($self,$obj) = @_; | |||||||||||||||||||||
| 389 | 4 | ▶ | if($obj){ | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 390 | 2 | $self->{'_fontsize'} = $obj; | |||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||
| 392 | 4 | return $self->{'_fontsize'}; | |||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||
| 394 | |||||||||||||||||||||||
| 395 | =head2 color | ||||||||||||||||||||||
| 396 | |||||||||||||||||||||||
| 397 | Title : color | ||||||||||||||||||||||
| 398 | Usage : $picto->color(); | ||||||||||||||||||||||
| 399 | Function: get/set for color | ||||||||||||||||||||||
| 400 | Returns : a hash reference | ||||||||||||||||||||||
| 401 | Arguments: a hash reference | ||||||||||||||||||||||
| 402 | |||||||||||||||||||||||
| 403 | =cut | ||||||||||||||||||||||
| 404 | |||||||||||||||||||||||
| 405 | 4 | ▶ | sub color { | ||||||||||||||||||||
|
Subroutine
color: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 406 | 4 | my ($self,$obj) = @_; | |||||||||||||||||||||
| 407 | 4 | ▶ | if($obj){ | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 408 | 2 | $self->{'_color'} = $obj; | |||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||
| 410 | 4 | return $self->{'_color'}; | |||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||
| 412 | |||||||||||||||||||||||
| 413 | =head2 svg_obj | ||||||||||||||||||||||
| 414 | |||||||||||||||||||||||
| 415 | Title : svg_obj | ||||||||||||||||||||||
| 416 | Usage : $picto->svg_obj(); | ||||||||||||||||||||||
| 417 | Function: get/set for svg_obj | ||||||||||||||||||||||
| 418 | Returns : L<SVG> | ||||||||||||||||||||||
| 419 | Arguments: L<SVG> | ||||||||||||||||||||||
| 420 | |||||||||||||||||||||||
| 421 | =cut | ||||||||||||||||||||||
| 422 | |||||||||||||||||||||||
| 423 | 6 | ▶ | sub svg_obj { | ||||||||||||||||||||
|
Subroutine
svg_obj: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 424 | 6 | my ($self,$obj) = @_; | |||||||||||||||||||||
| 425 | 6 | ▶ | if($obj){ | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 426 | 4 | $self->{'_svg_obj'} = $obj; | |||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||
| 428 | 6 | return $self->{'_svg_obj'}; | |||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||
| 430 | |||||||||||||||||||||||
| 431 | =head2 plot_bits | ||||||||||||||||||||||
| 432 | |||||||||||||||||||||||
| 433 | Title : plot_bits | ||||||||||||||||||||||
| 434 | Usage : $picto->plot_bits(); | ||||||||||||||||||||||
| 435 | Function: get/set for plot_bits to indicate whether to plot | ||||||||||||||||||||||
| 436 | information content at each base position | ||||||||||||||||||||||
| 437 | Returns :1/0 | ||||||||||||||||||||||
| 438 | Arguments: 1/0 | ||||||||||||||||||||||
| 439 | |||||||||||||||||||||||
| 440 | =cut | ||||||||||||||||||||||
| 441 | |||||||||||||||||||||||
| 442 | 38 | ▶ | sub plot_bits { | ||||||||||||||||||||
|
Subroutine
plot_bits: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 443 | 38 | my ($self,$obj) = @_; | |||||||||||||||||||||
| 444 | 38 | ▶ | if($obj){ | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 445 | 2 | $self->{'_plot_bits'} = $obj; | |||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||
| 447 | 38 | return $self->{'_plot_bits'}; | |||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||
| 449 | |||||||||||||||||||||||
| 450 | =head2 normalize | ||||||||||||||||||||||
| 451 | |||||||||||||||||||||||
| 452 | Title : normalize | ||||||||||||||||||||||
| 453 | Usage : $picto->normalize($newval) | ||||||||||||||||||||||
| 454 | Function: get/set to make all columns the same height. | ||||||||||||||||||||||
| 455 | default is to scale height with information | ||||||||||||||||||||||
| 456 | content. | ||||||||||||||||||||||
| 457 | Returns : value of normalize (a scalar) | ||||||||||||||||||||||
| 458 | Args : on set, new value (a scalar or undef, optional) | ||||||||||||||||||||||
| 459 | |||||||||||||||||||||||
| 460 | |||||||||||||||||||||||
| 461 | =cut | ||||||||||||||||||||||
| 462 | |||||||||||||||||||||||
| 463 | 171 | ▶ | sub normalize{ | ||||||||||||||||||||
|
Subroutine
normalize: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 464 | 171 | my $self = shift; | |||||||||||||||||||||
| 465 | |||||||||||||||||||||||
| 466 | 171 | ▶ | return $self->{'normalize'} = shift if @_; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 467 | 170 | return $self->{'normalize'}; | |||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||
| 469 | |||||||||||||||||||||||
| 470 | =head2 background | ||||||||||||||||||||||
| 471 | |||||||||||||||||||||||
| 472 | Title : background | ||||||||||||||||||||||
| 473 | Usage : $picto->background(); | ||||||||||||||||||||||
| 474 | Function: get/set for hash reference of nucleodtide bgd frequencies | ||||||||||||||||||||||
| 475 | Returns : hash reference | ||||||||||||||||||||||
| 476 | Arguments: hash reference | ||||||||||||||||||||||
| 477 | |||||||||||||||||||||||
| 478 | =cut | ||||||||||||||||||||||
| 479 | |||||||||||||||||||||||
| 480 | 4 | ▶ | sub background { | ||||||||||||||||||||
|
Subroutine
background: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 481 | 4 | my ($self,$obj) = @_; | |||||||||||||||||||||
| 482 | 4 | ▶ | if($obj){ | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 483 | 2 | $self->{'_background'} = $obj; | |||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||
| 485 | 4 | return $self->{'_background'}; | |||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||
| 487 | |||||||||||||||||||||||
| 488 | =head2 pwm | ||||||||||||||||||||||
| 489 | |||||||||||||||||||||||
| 490 | Title : pwm | ||||||||||||||||||||||
| 491 | Usage : $picto->pwm(); | ||||||||||||||||||||||
| 492 | Function: get/set for pwm | ||||||||||||||||||||||
| 493 | Returns : int | ||||||||||||||||||||||
| 494 | Arguments: int | ||||||||||||||||||||||
| 495 | |||||||||||||||||||||||
| 496 | =cut | ||||||||||||||||||||||
| 497 | |||||||||||||||||||||||
| 498 | 1 | ▶ | sub pwm { | ||||||||||||||||||||
|
Subroutine
pwm: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||
| 499 | 1 | my ($self,$pwm) = @_; | |||||||||||||||||||||
| 500 | 1 | ▶ | if($pwm){ | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 501 | 1 | $self->{'_pwm'} = $pwm; | |||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||
| 503 | 1 | return $self->{'_pwm'}; | |||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||
| 505 | |||||||||||||||||||||||
| 506 | #utility method for returning log 2 | ||||||||||||||||||||||
| 507 | 136 | ▶ | sub log2 { | ||||||||||||||||||||
|
Subroutine
log2: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 508 | 136 | my ($val) = @_; | |||||||||||||||||||||
| 509 | 136 | ▶ | return 0 if $val==0; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 510 | 121 | return log($val)/log(2); | |||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||
| 512 | |||||||||||||||||||||||
| 513 | |||||||||||||||||||||||
| 514 | 2 | 1; | |||||||||||||||||||||