1 # $Id: Semphy.pm,v 1.3 2007/05/25 10:14:55 sendu Exp $
3 # BioPerl module for Bio::Tools::Run::Phylo::Semphy
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::Semphy - Wrapper for Semphy
21 use Bio::Tools::Run::Phylo::Semphy;
23 # Make a Semphy factory
24 $factory = Bio::Tools::Run::Phylo::Semphy->new();
26 # Run Semphy with an alignment
27 my $tree = $factory->run($alignfilename);
29 # or with alignment object
30 $tree = $factory->run($bio_simplalign);
32 # you can supply an initial tree as well, which can be a newick tree file,
33 # Bio::Tree::Tree object...
34 $tree = $factory->run($bio_simplalign, $tree_obj);
36 # ... or Bio::DB::Taxonomy object
37 $tree = $factory->run($bio_simplalign, $bio_db_taxonomy);
39 # (mixtures of all the above are possible)
41 # $tree isa Bio::Tree::Tree
45 This is a wrapper for running the Semphy application by N. Friedman et a.. You
46 can get details here: http://compbio.cs.huji.ac.il/semphy/. Semphy is used for
47 phylogenetic reconstruction (making a tree with branch lengths from an aligned
48 set of input sequences).
50 You can try supplying normal Semphy command-line arguments to new(), eg.
51 new(-hky => 1) or calling arg-named methods (excluding the initial hyphen(s),
52 eg. $factory->hky(1) to set the --hky switch to true).
53 Note that Semphy args are case-sensitive. To distinguish between Bioperl's
54 -verbose and the Semphy's --verbose, you must set Semphy's verbosity with
55 -semphy_verbose or the semphy_verbose() method.
58 You will need to enable this Semphy wrapper to find the Semphy program.
59 This can be done in (at least) three ways:
61 1. Make sure the Semphy executable is in your path.
62 2. Define an environmental variable SEMPHYDIR which is a
63 directory which contains the Semphy application:
66 export SEMPHYDIR=/home/username/semphy/
70 setenv SEMPHYDIR /home/username/semphy
72 3. Include a definition of an environmental variable SEMPHYDIR in
73 every script that will use this Semphy wrapper module, e.g.:
75 BEGIN { $ENV{SEMPHYDIR} = '/home/username/semphy/' }
76 use Bio::Tools::Run::Phylo::Semphy;
82 User feedback is an integral part of the evolution of this and other
83 Bioperl modules. Send your comments and suggestions preferably to
84 the Bioperl mailing list. Your participation is much appreciated.
86 bioperl-l@bioperl.org - General discussion
87 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
91 Please direct usage questions or support issues to the mailing list:
93 I<bioperl-l@bioperl.org>
95 rather than to the module maintainer directly. Many experienced and
96 reponsive experts will be able look at the problem and quickly
97 address it. Please include a thorough description of the problem
98 with code and data examples if at all possible.
100 =head2 Reporting Bugs
102 Report bugs to the Bioperl bug tracking system to help us keep track
103 of the bugs and their resolution. Bug reports can be submitted via
106 http://redmine.open-bio.org/projects/bioperl/
108 =head1 AUTHOR - Sendu Bala
110 Email bix@sendu.me.uk
114 The rest of the documentation details each of the object methods.
115 Internal methods are usually preceded with a _
119 package Bio
::Tools
::Run
::Phylo
::Semphy
;
126 use base
qw(Bio::Tools::Run::Phylo::PhyloBase);
128 our $PROGRAM_NAME = 'semphy';
129 our $PROGRAM_DIR = $ENV{'SEMPHYDIR'};
131 # methods for the semphy args we support
132 our %PARAMS = (outputfile
=> 'o',
133 treeoutputfile
=> 'T',
141 BPrepeats
=> 'BPrepeats',
142 BPconsensus
=> 'BPconsensus',
144 modelfile
=> 'modelfile',
147 semphy_verbose
=> 'semphy_verbose');
148 our %SWITCHES = (homogeneousRatesDTME
=> 'homogeneousRatesDTME',
150 pairwiseGammaDTME
=> 'pairwiseGammaDTME',
151 commonAlphaDTME
=> 'commonAlphaDTME',
152 rate4siteDTME
=> 'rate4siteDTME',
153 posteriorDTME
=> 'posteriorDTME',
154 BPonUserTree
=> 'BPonUserTree',
165 optimizeAlpha
=> 'O',
169 PerPosPosterior
=> 'B',
172 # just to be explicit, args we don't support (yet) or we handle ourselves
173 our @UNSUPPORTED = qw(h help full-help s sequence t tree);
179 Usage : $factory>program_name()
180 Function: holds the program name
187 return $PROGRAM_NAME;
193 Usage : $factory->program_dir(@params)
194 Function: returns the program directory, obtained from ENV variable.
207 Usage : $factory = Bio::Tools::Run::Phylo::Semphy->new()
208 Function: creates a new Semphy factory
209 Returns : Bio::Tools::Run::Phylo::Semphy
210 Args : Most options understood by Semphy can be supplied as key =>
211 value pairs, with a true value for switches.
213 These options can NOT be used with this wrapper (they are handled
214 internally or don't make sense in this context):
215 -h | --help | --fill-help
219 To distinguish between Bioperl's -verbose and the Semphy's --verbose,
220 you must set Semphy's verbosity with -semphy_verbose
225 my ($class, @args) = @_;
226 my $self = $class->SUPER::new
(@args);
228 $self->_set_from_args(\
@args, -methods
=> {(map { $_ => $PARAMS{$_} } keys %PARAMS),
229 (map { $_ => $SWITCHES{$_} } keys %SWITCHES),
232 -case_sensitive
=> 1);
240 Usage : $result = $factory->run($fasta_align_file);
242 $result = $factory->run($align_object);
244 $result = $factory->run($fasta_align_file, $newick_tree_file);
246 $result = $factory->run($align_object, $tree_object);
248 $result = $factory->run($align_object, $db_taxonomy_object);
249 Function: Runs Semphy on an alignment.
250 Returns : Bio::Tree::Tree
251 Args : The first argument represents an alignment, the second (optional)
252 argument a species tree (to set an initial tree: normally the -t
254 The alignment can be provided as a multi-fasta format alignment
255 filename, or a Bio::Align::AlignI compliant object (eg. a
257 The species tree can be provided as a newick format tree filename
258 or a Bio::Tree::TreeI compliant object. Alternatively a
259 Bio::DB::Taxonomy object can be supplied, in which case the species
260 tree will be generated by using the alignment sequence names as
261 species names and looking for those in the supplied database.
263 In all cases where an initial tree was supplied, the alignment
264 sequence names must correspond to node ids in the species tree.
269 my ($self, $aln, $tree) = @_;
271 $aln || $self->throw("alignment must be supplied");
272 $self->_alignment($aln);
277 # check node and seq names match
287 my $exe = $self->executable || return;
289 my $aln_file = $self->_write_alignment;
291 # generate a semphy-friendly tree file
292 my $tree = $self->_tree;
295 $tree = $self->_write_tree;
299 my ($tfh, $tempfile) = $self->io->tempfile(-dir
=> $self->tempdir);
304 my $command = $exe.$self->_setparams($aln_file, $tree_file);
305 $self->debug("semphy command = $command\n");
307 open(my $pipe, "$command |") || $self->throw("semphy call ($command) failed to start: $? | $!");
310 print unless $self->quiet;
313 close($pipe) || ($error ?
$self->warn("semphy call ($command) failed: $error") : $self->throw("semphy call ($command) crashed: $?"));
315 my $result_file = $self->T();
316 my $tio = Bio
::TreeIO
->new(-format
=> 'newick', -file
=> $result_file);
317 my $result_tree = $tio->next_tree;
325 Usage : Internal function, not to be called directly
326 Function: Creates a string of params to be used in the command string
327 Returns : string of params
328 Args : alignment and tree file names
333 my ($self, $aln_file, $tree_file) = @_;
335 my $param_string = ' -s '.$aln_file;
336 $param_string .= ' -t '.$tree_file if $tree_file;
338 my %methods = map { $_ => $_ } keys %PARAMS;
339 $methods{'semphy_verbose'} = 'verbose';
340 $param_string .= $self->SUPER::_setparams
(-params
=> \
%methods,
341 -switches
=> [keys %SWITCHES],
344 $param_string .= ' 2>&1';
345 $param_string .= ' 1>/dev/null' if $self->quiet;
347 return $param_string;