Tools/Run/Phylo/PAML/Yn00.pm

filter: Statementstmt 27.6% 37 / 134 Branchbran 3.7% 2 / 54 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 55.0% 11 / 20 Podpod 100% 9 / 9 totaltotal 23.8% 59 / 247 SCAR 64.8
CC
34
Cov
19%
run
272.0
set_default_parameters
42.0
set_parameter
30.0
CRAP 649.9
« Tools/Phylo/PAML.pm ↑ Summary Tools/Run/Phylo/PAML/Codeml.pm »
1 package Bio::Tools::Run::Phylo::PAML::Yn00;
2 2 $Bio::Tools::Run::Phylo::PAML::Yn00::VERSION = '1.7.2';
3 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use vars qw(@ISA %VALIDVALUES $MINNAMELEN $PROGRAMNAME $PROGRAM);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Bio::AlignIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Bio::TreeIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Bio::Tools::Run::WrapperBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Bio::Tools::Phylo::PAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 @ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
16  
17 # ABSTRACT: Wrapper aroud the PAML program yn00
18 # AUTHOR: Jason Stajich <jason@bioperl.org>
19 # OWNER: Jason Stajich <jason@bioperl.org>
20 # LICENSE: Perl_5
21  
22  
23  
24 BEGIN {
25  
26 2 ▶ $MINNAMELEN = 25;
Subroutine BEGIN: called CC=3 SCAR=12.0
27 2 ▶ $PROGRAMNAME = 'yn00' . ($^O =~ /mswin/i ?'.exe':'');
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /mswin/i ? : 0 2 2
28 2 ▶ if( defined $ENV{'PAMLDIR'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"PAMLDIR"}) 0 2 2
29 0 $PROGRAM = Bio::Root::IO->catfile($ENV{'PAMLDIR'},$PROGRAMNAME);
30 }
31 # valid values for parameters, the default one is always
32 # the first one in the array
33 # much of the documentation here is lifted directly from the codeml.ctl
34 # example file provided with the package
35 %VALIDVALUES = (
36 2 'noisy' => [ 0..3,9],
37 'verbose' => [ 0,1,2], # 0:concise, 1:detailed, 2:too much
38  
39 'weighting' => [0,1], # weighting pathways between codons
40 'commonf3x4' => [0,1], # use same f3x4 for all sites
41  
42 # (icode) genetic code
43 # 0:universal code
44 # 1:mamalian mt
45 # 2:yeast mt
46 # 3:mold mt,
47 # 4:invertebrate mt
48 # 5:ciliate nuclear
49 # 6:echinoderm mt
50 # 7:euplotid mt
51 # 8:alternative yeast nu.
52 # 9:ascidian mt
53 #10:blepharisma nu
54 # these correspond to 1-11 in the genbank transl table
55  
56 'icode' => [ 0..10],
57 'ndata' => [1..10],
58 );
59 }
60  
61  
62  
63 sub program_name {
64 0 ▶ return $PROGRAMNAME;
Subroutine program_name: not called CC=1 SCAR=6.9
Pod documented
65 }
66  
67  
68 sub program_dir {
69 0 ▶ return Bio::Root::IO->catfile($ENV{PAMLDIR}) if $ENV{PAMLDIR};
Subroutine program_dir: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PAMLDIR"} 0 0 0
70 }
71  
72  
73 sub new {
74 0 ▶ my($class,@args) = @_;
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
75  
76 0 my $self = $class->SUPER::new(@args);
77 0 my ($aln,$st) = $self->_rearrange([qw(ALIGNMENT SAVE_TEMPFILES)],
78 @args);
79 0 ▶ defined $aln && $self->alignment($aln);
Branch: 1 branch
BranchTrueFalseTotal
defined $aln and $self->alignment($aln) 0 0 0
80 0 ▶ defined $st && $self->save_tempfiles($st);
Branch: 1 branch
BranchTrueFalseTotal
defined $st and $self->save_tempfiles($st) 0 0 0
81  
82 0 $self->set_default_parameters();
83 0 return $self;
84 }
85  
86  
87 sub run{
88 0 ▶ my ($self,$aln) = @_;
Subroutine run: not called CC=16 SCAR=56.1
Pod documented
89 0 ▶ ($aln) ||= $self->alignment();
Condition0%0/3
$aln ||= $self->alignment
l!l&&r!l&&!r
000
MC/DC0%0/2
$aln ||= $self->alignment
$aln $self->alignment
Truth table0%0/3
A ||= B
A= $alnB= $self->alignment
ABresult
1X1
011
000
90 0 ▶ if( ! $aln ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($aln) 0 0 0
91 0 $self->warn("must have supplied a valid alignment file in order to run yn00");
92 0 return 0;
93 }
94 0 my ($tmpdir) = $self->tempdir();
95 0 my ($tempseqFH,$tempseqfile);
96 0 ▶ if( ! ref($aln) && -e $aln ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $aln and -e $aln) { } 0 0 0
Condition0%0/3
not ref $aln and -e $aln
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $aln and -e $aln
not ref $aln -e $aln
Truth table0%0/3
not(A) and B
A= not ref $alnB= -e $aln
ABresult
0X0
100
111
97 0 $tempseqfile = $aln;
98 } else {
99 0 ▶ ($tempseqFH,$tempseqfile) = $self->io->tempfile
Branch: 1 branch
BranchTrueFalseTotal
$self->save_tempfiles ? : 0 0 0
100 ('-dir' => $tmpdir,
101 UNLINK => ($self->save_tempfiles ? 0 : 1));
102 0 ▶ my $alnout = Bio::AlignIO->new('-format' => 'phylip',
Branch: 1 branch
BranchTrueFalseTotal
$Bio::Tools::Run::Phylo::PAML::Yn00::MINNAMELEN > $aln->maxdisplayname_length ? : 0 0 0
103 '-fh' => $tempseqFH,
104 '-interleaved' => 0,
105 '-idlength' => $MINNAMELEN > $aln->maxdisplayname_length() ? $MINNAMELEN : $aln->maxdisplayname_length() +1);
106  
107 0 $alnout->write_aln($aln);
108 0 $alnout->close();
109 0 undef $alnout;
110 0 close($tempseqFH);
111 0 undef $tempseqFH;
112 }
113 # now let's print the yn.ctl file.
114 # many of the these programs are finicky about what the filename is
115 # and won't even run without the properly named file. Ack
116  
117 0 my $yn_ctl = "$tmpdir/yn00.ctl";
118 0 ▶ open(YN, ">$yn_ctl") or $self->throw("cannot open $yn_ctl for writing");
Branch: 1 branch
BranchTrueFalseTotal
open YN, ">$yn_ctl" or $self->throw("cannot open $yn_ctl for writing") 0 0 0
119 0 print YN "seqfile = $tempseqfile\n";
120  
121 0 my $outfile = $self->outfile_name;
122  
123 0 print YN "outfile = $outfile\n";
124 0 my %params = $self->get_parameters;
125 0 ▶ while( my ($param,$val) = each %params ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %params) 0 0 0
126 0 print YN "$param = $val\n";
127 }
128 0 close(YN);
129 0 my ($rc,$parser) = (1);
130 {
131 0 my $cwd = cwd();
132 0 my $exit_status;
133 0 chdir($tmpdir);
134 0 my $ynexe = $self->executable();
135 0 ▶ $self->throw("unable to find executable for 'yn'") unless $ynexe;
Branch: 1 branch
BranchTrueFalseTotal
unless $ynexe 0 0 0
136 0 open(RUN, "$ynexe |");
137 0 my @output = <RUN>;
138 0 $exit_status = close(RUN);
139 0 $self->error_string(join('',@output));
140 0 ▶ if( (grep { /\berr(or)?: /io } @output) || !$exit_status ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {/\berr(or)?: /io;} @output or not $exit_status) 0 0 0
Condition0%0/3
grep {/\berr(or)?: /io;} @output or not $exit_status
l!l&&r!l&&!r
000
MC/DC0%0/2
grep {/\berr(or)?: /io;} @output or not $exit_status
grep {/\berr(or)?: /io;} @output not $exit_status
Truth table0%0/3
A or not(B)
A= grep {/\berr(or)?: /io;} @outputB= not $exit_status
ABresult
1X1
011
000
141 0 $self->warn("There was an error - see error_string for the program output");
142 0 $rc = 0;
143 }
144 0 eval {
145 0 $parser = Bio::Tools::Phylo::PAML->new(-file => "$tmpdir/mlc",
146 -dir => "$tmpdir");
147  
148 };
149 0 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
150 0 $self->warn($self->error_string);
151 }
152 0 chdir($cwd);
153 }
154 0 ▶ if( $self->verbose > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose > 0) 0 0 0
155 0 open(IN, "$tmpdir/mlc");
156 0 ▶ while(<IN>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline IN)) 0 0 0
157 0 $self->debug($_);
158 }
159 }
160  
161 0 ▶ unless ( $self->save_tempfiles ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->save_tempfiles) 0 0 0
162 0 unlink("$yn_ctl");
163 0 $self->cleanup();
164 }
165 0 return ($rc,$parser);
166 }
167  
168  
169 sub error_string{
170 0 ▶ my ($self,$value) = @_;
Subroutine error_string: not called CC=2 SCAR=17.9
Pod documented
171 0 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
172 0 $self->{'error_string'} = $value;
173 }
174 0 return $self->{'error_string'};
175  
176 }
177  
178  
179 sub alignment{
180 0 ▶ my ($self,$aln) = @_;
Subroutine alignment: not called CC=4 SCAR=30.0
Pod documented
181 0 ▶ if( defined $aln ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $aln) 0 0 0
182 0 ▶ if( !ref($aln) || ! $aln->isa('Bio::Align::AlignI') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $aln and $aln->isa("Bio::Align::AlignI")) 0 0 0
Condition0%0/3
ref $aln and $aln->isa("Bio::Align::AlignI")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $aln and $aln->isa("Bio::Align::AlignI")
ref $aln $aln->isa("Bio::Align::AlignI")
Truth table0%0/3
A and B
A= ref $alnB= $aln->isa("Bio::Align::AlignI")
ABresult
0X0
100
111
183 0 $self->warn("Must specify a valid Bio::Align::AlignI object to the alignment function");
184 0 return undef;
185 }
186 0 $self->{'_alignment'} = $aln;
187 }
188 0 return $self->{'_alignment'};
189 }
190  
191  
192 sub get_parameters{
193 0 ▶ my ($self) = @_;
Subroutine get_parameters: not called CC=1 SCAR=6.9
Pod documented
194 # we're returning a copy of this
195 0 return %{ $self->{'_codemlparams'} };
196 }
197  
198  
199  
200 sub set_parameter{
201 0 ▶ my ($self,$param,$value) = @_;
Subroutine set_parameter: not called CC=5 SCAR=34.0
Pod documented
202 0 ▶ if( ! defined $VALIDVALUES{$param} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Bio::Tools::Run::Phylo::PAML::Yn00::VALIDVALUES{$param}) 0 0 0
203 0 $self->warn("unknown parameter $param will not set unless you force by setting no_param_checks to true");
204 0 return 0;
205 }
206 0 ▶ if( ref( $VALIDVALUES{$param}) =~ /ARRAY/i &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref($Bio::Tools::Run::Phylo::PAML::Yn00::VALIDVALUES{$param}) =~ /ARRAY/i and scalar @{$Bio::Tools::Run::Phylo::PAML::Yn00::VALIDVALUES{$param};} > 0) 0 0 0
Condition0%0/3
ref($Bio::Tools::Run::Phylo::PAML::Yn00::VALIDVALUES{$param}) =~ /ARRAY/i and scalar @{$Bio::Tools::Run::Phylo::PAML::Yn00::VALIDVALUES{$param};} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
ref($Bio::Tools::Run::Phylo::PAML::Yn00::VALIDVALUES{$param}) =~ /ARRAY/i and scalar @{$Bio::Tools::Run::Phylo::PAML::Yn00::VALIDVALUES{$param};} > 0
ref($Bio::Tools::Run::Phylo::PAML::Yn00::VALIDVALUES{$param}) =~ /ARRAY/i scalar @{$Bio::Tools::Run::Phylo::PAML::Yn00::VALIDVALUES{$param};} > 0
Truth table0%0/3
A and B
A= ref($Bio::Tools::Run::Phylo::PAML::Yn00::VALIDVALUES{$param}) =~ /ARRAY/iB= scalar @{$Bio::Tools::Run::Phylo::PAML::Yn00::VALIDVALUES{$param};} > 0
ABresult
0X0
100
111
207 0 scalar @{$VALIDVALUES{$param}} > 0 ) {
208  
209 0 ▶ unless ( grep {$value} @{ $VALIDVALUES{$param} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$value;} @{$Bio::Tools::Run::Phylo::PAML::Yn00::VALIDVALUES{$param};}) 0 0 0
210 0 $self->warn("parameter $param specified value $value is not recognized, please see the documentation and the code for this module or set the no_param_checks to a true value");
211 0 return 0;
212 }
213 }
214 0 $self->{'_codemlparams'}->{$param} = $value;
215 0 return 1;
216 }
217  
218  
219 sub set_default_parameters{
220 0 ▶ my ($self,$keepold) = @_;
Subroutine set_default_parameters: not called CC=6 SCAR=37.4
Pod documented
221 0 ▶ $keepold = 0 unless defined $keepold;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $keepold 0 0 0
222  
223 0 ▶ while( my ($param,$val) = each %VALIDVALUES ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %Bio::Tools::Run::Phylo::PAML::Yn00::VALIDVALUES) 0 0 0
224 # skip if we want to keep old values and it is already set
225 0 ▶ next if( defined $self->{'_codemlparams'}->{$param} && $keepold);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_codemlparams"}{$param} and $keepold 0 0 0
Condition0%0/3
defined $self->{"_codemlparams"}{$param} and $keepold
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"_codemlparams"}{$param} and $keepold
defined $self->{"_codemlparams"}{$param} $keepold
Truth table0%0/3
A and B
A= defined $self->{"_codemlparams"}{$param}B= $keepold
ABresult
0X0
100
111
226 0 ▶ if(ref($val)=~/ARRAY/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($val) =~ /ARRAY/i) { } 0 0 0
227 0 $self->{'_codemlparams'}->{$param} = $val->[0];
228 } else {
229 0 $self->{'_codemlparams'}->{$param} = $val;
230 }
231 }
232 }
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243 2 1;
244  
245 __END__
« Tools/Phylo/PAML.pm ↑ Summary Tools/Run/Phylo/PAML/Codeml.pm »