Tools/Run/Phylo/Raxml.pm

filter: Statementstmt 39.3% 48 / 122 Branchbran 5.5% 2 / 36 Conditioncond 5.8% 1 / 17 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 66.6% 14 / 21 Podpod 100% 7 / 7 totaltotal 33.8% 72 / 213 CC 28 SCAR 35.0
CC
28
Cov
29%
_setparams
110.0
_run
42.0
run
20.0
CRAP 33.3
« DB/SoapEUtilities/FetchAdaptor/species.pm ↑ Summary Tools/Run/Phylo/Hyphy/Modeltest.pm »
1 #
2 # BioPerl module for Bio::Tools::Run::Phylo::Raxml
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Copyright Brian Osborne
7 #
8 # You may distribute this module under the same terms as perl itself
9 #
10 # POD documentation - main docs before the code
11  
12 =head1 NAME
13  
14 Bio::Tools::Run::Phylo::Raxml
15  
16 =head1 SYNOPSIS
17  
18 # Build a Raxml factory
19 $factory = Bio::Tools::Run::Phylo::Raxml->new(-p => 100);
20  
21 # Get an alignment
22 my $alignio = Bio::AlignIO->new(
23 -format => 'fasta',
24 -file => '219877.cdna.fasta');
25 my $alnobj = $alignio->next_aln;
26  
27 # Analyze the aligment and get a Tree
28 my $tree = $factory->run($alnobj);
29  
30 =head1 DESCRIPTION
31  
32 Get a Bio::Tree object using raxml given a protein or DNA alignment.
33  
34 =head1 FEEDBACK
35  
36 =head2 Mailing Lists
37  
38 User feedback is an integral part of the evolution of this and other
39 Bioperl modules. Send your comments and suggestions preferably to one
40 of the Bioperl mailing lists. Your participation is much appreciated.
41  
42 bioperl-l@bioperl.org - General discussion
43 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
44  
45 =head2 Support
46  
47 Please direct usage questions or support issues to the mailing list:
48  
49 I<bioperl-l@bioperl.org>
50  
51 Do not contact the module maintainer directly. Many experienced experts
52 at bioperl-l will be able look at the problem and quickly
53 address it. Please include a thorough description of the problem
54 with code and data examples if at all possible.
55  
56 =head2 Reporting Bugs
57  
58 Report bugs to the Bioperl bug tracking system to help us keep track
59 the bugs and their resolution. Bug reports can be submitted via the web:
60  
61 http://redmine.open-bio.org/projects/bioperl/
62  
63 =head1 AUTHOR - Brian Osborne
64  
65 Email briano@bioteam.net
66  
67 =head1 APPENDIX
68  
69 The rest of the documentation details each of the object
70 methods. Internal methods are usually preceded with a _
71  
72 =cut
73  
74 package Bio::Tools::Run::Phylo::Raxml;
75  
76 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
77 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
78 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
79 1 ▶use Bio::Seq;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 1 ▶use Bio::SeqIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 1 ▶use Bio::TreeIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 1 ▶use Bio::AlignIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
83 1 ▶use Bio::Root::IO;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 1 ▶use base qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 1 our @Raxml_PARAMS =
89 qw(s n m a A b B c e E f g G i I J o p P q r R S t T w W x z N);
90 1 our @Raxml_SWITCHES =
91 qw(SSE3 PTHREADS PTHREADS-SSE3 HYBRID HYBRID-SSE3 F h k K M j U v X y C d D);
92 1 our $PROGRAM_NAME = 'raxml';
93  
94 # Specify some model if none is specified
95 1 my $DEFAULTAAMODEL = 'PROTCATDAYHOFF';
96 1 my $DEFAULTNTMODEL = 'GTRCAT';
97  
98 =head2 new
99  
100 Title : new
101 Usage : my $treebuilder = Bio::Tools::Run::Phylo::Raxml->new();
102 Function: Constructor
103 Returns : Bio::Tools::Run::Phylo::Raxml
104 Args : Same as those used to run raxml. For example:
105  
106 $factory = Bio::Tools::Run::Phylo::Raxml->new(-p => 100, -SSE3 => 1)
107  
108 =cut
109  
110 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.2
Pod documented
111 1 my ( $class, @args ) = @_;
112 1 my $self = $class->SUPER::new(@args);
113  
114 1 $self->_set_from_args(
115 \@args,
116 -case_sensitive => 1,
117 -methods => [ @Raxml_PARAMS, @Raxml_SWITCHES ],
118 -create => 1
119 );
120  
121 1 my ($out,$quiet) = $self->SUPER::_rearrange( [qw(OUTFILE_NAME QUIET)], @args );
122  
123 1 ▶ $self->outfile_name( $out || '' );
Condition50%1/2
$out || ''
l!l
01
MC/DC0%0/1
$out || ''
$out
Truth table50%1/2
A
A= $out
Aresult
11
00
124 1 ▶ $self->quiet( $quiet ) if $quiet;
Branch: 1 branch
BranchTrueFalseTotal
if $quiet 1 0 1
125  
126 1 $self;
127 }
128  
129 =head2 program_name
130  
131 Title : program_name
132 Usage : $factory->program_name()
133 Function: holds the program name
134 Returns: string
135 Args : None
136  
137 =cut
138  
139 6 ▶sub program_name {
Subroutine program_name: called CC=1 SCAR=0.0
Pod documented
140 6 $PROGRAM_NAME;
141 }
142  
143 =head2 program_dir
144  
145 Title : program_dir
146 Usage : $factory->program_dir(@params)
147 Function: returns the program directory
148 Returns: string
149 Args :
150  
151 =cut
152  
153 3 ▶sub program_dir {
Subroutine program_dir: called CC=1 SCAR=0.0
Pod documented
154 3 undef;
155 }
156  
157 =head2 error_string
158  
159 Title : error_string
160 Usage : $obj->error_string($newval)
161 Function: Where the output from the last analysus run is stored.
162 Returns : value of error_string
163 Args : newvalue (optional)
164  
165 =cut
166  
167 0 ▶sub error_string {
Subroutine error_string: not called CC=2 SCAR=17.9
Pod documented
168 0 my ( $self, $value ) = @_;
169
170 0 ▶ $self->{'error_string'} = $value if ( defined $value );
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 0 0 0
171 0 $self->{'error_string'};
172 }
173  
174 =head2 version
175  
176 Title : version
177 Usage : exit if $prog->version() < 1.8
178 Function: Determine the version number of the program
179 Example :
180 Returns : float or undef
181 Args : none
182  
183 =cut
184  
185 0 ▶sub version {
Subroutine version: not called CC=3 SCAR=24.8
Pod documented
186 0 my ($self) = @_;
187 0 my $exe;
188  
189 0 ▶ return undef unless $exe = $self->executable;
Branch: 1 branch
BranchTrueFalseTotal
unless $exe = $self->executable 0 0 0
190 0 my $string = `$exe -v 2>&1`;
191  
192 0 $string =~ /raxml\s+version\s+([\d\.]+)/i;
193 0 ▶ return $1 || undef;
Condition0%0/2
$1 || undef
l!l
00
MC/DC0%0/1
$1 || undef
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
194 }
195  
196 =head2 quiet
197  
198 Title : quiet
199 Usage :
200 Function: get or set value for 'quiet'
201 Example :
202 Returns :
203 Args : the value
204  
205 =cut
206  
207 1 ▶sub quiet {
Subroutine quiet: called CC=2 SCAR=7.1
Pod documented
208 1 my ( $self, $value ) = @_;
209
210 1 ▶ $self->{'_quiet'} = $value if ( defined $value );
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 1 0 1
211 1 $self->{'_quiet'};
212 }
213  
214 =head2 run
215  
216 Title : run
217 Usage : $factory->run($stockholm_file) OR
218 $factory->run($align_object)
219 Function: Runs Raxml to generate a tree
220 Returns : Bio::Tree::Tree object
221 Args : File name for your input alignment in stockholm format, OR
222 Bio::Align::AlignI compliant object (eg. Bio::SimpleAlign).
223  
224 =cut
225  
226 0 ▶sub run {
Subroutine run: not called CC=4 SCAR=30.0
Pod documented
227 0 my ($self, $in) = @_;
228  
229 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
230 0 $in = $self->_write_alignfile($in);
231 }
232 elsif (! -e $in) {
233 0 $self->throw("When not supplying a Bio::Align::AlignI object, you must supply a readable filename");
234 }
235  
236 0 $self->_run($in);
237 }
238  
239 =head2 _run
240  
241 Title : _run
242 Usage : Internal function, not to be called directly
243 Function: Runs the application
244 Returns : Tree object
245 Args : Alignment file name
246  
247 =cut
248  
249 0 ▶sub _run {
Subroutine _run: not called CC=6 SCAR=37.4
250 0 my ( $self, $file ) = @_;
251  
252 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
253 0 my $param_str = $self->arguments . " " . $self->_setparams($file);
254 0 my $command = "$exe $param_str";
255 0 $self->debug("Raxml command = $command");
256  
257 0 my $status = system($command);
258
259 # raxml creates tree files with names like "RAxML_bestTree.ABDBxjjdfg3"
260 # if rapid bootstrapping was enabled, also a tree with RAxML_bipartitions.ABDBxjjdfg3
261 # with support values is created, which then should be returned
262 0 ▶ my $outfile = $self->f() eq 'a' ? 'RAxML_bipartitions.' : 'RAxML_bestTree.';
Branch: 1 branch
BranchTrueFalseTotal
$self->f eq 'a' ? : 0 0 0
263 0 $outfile .= $self->outfile_name;
264  
265 0 ▶ $outfile = File::Spec->catfile( ($self->w), $outfile ) if $self->w;
Branch: 1 branch
BranchTrueFalseTotal
if $self->w 0 0 0
266  
267 0 ▶ if ( !-e $outfile || -z $outfile ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -e $outfile or -z $outfile) 0 0 0
Condition0%0/3
not -e $outfile or -z $outfile
l!l&&r!l&&!r
000
MC/DC0%0/2
not -e $outfile or -z $outfile
not -e $outfile -z $outfile
Truth table0%0/3
not(A) or B
A= not -e $outfileB= -z $outfile
ABresult
1X1
011
000
268 0 $self->warn("Raxml call had status of $status: $? [command $command] \n");
269 0 return undef;
270 }
271  
272 0 my $treeio = Bio::TreeIO->new( -file => $outfile );
273 0 my $tree = $treeio->next_tree;
274  
275 # if bootstraps were enabled, the bootstraps are the ids; convert to
276 # bootstrap and no id
277 # if ($self->boot) {
278 # my @nodes = $tree->get_nodes;
279 # my %non_internal = map { $_ => 1 } ($tree->get_leaf_nodes, $tree->get_root_node);
280 # foreach my $node (@nodes) {
281 # next if exists $non_internal{$node};
282 # $node->bootstrap && next; # protect ourselves incase the parser improves
283 # $node->bootstrap($node->id);
284 # $node->id('');
285 # }
286 # }
287  
288 0 $tree;
289 }
290  
291 =head2 _write_alignfile
292  
293 Title : _write_alignfile
294 Usage : Internal function, not to be called directly
295 Function: Create an alignment file
296 Returns : filename
297 Args : Bio::Align::AlignI
298  
299 =cut
300  
301 0 ▶sub _write_alignfile {
Subroutine _write_alignfile: not called CC=2 SCAR=17.9
302 0 my ( $self, $align ) = @_;
303  
304 0 my ( $tfh, $tempfile ) = $self->io->tempfile( -dir => '.' );
305  
306 0 my $out = Bio::AlignIO->new(
307 -file => ">$tempfile",
308 -format => 'phylip'
309 );
310 0 $out->write_aln($align);
311 0 $out->close();
312 0 undef($out);
313 0 close($tfh);
314 0 undef($tfh);
315  
316 0 ▶ die "Alignment file $tempfile was not created" if ( ! -e $tempfile );
Branch: 1 branch
BranchTrueFalseTotal
unless -e $tempfile 0 0 0
317  
318 0 $tempfile;
319 }
320
321 =head2 _alphabet
322  
323 Title : _alphabet
324 Usage : my $alphabet = $self->_alphabet;
325 Function: Get the alphabet of the input alignment, defaults to 'dna'
326 Returns : 'dna' or 'protein'
327 Args : Alignment file
328  
329 =cut
330  
331 0 ▶sub _alphabet {
Subroutine _alphabet: not called CC=4 SCAR=30.0
332 0 my ( $self, $file ) = @_;
333  
334 0 ▶ if ($file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file) 0 0 0
335 0 ▶ if ( -e $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $file) { } 0 0 0
336 0 my $in = Bio::AlignIO->new( -file => $file );
337 0 my $aln = $in->next_aln;
338  
339 # arbitrary, the first one
340 0 my $seq = $aln->get_seq_by_pos(1);
341 0 my $alphabet = $seq->alphabet;
342 0 $self->{_alphabet} = $alphabet;
343 }
344 else {
345 0 die "File $file can not be found";
346 }
347 }
348  
349 # default is 'dna'
350 0 ▶ return $self->{'_alphabet'} || 'dna';
Condition0%0/2
$self->{'_alphabet'} || 'dna'
l!l
00
MC/DC0%0/1
$self->{'_alphabet'} || 'dna'
$self->{'_alphabet'}
Truth table0%0/2
A
A= $self->{'_alphabet'}
Aresult
11
00
351 }
352  
353 =head2 _setparams
354  
355 Title : _setparams
356 Usage : Internal function, not to be called directly
357 Function: Create parameter inputs for Raxml program
358 Example :
359 Returns : parameter string to be passed to Raxml
360 Args : name of calling object
361  
362 =cut
363  
364 0 ▶sub _setparams {
Subroutine _setparams: not called CC=10 SCAR=47.0
365 0 my ( $self, $infile ) = @_;
366 0 my $param_string = '';
367  
368 # If 'model' is not set with '-m' check the alphabet of the input,
369 # then specify the default model
370 0 ▶ if ( !$self->m ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->m) 0 0 0
371 0 ▶ my $model =
Branch: 1 branch
BranchTrueFalseTotal
$self->_alphabet($infile) eq 'dna' ? : 0 0 0
372 ( $self->_alphabet($infile) eq 'dna' )
373 ? $DEFAULTNTMODEL
374 : $DEFAULTAAMODEL;
375 0 $self->m($model);
376 }
377  
378 # Set default output file if no explicit output file has been given.
379 # Raxml insists that the output file name not contain '/' and its
380 # output directory is set using the '-w' argument.
381 0 ▶ if ( !$self->outfile_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->outfile_name) 0 0 0
382 0 my $dir = getcwd();
383 0 $self->w($dir);
384  
385 0 my ( $tfh, $outfile ) = $self->io->tempfile( -dir => $dir );
386 0 close($tfh);
387 0 undef $tfh;
388 0 $outfile = basename($outfile);
389 0 $self->outfile_name($outfile);
390 }
391  
392 0 for my $attr (@Raxml_PARAMS) {
393 0 my $value = $self->$attr();
394 0 ▶ next unless ( defined $value );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
395 0 $param_string .= ' -' . $attr . ' ' . $value . ' ';
396 }
397  
398 0 for my $attr (@Raxml_SWITCHES) {
399 0 my $value = $self->$attr();
400 0 ▶ next unless ($value);
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 0 0
401 0 $param_string .= ' -' . $attr . ' ';
402 }
403  
404 0 $param_string .= "-s $infile -n " . $self->outfile_name;
405  
406 0 my $null = File::Spec->devnull();
407 0 ▶ $param_string .= " > $null 2> $null"
Branch: 1 branch
BranchTrueFalseTotal
if $self->quiet or $self->verbose < 0 0 0 0
Condition0%0/3
$self->quiet or $self->verbose < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->quiet or $self->verbose < 0
$self->quiet $self->verbose < 0
Truth table0%0/3
A or B
A= $self->quietB= $self->verbose < 0
ABresult
1X1
011
000
408 if ( $self->quiet() || $self->verbose < 0 );
409  
410 0 $param_string;
411 }
412  
413 =head1 Bio::Tools::Run::BaseWrapper methods
414  
415 =cut
416  
417 =head2 no_param_checks
418  
419 Title : no_param_checks
420 Usage : $obj->no_param_checks($newval)
421 Function: Boolean flag as to whether or not we should
422 trust the sanity checks for parameter values
423 Returns : value of no_param_checks
424 Args : newvalue (optional)
425  
426 =cut
427  
428 =head2 save_tempfiles
429  
430 Title : save_tempfiles
431 Usage : $obj->save_tempfiles($newval)
432 Function:
433 Returns : value of save_tempfiles
434 Args : newvalue (optional)
435  
436 =cut
437  
438 =head2 outfile_name
439  
440 Title : outfile_name
441 Usage : my $outfile = $Raxml->outfile_name();
442 Function: Get/Set the name of the output file for this run
443 (if you wanted to do something special)
444 Returns : string
445 Args : [optional] string to set value to
446  
447 =cut
448  
449 =head2 tempdir
450  
451 Title : tempdir
452 Usage : my $tmpdir = $self->tempdir();
453 Function: Retrieve a temporary directory name (which is created)
454 Returns : string which is the name of the temporary directory
455 Args : none
456  
457 =cut
458  
459 =head2 cleanup
460  
461 Title : cleanup
462 Usage : $Raxml->cleanup();
463 Function: Will cleanup the tempdir directory
464 Returns : none
465 Args : none
466  
467 =cut
468  
469 =head2 io
470  
471 Title : io
472 Usage : $obj->io($newval)
473 Function: Gets a L<Bio::Root::IO> object
474 Returns : L<Bio::Root::IO>
475 Args : none
476  
477 =cut
478  
479 1 1; # Needed to keep compiler happy
480  
481 __END__
« DB/SoapEUtilities/FetchAdaptor/species.pm ↑ Summary Tools/Run/Phylo/Hyphy/Modeltest.pm »