blib/lib/Bio/Tools/Run/Phylo/Phylip/DrawGram.pm

filter: Statementstmt 36.2% 46 / 127 Branchbran 24.0% 13 / 54 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 10 / 15 Podpod 100% 5 / 5 totaltotal 35.9% 74 / 206 CC 32 SCAR 36.9
CC
32
Cov
32%
_setparams
110.0
_run
72.0
_setinput
20.0
CRAP 40.2
« blib/lib/Bio/Tools/Run/Phylo/LVB.pm ↑ Summary blib/lib/Bio/Tools/Run/Alignment/MAFFT.pm »
1 # $Id $
2 #
3 # BioPerl module for Bio::Tools::Run::Phylo::Phylip::DrawGram
4 #
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 #
7 # Cared for by Jason Stajich <jason-AT-bioperl_DOT_org>
8 #
9 # Copyright Jason Stajich
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::Phylip::DrawGram - use Phylip DrawTree program to draw phylograms or phenograms
18  
19 =head1 SYNOPSIS
20  
21 use Bio::Tools::Run::Phylo::Phylip::DrawGram;
22  
23 my $drawfact = Bio::Tools::Run::Phylo::Phylip::DrawGram->new();
24 my $treeimage = $drawfact->run($tree);
25  
26 =head1 DESCRIPTION
27  
28 This is a module for automating drawing of trees through Joe
29 Felsenstein's Phylip suite.
30  
31 =head1 FEEDBACK
32  
33 =head2 Mailing Lists
34  
35 User feedback is an integral part of the evolution of this and other
36 Bioperl modules. Send your comments and suggestions preferably to
37 the Bioperl mailing list. Your participation is much appreciated.
38  
39 bioperl-l@bioperl.org - General discussion
40 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
41  
42 =head2 Support
43  
44 Please direct usage questions or support issues to the mailing list:
45  
46 I<bioperl-l@bioperl.org>
47  
48 rather than to the module maintainer directly. Many experienced and
49 reponsive experts will be able look at the problem and quickly
50 address it. Please include a thorough description of the problem
51 with code and data examples if at all possible.
52  
53 =head2 Reporting Bugs
54  
55 Report bugs to the Bioperl bug tracking system to help us keep track
56 of the bugs and their resolution. Bug reports can be submitted via the
57 web:
58  
59 http://redmine.open-bio.org/projects/bioperl/
60  
61 =head1 AUTHOR - Jason Stajich
62  
63 Email jason-at-bioperl.org
64  
65 =head1 APPENDIX
66  
67 The rest of the documentation details each of the object methods.
68 Internal methods are usually preceded with a _
69  
70 =cut
71  
72  
73 # Let the code begin...
74  
75  
76 package Bio::Tools::Run::Phylo::Phylip::DrawGram;
77 1 use vars qw($AUTOLOAD @ISA $PROGRAM $PROGRAMDIR $PROGRAMNAME
78 $FONTFILE @DRAW_PARAMS @OTHER_SWITCHES
79 1 ▶ %OK_FIELD %DEFAULT);
Subroutine BEGIN: called CC=1 SCAR=0.0
80 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 1 ▶use Bio::Tools::Run::Phylo::Phylip::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 1 ▶use Bio::Tools::Run::Phylo::Phylip::PhylipConf qw(%Menu);
Subroutine BEGIN: called CC=1 SCAR=0.0
83 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 # inherit from Phylip::Base which has some methods for dealing with
85 # Phylip specifics
86 1 @ISA = qw(Bio::Tools::Run::Phylo::Phylip::Base);
87  
88 # You will need to enable the neighbor program. This
89 # can be done in (at least) 3 ways:
90 #
91 # 1. define an environmental variable PHYLIPDIR:
92 # export PHYLIPDIR=/home/shawnh/PHYLIP/bin
93 #
94 # 2. include a definition of an environmental variable PHYLIPDIR in
95 # every script that will use DrawGram.pm.
96 # $ENV{PHYLIPDIR} = '/home/shawnh/PHYLIP/bin';
97 #
98 # 3. You can set the path to the program through doing:
99 # my @params('program'=>'/usr/local/bin/drawgram');
100 # my $neighbor_factory = Bio::Tools::Run::Phylo::Phylip::DrawGram->new(@params)
101  
102 BEGIN {
103 1 ▶ %DEFAULT = ('PLOTTER' => 'P',
Subroutine BEGIN: called CC=3 SCAR=11.0
104 'SCREEN' => 'N');
105 1 ▶ $DEFAULT{'FONTFILE'} = Bio::Root::IO->catfile($ENV{'PHYLIPDIR'},"font1") if $ENV{'PHYLIPDIR'};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PHYLIPDIR"} 0 1 1
106 1 $PROGRAMNAME = 'drawgram';
107  
108 1 @DRAW_PARAMS = qw(PLOTTER SCREEN TREESTYLE USEBRANCHLENS
109 LABEL_ANGLE HORIZMARGINS VERTICALMARGINS
110 SCALE TREEDEPTH STEMLEN TIPSPACE ANCESTRALNODES
111 FONT);
112 1 @OTHER_SWITCHES = qw(QUIET);
113 1 foreach my $attr(@DRAW_PARAMS,@OTHER_SWITCHES) {
114 14 $OK_FIELD{$attr}++;
115 }
116 }
117  
118 =head2 program_name
119  
120 Title : program_name
121 Usage : >program_name()
122 Function: holds the program name
123 Returns: string
124 Args : None
125  
126 =cut
127  
128 sub program_name {
129 6 ▶ return $PROGRAMNAME;
Subroutine program_name: called CC=1 SCAR=0.0
Pod documented
130 }
131  
132 =head2 program_dir
133  
134 Title : program_dir
135 Usage : ->program_dir()
136 Function: returns the program directory, obtained from ENV variable.
137 Returns: string
138 Args :
139  
140 =cut
141  
142 sub program_dir {
143 3 ▶ return Bio::Root::IO->catfile($ENV{PHYLIPDIR}) if $ENV{PHYLIPDIR};
Subroutine program_dir: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PHYLIPDIR"} 0 3 3
144 }
145  
146 =head2 new
147  
148 Title : new
149 Usage : my $obj = Bio::Tools::Run::Phylo::Phylip::DrawGram->new();
150 Function: Builds a new Bio::Tools::Run::Phylo::Phylip::DrawGram object
151 Returns : an instance of Bio::Tools::Run::Phylo::Phylip::DrawGram
152 Args : The available DrawGram parameters
153  
154  
155 =cut
156  
157 sub new {
158 1 ▶ my($class,@args) = @_;
Subroutine new: called CC=7 SCAR=20.2
Pod documented
159  
160 1 my $self = $class->SUPER::new(@args);
161
162 1 my ($attr, $value);
163
164 1 ▶ while (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 2 1 3
165 2 $attr = shift @args;
166 2 $value = shift @args;
167 2 ▶ next if( $attr =~ /^-/ ); # don't want named parameters
Branch: 1 branch
BranchTrueFalseTotal
if $attr =~ /^-/ 1 1 2
168 1 ▶ if ($attr =~/PROGRAM/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr =~ /PROGRAM/i) 0 1 1
169 0 $self->executable($value);
170 0 next;
171 }
172 1 $self->$attr($value);
173 }
174 1 ▶ $self->plotter($DEFAULT{'PLOTTER'}) unless $self->plotter;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->plotter 1 0 1
175 1 ▶ $self->screen($DEFAULT{'SCREEN'}) unless $self->screen;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->screen 1 0 1
176 1 ▶ $self->fontfile($DEFAULT{'FONTFILE'}) unless $self->fontfile;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->fontfile 1 0 1
177 1 return $self;
178 }
179  
180  
181 sub AUTOLOAD {
182 4 ▶ my $self = shift;
Subroutine AUTOLOAD: called CC=3 SCAR=11.0
183 4 my $attr = $AUTOLOAD;
184 4 $attr =~ s/.*:://;
185 4 $attr = uc $attr;
186 4 ▶ $self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless $Bio::Tools::Run::Phylo::Phylip::DrawGram::OK_FIELD{$attr} 0 4 4
187 4 ▶ $self->{$attr} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2 2 4
188 4 return $self->{$attr};
189 }
190  
191 =head2 run
192  
193 Title : run
194 Usage : my $file = $app->run($treefile);
195 Function: Draw a tree
196 Returns : File containing the rendered tree
197 Args : either a Bio::Tree::TreeI
198 OR
199 filename of a tree in newick format
200  
201 =cut
202  
203 sub run{
204 0 ▶ my ($self,$input) = @_;
Subroutine run: not called CC=2 SCAR=17.9
Pod documented
205
206 # Create input file pointer
207 0 my ($infilename) = $self->_setinput($input);
208 0 ▶ if (!$infilename) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($infilename) 0 0 0
209 0 $self->throw("Problems setting up for drawgram. Probably bad input data in $input !");
210 }
211  
212 # Create parameter string to pass to neighbor program
213 0 my $param_string = $self->_setparams();
214  
215 # run drawgram
216 0 my $plotfile = $self->_run($infilename,$param_string);
217 0 return $plotfile;
218 }
219  
220 =head2 draw_tree
221  
222 Title : draw_tree
223 Usage : my $file = $app->draw_tree($treefile);
224 Function: This method is deprecated. Please use run instead.
225 Returns : File containing the rendered tree
226 Args : either a Bio::Tree::TreeI
227 OR
228 filename of a tree in newick format
229  
230 =cut
231  
232 sub draw_tree{
233 0 ▶ return shift->run(@_);
Subroutine draw_tree: not called CC=1 SCAR=6.9
Pod documented
234 }
235  
236 =head2 _run
237  
238 Title : _run
239 Usage : Internal function, not to be called directly
240 Function: makes actual system call to drawgram program
241 Example :
242 Returns : Bio::Tree object
243 Args : Name of a file the tree to draw in newick format
244 and a parameter string to be passed to drawgram
245  
246  
247 =cut
248  
249 sub _run {
250 0 ▶ my ($self,$infile,$param_string) = @_;
Subroutine _run: not called CC=8 SCAR=42.8
251 0 my $instring;
252 0 my $curpath = cwd;
253 0 ▶ unless( File::Spec->file_name_is_absolute($infile) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("File::Spec"->file_name_is_absolute($infile)) 0 0 0
254 0 $infile = $self->io->catfile($curpath,$infile);
255 }
256 0 $instring = $infile . "\n";
257 0 ▶ if( ! defined $self->fontfile ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->fontfile) 0 0 0
258 0 $self->throw("You must have defined a fontfile");
259 }
260  
261 0 ▶ if( -e $self->io->catfile($curpath,'fontfile') ) {
Branch: 2 branches
BranchTrueFalseTotal
if (-e $self->io->catfile($curpath, 'fontfile')) { } 0 0 0
elsif ('File::Spec'->file_name_is_absolute($self->fontfile)) { } 0 0 0
262 0 $instring .= $self->io->catfile($curpath,'fontfile')."\n";
263 } elsif( File::Spec->file_name_is_absolute($self->fontfile) ) {
264 0 $instring .= $self->io->catfile($self->fontfile)."\n";
265 } else {
266 0 $instring .= $self->io->catfile($curpath,$self->fontfile)."\n";
267 }
268
269 0 chdir($self->tempdir);
270 0 $instring .= $param_string;
271 0 $self->debug( "Program ".$self->executable." $param_string\n");
272 # open a pipe to run drawgram to bypass interactive menus
273 0 ▶ if ($self->quiet() || $self->verbose() < 0) {
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
274 0 open(DRAW,"|".$self->executable.">/dev/null");
275 }
276 else {
277 0 open(DRAW,"|".$self->executable);
278 }
279 0 print DRAW $instring;
280 0 close(DRAW);
281 0 chdir($curpath);
282 #get the results
283 0 my $plotfile = $self->io->catfile($self->tempdir,$self->plotfile);
284
285 0 ▶ $self->throw("drawgram did not create plotfile correctly ($plotfile)")
Branch: 1 branch
BranchTrueFalseTotal
unless -e $plotfile 0 0 0
286 unless (-e $plotfile);
287 0 return $plotfile;
288 }
289  
290 =head2 _setinput()
291  
292 Title : _setinput
293 Usage : Internal function, not to be called directly
294 Function: Create input file for drawing program
295 Example :
296 Returns : filename containing tree in newick format
297 Args : Bio::Tree::TreeI object
298  
299  
300 =cut
301  
302 sub _setinput {
303 0 ▶ my ($self, $input) = @_;
Subroutine _setinput: not called CC=4 SCAR=30.0
304 0 my $treefile;
305 0 ▶ unless (ref $input) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $input) { } 0 0 0
(do { $input->isa("Bio::Tree::TreeI") }) 0 0 0
306 # check that file exists or throw
307 0 $treefile = $input;
308 0 ▶ unless (-e $input) {return 0;}
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $input) 0 0 0
309
310 0 } elsif ($input->isa("Bio::Tree::TreeI")) {
311 # Open temporary file for both reading & writing of BioSeq array
312 0 my $tfh;
313 0 ($tfh,$treefile) = $self->io->tempfile(-dir=>$self->tempdir);
314 0 my $treeIO = Bio::TreeIO->new(-fh => $tfh,
315 -format=>'newick');
316 0 $treeIO->write_tree($input);
317 0 $treeIO->close();
318 0 close($tfh);
319 0 $tfh = undef;
320 }
321 0 return $treefile;
322 }
323  
324 =head2 _setparams()
325  
326 Title : _setparams
327 Usage : Internal function, not to be called directly
328 Function: Create parameter inputs for drawgram program
329 Example :
330 Returns : parameter string to be passed to drawgram
331 Args : name of calling object
332  
333 =cut
334  
335 sub _setparams {
336 0 ▶ my ($attr, $value, $self);
Subroutine _setparams: not called CC=10 SCAR=47.0
337  
338 #do nothing for now
339 0 $self = shift;
340 0 my $param_string = "";
341 0 my $cat = 0;
342 0 my ($hmargin,$vmargin);
343 0 my %menu = %{$Menu{$self->version}->{'DRAWGRAM'}};
344 0 foreach my $attr ( @DRAW_PARAMS) {
345 0 $value = $self->$attr();
346 0 ▶ next unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
347 0 my @vals;
348 0 ▶ if( ref($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) 0 0 0
349 0 ($value,@vals) = @$value;
350 }
351 0 $attr = uc($attr);
352 0 ▶ if( ! exists $menu{$attr} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $menu{$attr}) 0 0 0
353 0 $self->warn("unknown parameter $attr, known params are ".
354 join(",",keys %menu). "\n");
355 }
356 0 ▶ if( ref ($menu{$attr}) !~ /HASH/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref($menu{$attr}) =~ /HASH/i) 0 0 0
357 0 ▶ unless( @vals ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vals) { } 0 0 0
358 0 $param_string .= $menu{$attr};
359 } else {
360 0 $param_string .= sprintf($menu{$attr},$value,@vals);
361 }
362 0 next;
363 }
364 0 my $seen = 0;
365 0 for my $stype ( keys %{$menu{$attr}} ) {
366 0 ▶ if( $value =~ /$stype/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /$stype/i) 0 0 0
367 0 $param_string .= sprintf($menu{$attr}->{$stype},@vals);
368 0 $seen = 1;
369 0 last;
370 }
371 }
372 0 ▶ unless( $seen ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seen) 0 0 0
373 0 $self->warn("Unknown requested attribute $attr, $value is not known\n");
374 }
375 }
376 0 $param_string .="Y\n";
377 0 return $param_string;
378 }
379  
380  
381 =head1 Bio::Tools::Run::Wrapper methods
382  
383 =cut
384  
385 =head2 no_param_checks
386  
387 Title : no_param_checks
388 Usage : $obj->no_param_checks($newval)
389 Function: Boolean flag as to whether or not we should
390 trust the sanity checks for parameter values
391 Returns : value of no_param_checks
392 Args : newvalue (optional)
393  
394  
395 =cut
396  
397 =head2 save_tempfiles
398  
399 Title : save_tempfiles
400 Usage : $obj->save_tempfiles($newval)
401 Function:
402 Returns : value of save_tempfiles
403 Args : newvalue (optional)
404  
405  
406 =cut
407  
408 =head2 outfile_name
409  
410 Title : outfile_name
411 Usage : my $outfile = $dragram->outfile_name();
412 Function: Get/Set the name of the output file for this run
413 (if you wanted to do something special)
414 Returns : string
415 Args : [optional] string to set value to
416  
417  
418 =cut
419  
420  
421 =head2 tempdir
422  
423 Title : tempdir
424 Usage : my $tmpdir = $self->tempdir();
425 Function: Retrieve a temporary directory name (which is created)
426 Returns : string which is the name of the temporary directory
427 Args : none
428  
429  
430 =cut
431  
432 =head2 cleanup
433  
434 Title : cleanup
435 Usage : $codeml->cleanup();
436 Function: Will cleanup the tempdir directory after a DrawGram run
437 Returns : none
438 Args : none
439  
440  
441 =cut
442  
443 =head2 io
444  
445 Title : io
446 Usage : $obj->io($newval)
447 Function: Gets a L<Bio::Root::IO> object
448 Returns : L<Bio::Root::IO>
449 Args : none
450  
451  
452 =cut
453  
454 1 1; # Needed to keep compiler happy
« blib/lib/Bio/Tools/Run/Phylo/LVB.pm ↑ Summary blib/lib/Bio/Tools/Run/Alignment/MAFFT.pm »