File Coverage

blib/lib/Bio/Tools/Run/Phylo/Hyphy/FEL.pm
Criterion Covered Total %
statement 21 57 36.8
branch 0 18 0.0
condition n/a
subroutine 7 11 63.6
pod 4 4 100.0
total 32 90 35.5


line stmt bran cond sub pod time code
1             # $Id$
2             #
3             # BioPerl module for Bio::Tools::Run::Phylo::Hyphy::FEL
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::FEL - Wrapper around the Hyphy FEL analysis
18              
19             =head1 SYNOPSIS
20              
21             use Bio::Tools::Run::Phylo::Hyphy::FEL;
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              
30             my $treeio = Bio::TreeIO->new(
31             -format => 'newick', -file => 't/data/hyphy1.tree');
32              
33             my $fel = Bio::Tools::Run::Phylo::Hyphy::FEL->new();
34             $fel->alignment($aln);
35             $fel->tree($tree);
36             my ($rc,$results) = $fel->run();
37              
38             =head1 DESCRIPTION
39              
40             This is a wrapper around the FEL analysis of HyPhy ([Hy]pothesis
41             Testing Using [Phy]logenies) package of Sergei Kosakowsky Pond,
42             Spencer V. Muse, Simon D.W. Frost and Art Poon. See
43             http://www.hyphy.org for more information.
44              
45             This module will generate the correct list of options for interfacing
46             with TemplateBatchFiles/Ghostrides/Wrapper.bf.
47              
48             =head1 FEEDBACK
49              
50             =head2 Mailing Lists
51              
52             User feedback is an integral part of the evolution of this and other
53             Bioperl modules. Send your comments and suggestions preferably to
54             the Bioperl mailing list. Your participation is much appreciated.
55              
56             bioperl-l@bioperl.org - General discussion
57             http://bioperl.org/wiki/Mailing_lists - About the mailing lists
58              
59             =head2 Support
60              
61             Please direct usage questions or support issues to the mailing list:
62              
63             I
64              
65             rather than to the module maintainer directly. Many experienced and
66             reponsive experts will be able look at the problem and quickly
67             address it. Please include a thorough description of the problem
68             with code and data examples if at all possible.
69              
70             =head2 Reporting Bugs
71              
72             Report bugs to the Bioperl bug tracking system to help us keep track
73             of the bugs and their resolution. Bug reports can be submitted via the
74             web:
75              
76             http://redmine.open-bio.org/projects/bioperl/
77              
78             =head1 AUTHOR - Albert Vilella
79              
80             Email avilella-at-gmail-dot-com
81              
82             =head1 CONTRIBUTORS
83              
84             Additional contributors names and emails here
85              
86             =head1 APPENDIX
87              
88             The rest of the documentation details each of the object methods.
89             Internal methods are usually preceded with a _
90              
91             =cut
92              
93              
94             # Let the code begin...
95              
96              
97             package Bio::Tools::Run::Phylo::Hyphy::FEL;
98 1     1   1257 use strict;
  1         1  
  1         23  
99 1     1   3 use Bio::Root::Root;
  1         0  
  1         14  
100 1     1   2 use Bio::AlignIO;
  1         1  
  1         11  
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         16  
103 1     1   3 use Bio::Tools::Run::WrapperBase;
  1         1  
  1         15  
104              
105 1     1   7 use base qw(Bio::Root::Root Bio::Tools::Run::Phylo::Hyphy::Base);
  1         1  
  1         489  
