0
|
1 # $Id: Result.pm,v 1.2 2002/10/22 07:45:24 lapp Exp $
|
|
2 #
|
|
3 # BioPerl module for Bio::Tools::Phylo::Molphy::Result
|
|
4 #
|
|
5 # Cared for by Jason Stajich <jason@bioperl.org>
|
|
6 #
|
|
7 # Copyright Jason Stajich
|
|
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::Tools::Phylo::Molphy::Result - DESCRIPTION of Object
|
|
16
|
|
17 =head1 SYNOPSIS
|
|
18
|
|
19 Give standard usage here
|
|
20
|
|
21 =head1 DESCRIPTION
|
|
22
|
|
23 Describe the object here
|
|
24
|
|
25 =head1 FEEDBACK
|
|
26
|
|
27 =head2 Mailing Lists
|
|
28
|
|
29 User feedback is an integral part of the evolution of this and other
|
|
30 Bioperl modules. Send your comments and suggestions preferably to
|
|
31 the Bioperl mailing list. Your participation is much appreciated.
|
|
32
|
|
33 bioperl-l@bioperl.org - General discussion
|
|
34 http://bioperl.org/MailList.shtml - About the mailing lists
|
|
35
|
|
36 =head2 Reporting Bugs
|
|
37
|
|
38 Report bugs to the Bioperl bug tracking system to help us keep track
|
|
39 of the bugs and their resolution. Bug reports can be submitted via
|
|
40 email or the web:
|
|
41
|
|
42 bioperl-bugs@bioperl.org
|
|
43 http://bugzilla.bioperl.org/
|
|
44
|
|
45 =head1 AUTHOR - Jason Stajich
|
|
46
|
|
47 Email jason@bioperl.org
|
|
48
|
|
49 Describe contact details here
|
|
50
|
|
51 =head1 CONTRIBUTORS
|
|
52
|
|
53 Additional contributors names and emails here
|
|
54
|
|
55 =head1 APPENDIX
|
|
56
|
|
57 The rest of the documentation details each of the object methods.
|
|
58 Internal methods are usually preceded with a _
|
|
59
|
|
60 =cut
|
|
61
|
|
62
|
|
63 # Let the code begin...
|
|
64
|
|
65
|
|
66 package Bio::Tools::Phylo::Molphy::Result;
|
|
67 use vars qw(@ISA);
|
|
68 use strict;
|
|
69
|
|
70 # Object preamble - inherits from Bio::Root::Root
|
|
71
|
|
72 use Bio::Root::Root;
|
|
73
|
|
74
|
|
75 @ISA = qw(Bio::Root::Root );
|
|
76
|
|
77 =head2 new
|
|
78
|
|
79 Title : new
|
|
80 Usage : my $obj = new Bio::Tools::Phylo::Molphy::Result();
|
|
81 Function: Builds a new Bio::Tools::Phylo::Molphy::Result object
|
|
82 Returns : Bio::Tools::Phylo::Molphy::Result
|
|
83 Args :
|
|
84
|
|
85
|
|
86 =cut
|
|
87
|
|
88 sub new {
|
|
89 my($class,@args) = @_;
|
|
90
|
|
91 my $self = $class->SUPER::new(@args);
|
|
92 my ($trees,
|
|
93 $smat,$tmat,$freq,
|
|
94 $model, $sspace,
|
|
95 ) = $self->_rearrange([qw(TREES SUBSTITUTION_MATRIX
|
|
96 TRANSITION_MATRIX FREQUENCIES
|
|
97 MODEL SEARCH_SPACE)], @args);
|
|
98
|
|
99 if( $trees ) {
|
|
100 if(ref($trees) !~ /ARRAY/i ) {
|
|
101 $self->warn("Must have provided a valid array reference to initialize trees");
|
|
102 } else {
|
|
103 foreach my $t ( @$trees ) {
|
|
104 $self->add_tree($t);
|
|
105 }
|
|
106 }
|
|
107 }
|
|
108 # initialize things through object methods to be a good
|
|
109 # little OO programmer
|
|
110 if( ref($smat) =~ /HASH/i ) {
|
|
111 $self->substitution_matrix($smat);
|
|
112 }
|
|
113 if( ref($tmat) =~ /HASH/i ) {
|
|
114 $self->transition_probability_matrix($tmat);
|
|
115 }
|
|
116 if( ref($freq) =~ /HASH/i ) {
|
|
117 $self->residue_frequencies($freq);
|
|
118 }
|
|
119
|
|
120 $model && $self->model($model);
|
|
121 $sspace && $self->search_space($sspace);
|
|
122 $self->{'_treeiterator'} = 0;
|
|
123
|
|
124 return $self;
|
|
125 }
|
|
126
|
|
127 =head2 model
|
|
128
|
|
129 Title : model
|
|
130 Usage : $obj->model($newval)
|
|
131 Function:
|
|
132 Returns : value of model
|
|
133 Args : newvalue (optional)
|
|
134
|
|
135
|
|
136 =cut
|
|
137
|
|
138 sub model{
|
|
139 my ($self,$value) = @_;
|
|
140 if( defined $value) {
|
|
141 $self->{'model'} = $value;
|
|
142 }
|
|
143 return $self->{'model'};
|
|
144
|
|
145 }
|
|
146
|
|
147 =head2 substitution_matrix
|
|
148
|
|
149 Title : substitution_matrix
|
|
150 Usage : my $smat = $result->subsitution_matrix;
|
|
151 Function: Get the relative substitution matrix calculated in the ML procedure
|
|
152 Returns : reference to hash of hashes where key is the aa/nt name and value
|
|
153 is another hash ref which contains keys for all the aa/nt
|
|
154 possibilities
|
|
155 Args : none
|
|
156
|
|
157
|
|
158 =cut
|
|
159
|
|
160 sub substitution_matrix{
|
|
161 my ($self,$val) = @_;
|
|
162 if(defined $val ) {
|
|
163 if( ref($val) =~ /HASH/ ) {
|
|
164 foreach my $v (values %{$val} ) {
|
|
165 if( ref($v) !~ /HASH/i ) {
|
|
166 $self->warn("Must be a valid hashref of hashrefs for substition_matrix");
|
|
167 return undef;
|
|
168 }
|
|
169 }
|
|
170 $self->{'_substitution_matrix'} = $val;
|
|
171 } else {
|
|
172 $self->warn("Must be a valid hashref of hashrefs for substition_matrix");
|
|
173 return undef;
|
|
174 }
|
|
175 }
|
|
176 return $self->{'_substitution_matrix'};
|
|
177 }
|
|
178
|
|
179 =head2 transition_probability_matrix
|
|
180
|
|
181 Title : transition_probability_matrix
|
|
182 Usage : my $matrixref = $molphy->transition_probablity_matrix();
|
|
183 Function: Gets the observed transition probability matrix
|
|
184 Returns : hash of hashes of aa/nt transition to each other aa/nt
|
|
185 Args : none
|
|
186
|
|
187
|
|
188 =cut
|
|
189
|
|
190 sub transition_probability_matrix{
|
|
191 my ($self,$val) = @_;
|
|
192 if(defined $val ) {
|
|
193 if( ref($val) =~ /HASH/ ) {
|
|
194 foreach my $v (values %{$val} ) {
|
|
195 if( ref($v) !~ /HASH/i ) {
|
|
196 $self->warn("Must be a valid hashref of hashrefs for transition_probability_matrix");
|
|
197 return undef;
|
|
198 }
|
|
199 }
|
|
200 $self->{'_TPM'} = $val;
|
|
201 } else {
|
|
202 $self->warn("Must be a valid hashref of hashrefs for transition_probablity_matrix");
|
|
203 return undef;
|
|
204 }
|
|
205 }
|
|
206
|
|
207 # fix this for nucml where there are 2 values (one is just a transformation
|
|
208 # of the either, but how to represent?)
|
|
209 return $self->{'_TPM'};
|
|
210 }
|
|
211
|
|
212 =head2 residue_frequencies
|
|
213
|
|
214 Title : residue_frequencies
|
|
215 Usage : my %data = $molphy->residue_frequencies()
|
|
216 Function: Get the modeled and expected frequencies for
|
|
217 each of the residues in the sequence
|
|
218 Returns : hash of either aa (protml) or nt (nucml) frequencies
|
|
219 each key will point to an array reference where
|
|
220 1st slot is model's expected frequency
|
|
221 2nd slot is observed frequency in the data
|
|
222 $hash{'A'}->[0] =
|
|
223 Args : none
|
|
224
|
|
225
|
|
226 =cut
|
|
227
|
|
228 #'
|
|
229
|
|
230 sub residue_frequencies{
|
|
231 my ($self,$val) = @_;
|
|
232 if(defined $val ) {
|
|
233 if( ref($val) =~ /HASH/ ) {
|
|
234 $self->{'_residue_frequencies'} = $val;
|
|
235 } else {
|
|
236 $self->warn("Must be a valid hashref of hashrefs for residue_frequencies");
|
|
237 }
|
|
238 }
|
|
239 return %{$self->{'_residue_frequencies'}};
|
|
240 }
|
|
241
|
|
242 =head2 next_tree
|
|
243
|
|
244 Title : next_tree
|
|
245 Usage : my $tree = $factory->next_tree;
|
|
246 Function: Get the next tree from the factory
|
|
247 Returns : L<Bio::Tree::TreeI>
|
|
248 Args : none
|
|
249
|
|
250 =cut
|
|
251
|
|
252 sub next_tree{
|
|
253 my ($self,@args) = @_;
|
|
254 return $self->{'_trees'}->[$self->{'_treeiterator'}++] || undef;
|
|
255 }
|
|
256
|
|
257 =head2 rewind_tree
|
|
258
|
|
259 Title : rewind_tree_iterator
|
|
260 Usage : $result->rewind_tree()
|
|
261 Function: Rewinds the tree iterator so that next_tree can be
|
|
262 called again from the beginning
|
|
263 Returns : none
|
|
264 Args : none
|
|
265
|
|
266 =cut
|
|
267
|
|
268 sub rewind_tree_iterator {
|
|
269 shift->{'_treeiterator'} = 0;
|
|
270 }
|
|
271
|
|
272 =head2 add_tree
|
|
273
|
|
274 Title : add_tree
|
|
275 Usage : $result->add_tree($tree);
|
|
276 Function: Adds a tree
|
|
277 Returns : integer which is the number of trees stored
|
|
278 Args : L<Bio::Tree::TreeI>
|
|
279
|
|
280 =cut
|
|
281
|
|
282 sub add_tree{
|
|
283 my ($self,$tree) = @_;
|
|
284 if( $tree && ref($tree) && $tree->isa('Bio::Tree::TreeI') ) {
|
|
285 push @{$self->{'_trees'}},$tree;
|
|
286 }
|
|
287 return scalar @{$self->{'_trees'}};
|
|
288 }
|
|
289
|
|
290 =head2 search_space
|
|
291
|
|
292 Title : search_space
|
|
293 Usage : $obj->search_space($newval)
|
|
294 Function:
|
|
295 Returns : value of search_space
|
|
296 Args : newvalue (optional)
|
|
297
|
|
298
|
|
299 =cut
|
|
300
|
|
301 sub search_space{
|
|
302 my ($self,$value) = @_;
|
|
303 if( defined $value) {
|
|
304 $self->{'search_space'} = $value;
|
|
305 }
|
|
306 return $self->{'search_space'};
|
|
307 }
|
|
308
|
|
309 1;
|