| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Bio::Tools::Alignment::Overview; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
25980
|
use 5.008; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
79
|
|
|
4
|
2
|
|
|
2
|
|
9
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
72
|
|
|
5
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
|
2
|
|
|
|
|
9
|
|
|
|
2
|
|
|
|
|
54
|
|
|
6
|
2
|
|
|
2
|
|
2152
|
use GD::Simple; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "0.36"; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
|
11
|
|
|
|
|
|
|
my ($class, @args) = @_; |
|
12
|
|
|
|
|
|
|
my $self = {}; |
|
13
|
|
|
|
|
|
|
$self->{fileInput} = undef, |
|
14
|
|
|
|
|
|
|
$self->{fileOutput} = undef, |
|
15
|
|
|
|
|
|
|
$self->{Pencolor} = 'blue', |
|
16
|
|
|
|
|
|
|
bless($self, $class); |
|
17
|
|
|
|
|
|
|
return $self; |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub input { |
|
22
|
|
|
|
|
|
|
my $self = shift; |
|
23
|
|
|
|
|
|
|
if (@_) { $self->{fileInput} = shift}; |
|
24
|
|
|
|
|
|
|
return $self->{fileInput}; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub output { |
|
29
|
|
|
|
|
|
|
my $self = shift; |
|
30
|
|
|
|
|
|
|
if (@_) { $self->{fileOutput} = shift}; |
|
31
|
|
|
|
|
|
|
return $self->{fileOutput}; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub color { |
|
36
|
|
|
|
|
|
|
my $self = shift; |
|
37
|
|
|
|
|
|
|
if (@_) { $self->{penColor} = shift}; |
|
38
|
|
|
|
|
|
|
return $self->{penColor}; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub make_image{ |
|
43
|
|
|
|
|
|
|
my $self = shift; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# variables; |
|
46
|
|
|
|
|
|
|
my $fileInPath = $self->input or die "\n I think you forgot to pass me the input file. \n"; |
|
47
|
|
|
|
|
|
|
my $fileOutPath = $self->output or die "\n I think you forgot to pass me the output file. \n"; |
|
48
|
|
|
|
|
|
|
my $penColor = $self->color; |
|
49
|
|
|
|
|
|
|
my $seqCounter = 0; |
|
50
|
|
|
|
|
|
|
my $alignSize = 0; |
|
51
|
|
|
|
|
|
|
my $proportion = 0; |
|
52
|
|
|
|
|
|
|
my $height = 0; |
|
53
|
|
|
|
|
|
|
my $penSize = 6; |
|
54
|
|
|
|
|
|
|
my $background = 'white'; |
|
55
|
|
|
|
|
|
|
my $seqSpace = 10; |
|
56
|
|
|
|
|
|
|
my $img = ''; |
|
57
|
|
|
|
|
|
|
my $x = 10; |
|
58
|
|
|
|
|
|
|
my $y = 10; |
|
59
|
|
|
|
|
|
|
my $position = 0; |
|
60
|
|
|
|
|
|
|
my $char = ''; |
|
61
|
|
|
|
|
|
|
my %seqHash; |
|
62
|
|
|
|
|
|
|
my %sortedHash; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
open (my $fh, '<', "$fileInPath") or die "\n Can't load file, check the file name and its location \n"; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# iterates the file saving the sequences to a hash whit a 'id' number (seqCounter). |
|
67
|
|
|
|
|
|
|
while (my $line = <$fh>) { |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
next if $line !~ m/^\S+/; |
|
70
|
|
|
|
|
|
|
chomp $line; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
if ($line =~ m/^\>(.+)/) { |
|
73
|
|
|
|
|
|
|
$seqCounter++; |
|
74
|
|
|
|
|
|
|
$seqHash{$seqCounter} = ''; |
|
75
|
|
|
|
|
|
|
} else { |
|
76
|
|
|
|
|
|
|
$seqHash{$seqCounter} = $seqHash{$seqCounter}.$line; |
|
77
|
|
|
|
|
|
|
$alignSize = length($seqHash{$seqCounter}); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# gets the right proportion for images with 560 of weight. |
|
82
|
|
|
|
|
|
|
$proportion = $alignSize / 560; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# the height is cauculated based on the number os sequences in the hash. |
|
85
|
|
|
|
|
|
|
$height = keys (%seqHash); |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# this is an adjustment of the tickness of the lines that will representate the sequences. With fewer sequences |
|
88
|
|
|
|
|
|
|
# the pensize gets bigger and vice versa. |
|
89
|
|
|
|
|
|
|
$penSize = 6; |
|
90
|
|
|
|
|
|
|
$seqSpace = 10; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
if ($height > 20 && $height < 80) { |
|
93
|
|
|
|
|
|
|
$penSize = 4; |
|
94
|
|
|
|
|
|
|
$seqSpace = 8; |
|
95
|
|
|
|
|
|
|
} elsif ($height >= 80) { |
|
96
|
|
|
|
|
|
|
$penSize = 3; |
|
97
|
|
|
|
|
|
|
$seqSpace = 5; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# last adjustment in height size. |
|
101
|
|
|
|
|
|
|
$height = ($height * $seqSpace) + 20; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# now, lets draw! |
|
104
|
|
|
|
|
|
|
$img = GD::Simple->new(580, $height); |
|
105
|
|
|
|
|
|
|
$img->bgcolor(undef); |
|
106
|
|
|
|
|
|
|
$img->fgcolor('black'); |
|
107
|
|
|
|
|
|
|
$img->rectangle(0,0,579, ($height -1)); |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$x = 10; |
|
110
|
|
|
|
|
|
|
$y = 10; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
$img->bgcolor($background); |
|
113
|
|
|
|
|
|
|
$img->fgcolor($penColor); |
|
114
|
|
|
|
|
|
|
$img->penSize($penSize); |
|
115
|
|
|
|
|
|
|
$img->moveTo($x, $y); |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# first we create a new hash that will be sorted by sequence size. |
|
118
|
|
|
|
|
|
|
for my $key (keys %seqHash) { |
|
119
|
|
|
|
|
|
|
my $counter; |
|
120
|
|
|
|
|
|
|
$counter = $seqHash{$key} =~ s/(\w)/$1/g; |
|
121
|
|
|
|
|
|
|
$sortedHash{$key} = $counter; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# this is the part were the drawn is actually made. |
|
125
|
|
|
|
|
|
|
for my $key (sort { $sortedHash{$b} <=> $sortedHash{$a} } keys %sortedHash) { |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
my @elements = split(//, $seqHash{$key}); |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
for my $char (@elements) { |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
if ($char eq '-') { |
|
132
|
|
|
|
|
|
|
$position++; |
|
133
|
|
|
|
|
|
|
$img->moveTo( ($x + ($position / $proportion) ), ($y) ); |
|
134
|
|
|
|
|
|
|
} else { |
|
135
|
|
|
|
|
|
|
$position++; |
|
136
|
|
|
|
|
|
|
$img->lineTo( ($x + ($position / $proportion) ), ($y) ); |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
$x = 10; |
|
141
|
|
|
|
|
|
|
$y += $seqSpace; |
|
142
|
|
|
|
|
|
|
$position = 0; |
|
143
|
|
|
|
|
|
|
$img->moveTo($x, $y); |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
open (my $fh2, '>', "$fileOutPath.png" ) or die "\n Error in creating out file! \n"; |
|
147
|
|
|
|
|
|
|
print $fh2 $img->png; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
1; |
|
151
|
|
|
|
|
|
|
__END__; |