106              
107             =head2 Default Values
108              
109             Valid and default values for FEL 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             INCOMPLETE DOCUMENTATION OF ALL METHODS
114              
115             =cut
116              
117             =head2 valid_values
118              
119             Title : valid_values
120             Usage : $factory->valid_values()
121             Function: returns the possible parameters
122             Returns: an array holding all possible parameters. The default
123             values are always the first one listed. These descriptions are
124             essentially lifted from the python wrapper or provided by the author.
125             Args : None
126              
127             =cut
128              
129              
130             sub valid_values {
131 0 0   0 1   my $null = ($^O =~ m/mswin/i) ? 'NUL' : '/dev/null';
132             return
133             (
134 0           {'geneticCode' => [ "Universal","VertebratemtDNA","YeastmtDNA","Mold/ProtozoanmtDNA",
135             "InvertebratemtDNA","CiliateNuclear","EchinodermmtDNA","EuplotidNuclear",
136             "Alt.YeastNuclear","AscidianmtDNA","FlatwormmtDNA","BlepharismaNuclear"]},
137             {'New/Restore' => [ "New Analysis", "Restore"]},
138             {'tempalnfile' => undef }, # aln file goes here
139             {'Model Options' => [ { "Custom" => '010010' },
140             { "Default" => undef } ]
141             },
142             {'temptreefile' => undef }, # tree file goes here
143             {'Model Fit Results' => [ $null] }, # Windows have NUL instead of /dev/null
144             {'dN/dS bias parameter' => [ { "Estimate dN/dS only" => undef },
145             { "Neutral" => undef },
146             { "Estimate" => undef },
147             { "Estimate + CI" => undef },
148             { "User" => '3' } ] },
149             {'Ancestor Counting' => [ 'Two rate FEL','Single Ancestor Counting','Weighted Ancestor Counting',
150             'Sample Ancestal States','Process Sampled Ancestal States',
151             'One rate FEL','Rate Distribution',
152             'Full site-by-site LRT','Multirate FEL'] },
153             {'Significance level' => '0.05' },
154             {'Branch Options' => ['Internal Only','All','A Subtree only','Custom subset'] },
155             {'outfile' => undef }, # outfile goes here
156             );
157             }
158              
159              
160             =head2 new
161              
162             Title : new
163             Usage : my $obj = Bio::Tools::Run::Phylo::Hyphy::FEL->new();
164             Function: Builds a new Bio::Tools::Run::Phylo::Hyphy::FEL object
165             Returns : Bio::Tools::Run::Phylo::Hyphy::FEL
166             Args : -alignment => the Bio::Align::AlignI object
167             -save_tempfiles => boolean to save the generated tempfiles and
168             NOT cleanup after onesself (default FALSE)
169             -tree => the Bio::Tree::TreeI object
170             -params => a hashref of parameters (all passed to set_parameter)
171             -executable => where the hyphy executable resides
172              
173             See also: L, L
174              
175             =cut
176              
177             sub new {
178 0     0 1   my($class,@args) = @_;
179              
180 0           my $self = $class->SUPER::new(@args);
181 0           my ($aln, $tree, $st, $params, $exe,
182             $ubl) = $self->_rearrange([qw(ALIGNMENT TREE SAVE_TEMPFILES
183             PARAMS EXECUTABLE)],
184             @args);
185 0 0         defined $aln && $self->alignment($aln);
186 0 0         defined $tree && $self->tree($tree);
187 0 0         defined $st && $self->save_tempfiles($st);
188 0 0         defined $exe && $self->executable($exe);
189              
190 0           $self->set_default_parameters();
191 0 0         if( defined $params ) {
192 0 0         if( ref($params) !~ /HASH/i ) {
193 0           $self->warn("Must provide a valid hash ref for parameter -FLAGS");
194             } else {
195 0           map { $self->set_parameter($_, $$params{$_}) } keys %$params;
  0            
196             }
197             }
198 0           return $self;
199             }
200              
201              
202             =head2 run
203              
204             Title : run
205             Usage : my ($rc,$results) = $fel->run($aln);
206             Function: run the fel analysis using the default or updated parameters
207             the alignment parameter must have been set
208             Returns : Return code, Hash
209             Args : L object,
210             L object [optional]
211              
212              
213             =cut
214              
215             sub run {
216 0     0 1   my $self = shift;
217 0           my ($rc, $run_results) = $self->SUPER::run();
218 0           my $results ={};
219 0           my $outfile = $self->outfile_name();
220 0 0         open(OUTFILE, "$outfile") or $self->throw("cannot open $outfile for reading");
221 0           my $readed_header = 0;
222 0           my @elems;
223 0           while () {
224 0 0         if ($readed_header) {
225             # FEL results are csv
226 0           my @values = split("\,",$_);
227 0           for my $i (0 .. (scalar(@values)-1)) {
228 0           $elems[$i] =~ s/\n//g;
229 0           push @{$results->{$elems[$i]}}, $values[$i];
  0            
230             }
231             } else {
232 0           @elems = split("\,",$_);
233 0           $readed_header = 1;
234             }
235             }
236 0           return ($rc, $results);
237             }
238              
239              
240             =head2 create_wrapper
241              
242             Title : create_wrapper
243             Usage : $self->create_wrapper
244             Function: It will create the wrapper file that interfaces with the analysis bf file
245             Example :
246             Returns :
247             Args :
248              
249              
250             =cut
251              
252             sub create_wrapper {
253 0     0 1   my $self = shift;
254              
255 0           my $batchfile = "QuickSelectionDetection.bf";
256 0           $self->SUPER::create_wrapper($batchfile);
257             }
258              
259              
260             1;