3 # BioPerl module for Bio::Tools::Run::Phylo::QuickTree
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Sendu Bala <bix@sendu.me.uk>
11 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
17 Bio::Tools::Run::Phylo::QuickTree - Wrapper for rapid reconstruction of
18 phylogenies using QuickTree
22 use Bio::Tools::Run::Phylo::QuickTree;
24 # Make a QuickTree factory
26 $factory = Bio::Tools::Run::Phylo::QuickTree->new(@params);
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);
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/
39 Currently only input with alignments and output of trees is supported. (Ie.
40 no support for distance matrix in/out.)
42 You will need to enable this QuickTree wrapper to find the quicktree program.
43 This can be done in (at least) three ways:
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:
50 export QUICKTREEDIR=/home/username/quicktree_1.1/bin
54 setenv QUICKTREEDIR /home/username/quicktree_1.1/bin
56 3. Include a definition of an environmental variable QUICKTREEDIR in
57 every script that will use this QuickTree wrapper module, e.g.:
59 BEGIN { $ENV{QUICKTREEDIR} = '/home/username/quicktree_1.1/bin' }
60 use Bio::Tools::Run::Phylo::QuickTree;
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.
70 bioperl-l@bioperl.org - General discussion
71 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
75 Please direct usage questions or support issues to the mailing list:
77 I<bioperl-l@bioperl.org>
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.
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
90 http://redmine.open-bio.org/projects/bioperl/
92 =head1 AUTHOR - Sendu Bala
98 The rest of the documentation details each of the object methods.
99 Internal methods are usually preceded with a _
103 package Bio
::Tools
::Run
::Phylo
::QuickTree
;
109 use base
qw(Bio::Tools::Run::WrapperBase);
111 our $PROGRAM_NAME = 'quicktree';
112 our $PROGRAM_DIR = $ENV{'QUICKTREEDIR'};
117 Usage : $factory>program_name()
118 Function: holds the program name
125 return $PROGRAM_NAME;
131 Usage : $factory->program_dir(@params)
132 Function: returns the program directory, obtained from ENV variable.
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
152 -boot => int # Calculate bootstrap values with n iterations [0]
157 my ($class, @args) = @_;
158 my $self = $class->SUPER::new
(@args);
160 # for consistency with other run modules, allow params to be dashless
162 while (my ($key, $val) = each %args) {
165 $args{'-'.$key} = $val;
169 my ($upgma, $kimura, $boot) = $self->_rearrange([qw(UPGMA
173 $self->upgma(1) if $upgma;
174 $self->kimura(1) if $kimura;
175 $self->boot($boot) if $boot;
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.
191 my ($self, $bool) = @_;
192 if (defined ($bool)) {
193 $self->{upgma
} = $bool;
195 return $self->{upgma
} || 0;
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.
209 my ($self, $bool) = @_;
210 if (defined ($bool)) {
211 $self->{kimura
} = $bool;
213 return $self->{kimura
} || 0;
219 Usage : $factory->boot(100);
220 Function: Choose to calculate bootstrap values with the supplied number of
222 Returns : int (default 0)
223 Args : None to get, int to set.
228 my ($self, $int) = @_;
229 if (defined ($int)) {
230 $self->{boot
} = $int;
232 return $self->{boot
} || 0;
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 compliant object (eg. Bio::SimpleAlign).
248 my ($self, $in) = @_;
250 if (ref $in && $in->isa("Bio::Align::AlignI")) {
251 $in = $self->_writeAlignFile($in);
254 $self->throw("When not supplying a Bio::Align::AlignI object, you must supply a readable filename");
257 return $self->_run($in);
261 my ($self, $file)= @_;
263 my $exe = $self->executable || return;
264 my $param_str = $self->arguments." ".$self->_setparams;
265 my $command = $exe." $param_str ".$file;
267 $self->debug("QuickTree command = $command");
269 open(my $result, "$command |") || $self->throw("QuickTree call ($command) crashed: $?");
270 my $treeio = Bio
::TreeIO
->new(-format
=> 'nhx', -fh
=> $result);
271 my $tree = $treeio->next_tree;
274 # if bootstraps were enabled, the bootstraps are the ids; convert to
275 # bootstrap and no id
277 my @nodes = $tree->get_nodes;
278 my %non_internal = map { $_ => 1 } ($tree->get_leaf_nodes, $tree->get_root_node);
279 foreach my $node (@nodes) {
280 next if exists $non_internal{$node};
281 $node->bootstrap && next; # protect ourselves incase the parser improves
282 $node->bootstrap($node->id);
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
302 my $param_string = '-in a -out t';
304 $param_string .= ' -upgma' if $self->upgma;
305 $param_string .= ' -kimura' if $self->kimura;
306 $param_string .= ' -boot '.$self->boot if $self->boot;
308 return $param_string;
311 =head2 _writeAlignFile
313 Title : _writeAlignFile
314 Usage : obj->_writeAlignFile($seq)
315 Function: Internal(not to be used directly)
317 Args : Bio::Align::AlignI
322 my ($self, $align) = @_;
324 my ($tfh, $tempfile) = $self->io->tempfile(-dir
=>$self->tempdir);
326 my $out = Bio
::AlignIO
->new('-fh' => $tfh,
327 '-format' => 'stockholm');
328 $out->write_aln($align);