File Coverage

blib/lib/Bio/Tools/Run/Phylo/Hyphy/Modeltest.pm
Criterion Covered Total %
statement 24 59 40.6
branch 0 22 0.0
condition n/a
subroutine 8 12 66.6
pod 4 4 100.0
total 36 97 37.1


line stmt bran cond sub pod time code
1             # $Id$
2             #
3             # BioPerl module for Bio::Tools::Run::Phylo::Hyphy::Modeltest
4             #
5             # Please direct questions and support issues to
6             #
7             # Cared for by Albert Vilella
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
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     1   886 use vars qw(@ISA);
  1         1  
  1         41  
98 1     1   3 use strict;
  1         1  
  1         13  
99 1     1   3 use Bio::Root::Root;
  1         1  
  1         12  
100 1     1   3 use Bio::AlignIO;
  1         0  
  1         16  
101 1     1   2 use Bio::TreeIO;
  1         1  
  1         12  
102 1     1   3 use Bio::Tools::Run::Phylo::Hyphy::Base;
  1         1  
  1         14  
103 1     1   3 use Bio::Tools::Run::WrapperBase;
  1         1  
  1         19  
104              
105 1     1   3 use base qw(Bio::Root::Root Bio::Tools::Run::Phylo::Hyphy::Base);
  1         0  
  1         441  
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             sub valid_values {
129             return
130             (
131 0     0 1   {'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, L
157              
158             =cut
159              
160             sub new {
161 0     0 1   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 0         defined $aln && $self->alignment($aln);
169 0 0         defined $tree && $self->tree($tree);
170 0 0         defined $st && $self->save_tempfiles($st);
171 0 0         defined $exe && $self->executable($exe);
172              
173 0           $self->set_default_parameters();
174 0 0         if( defined $params ) {
175 0 0         if( ref($params) !~ /HASH/i ) {
176 0           $self->warn("Must provide a valid hash ref for parameter -FLAGS");
177             } else {
178 0           map { $self->set_parameter($_, $$params{$_}) } keys %$params;
  0            
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 object,
193             L object [optional]
194              
195             =cut
196              
197             sub run {
198 0     0 1   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) {
205 0 0         if ($line =~ m/Hierarchical Testing based model \((.*)\)/) {
    0          
    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             sub create_wrapper {
237 0     0 1   my $self = shift;
238              
239 0           my $batchfile = "ModelTest.bf";
240 0           $self->SUPER::create_wrapper($batchfile);
241             }
242              
243             1;