line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
###################################################### |
2
|
|
|
|
|
|
|
# WeightSet.pm |
3
|
|
|
|
|
|
|
###################################################### |
4
|
|
|
|
|
|
|
# Author: Chengzhi Liang, Weigang Qiu, Peter Yang, Thomas Hladish |
5
|
|
|
|
|
|
|
# $Id: WeightSet.pm,v 1.26 2007/09/24 04:52:11 rvos Exp $ |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#################### START POD DOCUMENTATION ################## |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Bio::NEXUS::WeightSet - Represents column weights in alignment ( for each character) |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
new Bio::NEXUS::WeightSet($name, \@weights, $iswt); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
A module representing column weights in alignment (for each character) |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 FEEDBACK |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
All feedback (bugs, feature enhancements, etc.) are all greatly appreciated. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 AUTHOR |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Chengzhi Liang (liangc@umbi.umd.edu) |
28
|
|
|
|
|
|
|
Weigang Qiu (weigang@genectr.hunter.cuny.edu) |
29
|
|
|
|
|
|
|
Thomas Hladish (tjhladish at yahoo) |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Peter Yang (pyang@rice.edu) |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 METHODS |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
package Bio::NEXUS::WeightSet; |
40
|
|
|
|
|
|
|
|
41
|
34
|
|
|
34
|
|
244
|
use strict; |
|
34
|
|
|
|
|
72
|
|
|
34
|
|
|
|
|
1409
|
|
42
|
34
|
|
|
34
|
|
197
|
use Bio::NEXUS::Functions; |
|
34
|
|
|
|
|
75
|
|
|
34
|
|
|
|
|
7771
|
|
43
|
|
|
|
|
|
|
#use Data::Dumper; # XXX this is not used, might as well not import it! |
44
|
|
|
|
|
|
|
#use Carp; # XXX this is not used, might as well not import it! |
45
|
34
|
|
|
34
|
|
196
|
use Bio::NEXUS::Util::Exceptions; |
|
34
|
|
|
|
|
71
|
|
|
34
|
|
|
|
|
1382
|
|
46
|
34
|
|
|
34
|
|
190
|
use Bio::NEXUS::Util::Logger; |
|
34
|
|
|
|
|
69
|
|
|
34
|
|
|
|
|
1037
|
|
47
|
34
|
|
|
34
|
|
197
|
use vars qw($VERSION $AUTOLOAD); |
|
34
|
|
|
|
|
70
|
|
|
34
|
|
|
|
|
2658
|
|
48
|
34
|
|
|
34
|
|
207
|
use Bio::NEXUS; $VERSION = $Bio::NEXUS::VERSION; |
|
34
|
|
|
|
|
70
|
|
|
34
|
|
|
|
|
35298
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $logger = Bio::NEXUS::Util::Logger->new(); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 new |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Title : new |
55
|
|
|
|
|
|
|
Usage : $node = new Bio::NEXUS::WeightSet($name, \@weights); |
56
|
|
|
|
|
|
|
Function: Creates a new Bio::NEXUS::WeightSet object |
57
|
|
|
|
|
|
|
Returns : Bio::NEXUS::WeightSet object |
58
|
|
|
|
|
|
|
Args : none |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub new { |
63
|
8
|
|
|
8
|
1
|
276
|
my ( $class, $name, $weights, $iswt, $tokens, $type ) = @_; |
64
|
8
|
|
|
|
|
61
|
my $self = { |
65
|
|
|
|
|
|
|
'name' => $name, |
66
|
|
|
|
|
|
|
'weights' => $weights, |
67
|
|
|
|
|
|
|
'is_wt' => $iswt, |
68
|
|
|
|
|
|
|
'_is_tokens' => $tokens, |
69
|
|
|
|
|
|
|
'type' => $type |
70
|
|
|
|
|
|
|
}; |
71
|
8
|
|
|
|
|
27
|
bless $self, $class; |
72
|
8
|
|
|
|
|
29
|
return $self; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=begin comment |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Title : _parse_weights |
78
|
|
|
|
|
|
|
Usage : $self->_parse_weights(weight_string); |
79
|
|
|
|
|
|
|
Function: parses the weight string and store the contents to the object ($self) |
80
|
|
|
|
|
|
|
Returns : none |
81
|
|
|
|
|
|
|
Args : weight-string from the WeightSet block in the NEXUS file |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=end comment |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _parse_weights { |
88
|
0
|
|
|
0
|
|
0
|
my ( $self, $wt_string ) = @_; |
89
|
0
|
|
|
|
|
0
|
$wt_string =~ s/^\s+//; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
0
|
my $delimiter = ''; |
92
|
0
|
0
|
|
|
|
0
|
if ( $self->_is_tokens() ) { $delimiter = '\s+' } |
|
0
|
|
|
|
|
0
|
|
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
0
|
my @weights = split /$delimiter/, $wt_string; |
95
|
0
|
|
|
|
|
0
|
$self->{'weights'} = [@weights]; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 set_weights |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Title : set_weights |
101
|
|
|
|
|
|
|
Usage : $weight->set_weights(\@weights); |
102
|
|
|
|
|
|
|
Function: stores it in the list weights |
103
|
|
|
|
|
|
|
Returns : none |
104
|
|
|
|
|
|
|
Args : list of weights |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub set_weights { |
109
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $weights ) = @_; |
110
|
0
|
|
|
|
|
0
|
$self->{'weights'} = $weights; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 get_weights |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Title : get_weights |
116
|
|
|
|
|
|
|
Usage : @wts=@{$weightset->get_weights()}; |
117
|
|
|
|
|
|
|
Function: Returns the weights array |
118
|
|
|
|
|
|
|
Returns : reference to array containing weights |
119
|
|
|
|
|
|
|
Args : none |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
3
|
|
|
3
|
1
|
66
|
sub get_weights { shift->{'weights'} } |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 select_weights |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Title : select_weights |
128
|
|
|
|
|
|
|
Usage : $set->select_weights($columns); |
129
|
|
|
|
|
|
|
Function: select a subset of characters |
130
|
|
|
|
|
|
|
Returns : new self with subset of weights |
131
|
|
|
|
|
|
|
Args : column numbers |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub select_weights { |
136
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $columns ) = @_; |
137
|
0
|
|
|
|
|
0
|
my @weights = @{ $self->{'weights'} }; |
|
0
|
|
|
|
|
0
|
|
138
|
0
|
|
|
|
|
0
|
my @newweights = (); |
139
|
0
|
|
|
|
|
0
|
for my $i ( @{$columns} ) { |
|
0
|
|
|
|
|
0
|
|
140
|
0
|
|
|
|
|
0
|
push @newweights, $weights[$i]; |
141
|
|
|
|
|
|
|
} |
142
|
0
|
|
|
|
|
0
|
$self->{'weights'} = \@newweights; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 is_wt |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Title : is_wt |
148
|
|
|
|
|
|
|
Usage : croak unless $weight->is_wt(); |
149
|
|
|
|
|
|
|
Function: Returns if object has weights (1 yes, 0 no) |
150
|
|
|
|
|
|
|
Returns : weight existence (integer) |
151
|
|
|
|
|
|
|
Args : none |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |
154
|
|
|
|
|
|
|
|
155
|
2
|
|
|
2
|
1
|
13
|
sub is_wt { !!shift->{'is_wt'} } |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=begin comment |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Title : _is_tokens |
160
|
|
|
|
|
|
|
Usage : if ( $weight->_is_tokens() ) {} |
161
|
|
|
|
|
|
|
Function: tests whether tokens attribute is set to true |
162
|
|
|
|
|
|
|
Returns : boolean |
163
|
|
|
|
|
|
|
Args : none |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=end comment |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |
168
|
|
|
|
|
|
|
|
169
|
2
|
|
|
2
|
|
10
|
sub _is_tokens { !!shift->{'_is_tokens'} } |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=begin comment |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Title : _is_vector |
174
|
|
|
|
|
|
|
Usage : if ( $weight->_is_vector() ) {} |
175
|
|
|
|
|
|
|
Function: tests whether type attribute is set to vector |
176
|
|
|
|
|
|
|
Returns : boolean |
177
|
|
|
|
|
|
|
Args : none |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=end comment |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |
182
|
|
|
|
|
|
|
|
183
|
2
|
|
|
2
|
|
11
|
sub _is_vector { uc( shift->{'type'} ) eq 'VECTOR' } |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 set_name |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Title : set_name |
188
|
|
|
|
|
|
|
Usage : $weight->set_name($name); |
189
|
|
|
|
|
|
|
Function: Sets the name of the weightset |
190
|
|
|
|
|
|
|
Returns : none |
191
|
|
|
|
|
|
|
Args : name (string) |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub set_name { |
196
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $name ) = @_; |
197
|
0
|
|
|
|
|
0
|
$self->{'name'} = $name; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head2 get_name |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Title : get_name |
203
|
|
|
|
|
|
|
Usage : $name=$weight->get_name(); |
204
|
|
|
|
|
|
|
Function: Returns the name of the weightset |
205
|
|
|
|
|
|
|
Returns : name (string) |
206
|
|
|
|
|
|
|
Args : none |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |
209
|
|
|
|
|
|
|
|
210
|
4
|
|
|
4
|
1
|
28
|
sub get_name { shift->{'name'} } |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head2 equals |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Name : equals |
215
|
|
|
|
|
|
|
Usage : $set->equals($another); |
216
|
|
|
|
|
|
|
Function: compare if two WeightSet objects are equal |
217
|
|
|
|
|
|
|
Returns : boolean |
218
|
|
|
|
|
|
|
Args : an WeightSet object |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=cut |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub equals { |
223
|
0
|
|
|
0
|
1
|
|
my ( $self, $weights ) = @_; |
224
|
0
|
0
|
|
|
|
|
if ( $self->get_name() ne $weights->get_name() ) { return 0; } |
|
0
|
|
|
|
|
|
|
225
|
0
|
|
|
|
|
|
my @weights1 = @{ $self->get_weights() }; |
|
0
|
|
|
|
|
|
|
226
|
0
|
|
|
|
|
|
my @weights2 = @{ $weights->get_weights() }; |
|
0
|
|
|
|
|
|
|
227
|
0
|
0
|
|
|
|
|
if ( @weights1 != @weights2 ) { return 0; } |
|
0
|
|
|
|
|
|
|
228
|
0
|
|
|
|
|
|
for ( my $i = 0; $i < @weights1; $i++ ) { |
229
|
0
|
0
|
|
|
|
|
if ( $weights1[$i] eq $weights2[$i] ) { return 0; } |
|
0
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
} |
231
|
0
|
|
|
|
|
|
return 1; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub AUTOLOAD { |
235
|
0
|
0
|
|
0
|
|
|
return if $AUTOLOAD =~ /DESTROY$/; |
236
|
0
|
|
|
|
|
|
my $package_name = __PACKAGE__ . '::'; |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
# The following methods are deprecated and are temporarily supported |
239
|
|
|
|
|
|
|
# via a warning and a redirection |
240
|
0
|
|
|
|
|
|
my %synonym_for = ( |
241
|
|
|
|
|
|
|
"${package_name}is_tokens" => "${package_name}_is_tokens", |
242
|
|
|
|
|
|
|
"${package_name}is_vector" => "${package_name}_is_vector", |
243
|
|
|
|
|
|
|
); |
244
|
|
|
|
|
|
|
|
245
|
0
|
0
|
|
|
|
|
if ( defined $synonym_for{$AUTOLOAD} ) { |
246
|
0
|
|
|
|
|
|
$logger->warn( "$AUTOLOAD() is deprecated; use $synonym_for{$AUTOLOAD}() instead" ); |
247
|
0
|
|
|
|
|
|
goto &{ $synonym_for{$AUTOLOAD} }; |
|
0
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
else { |
250
|
0
|
|
|
|
|
|
Bio::NEXUS::Util::Exceptions::UnknownMethod->throw( |
251
|
|
|
|
|
|
|
'error' => "ERROR: Unknown method $AUTOLOAD called" |
252
|
|
|
|
|
|
|
); |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
1; |