2 # BioPerl module for Bio::Tools::Phylo::Molphy::Result
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Jason Stajich <jason@bioperl.org>
8 # Copyright Jason Stajich
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::Tools::Phylo::Molphy::Result - container for data parsed from a ProtML run
20 # do not use this object directly, you will get it back as part of a
22 use Bio::Tools::Phylo::Molphy;
23 my $parser = Bio::Tools::Phylo::Molphy->new(-file => 'output.protml');
24 while( my $r = $parser->next_result ) {
25 # r is a Bio::Tools::Phylo::Molphy::Result object
27 # print the model name
28 print $r->model, "\n";
30 # get the substitution matrix
31 # this is a hash of 3letter aa codes -> 3letter aa codes representing
33 my $smat = $r->substitution_matrix;
34 print "Arg -> Gln substitution rate is %d\n",
35 $smat->{'Arg'}->{'Gln'}, "\n";
37 # get the transition probablity matrix
38 # this is a hash of 3letter aa codes -> 3letter aa codes representing
39 # transition probabilty
40 my $tmat = $r->transition_probability_matrix;
41 print "Arg -> Gln transition probablity is %.2f\n",
42 $tmat->{'Arg'}->{'Gln'}, "\n";
44 # get the frequency for each of the residues
45 my $rfreqs = $r->residue_frequencies;
47 foreach my $residue ( keys %{$rfreqs} ) {
48 printf "residue %s expected freq: %.2f observed freq: %.2f\n",
49 $residue,$rfreqs->{$residue}->[0], $rfreqs->{$residue}->[1];
53 while( my $t = $r->next_tree ) {
57 print "search space is ", $r->search_space, "\n",
58 "1st tree score is ", $trees[0]->score, "\n";
60 # writing to STDOUT, use -file => '>filename' to specify a file
61 my $out = Bio::TreeIO->new(-format => "newick");
62 $out->write_tree($trees[0]); # writing only the 1st tree
68 A container for data parsed from a ProtML run.
75 User feedback is an integral part of the evolution of this and other
76 Bioperl modules. Send your comments and suggestions preferably to
77 the Bioperl mailing list. Your participation is much appreciated.
79 bioperl-l@bioperl.org - General discussion
80 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
84 Please direct usage questions or support issues to the mailing list:
86 I<bioperl-l@bioperl.org>
88 rather than to the module maintainer directly. Many experienced and
89 reponsive experts will be able look at the problem and quickly
90 address it. Please include a thorough description of the problem
91 with code and data examples if at all possible.
95 Report bugs to the Bioperl bug tracking system to help us keep track
96 of the bugs and their resolution. Bug reports can be submitted via the
99 https://github.com/bioperl/bioperl-live/issues
101 =head1 AUTHOR - Jason Stajich
103 Email jason-at-bioperl.org
107 The rest of the documentation details each of the object methods.
108 Internal methods are usually preceded with a _
113 # Let the code begin...
116 package Bio
::Tools
::Phylo
::Molphy
::Result
;
119 # Object preamble - inherits from Bio::Root::Root
123 use base
qw(Bio::Root::Root);
128 Usage : my $obj = Bio::Tools::Phylo::Molphy::Result->new();
129 Function: Builds a new Bio::Tools::Phylo::Molphy::Result object
130 Returns : Bio::Tools::Phylo::Molphy::Result
137 my($class,@args) = @_;
139 my $self = $class->SUPER::new
(@args);
140 my ($trees,$smat,$freq,
142 ) = $self->_rearrange([qw(TREES SUBSTITUTION_MATRIX
144 MODEL SEARCH_SPACE)], @args);
147 if(ref($trees) !~ /ARRAY/i ) {
148 $self->warn("Must provide a valid array reference to initialize trees");
150 foreach my $t ( @
$trees ) {
155 # initialize things through object methods to be a good
156 # little OO programmer
157 if( ref($smat) =~ /HASH/i ) {
158 $self->substitution_matrix($smat);
160 if( ref($freq) =~ /HASH/i ) {
161 $self->residue_frequencies($freq);
164 $model && $self->model($model);
165 $sspace && $self->search_space($sspace);
166 $self->{'_treeiterator'} = 0;
174 Usage : $obj->model($newval)
176 Returns : value of model
177 Args : newvalue (optional)
183 my ($self,$value) = @_;
184 if( defined $value) {
185 $self->{'model'} = $value;
187 return $self->{'model'};
191 =head2 substitution_matrix
193 Title : substitution_matrix
194 Usage : my $smat = $result->subsitution_matrix;
195 Function: Get the relative substitution matrix calculated in the ML procedure
196 Returns : reference to hash of hashes where key is the aa/nt name and value
197 is another hash ref which contains keys for all the aa/nt
204 sub substitution_matrix
{
205 my ($self,$val) = @_;
207 if( ref($val) =~ /HASH/ ) {
208 foreach my $v (values %{$val} ) {
209 if( ref($v) !~ /HASH/i ) {
210 $self->warn("Must be a valid hashref of hashrefs for substition_matrix");
214 $self->{'_substitution_matrix'} = $val;
216 $self->warn("Must be a valid hashref of hashrefs for substition_matrix");
220 return $self->{'_substitution_matrix'};
223 =head2 transition_probability_matrix
225 Title : transition_probability_matrix
226 Usage : my $matrixref = $molphy->transition_probablity_matrix();
227 Function: Gets the observed transition probability matrix
228 Returns : hash of hashes of aa/nt transition to each other aa/nt
229 Args : Transition matrix type, typically
230 '1PAM-1.0e05' or '1PAM-1.0e07'
235 sub transition_probability_matrix
{
236 my ($self,$type,$val) = @_;
237 $type = '1PAM-1.0e7' unless defined $type;
239 if( ref($val) =~ /HASH/ ) {
240 foreach my $v (values %{$val} ) {
241 if( ref($v) !~ /HASH/i ) {
242 $self->warn("Must be a valid hashref of hashrefs for transition_probability_matrix");
246 $self->{'_TPM'}->{$type} = $val;
248 $self->warn("Must be a valid hashref of hashrefs for transition_probablity_matrix");
253 # fix this for nucml where there are 2 values (one is just a transformation
254 # of the either, but how to represent?)
255 return $self->{'_TPM'}->{$type};
258 =head2 residue_frequencies
260 Title : residue_frequencies
261 Usage : my %data = $molphy->residue_frequencies()
262 Function: Get the modeled and expected frequencies for
263 each of the residues in the sequence
264 Returns : hash of either aa (protml) or nt (nucml) frequencies
265 each key will point to an array reference where
266 1st slot is model's expected frequency
267 2nd slot is observed frequency in the data
276 sub residue_frequencies
{
277 my ($self,$val) = @_;
279 if( ref($val) =~ /HASH/ ) {
280 $self->{'_residue_frequencies'} = $val;
282 $self->warn("Must be a valid hashref of hashrefs for residue_frequencies");
285 return %{$self->{'_residue_frequencies'}};
291 Usage : my $tree = $factory->next_tree;
292 Function: Get the next tree from the factory
293 Returns : L<Bio::Tree::TreeI>
299 my ($self,@args) = @_;
300 return $self->{'_trees'}->[$self->{'_treeiterator'}++] || undef;
305 Title : rewind_tree_iterator
306 Usage : $result->rewind_tree()
307 Function: Rewinds the tree iterator so that next_tree can be
308 called again from the beginning
314 sub rewind_tree_iterator
{
315 shift->{'_treeiterator'} = 0;
321 Usage : $result->add_tree($tree);
322 Function: Adds a tree
323 Returns : integer which is the number of trees stored
324 Args : L<Bio::Tree::TreeI>
329 my ($self,$tree) = @_;
330 if( $tree && ref($tree) && $tree->isa('Bio::Tree::TreeI') ) {
331 push @
{$self->{'_trees'}},$tree;
333 return scalar @
{$self->{'_trees'}};
339 Usage : $obj->search_space($newval)
341 Returns : value of search_space
342 Args : newvalue (optional)
348 my ($self,$value) = @_;
349 if( defined $value) {
350 $self->{'search_space'} = $value;
352 return $self->{'search_space'};