Tools/Run/Phylo/Hyphy/Modeltest.pm

filter: Statementstmt 41.6% 25 / 60 Branchbran 0.0% 0 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 8 / 12 Podpod 100% 4 / 4 totaltotal 37.0% 37 / 100 CC 13 SCAR 35.0
CC
13
Cov
30%
new
56.0
run
56.0
valid_values
2.0
CRAP 33.2
« Tools/Run/Phylo/Raxml.pm ↑ Summary Tools/Run/Alignment/Blat.pm »
1 # $Id$
2 #
3 # BioPerl module for Bio::Tools::Run::Phylo::Hyphy::Modeltest
4 #
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 #
7 # Cared for by Albert Vilella <avilella-at-gmail-dot-com>
8 #
9 # Copyright Albert Vilella
10 #
11 # You may distribute this module under the same terms as perl itself
12  
13 # POD documentation - main docs before the code
14  
15 =head1 NAME
16  
17 Bio::Tools::Run::Phylo::Hyphy::Modeltest - Wrapper around the Hyphy Modeltest analysis
18  
19 =head1 SYNOPSIS
20  
21 use Bio::Tools::Run::Phylo::Hyphy::Modeltest;
22 use Bio::AlignIO;
23 use Bio::TreeIO;
24  
25 my $alignio = Bio::AlignIO->new(-format => 'fasta',
26 -file => 't/data/hyphy1.fasta');
27  
28 my $aln = $alignio->next_aln;
29 my $treeio = Bio::TreeIO->new(
30 -format => 'newick', -file => 't/data/hyphy1.tree');
31  
32 my $modeltest = Bio::Tools::Run::Phylo::Hyphy::Modeltest->new();
33 $modeltest->alignment($aln);
34 $modeltest->tree($tree);
35 my ($rc,$results) = $modeltest->run();
36  
37 =head1 DESCRIPTION
38  
39 This is a wrapper around the Modeltest analysis of HyPhy ([Hy]pothesis
40 Testing Using [Phy]logenies) package of Sergei Kosakowsky Pond,
41 Spencer V. Muse, Simon D.W. Frost and Art Poon. See
42 http://www.hyphy.org for more information.
43  
44 This module will generate the correct list of options for interfacing
45 with TemplateBatchFiles/Modeltest.bf.
46  
47 =head1 FEEDBACK
48  
49 =head2 Mailing Lists
50  
51 User feedback is an integral part of the evolution of this and other
52 Bioperl modules. Send your comments and suggestions preferably to
53 the Bioperl mailing list. Your participation is much appreciated.
54  
55 bioperl-l@bioperl.org - General discussion
56 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
57  
58 =head2 Support
59  
60 Please direct usage questions or support issues to the mailing list:
61  
62 I<bioperl-l@bioperl.org>
63  
64 rather than to the module maintainer directly. Many experienced and
65 reponsive experts will be able look at the problem and quickly
66 address it. Please include a thorough description of the problem
67 with code and data examples if at all possible.
68  
69 =head2 Reporting Bugs
70  
71 Report bugs to the Bioperl bug tracking system to help us keep track
72 of the bugs and their resolution. Bug reports can be submitted via the
73 web:
74  
75 http://redmine.open-bio.org/projects/bioperl/
76  
77 =head1 AUTHOR - Albert Vilella
78  
79 Email avilella-at-gmail-dot-com
80  
81 =head1 CONTRIBUTORS
82  
83 Additional contributors names and emails here
84  
85 =head1 APPENDIX
86  
87 The rest of the documentation details each of the object methods.
88 Internal methods are usually preceded with a _
89  
90 =cut
91  
92  
93 # Let the code begin...
94  
95  
96 package Bio::Tools::Run::Phylo::Hyphy::Modeltest;
97 1 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
98 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
99 1 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
100 1 ▶use Bio::AlignIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
101 1 ▶use Bio::TreeIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
102 1 ▶use Bio::Tools::Run::Phylo::Hyphy::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
103 1 ▶use Bio::Tools::Run::WrapperBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
104  
105 1 ▶use base qw(Bio::Root::Root Bio::Tools::Run::Phylo::Hyphy::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
106  
107 =head2 Default Values
108  
109 Valid and default values for Modeltest are listed below. The default
110 values are always the first one listed. These descriptions are
111 essentially lifted from the python wrapper or provided by the author.
112  
113 =cut
114  
115 =head2 valid_values
116  
117 Title : valid_values
118 Usage : $factory->valid_values()
119 Function: returns the possible parameters
120 Returns: an array holding all possible parameters. The default
121 values are always the first one listed. These descriptions are
122 essentially lifted from the python wrapper or provided by the author.
123 Args : None
124  
125 =cut
126  
127  
128 0 ▶sub valid_values {
Subroutine valid_values: not called CC=1 SCAR=6.9
Pod documented
129 return
130 (
131 0 {'tempalnfile' => undef }, # aln file goes here
132 {'temptreefile' => undef }, # tree file goes here
133 {'Number of Rate Classes' => [ '4' ] },
134 {'Model Selection Method' => [ 'Both',
135 'Hierarchical Test',
136 'AIC Test'] },
137 {'Model rejection level' => '0.05' },
138 {'hieoutfile' => undef },
139 {'aicoutfile' => undef }
140 );
141 }
142  
143 =head2 new
144  
145 Title : new
146 Usage : my $obj = Bio::Tools::Run::Phylo::Hyphy::Modeltest->new();
147 Function: Builds a new Bio::Tools::Run::Phylo::Hyphy::Modeltest object
148 Returns : Bio::Tools::Run::Phylo::Hyphy::Modeltest
149 Args : -alignment => the Bio::Align::AlignI object
150 -save_tempfiles => boolean to save the generated tempfiles and
151 NOT cleanup after onesself (default FALSE)
152 -tree => the Bio::Tree::TreeI object
153 -params => a hashref of parameters (all passed to set_parameter)
154 -executable => where the hyphy executable resides
155  
156 See also: L<Bio::Tree::TreeI>, L<Bio::Align::AlignI>
157  
158 =cut
159  
160 0 ▶sub new {
Subroutine new: not called CC=7 SCAR=40.3
Pod documented
161 0 my($class,@args) = @_;
162  
163 0 my $self = $class->SUPER::new(@args);
164 0 my ($aln, $tree, $st, $params, $exe,
165 $ubl) = $self->_rearrange([qw(ALIGNMENT TREE SAVE_TEMPFILES
166 PARAMS EXECUTABLE)],
167 @args);
168 0 ▶ defined $aln && $self->alignment($aln);
Branch: 1 branch
BranchTrueFalseTotal
defined $aln and $self->alignment($aln) 0 0 0
169 0 ▶ defined $tree && $self->tree($tree);
Branch: 1 branch
BranchTrueFalseTotal
defined $tree and $self->tree($tree) 0 0 0
170 0 ▶ defined $st && $self->save_tempfiles($st);
Branch: 1 branch
BranchTrueFalseTotal
defined $st and $self->save_tempfiles($st) 0 0 0
171 0 ▶ defined $exe && $self->executable($exe);
Branch: 1 branch
BranchTrueFalseTotal
defined $exe and $self->executable($exe) 0 0 0
172  
173 0 $self->set_default_parameters();
174 0 ▶ if( defined $params ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params) 0 0 0
175 0 ▶ if( ref($params) !~ /HASH/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref($params) =~ /HASH/i) { } 0 0 0
176 0 $self->warn("Must provide a valid hash ref for parameter -FLAGS");
177 } else {
178 0 map { $self->set_parameter($_, $$params{$_}) } keys %$params;
179 }
180 }
181 0 return $self;
182 }
183  
184  
185 =head2 run
186  
187 Title : run
188 Usage : my ($rc,$results) = $modeltest->run($aln);
189 Function: run the modeltest analysis using the default or updated parameters
190 the alignment parameter must have been set
191 Returns : Return code, hash containing the "Hierarchical Testing" and "AIC" results, both as hashes.
192 Args : L<Bio::Align::AlignI> object,
193 L<Bio::Tree::TreeI> object [optional]
194  
195 =cut
196  
197 0 ▶sub run {
Subroutine run: not called CC=7 SCAR=40.3
Pod documented
198 0 my $self = shift;
199 0 my ($rc, $run_results) = $self->SUPER::run();
200 0 my $results = {};
201 0 my @run_result_array = split (/\n/, $run_results);
202 0 my $line = shift @run_result_array;
203 0 my $current_model = "error"; # if this stays "error" when you're trying to add results for a model, something's wrong.
204 0 ▶ while (defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line) 0 0 0
205 0 ▶ if ($line =~ m/Hierarchical Testing based model \((.*)\)/) {
Branch: 5 branches
BranchTrueFalseTotal
if ($line =~ /Hierarchical Testing based model \((.*)\)/) { } 0 0 0
elsif ($line =~ /AIC based model \((.*)\)/) { } 0 0 0
elsif ($line =~ /Model String:(\d+)/) { } 0 0 0
elsif ($line =~ /Model Options: (.+)/) { } 0 0 0
elsif ($line =~ /Equilibrium Frequencies Option: (.+)/) { } 0 0 0
206 0 $current_model = "Hierarchical Testing";
207 0 $results->{$current_model}{'model_name'} = $1;
208 } elsif ($line =~ m/AIC based model \((.*)\)/) {
209 0 $current_model = "AIC";
210 0 $results->{$current_model}{'model_name'} = $1;
211 } elsif ($line =~ m/Model String:(\d+)/) {
212 0 $results->{$current_model}{'model_string'} = $1;
213 } elsif ($line =~ m/Model Options: (.+)/) {
214 0 $results->{$current_model}{'model_options'} = $1;
215 } elsif ($line =~ m/Equilibrium Frequencies Option: (.+)/) {
216 0 $results->{$current_model}{'eq_freq_option'} = $1;
217 }
218 0 $line = shift @run_result_array;
219 }
220 0 return ($rc,$results);
221 }
222  
223  
224 =head2 create_wrapper
225  
226 Title : create_wrapper
227 Usage : $self->create_wrapper
228 Function: It will create the wrapper file that interfaces with the analysis bf file
229 Example :
230 Returns :
231 Args :
232  
233  
234 =cut
235  
236 0 ▶sub create_wrapper {
Subroutine create_wrapper: not called CC=1 SCAR=6.9
Pod documented
237 0 my $self = shift;
238  
239 0 my $batchfile = "ModelTest.bf";
240 0 $self->SUPER::create_wrapper($batchfile);
241 }
242  
243 1 1;
« Tools/Run/Phylo/Raxml.pm ↑ Summary Tools/Run/Alignment/Blat.pm »