blib/lib/Bio/Tools/Run/Phylo/QuickTree.pm

filter: Statementstmt 32.5% 26 / 80 Branchbran 11.7% 4 / 34 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 50.0% 7 / 14 Podpod 100% 7 / 7 totaltotal 28.9% 44 / 152 CC 24 SCAR 29.7
CC
24
Cov
24%
_run
56.0
run
20.0
_setparams
20.0
CRAP 19.4
« blib/lib/Bio/Tools/Run/Coil.pm ↑ Summary blib/lib/Bio/Tools/Run/Pseudowise.pm »
1 # $Id$
2 #
3 # BioPerl module for Bio::Tools::Run::Phylo::QuickTree
4 #
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 #
7 # Cared for by Sendu Bala <bix@sendu.me.uk>
8 #
9 # Copyright Sendu Bala
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::QuickTree - Wrapper for rapid reconstruction of
18 phylogenies using QuickTree
19  
20 =head1 SYNOPSIS
21  
22 use Bio::Tools::Run::Phylo::QuickTree;
23  
24 # Make a QuickTree factory
25 @params = ();
26 $factory = Bio::Tools::Run::Phylo::QuickTree->new(@params);
27  
28 # Pass the factory an alignment
29 $inputfilename = 't/data/cysprot.stockholm';
30 $tree = $factory->run($inputfilename); # $tree is a Bio::Tree::Tree object.
31 # or get a Bio::Align::AlignI (SimpleAlign) object from somewhere
32 $tree = $factory->run($aln);
33  
34 =head1 DESCRIPTION
35  
36 This is a wrapper for running the QuickTree application by Kevin Howe. You
37 can download it here: http://www.sanger.ac.uk/Software/analysis/quicktree/
38  
39 Currently only input with alignments and output of trees is supported. (Ie.
40 no support for distance matrix in/out.)
41  
42 You will need to enable this QuickTree wrapper to find the quicktree program.
43 This can be done in (at least) three ways:
44  
45 1. Make sure the QuickTree executable is in your path.
46 2. Define an environmental variable QUICKTREEDIR which is a
47 directory which contains the 'quicktree' application:
48 In bash:
49  
50 export QUICKTREEDIR=/home/username/quicktree_1.1/bin
51  
52 In csh/tcsh:
53  
54 setenv QUICKTREEDIR /home/username/quicktree_1.1/bin
55  
56 3. Include a definition of an environmental variable QUICKTREEDIR in
57 every script that will use this QuickTree wrapper module, e.g.:
58  
59 BEGIN { $ENV{QUICKTREEDIR} = '/home/username/quicktree_1.1/bin' }
60 use Bio::Tools::Run::Phylo::QuickTree;
61  
62 =head1 FEEDBACK
63  
64 =head2 Mailing Lists
65  
66 User feedback is an integral part of the evolution of this and other
67 Bioperl modules. Send your comments and suggestions preferably to
68 the Bioperl mailing list. Your participation is much appreciated.
69  
70 bioperl-l@bioperl.org - General discussion
71 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
72  
73 =head2 Support
74  
75 Please direct usage questions or support issues to the mailing list:
76  
77 I<bioperl-l@bioperl.org>
78  
79 rather than to the module maintainer directly. Many experienced and
80 reponsive experts will be able look at the problem and quickly
81 address it. Please include a thorough description of the problem
82 with code and data examples if at all possible.
83  
84 =head2 Reporting Bugs
85  
86 Report bugs to the Bioperl bug tracking system to help us keep track
87 of the bugs and their resolution. Bug reports can be submitted via
88 the web:
89  
90 http://redmine.open-bio.org/projects/bioperl/
91  
92 =head1 AUTHOR - Sendu Bala
93  
94 Email bix@sendu.me.uk
95  
96 =head1 APPENDIX
97  
98 The rest of the documentation details each of the object methods.
99 Internal methods are usually preceded with a _
100  
101 =cut
102  
103 package Bio::Tools::Run::Phylo::QuickTree;
104 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
105  
106 1 ▶use Bio::AlignIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
107 1 ▶use Bio::TreeIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
108  
109 1 ▶use base qw(Bio::Tools::Run::WrapperBase);
Subroutine BEGIN: called CC=1 SCAR=0.0
110  
111 1 our $PROGRAM_NAME = 'quicktree';
112 1 our $PROGRAM_DIR = $ENV{'QUICKTREEDIR'};
113  
114 =head2 program_name
115  
116 Title : program_name
117 Usage : $factory>program_name()
118 Function: holds the program name
119 Returns : string
120 Args : None
121  
122 =cut
123  
124 sub program_name {
125 7 ▶ return $PROGRAM_NAME;
Subroutine program_name: called CC=1 SCAR=0.0
Pod documented
126 }
127  
128 =head2 program_dir
129  
130 Title : program_dir
131 Usage : $factory->program_dir(@params)
132 Function: returns the program directory, obtained from ENV variable.
133 Returns : string
134 Args : None
135  
136 =cut
137  
138 sub program_dir {
139 4 ▶ return $PROGRAM_DIR;
Subroutine program_dir: called CC=1 SCAR=0.0
Pod documented
140 }
141  
142 =head2 new
143  
144 Title : new
145 Usage : $factory = Bio::Tools::Run::Phylo::QuickTree->new(@params)
146 Function: creates a new QuickTree factory
147 Returns : Bio::Tools::Run::Phylo::QuickTree
148 Args : Optionally, provide any of the following (default in []):
149 -upgma => boolean # Use the UPGMA method to construct the tree [0]
150 -kimura => boolean # Use the kimura translation for pairwise
151 # distances [0]
152 -boot => int # Calculate bootstrap values with n iterations [0]
153  
154 =cut
155  
156 sub new {
157 1 ▶ my ($class, @args) = @_;
Subroutine new: called CC=6 SCAR=21.4
Pod documented
158 1 my $self = $class->SUPER::new(@args);
159
160 # for consistency with other run modules, allow params to be dashless
161 1 my %args = @args;
162 1 ▶ while (my ($key, $val) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 0 1 1
163 0 ▶ if ($key !~ /^-/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($key =~ /^-/) 0 0 0
164 0 delete $args{$key};
165 0 $args{'-'.$key} = $val;
166 }
167 }
168
169 1 my ($upgma, $kimura, $boot) = $self->_rearrange([qw(UPGMA
170 KIMURA
171 BOOT)], %args);
172
173 1 ▶ $self->upgma(1) if $upgma;
Branch: 1 branch
BranchTrueFalseTotal
if $upgma 0 1 1
174 1 ▶ $self->kimura(1) if $kimura;
Branch: 1 branch
BranchTrueFalseTotal
if $kimura 0 1 1
175 1 ▶ $self->boot($boot) if $boot;
Branch: 1 branch
BranchTrueFalseTotal
if $boot 0 1 1
176
177 1 return $self;
178 }
179  
180 =head2 upgma
181  
182 Title : upgma
183 Usage : $factory->upgma(1);
184 Function: Choose to use the UPGMA method to construct the tree.
185 Returns : boolean (default 0)
186 Args : None to get, boolean to set.
187  
188 =cut
189  
190 sub upgma {
191 0 ▶ my ($self, $bool) = @_;
Subroutine upgma: not called CC=3 SCAR=24.8
Pod documented
192 0 ▶ if (defined ($bool)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bool) 0 0 0
193 0 $self->{upgma} = $bool;
194 }
195 0 ▶ return $self->{upgma} || 0;
Condition0%0/2
$self->{'upgma'} || 0
l!l
00
MC/DC0%0/1
$self->{'upgma'} || 0
$self->{'upgma'}
Truth table0%0/2
A
A= $self->{'upgma'}
Aresult
11
00
196 }
197  
198 =head2 kimura
199  
200 Title : kimura
201 Usage : $factory->kimura(1);
202 Function: Choose to use the kimura translation for pairwise distances.
203 Returns : boolean (default 0)
204 Args : None to get, boolean to set.
205  
206 =cut
207  
208 sub kimura {
209 0 ▶ my ($self, $bool) = @_;
Subroutine kimura: not called CC=3 SCAR=24.8
Pod documented
210 0 ▶ if (defined ($bool)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bool) 0 0 0
211 0 $self->{kimura} = $bool;
212 }
213 0 ▶ return $self->{kimura} || 0;
Condition0%0/2
$self->{'kimura'} || 0
l!l
00
MC/DC0%0/1
$self->{'kimura'} || 0
$self->{'kimura'}
Truth table0%0/2
A
A= $self->{'kimura'}
Aresult
11
00
214 }
215  
216 =head2 boot
217  
218 Title : boot
219 Usage : $factory->boot(100);
220 Function: Choose to calculate bootstrap values with the supplied number of
221 iterations.
222 Returns : int (default 0)
223 Args : None to get, int to set.
224  
225 =cut
226  
227 sub boot {
228 0 ▶ my ($self, $int) = @_;
Subroutine boot: not called CC=3 SCAR=24.8
Pod documented
229 0 ▶ if (defined ($int)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $int) 0 0 0
230 0 $self->{boot} = $int;
231 }
232 0 ▶ return $self->{boot} || 0;
Condition0%0/2
$self->{'boot'} || 0
l!l
00
MC/DC0%0/1
$self->{'boot'} || 0
$self->{'boot'}
Truth table0%0/2
A
A= $self->{'boot'}
Aresult
11
00
233 }
234  
235 =head2 run
236  
237 Title : run
238 Usage : $factory->run($stockholm_file);
239 $factory->run($align_object);
240 Function: Runs QuickTree to generate a tree
241 Returns : Bio::Tree::Tree object
242 Args : file name for your input alignment in stockholm format, OR
243 Bio::Align::AlignI complient object (eg. Bio::SimpleAlign).
244  
245 =cut
246  
247 sub run {
248 0 ▶ my ($self, $in) = @_;
Subroutine run: not called CC=4 SCAR=30.0
Pod documented
249  
250 0 ▶ if (ref $in && $in->isa("Bio::Align::AlignI")) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $in and $in->isa('Bio::Align::AlignI')) { } 0 0 0
elsif (not -e $in) { } 0 0 0
Condition0%0/3
ref $in and $in->isa("Bio::Align::AlignI")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $in and $in->isa("Bio::Align::AlignI")
ref $in $in->isa("Bio::Align::AlignI")
Truth table0%0/3
A and B
A= ref $inB= $in->isa("Bio::Align::AlignI")
ABresult
0X0
100
111
251 0 $in = $self->_writeAlignFile($in);
252 }
253 elsif (! -e $in) {
254 0 $self->throw("When not supplying a Bio::Align::AlignI object, you must supply a readable filename");
255 }
256
257 0 return $self->_run($in);
258 }
259  
260 sub _run {
261 0 ▶ my ($self, $file)= @_;
Subroutine _run: not called CC=7 SCAR=40.3
262
263 0 ▶ my $exe = $self->executable || return;
Condition0%0/2
$self->executable || (return)
l!l
00
MC/DC0%0/1
$self->executable || (return)
$self->executable
Truth table0%0/2
A
A= $self->executable
Aresult
11
00
264 0 my $param_str = $self->arguments." ".$self->_setparams;
265 0 my $command = $exe." $param_str ".$file;
266
267 0 $self->debug("QuickTree command = $command");
268
269 0 ▶ open(my $result, "$command |") || $self->throw("QuickTree call ($command) crashed: $?");
Branch: 1 branch
BranchTrueFalseTotal
open my $result, "$command |" or $self->throw("QuickTree call ($command) crashed: $?") 0 0 0
270 0 my $treeio = Bio::TreeIO->new(-format => 'nhx', -fh => $result);
271 0 my $tree = $treeio->next_tree;
272 0 close($result);
273
274 # if bootstraps were enabled, the bootstraps are the ids; convert to
275 # bootstrap and no id
276 0 ▶ if ($self->boot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->boot) 0 0 0
277 0 my @nodes = $tree->get_nodes;
278 0 my %non_internal = map { $_ => 1 } ($tree->get_leaf_nodes, $tree->get_root_node);
279 0 foreach my $node (@nodes) {
280 0 ▶ next if exists $non_internal{$node};
Branch: 1 branch
BranchTrueFalseTotal
if exists $non_internal{$node} 0 0 0
281 0 ▶ $node->bootstrap && next; # protect ourselves incase the parser improves
Branch: 1 branch
BranchTrueFalseTotal
$node->bootstrap and next 0 0 0
282 0 $node->bootstrap($node->id);
283 0 $node->id('');
284 }
285 }
286
287 0 return $tree;
288 }
289  
290 =head2 _setparams
291  
292 Title : _setparams
293 Usage : Internal function, not to be called directly
294 Function: Creates a string of params to be used in the command string
295 Returns : string of params
296 Args : none
297  
298 =cut
299  
300 sub _setparams {
301 0 ▶ my $self = shift;
Subroutine _setparams: not called CC=4 SCAR=30.0
302 0 my $param_string = '-in a -out t';
303
304 0 ▶ $param_string .= ' -upgma' if $self->upgma;
Branch: 1 branch
BranchTrueFalseTotal
if $self->upgma 0 0 0
305 0 ▶ $param_string .= ' -kimura' if $self->kimura;
Branch: 1 branch
BranchTrueFalseTotal
if $self->kimura 0 0 0
306 0 ▶ $param_string .= ' -boot '.$self->boot if $self->boot;
Branch: 1 branch
BranchTrueFalseTotal
if $self->boot 0 0 0
307
308 0 return $param_string;
309 }
310  
311 =head2 _writeAlignFile
312  
313 Title : _writeAlignFile
314 Usage : obj->_writeAlignFile($seq)
315 Function: Internal(not to be used directly)
316 Returns : filename
317 Args : Bio::Align::AlignI
318  
319 =cut
320  
321 sub _writeAlignFile{
322 0 ▶ my ($self, $align) = @_;
Subroutine _writeAlignFile: not called CC=1 SCAR=6.9
323
324 0 my ($tfh, $tempfile) = $self->io->tempfile(-dir=>$self->tempdir);
325
326 0 my $out = Bio::AlignIO->new('-fh' => $tfh,
327 '-format' => 'stockholm');
328 0 $out->write_aln($align);
329 0 $out->close();
330 0 $out = undef;
331 0 close($tfh);
332 0 undef $tfh;
333 0 return $tempfile;
334 }
335  
336 1 1;
« blib/lib/Bio/Tools/Run/Coil.pm ↑ Summary blib/lib/Bio/Tools/Run/Pseudowise.pm »