Tools/Phylo/PAML.pm

filter: Statementstmt 87.2% 741 / 849 Branchbran 78.0% 423 / 542 Conditioncond 68.3% 110 / 161 MC/DCmcdc 46.8% 45 / 96 Subroutinesub 94.4% 34 / 36 Podpod 100% 2 / 2 totaltotal 80.3% 1355 / 1686 SCAR 69.3
CC
343
Cov
82%
_parse_rate_parametes
110.0
_parse_rst
83.1
_parse_NSsitesBatch
72.3
CRAP 1019.2
« Tools/Run/Phylo/PAML/Evolver.pm ↑ Summary Tools/Run/Phylo/PAML/Yn00.pm »
1 package Bio::Tools::Phylo::PAML;
2 7 $Bio::Tools::Phylo::PAML::VERSION = '1.7.2';
3 7 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 ▶use vars qw($RSTFILENAME);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 ▶use base qw(Bio::Root::Root Bio::Root::IO Bio::AnalysisParserI);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 7 ▶use IO::String;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use Bio::TreeIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 7 ▶use Bio::Tools::Phylo::PAML::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 7 ▶use Bio::LocatableSeq;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 7 ▶use Bio::PrimarySeq;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 7 ▶use Bio::Matrix::PhylipDist;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 7 ▶use Bio::Tools::Phylo::PAML::ModelResult;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # ABSTRACT: Parses output from the PAML programs codeml, baseml, basemlg, codemlsites and yn00
21 # AUTHOR: Jason Stajich <jason@bioperl.org>
22 # AUTHOR: Aaron Mackey <amackey@virginia.edu>
23 # OWNER: Jason Stajich <jason@bioperl.org>
24 # OWNER: Aaron Mackey <amackey@virginia.edu>
25 # LICENSE: Perl_5
26  
27 # AUTHOR: Albert Vilella <avilella@gmail.com>
28 # AUTHOR: Sendu Bala <bix@sendu.me.uk>
29 # AUTHOR: Dave Messina <dmessina@cpan.org>
30  
31  
32 BEGIN {
33 7 ▶ $RSTFILENAME = 'rst'; # where to get the RST data from
Subroutine BEGIN: called CC=1 SCAR=0.0
34 }
35  
36  
37 sub new {
38  
39 21 ▶ my ( $class, @args ) = @_;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
40  
41 21 my $self = $class->SUPER::new(@args);
42 21 $self->_initialize_io(@args);
43 21 my ($dir) = $self->_rearrange( [qw(DIR)], @args );
44 21 ▶ $self->{_dir} = $dir if defined $dir;
Branch: 1 branch
BranchTrueFalseTotal
if defined $dir 1 20 21
45 21 return $self;
46 }
47  
48  
49  
50 sub next_result {
51  
52 20 ▶ my ($self) = @_;
Subroutine next_result: called CC=39 SCAR=38.6
Pod documented
53 20 my %data;
54  
55 # parse the RST file, if it doesn't exist or if dir is not set
56 # this will just skip the parsing
57 20 $self->_parse_rst();
58 20 my $idlookup; # a hashreference to SEQID (number) ==> 'SEQUENCENAME'
59 # get the various codon and other sequence summary data, if necessary:
60 $self->_parse_summary
61 20 ▶ unless ( $self->{'_summary'} && !$self->{'_summary'}->{'multidata'} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_summary"} and not $self->{"_summary"}{"multidata"} 20 0 20
Condition33%1/3
$self->{"_summary"} and not $self->{"_summary"}{"multidata"}
!ll&&!rl&&r
2000
MC/DC0%0/2
$self->{"_summary"} and not $self->{"_summary"}{"multidata"}
$self->{"_summary"} not $self->{"_summary"}{"multidata"}
Truth table33%1/3
A and not(B)
A= $self->{"_summary"}B= not $self->{"_summary"}{"multidata"}
ABresult
0X0
100
111
62  
63 # OK, depending on seqtype and runmode now, one of a few things can happen:
64 20 my $seqtype = $self->{'_summary'}->{'seqtype'};
65 20 ▶ if ( $seqtype eq 'CODONML' || $seqtype eq 'AAML' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($seqtype eq 'CODONML' or $seqtype eq 'AAML') { } 16 4 20
elsif ($seqtype eq 'BASEML') { } 2 2 4
elsif ($seqtype eq 'YN00') { } 2 0 2
Condition100%3/3
$seqtype eq "CODONML" or $seqtype eq "AAML"
l!l&&r!l&&!r
1424
MC/DC100%2/2
$seqtype eq "CODONML" or $seqtype eq "AAML"
$seqtype eq "CODONML" $seqtype eq "AAML"
Truth table100%3/3
A or B
A= $seqtype eq "CODONML"B= $seqtype eq "AAML"
ABresult
1X1
011
000
66 16 my $has_model_line = 0;
67 16 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 73 8 81
68 73 ▶ if ( $seqtype eq 'CODONML'
Branch: 8 branches
BranchTrueFalseTotal
if ($seqtype eq 'CODONML' and /^pairwise comparison, codon frequencies:/) { } 8 65 73
elsif ($seqtype eq 'AAML' and /^ML distances of aa seqs\.$/) { } 1 64 65
elsif (/^Model\s+(\d+)/ or not $has_model_line and /^TREE/ and $seqtype eq 'CODONML' and not $self->{'_summary'}{'version'} =~ /4/) { } 9 55 64
elsif (/for each branch/) { } 2 53 55
elsif (/^TREE/) { } 3 50 53
elsif (/Heuristic tree search by stepwise addition$/) { } 0 50 50
elsif (/Heuristic tree search by NNI perturbation$/) { } 0 50 50
elsif (/^stage 0:/) { } 0 50 50
Condition100%3/3
$seqtype eq "CODONML" and /^pairwise comparison, codon frequencies:/
!ll&&!rl&&r
2638
MC/DC100%2/2
$seqtype eq "CODONML" and /^pairwise comparison, codon frequencies:/
$seqtype eq "CODONML" /^pairwise comparison, codon frequencies:/
Truth table100%3/3
A and B
A= $seqtype eq "CODONML"B= /^pairwise comparison, codon frequencies:/
ABresult
0X0
100
111
69 && m/^pairwise comparison, codon frequencies:/ )
70 {
71  
72 # runmode = -2, CODONML
73 8 $self->debug("pairwise Ka/Ks\n");
74 8 $self->_pushback($_);
75 8 %data = $self->_parse_PairwiseCodon;
76 8 last;
77 }
78 ▶ elsif ( $seqtype eq 'AAML' && m/^ML distances of aa seqs\.$/ ) {
Condition100%3/3
$seqtype eq "AAML" and /^ML distances of aa seqs\.$/
!ll&&!rl&&r
6311
MC/DC100%2/2
$seqtype eq "AAML" and /^ML distances of aa seqs\.$/
$seqtype eq "AAML" /^ML distances of aa seqs\.$/
Truth table100%3/3
A and B
A= $seqtype eq "AAML"B= /^ML distances of aa seqs\.$/
ABresult
0X0
100
111
79 1 $self->_pushback($_);
80  
81 # get AA distances
82 1 %data = ( '-AAMLdistmat' => $self->_parse_aa_dists() );
83  
84 # $self->_pushback($_);
85 # %data = $self->_parse_PairwiseAA;
86 # last;
87 }
88 ▶ elsif (
Condition100%12/12
/^Model\s+(\d+)/ or not $has_model_line and /^TREE/ and $seqtype eq "CODONML" and not $self->{"_summary"}{"version"} =~ /4/
l!l&&r!l&&!r
7255
not $has_model_line and /^TREE/ and $seqtype eq "CODONML" and not $self->{"_summary"}{"version"} =~ /4/
!ll&&!rl&&r
5322
not $has_model_line and /^TREE/ and $seqtype eq "CODONML"
!ll&&!rl&&r
5214
not $has_model_line and /^TREE/
!ll&&!rl&&r
5475
MC/DC100%5/5
/^Model\s+(\d+)/ or not $has_model_line and /^TREE/ and $seqtype eq "CODONML" and not $self->{"_summary"}{"version"} =~ /4/
/^Model\s+(\d+)/ not $has_model_line /^TREE/ $seqtype eq "CODONML" not $self->{"_summary"}{"version"} =~ /4/
Truth table100%6/6
A or not(B) and C and D and not(E)
A= /^Model\s+(\d+)/B= not $has_model_lineC= /^TREE/D= $seqtype eq "CODONML"E= not $self->{"_summary"}{"version"} =~ /4/
ABCDEresult
1XXXX1
011111
00XXX0
010XX0
0110X0
011100
89 m/^Model\s+(\d+)/
90 || ( ( !$has_model_line && m/^TREE/ )
91 && $seqtype eq 'CODONML'
92 && ($self->{'_summary'}->{'version'} !~ /4/))
93 # last bit to keep PAML >= 4 from being caught here
94 # bug 2482. Not sure this is the right fix, but tests
95 # pass and the bug's test case passes.
96 )
97 {
98 9 $self->_pushback($_);
99 9 my $model = $self->_parse_NSsitesBatch;
100 9 push @{ $data{'-NSsitesresults'} }, $model;
101 9 $has_model_line = 1;
102 }
103 elsif (m/for each branch/) {
104 2 my %branch_dnds = $self->_parse_branch_dnds;
105 2 ▶ if ( !defined $data{'-trees'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data{"-trees"}) 0 2 2
106 0 $self->warn(
107 "No trees have been loaded, can't do anything\n");
108 0 next;
109 }
110 2 my ($tree) = @{ $data{'-trees'} };
111 2 ▶ if ( !$tree
Branch: 1 branch
BranchTrueFalseTotal
unless ($tree and ref $tree and $tree->isa("Bio::Tree::Tree")) 0 2 2
Condition33%2/6
$tree and ref $tree and $tree->isa("Bio::Tree::Tree")
!ll&&!rl&&r
002
$tree and ref $tree
!ll&&!rl&&r
002
MC/DC0%0/3
$tree and ref $tree and $tree->isa("Bio::Tree::Tree")
$tree ref $tree $tree->isa("Bio::Tree::Tree")
Truth table25%1/4
A and B and C
A= $treeB= ref $treeC= $tree->isa("Bio::Tree::Tree")
ABCresult
0XX0
10X0
1100
1111
112 || !ref($tree)
113 || !$tree->isa('Bio::Tree::Tree') )
114 {
115 0 $self->warn("no tree object already stored!\n");
116 0 next;
117 }
118  
119 # These need to be added to the Node/branches
120 2 ▶ while ( my ( $k, $v ) = each %branch_dnds ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %branch_dnds) 22 2 24
121  
122 # we can probably do better by caching at some point
123 22 my @nodes;
124 22 for my $id ( split( /\.\./, $k ) ) {
125 my @nodes_L =
126 98 map { $tree->find_node( -id => $_ ) }
127 44 @{ $idlookup->{$id} };
128 44 ▶ my $n =
Branch: 1 branch
BranchTrueFalseTotal
@nodes_L < 2 ? : 14 30 44
129 @nodes_L < 2
130 ? shift(@nodes_L)
131 : $tree->get_lca(@nodes_L);
132 44 ▶ if ( !$n ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($n) 0 44 44
133 0 $self->warn("no node for $n\n");
134 }
135 44 ▶ unless ( $n->is_Leaf && $n->id ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($n->is_Leaf and $n->id) 30 14 44
Condition66%2/3
$n->is_Leaf and $n->id
!ll&&!rl&&r
30014
MC/DC50%1/2
$n->is_Leaf and $n->id
$n->is_Leaf $n->id
Truth table66%2/3
A and B
A= $n->is_LeafB= $n->id
ABresult
0X0
100
111
136 30 $n->id($id);
137 }
138 44 push @nodes, $n;
139 }
140 22 my ( $parent, $child ) = @nodes;
141 22 ▶ while ( my ( $kk, $vv ) = each %$v ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$v) 198 22 220
142 198 $child->add_tag_value( $kk, $vv );
143 }
144 }
145 }
146 elsif (m/^TREE/) {
147  
148 # runmode = 0
149 3 $self->_pushback($_);
150 3 ( $data{'-trees'}, $idlookup ) = $self->_parse_Forestry;
151  
152 #last;
153 }
154 elsif (m/Heuristic tree search by stepwise addition$/) {
155  
156 # runmode = 3
157 0 $self->throw(
158 -class => 'Bio::Root::NotImplemented',
159 -text => "StepwiseAddition not yet implemented!"
160 );
161  
162 # $self->_pushback($_);
163 # %data = $self->_parse_StepwiseAddition;
164 # last;
165  
166 }
167 elsif (m/Heuristic tree search by NNI perturbation$/) {
168  
169 # runmode = 4
170 0 $self->throw(
171 -class => 'Bio::Root::NotImplemented',
172 -text => "NNI Perturbation not yet implemented!"
173 );
174  
175 # $self->_pushback($_);
176 # %data = $self->_parse_Perturbation;
177 # last;
178  
179 }
180 elsif (m/^stage 0:/) {
181  
182 # runmode = (1 or 2)
183 0 $self->throw(
184 -class => 'Bio::Root::NotImplemented',
185 -text => "StarDecomposition not yet implemented!"
186 );
187  
188 0 $self->_pushback($_);
189 0 %data = $self->_parse_StarDecomposition;
190 0 last;
191 }
192 }
193 }
194 elsif ( $seqtype eq 'BASEML' ) {
195 2 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 3 2 5
196 3 ▶ if (/^Distances:/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^Distances:/) { } 2 1 3
elsif (/^TREE/) { } 1 0 1
197 2 $self->_pushback($_);
198 2 my ( $kappa, $alpha ) = $self->_parse_nt_dists();
199 2 %data = (
200 '-kappa_distmat' => $kappa,
201 '-alpha_distmat' => $alpha
202 );
203 }
204 elsif (/^TREE/) {
205 1 $self->_pushback($_);
206 1 ( $data{'-trees'}, $idlookup ) = $self->_parse_Forestry;
207 }
208 }
209 }
210 elsif ( $seqtype eq 'YN00' ) {
211 2 ▶ while ( $_ = $self->_readline ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ = $self->_readline) 3 0 3
212 3 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (/^Estimation by the method|\(B\) Yang & Nielsen \(2000\) method/) 2 1 3
213 m/^Estimation by the method|\(B\) Yang & Nielsen \(2000\) method/
214 )
215 {
216 2 $self->_pushback($_);
217 2 %data = $self->_parse_YN_Pairwise;
218 2 last;
219 }
220 }
221 }
222 20 ▶ if (%data) {
Branch: 1 branch
BranchTrueFalseTotal
if (%data) { } 20 0 20
223 20 $data{'-version'} = $self->{'_summary'}->{'version'};
224 20 $data{'-seqs'} = $self->{'_summary'}->{'seqs'};
225 20 $data{'-patterns'} = $self->{'_summary'}->{'patterns'};
226 20 $data{'-ngmatrix'} = $self->{'_summary'}->{'ngmatrix'};
227 20 $data{'-codonpos'} = $self->{'_summary'}->{'codonposition'};
228 20 $data{'-codonfreq'} = $self->{'_summary'}->{'codonfreqs'};
229 20 $data{'-model'} = $self->{'_summary'}->{'model'};
230 20 $data{'-seqfile'} = $self->{'_summary'}->{'seqfile'};
231 20 $data{'-aadistmat'} = $self->{'_summary'}->{'aadistmat'};
232 20 $data{'-stats'} = $self->{'_summary'}->{'stats'};
233 20 $data{'-aafreq'} = $self->{'_summary'}->{'aafreqs'};
234 20 $data{'-ntfreq'} = $self->{'_summary'}->{'ntfreqs'};
235 20 $data{'-input_params'} = $self->{'_summary'}->{'inputparams'};
236 20 $data{'-rst'} = $self->{'_rst'}->{'rctrted_seqs'};
237 20 $data{'-rst_persite'} = $self->{'_rst'}->{'persite'};
238 20 $data{'-rst_trees'} = $self->{'_rst'}->{'trees'};
239 20 return Bio::Tools::Phylo::PAML::Result->new(%data);
240 }
241 else {
242 0 return;
243 }
244 }
245  
246 sub _parse_summary {
247 20 ▶ my ($self) = @_;
Subroutine _parse_summary: called CC=23 SCAR=32.2
248  
249 # Depending on whether verbose > 0 or not, and whether the result
250 # set comes from a multi-data run, the first few lines could be
251 # various things; we're going to throw away any sequence data
252 # here, since we'll get it later anyways
253  
254 # multidata ? : \n\nData set 1\n
255 # verbose ? : cleandata ? : \nBefore deleting alignment gaps. \d sites\n
256 # [ sequence printout ]
257 # \nAfter deleting gaps. \d sites\n"
258 # : [ sequence printout ]
259 # CODONML (in paml 3.12 February 2002) <<-- what we want to see!
260  
261 20 my $SEQTYPES = qr( (?: (?: CODON | AA | BASE | CODON2AA ) ML ) | YN00 )x;
262 20 my $line;
263 20 ▶ $self->{'_already_parsed_seqs'} = $self->{'_already_parsed_seqs'} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_already_parsed_seqs'} ? : 0 20 20
264 20 my @lines;
265 20 ▶ while ( $_ = $self->_readline ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ = $self->_readline) 185 0 185
266 185 push @lines, $_;
267 185 ▶ if (m/^($SEQTYPES) \s+ # seqtype: CODONML, AAML, BASEML, CODON2AAML, YN00, etc
Branch: 6 branches
BranchTrueFalseTotal
if (/^($SEQTYPES) \s+ # seqtype: CODONML, AAML, BASEML, CODON2AAML, YN00, etc (?: \(in \s+ ([^\)]+?) \s* \) \s* )? # version: "paml 3.12 February 2002"; not present < 3.1 or YN00 (\S+) \s* # tree filename (?: (.+?) )? # model description (not there in YN00) \s* $ # trim any trailing space /ox) { } 20 165 185
elsif (/\s+?\d+?\s+?\d+?/ and $self->{'_already_parsed_seqs'} != 1) { } 6 159 165
elsif (/^Data set \d$/) { } 1 158 159
elsif (/^Before\s+deleting\s+alignment\s+gaps/) { } 0 158 158
elsif (@lines >= 3 and $self->{'_already_parsed_seqs'} != 1) { } 5 153 158
elsif (/Printing out site pattern counts/ and $self->{'_already_parsed_seqs'} != 1) { } 0 300 300
268 (?: \(in \s+ ([^\)]+?) \s* \) \s* )? # version: "paml 3.12 February 2002"; not present < 3.1 or YN00
269 (\S+) \s* # tree filename
270 (?: (.+?) )? # model description (not there in YN00)
271 \s* $ # trim any trailing space
272 /ox
273 )
274 {
275 20 @{ $self->{'_summary'} }{qw(seqtype version seqfile model)} =
276 ( $1, $2, $3, $4 );
277  
278 # in 4.3, the model is on its own line
279 20 ▶ if ( !defined $self->{'_summary'}->{'model'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_summary"}{"model"}) 8 12 20
280 8 my $model_line = $self->_readline;
281 8 chomp $model_line;
282 8 ▶ if ($model_line =~ /^Model:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($model_line =~ /^Model:/) 6 2 8
283 6 $self->{'_summary'}->{'model'} = $model_line;
284 }
285 }
286  
287 defined $self->{'_summary'}->{'model'}
288 20 ▶ && $self->{'_summary'}->{'model'} =~ s/Model:\s+//;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"_summary"}{"model"} and $self->{"_summary"}{"model"} =~ s/Model:\s+// 18 2 20
289 $self->_pushback($_)
290 20 ▶ if $self->{'_summary'}->{'seqtype'} eq 'AAMODEL';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_summary"}{"seqtype"} eq "AAMODEL" 0 20 20
291 20 last;
292 }
293 ▶ elsif ((m/\s+?\d+?\s+?\d+?/) && ( $self->{'_already_parsed_seqs'} != 1 )) {
Condition100%3/3
/\s+?\d+?\s+?\d+?/ and $self->{"_already_parsed_seqs"} != 1
!ll&&!rl&&r
108516
MC/DC100%2/2
/\s+?\d+?\s+?\d+?/ and $self->{"_already_parsed_seqs"} != 1
/\s+?\d+?\s+?\d+?/ $self->{"_already_parsed_seqs"} != 1
Truth table100%3/3
A and B
A= /\s+?\d+?\s+?\d+?/B= $self->{"_already_parsed_seqs"} != 1
ABresult
0X0
100
111
294 6 $self->_parse_seqs;
295 }
296 elsif (m/^Data set \d$/) {
297 1 $self->{'_summary'} = {};
298 1 $self->{'_summary'}->{'multidata'}++;
299 }
300 elsif (m/^Before\s+deleting\s+alignment\s+gaps/) { #Gap
301 0 my ($phylip_header) = $self->_readline;
302 0 $self->_parse_seqs;
303 }
304 ▶ elsif ( ( @lines >= 3 ) && ( $self->{'_already_parsed_seqs'} != 1 ) )
Condition100%3/3
@lines >= 3 and $self->{"_already_parsed_seqs"} != 1
!ll&&!rl&&r
191345
MC/DC100%2/2
@lines >= 3 and $self->{"_already_parsed_seqs"} != 1
@lines >= 3 $self->{"_already_parsed_seqs"} != 1
Truth table100%3/3
A and B
A= @lines >= 3B= $self->{"_already_parsed_seqs"} != 1
ABresult
0X0
100
111
305 { #No gap
306 # don't start parsing seqs yet if we're on a blank line
307 # (gives another opportunity to match one of the other regexes)
308 5 ▶ unless (/^\n$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/^\n$/) 2 3 5
309 2 $self->_parse_seqs;
310 }
311 }
312 ▶ elsif ( (/Printing out site pattern counts/)
Condition66%2/3
/Printing out site pattern counts/ and $self->{"_already_parsed_seqs"} != 1
!ll&&!rl&&r
14760
MC/DC0%0/2
/Printing out site pattern counts/ and $self->{"_already_parsed_seqs"} != 1
/Printing out site pattern counts/ $self->{"_already_parsed_seqs"} != 1
Truth table66%2/3
A and B
A= /Printing out site pattern counts/B= $self->{"_already_parsed_seqs"} != 1
ABresult
0X0
100
111
313 && ( $self->{'_already_parsed_seqs'} != 1 ) ) {
314 0 $self->_parse_patterns;
315 }
316 }
317  
318 20 ▶ unless ( defined $self->{'_summary'}->{'seqtype'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_summary"}{"seqtype"}) 0 20 20
319 0 $self->throw(
320 -class => 'Bio::Root::NotImplemented',
321 -text => 'Unknown format of PAML output did not see seqtype'
322 );
323 }
324 20 my $seqtype = $self->{'_summary'}->{'seqtype'};
325 20 ▶ if ( $seqtype eq "CODONML" ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($seqtype eq 'CODONML') { } 14 6 20
elsif ($seqtype eq 'AAML') { } 2 4 6
elsif ($seqtype eq 'CODON2AAML') { } 0 4 4
elsif ($seqtype eq 'BASEML') { } 2 2 4
elsif ($seqtype eq 'YN00') { } 2 0 2
326 14 $self->_parse_inputparams(); # settings from the .ctl file
327 # that get printed
328 14 $self->_parse_patterns(); # codon patterns - not very interesting
329 14 $self->_parse_seqs(); # the sequences data used for analysis
330 14 $self->_parse_codoncts(); # counts and distributions of codon/nt
331 # usage
332 14 $self->_parse_codon_freqs(); # codon frequencies
333 14 $self->_parse_distmat(); # NG distance matrices
334 }
335 elsif ( $seqtype eq "AAML" ) {
336 2 $self->_parse_inputparams;
337 2 $self->_parse_patterns();
338 2 $self->_parse_seqs(); # the sequences data used for analysis
339 2 $self->_parse_aa_freqs(); # AA frequencies
340 # get AA distances
341 2 $self->{'_summary'}->{'aadistmat'} = $self->_parse_aa_dists();
342  
343 }
344 elsif ( $seqtype eq "CODON2AAML" ) {
345 0 $self->throw(
346 -class => 'Bio::Root::NotImplemented',
347 -text => 'CODON2AAML parsing not yet implemented!'
348 );
349 }
350 elsif ( $seqtype eq "BASEML" ) {
351 2 $self->_parse_patterns();
352 2 $self->_parse_seqs();
353 2 $self->_parse_nt_freqs();
354  
355 }
356 elsif ( $seqtype eq "YN00" ) {
357 2 $self->_parse_codon_freqs();
358 2 $self->_parse_codoncts();
359 2 $self->_parse_distmat(); # NG distance matrices
360 }
361 else {
362 0 $self->throw(
363 -class => 'Bio::Root::NotImplemented',
364 -text => 'Unknown seqtype, not yet implemented!',
365 -value => $seqtype
366 );
367 }
368  
369 }
370  
371 sub _parse_inputparams {
372 16 ▶ my ($self) = @_;
Subroutine _parse_inputparams: called CC=6 SCAR=18.0
373 16 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 39 0 39
374 39 ▶ if (/^((?:Codon frequencies)|(?:Site-class models))\s*:\s+(.+)/) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^((?:Codon frequencies)|(?:Site-class models))\s*:\s+(.+)/) { } 10 29 39
elsif (/^\s+$/) { } 4 25 29
elsif (/^ns\s+=\s+/ or /^Frequencies/) { } 16 9 25
375 10 my ( $param, $val ) = ( $1, $2 );
376 10 $self->{'_summary'}->{'inputparams'}->{$param} = $val;
377 }
378 elsif (/^\s+$/) {
379 4 next;
380 }
381 ▶ elsif ( /^ns\s+=\s+/ || /^Frequencies/ ) {
Condition66%2/3
/^ns\s+=\s+/ or /^Frequencies/
l!l&&r!l&&!r
1609
MC/DC50%1/2
/^ns\s+=\s+/ or /^Frequencies/
/^ns\s+=\s+/ /^Frequencies/
Truth table66%2/3
A or B
A= /^ns\s+=\s+/B= /^Frequencies/
ABresult
1X1
011
000
382 16 $self->_pushback($_);
383 16 last;
384 }
385 }
386 }
387  
388 sub _parse_codon_freqs {
389 16 ▶ my ($self) = @_;
Subroutine _parse_codon_freqs: called CC=16 SCAR=27.7
390 16 my ( $okay, $done ) = ( 0, 0 );
391  
392 16 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 1495 0 1495
393 1495 ▶ if (/^Nei|\(A\) Nei/) { $self->_pushback($_); last }
Branch: 1 branch
BranchTrueFalseTotal
if (/^Nei|\(A\) Nei/) 2 1493 1495
394 1493 ▶ last if ($done);
Branch: 1 branch
BranchTrueFalseTotal
if $done 14 1479 1493
395 1479 ▶ next if (/^\s+/);
Branch: 1 branch
BranchTrueFalseTotal
if /^\s+/ 557 922 1479
396 next
397 922 ▶ unless ( $okay || /^Codon position x base \(3x4\) table\, overall/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $okay or /^Codon position x base \(3x4\) table\, overall/ 866 56 922
Condition100%3/3
$okay or /^Codon position x base \(3x4\) table\, overall/
l!l&&r!l&&!r
4214866
MC/DC100%2/2
$okay or /^Codon position x base \(3x4\) table\, overall/
$okay /^Codon position x base \(3x4\) table\, overall/
Truth table100%3/3
A or B
A= $okayB= /^Codon position x base \(3x4\) table\, overall/
ABresult
1X1
011
000
398 56 $okay = 1;
399 56 ▶ if (s/^position\s+(\d+):\s+//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^position\s+(\d+):\s+//) 42 14 56
400 42 my $pos = $1;
401 42 s/\s+$//;
402 42 my @bases = split;
403 42 foreach my $str (@bases) {
404 168 my ( $base, $freq ) = split( /:/, $str, 2 );
405 168 $self->{'_summary'}->{'codonposition'}->[ $pos - 1 ]->{$base} =
406 $freq;
407 }
408 42 ▶ $done = 1 if $pos == 3;
Branch: 1 branch
BranchTrueFalseTotal
if $pos == 3 14 28 42
409 }
410 }
411 16 $done = 0;
412 16 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 37 0 37
413 37 ▶ if (/^Nei\s\&\sGojobori|\(A\)\sNei-Gojobori/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^Nei\s\&\sGojobori|\(A\)\sNei-Gojobori/) 8 29 37
414 8 $self->_pushback($_);
415 8 last;
416 }
417 29 ▶ last if ($done);
Branch: 1 branch
BranchTrueFalseTotal
if $done 8 21 29
418 21 ▶ if (/^Codon frequencies under model, for use in evolver/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^Codon frequencies under model, for use in evolver/) 8 13 21
419 8 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 136 0 136
420 136 ▶ last if (/^\s+$/);
Branch: 1 branch
BranchTrueFalseTotal
if /^\s+$/ 8 128 136
421 128 s/^\s+//;
422 128 s/\s+$//;
423 128 push @{ $self->{'_summary'}->{'codonfreqs'} }, [split];
424 }
425 8 $done = 1;
426 }
427 }
428 }
429  
430 sub _parse_aa_freqs {
431 2 ▶ my ($self) = @_;
Subroutine _parse_aa_freqs: called CC=14 SCAR=26.5
432 2 my ( $okay, $done, $header ) = ( 0, 0, 0 );
433 2 my (@bases);
434 2 ▶ my $numseqs = scalar @{ $self->{'_summary'}->{'seqs'} || [] };
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_summary"}{"seqs"} or [] 0 2 2
435 2 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 34 0 34
436 34 ▶ if ( /^TREE/ || /^AA distances/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^TREE/ or /^AA distances/) 1 33 34
Condition66%2/3
/^TREE/ or /^AA distances/
l!l&&r!l&&!r
0133
MC/DC50%1/2
/^TREE/ or /^AA distances/
/^TREE/ /^AA distances/
Truth table66%2/3
A or B
A= /^TREE/B= /^AA distances/
ABresult
1X1
011
000
437 1 $self->_pushback($_);
438 1 last;
439 }
440 33 ▶ last if ($done);
Branch: 1 branch
BranchTrueFalseTotal
if $done 1 32 33
441 32 ▶ next if ( /^\s+$/ || /^\(Ambiguity/ );
Branch: 1 branch
BranchTrueFalseTotal
if /^\s+$/ or /^\(Ambiguity/ 12 20 32
Condition100%3/3
/^\s+$/ or /^\(Ambiguity/
l!l&&r!l&&!r
11120
MC/DC100%2/2
/^\s+$/ or /^\(Ambiguity/
/^\s+$/ /^\(Ambiguity/
Truth table100%3/3
A or B
A= /^\s+$/B= /^\(Ambiguity/
ABresult
1X1
011
000
442 20 ▶ if (/^Frequencies\./) {
Branch: 5 branches
BranchTrueFalseTotal
if (/^Frequencies\./) { } 2 18 20
elsif (not $okay) { } 0 18 18
elsif (not $header) { } 2 16 18
elsif (/^\#\s+constant\s+sites\:\s+ (\d+)\s+ # constant sites \(\s*([\d\.]+)\s*\%\s*\)/x) { } 2 14 16
elsif (/^ln\s+Lmax\s+\(unconstrained\)\s+\=\s+(\S+)/x) { } 1 13 14
443 2 $okay = 1;
444 }
445 elsif ( !$okay ) { # skip till we see 'Frequencies.
446 0 next;
447 }
448 elsif ( !$header ) {
449 2 s/^\s+//; # remove leading whitespace
450 2 @bases = split; # get an array of the all the aa names
451 2 $header = 1;
452 2 $self->{'_summary'}->{'aafreqs'} = {}; # reset/clear values
453 2 next;
454 }
455 elsif (
456 /^\#\s+constant\s+sites\:\s+
457 (\d+)\s+ # constant sites
458 \(\s*([\d\.]+)\s*\%\s*\)/x
459 )
460 {
461 2 $self->{'_summary'}->{'stats'}->{'constant_sites'} = $1;
462 2 $self->{'_summary'}->{'stats'}->{'constant_sites_percentage'} = $2;
463 }
464 elsif (/^ln\s+Lmax\s+\(unconstrained\)\s+\=\s+(\S+)/x) {
465 1 $self->{'_summary'}->{'stats'}->{'loglikelihood'} = $1;
466 1 $done = 1; # done for sure
467 }
468 else {
469 13 my ( $seqname, @freqs ) = split;
470 13 my $basect = 0;
471 13 foreach my $f (@freqs) {
472  
473 # this will also store 'Average'
474 $self->{'_summary'}->{'aafreqs'}->{$seqname}
475 260 ->{ $bases[ $basect++ ] } = $f;
476 }
477 }
478 }
479 }
480  
481 # This is for parsing the automatic tree output
482  
483 sub _parse_StarDecomposition {
484 0 ▶ my ($self) = @_;
Subroutine _parse_StarDecomposition: not called CC=1 SCAR=6.9
485 0 my %data;
486  
487 0 return %data;
488 }
489  
490 sub _parse_aa_dists {
491 3 ▶ my ($self) = @_;
Subroutine _parse_aa_dists: called CC=18 SCAR=29.5
492 3 my ( $okay, $seen, $done ) = ( 0, 0, 0 );
493 3 my ( %matrix, @names, @values );
494 3 ▶ my $numseqs = scalar @{ $self->{'_summary'}->{'seqs'} || [] };
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_summary"}{"seqs"} or [] 0 3 3
495 3 my $type = '';
496 3 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 23 1 24
497 23 ▶ last if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 2 21 23
498 21 ▶ if (/^TREE/) { $self->_pushback($_); last; }
Branch: 1 branch
BranchTrueFalseTotal
if (/^TREE/) 0 21 21
499 21 ▶ if (/^\s+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s+$/) 2 19 21
500 2 ▶ last if ($seen);
Branch: 1 branch
BranchTrueFalseTotal
if $seen 0 2 2
501 2 next;
502 }
503 19 ▶ if (/^(AA|ML) distances/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(AA|ML) distances/) 3 16 19
504 3 $okay = 1;
505 3 $type = $1;
506 3 next;
507 }
508 16 s/\s+$//g; # remove trailing space
509 16 ▶ if ($okay) {
Branch: 1 branch
BranchTrueFalseTotal
if ($okay) 16 0 16
510 16 my ( $seqname, @vl ) = split;
511 16 $seen = 1;
512 16 my $i = 0;
513  
514 # hacky workaround to problem with 3.14 aaml
515 16 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "ML" and not @names and @vl) 0 16 16
Condition83%5/6
$type eq "ML" and not @names and @vl
!ll&&!rl&&r
1510
$type eq "ML" and not @names
!ll&&!rl&&r
1141
MC/DC0%0/3
$type eq "ML" and not @names and @vl
$type eq "ML" not @names @vl
Truth table75%3/4
A and not(B) and C
A= $type eq "ML"B= not @namesC= @vl
ABCresult
0XX0
10X0
1100
1111
516 $type eq 'ML'
517 && !@names
518 && # first entry
519 @vl
520 )
521 { # not empty
522 0 push @names, $self->{'_summary'}->{'seqs'}->[0]->display_id;
523 }
524 16 for my $s (@names) {
525 35 ▶ last unless @vl;
Branch: 1 branch
BranchTrueFalseTotal
unless @vl 0 35 35
526 35 $matrix{$seqname}->{$s} = $matrix{$s}->{$seqname} = shift @vl;
527 }
528 16 push @names, $seqname;
529  
530 16 $matrix{$seqname}->{$seqname} = 0;
531 }
532 16 ▶ $done = 1 if ( scalar @names == $numseqs );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @names == $numseqs 3 13 16
533 }
534 3 my %dist;
535 3 my $i = 0;
536 3 @values = ();
537 3 foreach my $lname (@names) {
538 16 my @row;
539 16 my $j = 0;
540 16 foreach my $rname (@names) {
541 86 my $v = $matrix{$lname}->{$rname};
542 86 ▶ $v = $matrix{$rname}->{$lname} unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 86 86
543 86 push @row, $v;
544 86 $dist{$lname}{$rname} = [ $i, $j++ ];
545 }
546 16 $i++;
547 16 push @values, \@row;
548 }
549 return new Bio::Matrix::PhylipDist(
550 3 -program => $self->{'_summary'}->{'seqtype'},
551 -matrix => \%dist,
552 -names => \@names,
553 -values => \@values
554 );
555 }
556  
557 sub _parse_patterns {
558 18 ▶ my ($self) = @_;
Subroutine _parse_patterns: called CC=9 SCAR=22.1
559 18 my ( $patternct, @patterns, $ns, $ls );
560 18 ▶ return if exists $self->{'_summary'}->{'patterns'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_summary"}{"patterns"} 0 18 18
561  
562 18 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 99 0 99
563 99 ▶ if ( /^Codon\s+(usage|position)/ || /Model/ ) {
Branch: 4 branches
BranchTrueFalseTotal
if (/^Codon\s+(usage|position)/ or /Model/) { } 11 88 99
elsif ($patternct) { } 52 36 88
elsif (/^ns\s+\=\s*(\d+)\s+ls\s+\=\s*(\d+)/) { } 18 18 36
elsif (/^\# site patterns \=\s*(\d+)/) { } 7 11 18
Condition66%2/3
/^Codon\s+(usage|position)/ or /Model/
l!l&&r!l&&!r
11088
MC/DC50%1/2
/^Codon\s+(usage|position)/ or /Model/
/^Codon\s+(usage|position)/ /Model/
Truth table66%2/3
A or B
A= /^Codon\s+(usage|position)/B= /Model/
ABresult
1X1
011
000
564 11 $self->_pushback($_);
565 11 last;
566 }
567 elsif ($patternct) {
568  
569 # last unless ( @patterns == $patternct );
570 52 ▶ last if (/^\s+$/);
Branch: 1 branch
BranchTrueFalseTotal
if /^\s+$/ 7 45 52
571 45 s/^\s+//;
572 45 push @patterns, split;
573 }
574 elsif (/^ns\s+\=\s*(\d+)\s+ls\s+\=\s*(\d+)/) {
575 18 ( $ns, $ls ) = ( $1, $2 );
576 }
577 elsif (/^\# site patterns \=\s*(\d+)/) {
578 7 $patternct = $1;
579 }
580 else {
581  
582 # $self->debug("Unknown line: $_");
583 }
584 }
585 18 $self->{'_summary'}->{'patterns'} = {
586 -patterns => \@patterns,
587 -ns => $ns,
588 -ls => $ls
589 };
590 }
591  
592 sub _parse_seqs {
593  
594 # this should in fact be packed into a Bio::SimpleAlign object instead of
595 # an array but we'll stay with this for now
596 26 ▶ my ($self) = @_;
Subroutine _parse_seqs: called CC=11 SCAR=24.0
597  
598 # Use this flag to deal with paml 4 vs 3 differences
599 # In PAML 4 the sequences precede the CODONML|BASEML|AAML
600 # while in PAML3 the files start off with this
601 26 ▶ return 1 if $self->{'_already_parsed_seqs'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_already_parsed_seqs"} 8 18 26
602 18 my ( @firstseq, @seqs );
603 18 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 91 0 91
604 91 ▶ if (/^(Printing|After|TREE|Codon)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(Printing|After|TREE|Codon)/) 5 86 91
605 5 $self->_pushback($_);
606 5 last;
607 }
608 86 ▶ last if ( /^\s+$/ && @seqs > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if /^\s+$/ and @seqs > 0 13 73 86
Condition100%3/3
/^\s+$/ and @seqs > 0
!ll&&!rl&&r
67613
MC/DC100%2/2
/^\s+$/ and @seqs > 0
/^\s+$/ @seqs > 0
Truth table100%3/3
A and B
A= /^\s+$/B= @seqs > 0
ABresult
0X0
100
111
609 73 ▶ next if (/^\s+$/);
Branch: 1 branch
BranchTrueFalseTotal
if /^\s+$/ 6 67 73
610 67 ▶ next if (/^\d+\s+$/);
Branch: 1 branch
BranchTrueFalseTotal
if /^\d+\s+$/ 1 66 67
611  
612 # we are reading PHYLIP format
613 66 my ( $name, $seqstr ) = split( /\s+/, $_, 2 );
614 66 $seqstr =~ s/\s+//g; # remove whitespace
615 66 ▶ unless (@firstseq) {
Branch: 1 branch
BranchTrueFalseTotal
if (@firstseq) { } 53 13 66
616 13 @firstseq = split( //, $seqstr );
617 13 push @seqs,
618 Bio::LocatableSeq->new(
619 -display_id => $name,
620 -seq => $seqstr
621 );
622 }
623 else {
624  
625 53 my $i = 0;
626 53 my $v;
627 53 ▶ while ( ( $v = index( $seqstr, '.', $i ) ) >= $i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($v = index($seqstr, ".", $i)) >= $i) 2741 53 2794
628  
629 # replace the '.' with the correct seq from the
630 2741 substr( $seqstr, $v, 1, $firstseq[$v] );
631 2741 $i = $v;
632 }
633 53 push @seqs,
634 Bio::LocatableSeq->new(
635 -display_id => $name,
636 -seq => $seqstr
637 );
638 }
639 }
640 18 ▶ if ( @seqs > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@seqs > 0) 13 5 18
641 13 $self->{'_summary'}->{'seqs'} = \@seqs;
642 13 $self->{'_already_parsed_seqs'} = 1;
643 }
644 18 1;
645 }
646  
647 ▶sub _parse_codoncts { }
Subroutine _parse_codoncts: called CC=1 SCAR=0.0
648  
649 sub _parse_distmat {
650 16 ▶ my ($self) = @_;
Subroutine _parse_distmat: called CC=21 SCAR=30.6
651 16 my @results;
652 16 my $ver = 3.14;
653 16 my $firstseq, my $secondseq;
654  
655 16 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 24 0 24
656 24 ▶ next if /^\s+$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s+$/ 8 16 24
657  
658 # We need to get the names of the sequences if this is from YN00:
659 16 ▶ if (/^\(A\)\sNei-Gojobori\s\(1986\)\smethod/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\(A\)\sNei-Gojobori\s\(1986\)\smethod/) 1 15 16
660 1 $ver = 3.15;
661 1 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 9 0 9
662 9 ▶ if ($_ =~ m/.*\d+?\.\d+?\s*\(.*/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /.*\d+?\.\d+?\s*\(.*/) 1 8 9
663 1 $secondseq = $_;
664 1 last;
665 }
666 8 $firstseq = $_;
667 }
668 }
669 16 last;
670 }
671  
672 #return unless (/^Nei\s*\&\s*Gojobori/);
673  
674 # skip the next 3 lines
675 16 ▶ if ( $self->{'_summary'}->{'seqtype'} eq 'CODONML' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_summary"}{"seqtype"} eq "CODONML") 14 2 16
676 14 $self->_readline;
677 14 $self->_readline;
678 14 $self->_readline;
679 }
680 16 my $seqct = 0;
681 16 my @seqs;
682 16 ▶ if ( $self->{'_summary'}->{'seqtype'} eq 'YN00' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_summary"}{"seqtype"} eq "YN00") 2 14 16
683 2 ▶ if ($firstseq) {
Branch: 1 branch
BranchTrueFalseTotal
if ($firstseq) 1 1 2
684 1 $firstseq =~ s/(.+?)\s+.*/$1/;
685 1 $secondseq =~ s/(.+?)\s+.*/$1/;
686 1 chomp $firstseq;
687 1 chomp $secondseq;
688 1 push @seqs, Bio::PrimarySeq->new( -display_id => $firstseq );
689 1 push @seqs, Bio::PrimarySeq->new( -display_id => $secondseq );
690 }
691 }
692 16 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 98 0 98
693 98 ▶ last if ( /^\s+$/ && exists $self->{'_summary'}->{'ngmatrix'} );
Branch: 1 branch
BranchTrueFalseTotal
if /^\s+$/ and exists $self->{"_summary"}{"ngmatrix"} 16 82 98
Condition66%2/3
/^\s+$/ and exists $self->{"_summary"}{"ngmatrix"}
!ll&&!rl&&r
82016
MC/DC50%1/2
/^\s+$/ and exists $self->{"_summary"}{"ngmatrix"}
/^\s+$/ exists $self->{"_summary"}{"ngmatrix"}
Truth table66%2/3
A and B
A= /^\s+$/B= exists $self->{"_summary"}{"ngmatrix"}
ABresult
0X0
100
111
694 82 ▶ next if ( /^\s+$/ || /^NOTE:/i );
Branch: 1 branch
BranchTrueFalseTotal
if /^\s+$/ or /^NOTE:/i 0 82 82
Condition33%1/3
/^\s+$/ or /^NOTE:/i
l!l&&r!l&&!r
0082
MC/DC0%0/2
/^\s+$/ or /^NOTE:/i
/^\s+$/ /^NOTE:/i
Truth table33%1/3
A or B
A= /^\s+$/B= /^NOTE:/i
ABresult
1X1
011
000
695 82 chomp;
696  
697 82 my ( $seq, $rest );
698 82 ▶ if ( $self->{'_summary'}->{'seqtype'} eq 'YN00' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_summary'}{'seqtype'} eq 'YN00') { } 12 70 82
699 12 ( $seq, $rest ) = split( /\s+/, $_, 2 );
700 }
701 else {
702 70 $_ =~ m/(.+?)\s*(-*\d+?\.\d+?.*)/;
703 70 $seq = $1;
704 70 $rest = $2;
705 }
706 82 ▶ $rest = '' unless defined $rest; # get rid of empty messages
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rest 14 68 82
707 82 my $j = 0;
708 82 ▶ if ( $self->{'_summary'}->{'seqtype'} eq 'YN00' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_summary"}{"seqtype"} eq "YN00") 12 70 82
709 12 push @seqs, Bio::PrimarySeq->new( -display_id => $seq );
710 }
711 82 ▶ while ($rest
Branch: 1 branch
BranchTrueFalseTotal
if ($rest and $rest =~ /(\-?\d+(\.\d+)?)\s*\(\-?(\d+(\.\d+)?)\s+(\-?\d+(\.\d+)?)\)/g) 218 82 300
Condition100%3/3
$rest and $rest =~ /(\-?\d+(\.\d+)?)\s*\(\-?(\d+(\.\d+)?)\s+(\-?\d+(\.\d+)?)\)/g
!ll&&!rl&&r
1567218
MC/DC100%2/2
$rest and $rest =~ /(\-?\d+(\.\d+)?)\s*\(\-?(\d+(\.\d+)?)\s+(\-?\d+(\.\d+)?)\)/g
$rest $rest =~ /(\-?\d+(\.\d+)?)\s*\(\-?(\d+(\.\d+)?)\s+(\-?\d+(\.\d+)?)\)/g
Truth table100%3/3
A and B
A= $restB= $rest =~ /(\-?\d+(\.\d+)?)\s*\(\-?(\d+(\.\d+)?)\s+(\-?\d+(\.\d+)?)\)/g
ABresult
0X0
100
111
712 && $rest =~
713 /(\-?\d+(\.\d+)?)\s*\(\-?(\d+(\.\d+)?)\s+(\-?\d+(\.\d+)?)\)/g )
714 {
715 218 $self->{'_summary'}->{'ngmatrix'}->[ $j++ ]->[$seqct] = {
716 'omega' => $1,
717 'dN' => $3,
718 'dS' => $5
719 };
720 }
721 82 $seqct++;
722 }
723 16 ▶ if ( $self->{'_summary'}->{'seqtype'} eq 'YN00' && @seqs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_summary"}{"seqtype"} eq "YN00" and @seqs) 2 14 16
Condition66%2/3
$self->{"_summary"}{"seqtype"} eq "YN00" and @seqs
!ll&&!rl&&r
1402
MC/DC50%1/2
$self->{"_summary"}{"seqtype"} eq "YN00" and @seqs
$self->{"_summary"}{"seqtype"} eq "YN00" @seqs
Truth table66%2/3
A and B
A= $self->{"_summary"}{"seqtype"} eq "YN00"B= @seqs
ABresult
0X0
100
111
724 2 $self->{'_summary'}->{'seqs'} = \@seqs;
725 }
726  
727 16 1;
728 }
729  
730 sub _parse_PairwiseCodon {
731 8 ▶ my ($self) = @_;
Subroutine _parse_PairwiseCodon: called CC=15 SCAR=27.8
732 8 my @result;
733 8 my ( $a, $b, $log, $model, $t, $kappa, $omega, $fixedkappa );
734 # check to see if we have a fixed kappa:
735 8 ▶ if ( $self->{'_summary'}->{'model'} =~ /kappa = (\d+?\.\d+?) fixed/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_summary"}{"model"} =~ /kappa = (\d+?\.\d+?) fixed/) 1 7 8
736 1 $fixedkappa = $1;
737 }
738 8 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 680 8 688
739 680 ▶ if (/^pairwise comparison, codon frequencies\:\s*(\S+)\./) {
Branch: 6 branches
BranchTrueFalseTotal
if (/^pairwise comparison, codon frequencies\:\s*(\S+)\./) { } 8 672 680
elsif (/^(\d+)\s+\((\S+)\)\s+\.\.\.\s+(\d+)\s+\((\S+)\)/) { } 112 560 672
elsif (/^lnL\s+\=\s*(\-?\d+(\.\d+)?)/) { } 112 448 560
elsif (/^t\=\s*(\d+(\.\d+)?)\s+/) { } 112 336 448
elsif (/^\s+$/) { } 336 0 336
elsif (/^\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)/) { } 0 0 0
740 8 $model = $1;
741 }
742 # 1st line of a pair block, e.g.
743 # 2 (all_c7259) ... 1 (all_s57600)
744 elsif (/^(\d+)\s+\((\S+)\)\s+\.\.\.\s+(\d+)\s+\((\S+)\)/) {
745 112 ( $a, $b ) = ( $1, $3 );
746 }
747 # 2nd line of a pair block, e.g.
748 # lnL = -126.880601
749 elsif (/^lnL\s+\=\s*(\-?\d+(\.\d+)?)/) {
750 112 $log = $1;
751 112 ▶ if ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 112 0 112
752 # 3rd line of a pair block, e.g.
753 # 0.19045 2.92330 0.10941
754 112 s/^\s+//;
755 112 ( $t, $kappa, $omega ) = split;
756 # if there was a fixed kappa, there will only be two values here ($t, $omega) and $kappa = $fixedkappa.
757 112 ▶ if ($omega eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($omega eq "") 1 111 112
758 1 $omega = $kappa;
759 1 $kappa = $fixedkappa;
760 }
761 }
762 }
763 # 5th line of a pair block, e.g.
764 # t= 0.1904 S= 5.8 N= 135.2 dN/dS= 0.1094 dN= 0.0476 dS= 0.4353
765 # OR lines like (note last field; this includes a fix for bug #3040)
766 # t= 0.0439 S= 0.0 N= 141.0 dN/dS= 0.1626 dN= 0.0146 dS= nan
767 elsif (m/^t\=\s*(\d+(\.\d+)?)\s+/)
768 {
769 # Breaking out each piece individually so that you can see
770 # what each regexp actually looks for
771 112 my $parse_string = $_;
772 112 $parse_string =~ m/.*t\s*\=\s*(\d+?\.\d+?)\s/;
773 112 my $temp_t = $1;
774 112 $parse_string =~ m/\sS\s*\=\s*(\d+?\.\d+?)\s/;
775 112 my $temp_S = $1;
776 112 $parse_string =~ m/\sN\s*\=\s*(\d+?\.\d+?)\s/;
777 112 my $temp_N = $1;
778 112 $parse_string =~ m/\sdN\/dS\s*\=\s*(\d+?\.\d+?)\s/;
779 112 my $temp_omega = $1;
780 112 $parse_string =~ m/\sdN\s*\=\s*(\d+?\.\d+?)\s/;
781 112 my $temp_dN = $1;
782 112 $parse_string =~ m/\sdS\s*\=\s*(.+)\s/;
783 112 my $temp_dS = $1;
784 112 ▶ $result[ $b - 1 ]->[ $a - 1 ] = {
Branch: 2 branches
BranchTrueFalseTotal
defined $t && length $t ? : 112 0 112
defined $omega && length $omega ? : 112 0 112
Condition33%2/6
defined $t and length $t
!ll&&!rl&&r
00112
defined $omega and length $omega
!ll&&!rl&&r
00112
MC/DC0%0/2
defined $t and length $t
defined $t length $t
MC/DC0%0/2
defined $omega and length $omega
defined $omega length $omega
Truth table33%1/3
A and B
A= defined $tB= length $t
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $omegaB= length $omega
ABresult
0X0
100
111
785 'lnL' => $log,
786 't' => defined $t && length($t) ? $t : $temp_t,
787 'S' => $temp_S,
788 'N' => $temp_N,
789 'kappa' => $kappa,
790 'omega' => defined $omega && length($omega) ? $omega : $temp_omega,
791 'dN' => $temp_dN,
792 'dS' => $temp_dS
793 };
794 }
795 # 4th line of a pair block (which is blank)
796 elsif (/^\s+$/) {
797 336 next;
798 }
799 elsif (/^\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)/) {
800 }
801 else {
802 0 $self->debug("unknown line: $_");
803 }
804 }
805 8 return ( -mlmatrix => \@result );
806 }
807  
808 sub _parse_YN_Pairwise {
809 2 ▶ my ($self) = @_;
Subroutine _parse_YN_Pairwise: called CC=7 SCAR=19.5
810 2 my @result;
811 2 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 11 0 11
812 11 ▶ last if (/^seq\.\s+seq\./);
Branch: 1 branch
BranchTrueFalseTotal
if /^seq\.\s+seq\./ 2 9 11
813 }
814 2 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 51 1 52
815 51 ▶ if (
Branch: 3 branches
BranchTrueFalseTotal
if (/^\s+(\d+)\s+ # seq # (\d+)\s+ # seq # (\d+(\.\d+))\s+ # S (\d+(\.\d+))\s+ # N (\d+(\.\d+))\s+ # t (\d+(\.\d+))\s+ # kappa (\d+(\.\d+))\s+ # omega \-??(\d+(\.\d+))\s+ # dN \+\-\s+ \-??(\d+(\.\d+))\s+ # dN SE \-??(\d+(\.\d+))\s+ # dS \+\-\s+ \-??(\d+(\.\d+))\s+ # dS SE /ox) { } 43 8 51
elsif (/^\s+$/) { } 4 4 8
elsif (/^\(C\) LWL85, LPB93 & LWLm methods/) { } 1 3 4
816 m/^\s+(\d+)\s+ # seq #
817 (\d+)\s+ # seq #
818 (\d+(\.\d+))\s+ # S
819 (\d+(\.\d+))\s+ # N
820 (\d+(\.\d+))\s+ # t
821 (\d+(\.\d+))\s+ # kappa
822 (\d+(\.\d+))\s+ # omega
823 \-??(\d+(\.\d+))\s+ # dN
824 \+\-\s+
825 \-??(\d+(\.\d+))\s+ # dN SE
826 \-??(\d+(\.\d+))\s+ # dS
827 \+\-\s+
828 \-??(\d+(\.\d+))\s+ # dS SE
829 /ox
830 )
831 {
832  
833 43 $result[ $2 - 1 ]->[ $1 - 1 ] = {
834 'S' => $3,
835 'N' => $5,
836 't' => $7,
837 'kappa' => $9,
838 'omega' => $11,
839 'dN' => $13,
840 'dN_SE' => $15,
841 'dS' => $17,
842 'dS_SE' => $19,
843 };
844 }
845 elsif (/^\s+$/) {
846 4 next;
847 }
848 elsif (/^\(C\) LWL85, LPB93 & LWLm methods/) {
849 1 $self->_pushback($_);
850 1 last;
851 }
852 }
853 2 return ( -mlmatrix => \@result );
854 }
855  
856 sub _parse_Forestry {
857 13 ▶ my ($self) = @_;
Subroutine _parse_Forestry: called CC=27 SCAR=34.1
858 13 my ( $instancecount, $num_param, $loglikelihood, $score, $done,
859 $treelength ) = ( 0, 0, 0, 0, 0, 0 );
860 13 my $okay = 0;
861 13 my ( @ids, %match, @branches, @trees );
862 13 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 175 2 177
863 175 ▶ last if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 0 175 175
864 175 ▶ if (s/^TREE\s+\#\s*\d+:\s+//) {
Branch: 7 branches
BranchTrueFalseTotal
if (s/^TREE\s+\#\s*\d+:\s+//) { } 13 162 175
elsif (/^Node\s+\&/ or /^\s+N37/ or /^(CODONML|AAML|YN00|BASEML)/ or /^\*\*/ or /^Detailed output identifying parameters/) { } 11 151 162
elsif (/^tree\s+length\s+\=\s+(\S+)/) { } 13 138 151
elsif (/^\s*lnL\(.+np\:\s*(\d+)\)\:\s+(\S+)/) { } 13 125 138
elsif (/^\(/) { } 26 99 125
elsif (/^SEs for parameters/) { } 3 96 99
elsif (/^\s*\d+\.\.\d+/) { } 13 83 96
865 13 ($score) = (s/MP\s+score\:\s+(\S+)\s+$//);
866 13 @ids = /(\d+)[\,\)]/g;
867 }
868 ▶ elsif (/^Node\s+\&/
Condition41%5/12
/^Node\s+\&/ or /^\s+N37/ or /^(CODONML|AAML|YN00|BASEML)/ or /^\*\*/ or /^Detailed output identifying parameters/
l!l&&r!l&&!r
011151
/^Node\s+\&/ or /^\s+N37/ or /^(CODONML|AAML|YN00|BASEML)/ or /^\*\*/
l!l&&r!l&&!r
00162
/^Node\s+\&/ or /^\s+N37/ or /^(CODONML|AAML|YN00|BASEML)/
l!l&&r!l&&!r
00162
/^Node\s+\&/ or /^\s+N37/
l!l&&r!l&&!r
00162
MC/DC20%1/5
/^Node\s+\&/ or /^\s+N37/ or /^(CODONML|AAML|YN00|BASEML)/ or /^\*\*/ or /^Detailed output identifying parameters/
/^Node\s+\&/ /^\s+N37/ /^(CODONML|AAML|YN00|BASEML)/ /^\*\*/ /^Detailed output identifying parameters/
Truth table33%2/6
A or B or C or D or E
A= /^Node\s+\&/B= /^\s+N37/C= /^(CODONML|AAML|YN00|BASEML)/D= /^\*\*/E= /^Detailed output identifying parameters/
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
869 || /^\s+N37/
870 || /^(CODONML|AAML|YN00|BASEML)/
871 || /^\*\*/
872 || /^Detailed output identifying parameters/ )
873 {
874 11 $self->_pushback($_);
875 11 $done = 1;
876 11 last;
877 }
878 elsif (/^tree\s+length\s+\=\s+(\S+)/) {
879 13 $treelength = $1; # not going to store this for now
880 # as it is directly calculated from
881 # $tree->total_branch_length;
882 }
883 elsif (/^\s*lnL\(.+np\:\s*(\d+)\)\:\s+(\S+)/) {
884  
885 # elsif( /^\s*lnL\(.+\)\:\s+(\S+)/ ) {
886 13 ( $num_param, $loglikelihood ) = ( $1, $2 );
887 }
888 elsif (/^\(/) {
889 26 s/([\,:])\s+/$1/g;
890 26 my $treestr = IO::String->new($_);
891 26 my $treeio = Bio::TreeIO->new(
892 -fh => $treestr,
893 -format => 'newick'
894 );
895 26 my $tree = $treeio->next_tree;
896 26 ▶ if ($tree) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tree) 26 0 26
897 26 $tree->score($loglikelihood);
898 26 $tree->id("num_param:$num_param");
899 26 ▶ if ( $okay > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($okay > 0) 13 13 26
900  
901 # we don't save the trees with the number labels
902 13 ▶ if ( !%match && @ids ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not %match and @ids) 13 0 13
Condition33%1/3
not %match and @ids
!ll&&!rl&&r
0013
MC/DC0%0/2
not %match and @ids
not %match @ids
Truth table33%1/3
not(A) and B
A= not %matchB= @ids
ABresult
0X0
100
111
903 13 my $i = 0;
904 13 for my $m (/([^():,]+):/g) {
905 66 $match{ shift @ids } = [$m];
906 }
907 13 my %grp;
908 13 ▶ while ( my $br = shift @branches ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $br = shift @branches) 120 13 133
909 120 my ( $parent, $child ) = @$br;
910 120 ▶ if ( $match{$child} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match{$child}) { } 93 27 120
911 93 push @{ $match{$parent} }, @{ $match{$child} };
912 }
913 else {
914 27 push @branches, $br;
915 }
916 }
917 13 ▶ if ( $self->verbose > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose > 1) 0 13 13
918 0 for my $k ( sort { $a <=> $b } keys %match ) {
919 $self->debug( "$k -> ",
920 0 join( ",", @{ $match{$k} } ), "\n" );
921 }
922 }
923 }
924  
925 # Associate SEs to nodes using tags
926 13 ▶ if ( defined( $self->{_SEs} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_SEs"}) 3 10 13
927 3 my @SEs = split( " ", $self->{_SEs} );
928 3 my $i = 0;
929 3 foreach my $parent_id ( map { /\d+\.\.(\d+)/ }
930 split( " ", $self->{_branch_ids} ) )
931 {
932 33 my @nodes;
933 33 my @node_ids = @{ $match{$parent_id} };
934 my @nodes_L =
935 33 map { $tree->find_node( -id => $_ ) } @node_ids;
936 33 ▶ my $n =
Branch: 1 branch
BranchTrueFalseTotal
@nodes_L < 2 ? : 21 12 33
937 @nodes_L < 2
938 ? shift(@nodes_L)
939 : $tree->get_lca(@nodes_L);
940 33 ▶ if ( !$n ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($n) 0 33 33
941 0 $self->warn(
942 "no node could be found for node in SE assignation (no lca?)"
943 );
944 }
945 33 $n->add_tag_value( 'SE', $SEs[$i] );
946 33 $i++;
947 }
948 }
949 13 push @trees, $tree;
950 }
951 }
952 26 $okay++;
953 }
954 elsif (/^SEs for parameters/) {
955 3 my $se_line = $self->_readline;
956 3 $se_line =~ s/\n//;
957 3 $self->{_SEs} = $se_line;
958 }
959 elsif (/^\s*\d+\.\.\d+/) {
960 13 push @branches, map { [ split( /\.\./, $_ ) ] } split;
961 13 my $ids = $_;
962 13 $ids =~ s/\n//;
963 13 $self->{_branch_ids} = $ids;
964 }
965 }
966 13 return \@trees, \%match;
967 }
968  
969 sub _parse_NSsitesBatch {
970 9 ▶ my $self = shift;
Subroutine _parse_NSsitesBatch: called CC=42 SCAR=42.8
971 9 my ( %data, $idlookup );
972 9 my ( $okay, $done ) = ( 0, 0 );
973 9 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 120 4 124
974 120 ▶ last if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 5 115 120
975 115 ▶ next if /^\s+$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s+$/ 47 68 115
976 68 ▶ next unless ( $okay || /^Model\s+\d+/ || /^TREE/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $okay or /^Model\s+\d+/ or /^TREE/ 0 68 68
Condition83%5/6
$okay or /^Model\s+\d+/ or /^TREE/
l!l&&r!l&&!r
6620
$okay or /^Model\s+\d+/
l!l&&r!l&&!r
5972
MC/DC0%0/3
$okay or /^Model\s+\d+/ or /^TREE/
$okay /^Model\s+\d+/ /^TREE/
Truth table75%3/4
A or B or C
A= $okayB= /^Model\s+\d+/C= /^TREE/
ABCresult
1XX1
01X1
0011
0000
977  
978 68 ▶ if (/^Model\s+(\d+)/) {
Branch: 10 branches
BranchTrueFalseTotal
if (/^Model\s+(\d+)/) { } 7 61 68
elsif (/^Time used\:\s+(\S+)/) { } 7 54 61
elsif (m[^kappa\s+\(ts/tv\)\s+\=\s+(\S+)]) { } 9 45 54
elsif (/^TREE/) { } 9 36 45
elsif (m[^omega\s+\(dn/ds\)\s+\=\s+(\S+)]i) { } 1 35 36
elsif (/^(Naive Empirical Bayes)|(Bayes Empirical Bayes)|(Positively\sselected\ssites)/i) { } 6 29 35
elsif (/^dN/i) { } 15 14 29
elsif (/^Parameters in beta:/) { } 0 14 14
elsif (/^Parameters in beta\&w\>1:/) { } 0 14 14
elsif (/^alpha\s+\(gamma\)\s+\=\s+(\S+)/) { } 3 11 14
979 7 ▶ if ($okay) {
Branch: 1 branch
BranchTrueFalseTotal
if ($okay) { } 0 7 7
980  
981 # this only happens if $okay was already 1 and
982 # we hit a Model line
983 0 $self->_pushback($_);
984 0 $done = 1;
985 }
986 else {
987 7 chomp;
988 7 $data{'-model_num'} = $1;
989 7 ( $data{'-model_description'} ) = (/\:\s+(.+)/);
990 7 $okay = 1;
991 }
992 }
993 elsif (/^Time used\:\s+(\S+)/) {
994 7 $data{'-time_used'} = $1;
995 7 $done = 1;
996 }
997 elsif (/^kappa\s+\(ts\/tv\)\s+\=\s+(\S+)/) {
998 9 $data{'-kappa'} = $1;
999 }
1000 elsif (/^TREE/) {
1001 9 $self->_pushback($_);
1002 9 ( $data{'-trees'}, $idlookup ) = $self->_parse_Forestry;
1003 9 ▶ if ( defined $data{'-trees'}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data{"-trees"} and scalar @{$data{"-trees"};}) 9 0 9
Condition50%1/2
defined $data{"-trees"} and scalar @{$data{"-trees"};}
!ll
09
MC/DC0%0/1
defined $data{"-trees"} and scalar @{$data{"-trees"};}
defined $data{"-trees"}
Truth table50%1/2
A
A= defined $data{"-trees"}
Aresult
00
11
1004 9 && scalar @{ $data{'-trees'} } )
1005 {
1006 9 $data{'-likelihood'} = $data{'-trees'}->[0]->score;
1007 }
1008 9 $okay = 1;
1009 }
1010 elsif (/^omega\s+\(dn\/ds\)\s+\=\s+(\S+)/i) {
1011  
1012 # for M0 (single ratio for the entire tree)
1013 # explicitly put '1.00000' rather than '1', because \d+\.\d{5}
1014 # is reported in all other cases.
1015 1 my @p = (q/1.00000/); # since there is only one class,
1016 1 my @w = $1;
1017 1 $data{'-dnds_site_classes'} = {
1018 'p' => \@p,
1019 'w' => \@w
1020 };
1021  
1022 # since no K=X is provided, put 1 here
1023 1 $data{q/-num_site_classes/} = 1;
1024 }
1025 elsif (
1026 /^(Naive Empirical Bayes)|(Bayes Empirical Bayes)|(Positively\sselected\ssites)/i
1027 )
1028 {
1029 6 $self->_pushback($_);
1030 6 my ( $sites, $neb, $beb ) = $self->_parse_Pos_selected_sites;
1031 6 $data{'-pos_sites'} = $sites;
1032 6 $data{'-neb_sites'} = $neb;
1033 6 $data{'-beb_sites'} = $beb;
1034 }
1035 elsif (/^dN/i) {
1036 15 ▶ if (/K\=(\d+)/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/K\=(\d+)/) { } 7 8 15
elsif (/for each branch/) { } 8 0 8
1037 7 $data{'-num_site_classes'} = $1;
1038 7 ▶ while ( $_ = $self->_readline ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ = $self->_readline) 12 0 12
1039 12 ▶ unless ( $_ =~ /^\s+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ =~ /^\s+$/) 7 5 12
1040 7 $self->_pushback($_);
1041 7 last;
1042 }
1043 }
1044 7 ▶ if (/^site class/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^site class/) { } 1 6 7
1045 1 $self->_readline;
1046 1 my $tmp = $self->_readline;
1047 1 my @p = $tmp =~ /(\d+\.\d{5})/g;
1048 1 $tmp = $self->_readline;
1049 1 my @b_w = $tmp =~ /(\d+\.\d{5})/g;
1050 1 $tmp = $self->_readline;
1051 1 my @f_w = $tmp =~ /(\d+\.\d{5})/g;
1052 1 my @w;
1053  
1054 1 foreach my $i ( 0 .. $#b_w ) {
1055 4 push @w,
1056 {
1057 q/background/ => $b_w[$i],
1058 q/foreground/ => $f_w[$i]
1059 };
1060 }
1061 1 $data{'-dnds_site_classes'} = {
1062 q/p/ => \@p,
1063 q/w/ => \@w
1064 };
1065 }
1066 else {
1067 6 my $tmp = $self->_readline;
1068 6 my @p = $tmp =~ /(\d+\.\d{5})/g;
1069 6 $tmp = $self->_readline;
1070 6 my @w = $tmp =~ /(\d+\.\d{5})/g;
1071 6 $data{'-dnds_site_classes'} = {
1072 'p' => \@p,
1073 'w' => \@w
1074 };
1075 }
1076 }
1077 elsif (/for each branch/) {
1078 8 my %branch_dnds = $self->_parse_branch_dnds;
1079 8 ▶ if ( !defined $data{'-trees'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data{"-trees"}) 0 8 8
1080 0 $self->warn(
1081 "No trees have been loaded, can't do anything\n");
1082 0 next;
1083 }
1084 8 my ($tree) = @{ $data{'-trees'} };
1085 8 ▶ if ( !$tree
Branch: 1 branch
BranchTrueFalseTotal
unless ($tree and ref $tree and $tree->isa("Bio::Tree::Tree")) 0 8 8
Condition33%2/6
$tree and ref $tree and $tree->isa("Bio::Tree::Tree")
!ll&&!rl&&r
008
$tree and ref $tree
!ll&&!rl&&r
008
MC/DC0%0/3
$tree and ref $tree and $tree->isa("Bio::Tree::Tree")
$tree ref $tree $tree->isa("Bio::Tree::Tree")
Truth table25%1/4
A and B and C
A= $treeB= ref $treeC= $tree->isa("Bio::Tree::Tree")
ABCresult
0XX0
10X0
1100
1111
1086 || !ref($tree)
1087 || !$tree->isa('Bio::Tree::Tree') )
1088 {
1089 0 $self->warn("no tree object already stored!\n");
1090 0 next;
1091 }
1092  
1093 # These need to be added to the Node/branches
1094 8 ▶ while ( my ( $k, $v ) = each %branch_dnds ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %branch_dnds) 56 8 64
1095  
1096 # we can probably do better by caching at some point
1097 56 my @nodes;
1098 56 for my $id ( split( /\.\./, $k ) ) {
1099 my @nodes_L =
1100 241 map { $tree->find_node( -id => $_ ) }
1101 112 @{ $idlookup->{$id} };
1102 112 ▶ my $n =
Branch: 1 branch
BranchTrueFalseTotal
@nodes_L < 2 ? : 40 72 112
1103 @nodes_L < 2
1104 ? shift(@nodes_L)
1105 : $tree->get_lca(@nodes_L);
1106 112 ▶ if ( !$n ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($n) 0 112 112
1107 0 $self->warn(
1108 "no node could be found for $id (no lca?)");
1109 }
1110 112 ▶ unless ( $n->is_Leaf && $n->id ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($n->is_Leaf and $n->id) 72 40 112
Condition66%2/3
$n->is_Leaf and $n->id
!ll&&!rl&&r
72040
MC/DC50%1/2
$n->is_Leaf and $n->id
$n->is_Leaf $n->id
Truth table66%2/3
A and B
A= $n->is_LeafB= $n->id
ABresult
0X0
100
111
1111 72 $n->id($id);
1112 }
1113 112 push @nodes, $n;
1114 }
1115 56 my ( $parent, $child ) = @nodes;
1116 56 ▶ while ( my ( $kk, $vv ) = each %$v ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$v) 504 56 560
1117 504 $child->add_tag_value( $kk, $vv );
1118 }
1119 }
1120 }
1121 }
1122 elsif (/^Parameters in beta:/) {
1123 0 $_ = $self->_readline; # need the next line
1124 0 ▶ if (/p\=\s+(\S+)\s+q\=\s+(\S+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/p\=\s+(\S+)\s+q\=\s+(\S+)/) { } 0 0 0
1125 0 $data{'-shape_params'} = {
1126 'shape' => 'beta',
1127 'p' => $1,
1128 'q' => $2
1129 };
1130 }
1131 else {
1132 0 $self->warn("unparseable beta parameters: $_");
1133 }
1134 }
1135 elsif (/^Parameters in beta\&w\>1:/) {
1136  
1137 # Parameters in beta&w>1:
1138 # p0= 1.00000 p= 0.07642 q= 0.85550
1139 # (p1= 0.00000) w= 1.00000
1140 0 $_ = $self->_readline; # need the next line
1141 0 my ( $p0, $p, $q, $p1, $w );
1142 0 ▶ if (/p0\=\s+(\S+)\s+p\=\s+(\S+)\s+q\=\s+(\S+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/p0\=\s+(\S+)\s+p\=\s+(\S+)\s+q\=\s+(\S+)/) { } 0 0 0
1143 0 $p0 = $1;
1144 0 $p = $2;
1145 0 $q = $3;
1146 }
1147 else {
1148 0 $self->warn("unparseable beta parameters: $_");
1149 }
1150 0 $_ = $self->_readline; # need the next line
1151 0 ▶ if (/\(p1\=\s+(\S+)\)\s+w\=\s*(\S+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\(p1\=\s+(\S+)\)\s+w\=\s*(\S+)/) { } 0 0 0
1152 0 $p1 = $1;
1153 0 $w = $2;
1154 0 $data{'-shape_params'} = {
1155 'shape' => 'beta',
1156 'p0' => $p0,
1157 'p' => $p,
1158 'q' => $q,
1159 'p1' => $p1,
1160 'w' => $w
1161 };
1162 }
1163 else {
1164 0 $self->warn("unparseable beta parameters: $_");
1165 }
1166 }
1167 elsif (/^alpha\s+\(gamma\)\s+\=\s+(\S+)/) {
1168 3 my $gamma = $1;
1169 3 $_ = $self->_readline;
1170 3 my ( @r, @f );
1171 3 ▶ if (s/^r\s+\(\s*\d+\)\:\s+//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^r\s+\(\s*\d+\)\:\s+//) 3 0 3
1172 3 @r = split;
1173 }
1174 3 $_ = $self->_readline;
1175 3 ▶ if (s/^f\s*\:\s+//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^f\s*\:\s+//) 3 0 3
1176 3 @f = split;
1177 }
1178 3 $data{'-shape_params'} = {
1179 'shape' => 'alpha',
1180 'gamma' => $gamma,
1181 'r' => \@r,
1182 'f' => \@f
1183 };
1184 }
1185 }
1186 9 return new Bio::Tools::Phylo::PAML::ModelResult(%data);
1187 }
1188  
1189 sub _parse_Pos_selected_sites {
1190 6 ▶ my $self = shift;
Subroutine _parse_Pos_selected_sites: called CC=18 SCAR=28.9
1191 6 my $okay = 0;
1192 6 my (%sites) = (
1193 'default' => [],
1194 'neb' => [],
1195 'beb' => []
1196 );
1197 6 my $type = 'default';
1198 6 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 116 2 118
1199 116 ▶ next if ( /^\s+$/ || /^\s+Pr\(w\>1\)/ );
Branch: 1 branch
BranchTrueFalseTotal
if /^\s+$/ or /^\s+Pr\(w\>1\)/ 36 80 116
Condition100%3/3
/^\s+$/ or /^\s+Pr\(w\>1\)/
l!l&&r!l&&!r
33380
MC/DC100%2/2
/^\s+$/ or /^\s+Pr\(w\>1\)/
/^\s+$/ /^\s+Pr\(w\>1\)/
Truth table100%3/3
A or B
A= /^\s+$/B= /^\s+Pr\(w\>1\)/
ABresult
1X1
011
000
1200 80 ▶ if ( /^Time used/ || /^TREE/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^Time used/ or /^TREE/) 4 76 80
Condition66%2/3
/^Time used/ or /^TREE/
l!l&&r!l&&!r
4076
MC/DC50%1/2
/^Time used/ or /^TREE/
/^Time used/ /^TREE/
Truth table66%2/3
A or B
A= /^Time used/B= /^TREE/
ABresult
1X1
011
000
1201 4 $self->_pushback($_);
1202 4 last;
1203 }
1204 76 ▶ if (/^Naive Empirical Bayes/i) {
Branch: 6 branches
BranchTrueFalseTotal
if (/^Naive Empirical Bayes/i) { } 5 71 76
elsif (/^Bayes Empirical Bayes/i) { } 2 69 71
elsif (/^Positively selected sites/) { } 4 65 69
elsif ($okay and /^\s+(\d+)\s+(\S+)\s+(\-?\d+(?:\.\d+)?)(\**)\s+(\-?\d+(?:\.\d+)?)\s+\+\-\s+(\-?\d+(?:\.\d+)?)/) { } 9 56 65
elsif ($okay and /^\s+(\d+)\s+(\S+)\s+(\-?\d*(?:.\d+))(\**)\s+(\-?\d+(?:\.\d+)?)/) { } 8 48 56
elsif ($okay and /^\s+(\d+)\s+(\S)\s+([\d\.\-\+]+)(\**)/) { } 8 42 50
1205 5 $type = 'neb';
1206 }
1207 elsif (/^Bayes Empirical Bayes/i) {
1208 2 $type = 'beb';
1209 }
1210 elsif (/^Positively selected sites/) {
1211 4 $okay = 1;
1212 }
1213 ▶ elsif ( $okay
Condition100%3/3
$okay and /^\s+(\d+)\s+(\S+)\s+(\-?\d+(?:\.\d+)?)(\**)\s+(\-?\d+(?:\.\d+)?)\s+\+\-\s+(\-?\d+(?:\.\d+)?)/
!ll&&!rl&&r
2549
MC/DC100%2/2
$okay and /^\s+(\d+)\s+(\S+)\s+(\-?\d+(?:\.\d+)?)(\**)\s+(\-?\d+(?:\.\d+)?)\s+\+\-\s+(\-?\d+(?:\.\d+)?)/
$okay /^\s+(\d+)\s+(\S+)\s+(\-?\d+(?:\.\d+)?)(\**)\s+(\-?\d+(?:\.\d+)?)\s+\+\-\s+(\-?\d+(?:\.\d+)?)/
Truth table100%3/3
A and B
A= $okayB= /^\s+(\d+)\s+(\S+)\s+(\-?\d+(?:\.\d+)?)(\**)\s+(\-?\d+(?:\.\d+)?)\s+\+\-\s+(\-?\d+(?:\.\d+)?)/
ABresult
0X0
100
111
1214 && /^\s+(\d+)\s+(\S+)\s+(\-?\d+(?:\.\d+)?)(\**)\s+(\-?\d+(?:\.\d+)?)\s+\+\-\s+(\-?\d+(?:\.\d+)?)/
1215 )
1216 {
1217 9 my $signif = $4;
1218 9 ▶ $signif = '' unless defined $signif;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $signif 0 9 9
1219 9 push @{ $sites{$type} }, [ $1, $2, $3, $signif, $5, $6 ];
1220 }
1221 ▶ elsif ( $okay
Condition100%3/3
$okay and /^\s+(\d+)\s+(\S+)\s+(\-?\d*(?:.\d+))(\**)\s+(\-?\d+(?:\.\d+)?)/
!ll&&!rl&&r
2468
MC/DC100%2/2
$okay and /^\s+(\d+)\s+(\S+)\s+(\-?\d*(?:.\d+))(\**)\s+(\-?\d+(?:\.\d+)?)/
$okay /^\s+(\d+)\s+(\S+)\s+(\-?\d*(?:.\d+))(\**)\s+(\-?\d+(?:\.\d+)?)/
Truth table100%3/3
A and B
A= $okayB= /^\s+(\d+)\s+(\S+)\s+(\-?\d*(?:.\d+))(\**)\s+(\-?\d+(?:\.\d+)?)/
ABresult
0X0
100
111
1222 && /^\s+(\d+)\s+(\S+)\s+(\-?\d*(?:.\d+))(\**)\s+(\-?\d+(?:\.\d+)?)/
1223 )
1224 {
1225 8 my $signif = $4;
1226 8 ▶ $signif = '' unless defined $signif;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $signif 0 8 8
1227 8 push @{ $sites{$type} }, [ $1, $2, $3, $signif, $5 ];
1228 }
1229 ▶ elsif ( $okay && /^\s+(\d+)\s+(\S)\s+([\d\.\-\+]+)(\**)/ ) {
Condition100%3/3
$okay and /^\s+(\d+)\s+(\S)\s+([\d\.\-\+]+)(\**)/
!ll&&!rl&&r
2388
MC/DC100%2/2
$okay and /^\s+(\d+)\s+(\S)\s+([\d\.\-\+]+)(\**)/
$okay /^\s+(\d+)\s+(\S)\s+([\d\.\-\+]+)(\**)/
Truth table100%3/3
A and B
A= $okayB= /^\s+(\d+)\s+(\S)\s+([\d\.\-\+]+)(\**)/
ABresult
0X0
100
111
1230 8 my $signif = $4;
1231 8 ▶ $signif = '' unless defined $signif;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $signif 0 8 8
1232 8 push @{ $sites{$type} }, [ $1, $2, $3, $signif ];
1233 }
1234 }
1235 6 return ( $sites{'default'}, $sites{'neb'}, $sites{'beb'} );
1236 }
1237  
1238 sub _parse_branch_dnds {
1239 10 ▶ my $self = shift;
Subroutine _parse_branch_dnds: called CC=7 SCAR=19.5
1240 10 my ($okay) = (0);
1241 10 my %branch_dnds;
1242 my @header;
1243 10 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 136 0 136
1244 136 ▶ next if (/^\s+$/);
Branch: 1 branch
BranchTrueFalseTotal
if /^\s+$/ 38 98 136
1245 98 ▶ next unless ( $okay || /^\s+branch\s+t/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $okay or /^\s+branch\s+t/ 0 98 98
Condition66%2/3
$okay or /^\s+branch\s+t/
l!l&&r!l&&!r
88100
MC/DC0%0/2
$okay or /^\s+branch\s+t/
$okay /^\s+branch\s+t/
Truth table66%2/3
A or B
A= $okayB= /^\s+branch\s+t/
ABresult
1X1
011
000
1246 98 ▶ if (/^\s+branch\s+(.+)/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^\s+branch\s+(.+)/) { } 10 88 98
elsif (/^\s*(\d+\.\.\d+)/) { } 78 10 88
1247 10 s/^\s+//;
1248 10 @header = split( /\s+/, $_ );
1249 10 $okay = 1;
1250 }
1251 elsif (/^\s*(\d+\.\.\d+)/) {
1252 78 my $branch = $1;
1253 78 s/^\s+//;
1254 78 my $i = 0;
1255  
1256 # fancyness just maps the header names like 't' or 'dN'
1257 # into the hash so we get at the end of the day
1258 # 't' => 0.067
1259 # 'dN'=> 0.001
1260 78 $branch_dnds{$branch} = { map { $header[ $i++ ] => $_ } split };
1261 }
1262 else {
1263 10 $self->_pushback($_);
1264 10 last;
1265 }
1266 }
1267 10 return %branch_dnds;
1268 }
1269  
1270 #baseml stuff
1271 sub _parse_nt_freqs {
1272 2 ▶ my ($self) = @_;
Subroutine _parse_nt_freqs: called CC=14 SCAR=27.3
1273 2 my ( $okay, $done, $header ) = ( 0, 0, 0 );
1274 2 my (@bases);
1275 2 ▶ my $numseqs = scalar @{ $self->{'_summary'}->{'seqs'} || [] };
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_summary"}{"seqs"} or [] 0 2 2
1276 2 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 28 0 28
1277 28 ▶ if ( /^TREE/ || /^Distances/ ) { $self->_pushback($_); last }
Branch: 1 branch
BranchTrueFalseTotal
if (/^TREE/ or /^Distances/) 0 28 28
Condition33%1/3
/^TREE/ or /^Distances/
l!l&&r!l&&!r
0028
MC/DC0%0/2
/^TREE/ or /^Distances/
/^TREE/ /^Distances/
Truth table33%1/3
A or B
A= /^TREE/B= /^Distances/
ABresult
1X1
011
000
1278 28 ▶ last if ($done);
Branch: 1 branch
BranchTrueFalseTotal
if $done 2 26 28
1279 26 ▶ next if ( /^\s+$/ || /^\(Ambiguity/ );
Branch: 1 branch
BranchTrueFalseTotal
if /^\s+$/ or /^\(Ambiguity/ 10 16 26
Condition66%2/3
/^\s+$/ or /^\(Ambiguity/
l!l&&r!l&&!r
10016
MC/DC50%1/2
/^\s+$/ or /^\(Ambiguity/
/^\s+$/ /^\(Ambiguity/
Truth table66%2/3
A or B
A= /^\s+$/B= /^\(Ambiguity/
ABresult
1X1
011
000
1280 16 ▶ if (/^Frequencies\./) {
Branch: 5 branches
BranchTrueFalseTotal
if (/^Frequencies\./) { } 2 14 16
elsif (not $okay) { } 0 14 14
elsif (not $header) { } 2 12 14
elsif (/^\#\s+constant\s+sites\:\s+ (\d+)\s+ # constant sites \(\s*([\d\.]+)\s*\%\s*\)/ox) { } 2 10 12
elsif (/^ln\s+Lmax\s+\(unconstrained\)\s+\=\s+(\S+)/ox) { } 2 8 10
1281 2 $okay = 1;
1282 }
1283 elsif ( !$okay ) { # skip till we see 'Frequencies.
1284 0 next;
1285 }
1286 elsif ( !$header ) {
1287 2 s/^\s+//; # remove leading whitespace
1288 2 @bases = split; # get an array of the all the aa names
1289 2 $header = 1;
1290 2 $self->{'_summary'}->{'ntfreqs'} = {}; # reset/clear values
1291 2 next;
1292 }
1293 elsif (
1294 /^\#\s+constant\s+sites\:\s+
1295 (\d+)\s+ # constant sites
1296 \(\s*([\d\.]+)\s*\%\s*\)/ox
1297 )
1298 {
1299 2 $self->{'_summary'}->{'stats'}->{'constant_sites'} = $1;
1300 2 $self->{'_summary'}->{'stats'}->{'constant_sites_percentage'} = $2;
1301 }
1302 elsif (/^ln\s+Lmax\s+\(unconstrained\)\s+\=\s+(\S+)/ox) {
1303 2 $self->{'_summary'}->{'stats'}->{'loglikelihood'} = $1;
1304 2 $done = 1; # done for sure
1305 }
1306 else {
1307 8 my ( $seqname, @freqs ) = split;
1308 8 my $basect = 0;
1309 8 foreach my $f (@freqs) {
1310  
1311 # this will also store 'Average'
1312 $self->{'_summary'}->{'ntfreqs'}->{$seqname}
1313 32 ->{ $bases[ $basect++ ] } = $f;
1314 }
1315 }
1316 }
1317 }
1318  
1319 sub _parse_nt_dists {
1320 2 ▶ my ($self) = @_;
Subroutine _parse_nt_dists: called CC=16 SCAR=27.9
1321 2 my ( $okay, $seen, $done ) = ( 0, 0, 0 );
1322 2 my ( %matrix, @names );
1323 2 ▶ my $numseqs = scalar @{ $self->{'_summary'}->{'seqs'} || [] };
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_summary"}{"seqs"} or [] 0 2 2
1324 2 my $type = '';
1325 2 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 13 1 14
1326 13 ▶ if (/^TREE/) { $self->_pushback($_); last; }
Branch: 1 branch
BranchTrueFalseTotal
if (/^TREE/) 0 13 13
1327 13 ▶ last if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 1 12 13
1328 12 ▶ next if (/^This matrix is not used in later/);
Branch: 1 branch
BranchTrueFalseTotal
if /^This matrix is not used in later/ 2 10 12
1329 10 ▶ if (/^\s+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s+$/) 2 8 10
1330 2 ▶ last if ($seen);
Branch: 1 branch
BranchTrueFalseTotal
if $seen 0 2 2
1331 2 next;
1332 }
1333 8 ▶ if (/^Distances:(\S+)\s+\(([^\)]+)\)\s+\(alpha set at (\-?\d+\.\d+)\)/)
Branch: 1 branch
BranchTrueFalseTotal
if (/^Distances:(\S+)\s+\(([^\)]+)\)\s+\(alpha set at (\-?\d+\.\d+)\)/) 2 6 8
1334 {
1335 2 $okay = 1;
1336 2 $type = $1;
1337 2 next;
1338 }
1339 6 s/\s+$//g; # remove trailing space
1340 6 ▶ if ($okay) {
Branch: 1 branch
BranchTrueFalseTotal
if ($okay) 6 0 6
1341 6 my ( $seqname, $vl ) = split( /\s+/, $_, 2 );
1342 6 $seen = 1;
1343 6 my $i = 0;
1344 6 ▶ if ( defined $vl ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $vl) 4 2 6
1345 4 ▶ while ( $vl =~ /(\-?\d+\.\d+)\s*\(\s*(\-?\d+\.\d+)\s*\)\s*/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vl =~ /(\-?\d+\.\d+)\s*\(\s*(\-?\d+\.\d+)\s*\)\s*/g) 6 4 10
1346 6 my ( $kappa, $alpha ) = ( $1, $2 );
1347 $matrix{$seqname}{ $names[$i] } =
1348 6 $matrix{ $names[$i] }{$seqname} = [ $kappa, $alpha ];
1349  
1350 6 $i++;
1351 }
1352 4 ▶ unless ($i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($i) 0 4 4
1353 0 $self->warn("no matches for $vl\n");
1354 }
1355 }
1356 6 push @names, $seqname;
1357 6 $matrix{$seqname}->{$seqname} = [ 0, 0 ];
1358 }
1359 6 ▶ $done = 1 if ( scalar @names == $numseqs );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @names == $numseqs 2 4 6
1360 }
1361 2 my %dist;
1362 2 my $i = 0;
1363 2 my ( @kvalues, @avalues );
1364 2 foreach my $lname (@names) {
1365 6 my ( @arow, @krow );
1366 6 my $j = 0;
1367 6 foreach my $rname (@names) {
1368 18 my $v = $matrix{$lname}{$rname};
1369  
1370 18 push @krow, $v->[0]; # kappa values
1371 18 push @arow, $v->[1]; # alpha
1372 18 $dist{$lname}{$rname} = [ $i, $j++ ];
1373 }
1374 6 $i++;
1375 6 push @kvalues, \@krow;
1376 6 push @avalues, \@arow;
1377 }
1378 return (
1379 Bio::Matrix::PhylipDist->new(
1380 -program => $self->{'_summary'}->{'seqtype'},
1381 -matrix => \%dist,
1382 -names => \@names,
1383 -values => \@kvalues
1384 ),
1385 Bio::Matrix::PhylipDist->new(
1386 2 -program => $self->{'_summary'}->{'seqtype'},
1387 -matrix => \%dist,
1388 -names => \@names,
1389 -values => \@avalues
1390 )
1391 );
1392 }
1393  
1394 # BASEML
1395 sub _parse_rate_parametes {
1396 0 ▶ my $self = shift;
Subroutine _parse_rate_parametes: not called CC=10 SCAR=47.0
1397 0 my (%rate_parameters);
1398 0 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 0 0 0
1399 0 ▶ if (/^Rate\s+parameters:\s+/) {
Branch: 5 branches
BranchTrueFalseTotal
if (/^Rate\s+parameters:\s+/) { } 0 0 0
elsif (/^Base\s+frequencies:\s+/) { } 0 0 0
elsif (m[^Rate\s+matrix\s+Q,\s+Average\s+Ts/Tv\s+(\([^\)+]+\))?\s*\=\s+ (\-?\d+\.\d+)]x) { } 0 0 0
elsif (/^alpha\s+\(gamma,\s+K=\s*(\d+)\s*\)\s*\=\s*(\-?\d+\.\d+)/) { } 0 0 0
elsif (s/^(r|f):\s+//) { } 0 0 0
1400 0 s/\s+$//;
1401 0 $rate_parameters{'rate_parameters'} = [ split( /\s+/, $_ ) ];
1402 }
1403 elsif (/^Base\s+frequencies:\s+/) {
1404 0 s/\s+$//;
1405 0 $rate_parameters{'base_frequencies'} = [ split( /\s+/, $_ ) ];
1406 }
1407 elsif (
1408 m/^Rate\s+matrix\s+Q,\s+Average\s+Ts\/Tv\s+(\([^\)+]+\))?\s*\=\s+
1409 (\-?\d+\.\d+)/x
1410 )
1411 {
1412 0 $rate_parameters{'average_TsTv'} = $1;
1413 0 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 0 0 0
1414  
1415 # short circuit
1416 0 ▶ last if (/^\s+$/);
Branch: 1 branch
BranchTrueFalseTotal
if /^\s+$/ 0 0 0
1417 0 ▶ if (/^alpha/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^alpha/) 0 0 0
1418 0 $self->_pushback($_);
1419 0 last;
1420 }
1421 0 s/^\s+//;
1422 0 s/\s+$//;
1423 0 push @{ $rate_parameters{'rate_matrix_Q'} }, [split];
1424 }
1425 }
1426 elsif (/^alpha\s+\(gamma,\s+K=\s*(\d+)\s*\)\s*\=\s*(\-?\d+\.\d+)/) {
1427 0 $rate_parameters{'K'} = $1;
1428 0 $rate_parameters{'alpha'} = $2;
1429 }
1430 elsif (s/^(r|f):\s+//) {
1431 0 my ($p) = $1;
1432 0 s/\s+$//;
1433 0 $rate_parameters{$p} = [split];
1434 }
1435 }
1436 }
1437  
1438 # RST parsing
1439 sub _parse_rst {
1440 20 ▶ my ($self) = @_;
Subroutine _parse_rst: called CC=47 SCAR=44.2
1441 20 ▶ return unless $self->{'_dir'} && -d $self->{'_dir'} && -r $self->{'_dir'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_dir"} and -d $self->{"_dir"} and -r $self->{"_dir"} 0 1 1
Condition66%4/6
$self->{"_dir"} and -d $self->{"_dir"} and -r $self->{"_dir"}
!ll&&!rl&&r
1901
$self->{"_dir"} and -d $self->{"_dir"}
!ll&&!rl&&r
1901
MC/DC33%1/3
$self->{"_dir"} and -d $self->{"_dir"} and -r $self->{"_dir"}
$self->{"_dir"} -d $self->{"_dir"} -r $self->{"_dir"}
Truth table50%2/4
A and B and C
A= $self->{"_dir"}B= -d $self->{"_dir"}C= -r $self->{"_dir"}
ABCresult
0XX0
10X0
1100
1111
1442  
1443 1 my $rstfile = File::Spec->catfile( $self->{'_dir'}, $RSTFILENAME );
1444 1 ▶ return unless -e $rstfile && !-z $rstfile;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $rstfile and not -z $rstfile 0 1 1
Condition33%1/3
-e $rstfile and not -z $rstfile
!ll&&!rl&&r
001
MC/DC0%0/2
-e $rstfile and not -z $rstfile
-e $rstfile not -z $rstfile
Truth table33%1/3
A and not(B)
A= -e $rstfileB= not -z $rstfile
ABresult
0X0
100
111
1445 1 my $rstio = Bio::Root::IO->new( -file => $rstfile );
1446  
1447 # define whatever data structures you need to store the data
1448 # key points are to reuse existing bioperl objs (like Bio::Seq)
1449 # where appropriate
1450 1 my ( @firstseq, @seqs, @trees, @per_site_prob );
1451 1 my $count;
1452 1 ▶ while ( defined( $_ = $rstio->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $rstio->_readline)) 616 1 617
1453  
1454 # implement the parsing here
1455 616 ▶ if (/^TREE\s+\#\s+(\d+)/) {
Branch: 5 branches
BranchTrueFalseTotal
if (/^TREE\s+\#\s+(\d+)/) { } 1 615 616
elsif (/^Prob\sof\sbest\scharacter\sat\seach\snode,\slisted\sby\ssite/) { } 1 614 615
elsif (/^Check\sroot\sfor\sdirections\sof\schange\./ or /^Summary\sof\schanges\salong\sbranches\./) { } 1 613 614
elsif (/^Overall\s+accuracy\s+of\s+the\s+(\d+)\s+ancestral\s+sequences:/) { } 0 613 613
elsif (/^List of extant and reconstructed sequences/o) { } 3 610 613
1456 1 ▶ while ( defined( $_ = $rstio->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $rstio->_readline)) 10 0 10
1457 10 ▶ if (/tree\s+with\s+node\s+labels\s+for/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/tree\s+with\s+node\s+labels\s+for/) 1 9 10
1458 1 my $tree = Bio::TreeIO->new(
1459 -noclose => 1,
1460 -fh => $rstio->_fh,
1461 -format => 'newick'
1462 )->next_tree;
1463  
1464 # cleanup leading/trailing whitespace
1465 1 for my $n ( $tree->get_nodes ) {
1466 12 my $id = $n->id;
1467 12 $id =~ s/^\s+//;
1468 12 $id =~ s/\s+$//;
1469 12 $n->id($id);
1470 12 ▶ if ( defined( my $blen = $n->branch_length ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $blen = $n->branch_length)) 11 1 12
1471 11 $blen =~ s/^\s+//;
1472 11 $blen =~ s/\s+$//;
1473 11 $n->branch_length($blen);
1474 }
1475 }
1476 1 push @trees, $tree;
1477 1 last;
1478 }
1479 }
1480 }
1481 elsif (/^Prob\sof\sbest\scharacter\sat\seach\snode,\slisted\sby\ssite/)
1482 {
1483 1 $self->{'_rst'}->{'persite'} = [];
1484 1 ▶ while ( defined( $_ = $rstio->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $rstio->_readline)) 135 0 135
1485 135 ▶ next if ( /^Site/i || /^\s+$/ );
Branch: 1 branch
BranchTrueFalseTotal
if /^Site/i or /^\s+$/ 4 131 135
Condition100%3/3
/^Site/i or /^\s+$/
l!l&&r!l&&!r
13131
MC/DC100%2/2
/^Site/i or /^\s+$/
/^Site/i /^\s+$/
Truth table100%3/3
A or B
A= /^Site/iB= /^\s+$/
ABresult
1X1
011
000
1486 131 ▶ if (s/^\s+(\d+)\s+(\d+)\s+([^:]+)\s*:\s*(.+)//) {
Branch: 2 branches
BranchTrueFalseTotal
if (s/^\s+(\d+)\s+(\d+)\s+([^:]+)\s*:\s*(.+)//) { } 130 1 131
elsif (/^Summary\sof\schanges\salong\sbranches\./) { } 1 0 1
1487 130 my ( $sitenum, $freq, $extant, $ancestral ) =
1488 ( $1, $2, $3, $4 );
1489 130 my ( @anc_site, @extant_site );
1490 130 @extant_site = {};
1491 130 ▶ while ( $extant =~ s/^([A-Z\-]{3})\s+\(([A-Z*])\)\s+//g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extant =~ s/^([A-Z\-]{3})\s+\(([A-Z*])\)\s+//g) 910 130 1040
1492 910 push @extant_site, { 'codon' => $1, 'aa' => $2 };
1493 }
1494 130 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if ($ancestral =~ s/^([A-Z\-]{3})\s+([A-Z*])\s+ # codon AA (\S+)\s+ # Prob \(([A-Z*])\s+(\S+)\)\s*//gx) 650 130 780
1495 $ancestral =~ s/^([A-Z\-]{3})\s+([A-Z*])\s+ # codon AA
1496 (\S+)\s+ # Prob
1497 \(([A-Z*])\s+(\S+)\)\s*//xg # AA Prob
1498 )
1499 {
1500 650 push @anc_site,
1501 {
1502 'codon' => $1,
1503 'aa' => $2,
1504 'prob' => $3,
1505 'Yang95_aa' => $4,
1506 'Yang95_aa_prob' => $5
1507 };
1508 }
1509  
1510 # saving persite
1511 130 $self->{'_rst'}->{'persite'}->[$sitenum] =
1512 [ @extant_site, @anc_site ];
1513 }
1514 elsif (/^Summary\sof\schanges\salong\sbranches\./) {
1515 1 last;
1516 }
1517 }
1518 }
1519 ▶ elsif (/^Check\sroot\sfor\sdirections\sof\schange\./
Condition66%2/3
/^Check\sroot\sfor\sdirections\sof\schange\./ or /^Summary\sof\schanges\salong\sbranches\./
l!l&&r!l&&!r
10613
MC/DC50%1/2
/^Check\sroot\sfor\sdirections\sof\schange\./ or /^Summary\sof\schanges\salong\sbranches\./
/^Check\sroot\sfor\sdirections\sof\schange\./ /^Summary\sof\schanges\salong\sbranches\./
Truth table66%2/3
A or B
A= /^Check\sroot\sfor\sdirections\sof\schange\./B= /^Summary\sof\schanges\salong\sbranches\./
ABresult
1X1
011
000
1520 || /^Summary\sof\schanges\salong\sbranches\./ )
1521 {
1522 1 my ( @branches, @branch2node, $branch, $node );
1523 1 my $tree = $trees[-1];
1524 1 ▶ if ( !$tree ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tree) 0 1 1
1525 0 $self->warn("No tree built before parsing Branch changes\n");
1526 0 last;
1527 }
1528 my @nodes = (
1529 12 map { $_->[0] }
1530 30 sort { $a->[1] <=> $b->[1] }
1531 1 map { [ $_, $_->id =~ /^(\d+)\_?/ ] } $tree->get_nodes
1532 );
1533 1 unshift @nodes,
1534 undef; # fake first node so that index will match nodeid
1535 1 ▶ while ( defined( $_ = $rstio->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $rstio->_readline)) 93 0 93
1536 93 ▶ next if /^\s+$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s+$/ 36 57 93
1537 57 ▶ if (m/^List\sof\sextant\sand\sreconstructed\ssequences/) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^List\sof\sextant\sand\sreconstructed\ssequences/) { } 1 56 57
elsif (/^Branch\s+(\d+):\s+(\d+)\.\.(\d+)\s+/) { } 11 45 56
elsif (/^\s+(\d+)\s+([A-Z*])\s+(\S+)\s+\-\>\s+([A-Z*])\s+(\S+)?/) { } 45 0 45
1538 1 $rstio->_pushback($_);
1539 1 last;
1540 }
1541 elsif (/^Branch\s+(\d+):\s+(\d+)\.\.(\d+)\s+/) {
1542 11 my ( $left, $right );
1543 11 ( $branch, $left, $right ) = ( $1, $2, $3 );
1544 11 ($node) = $nodes[$right];
1545 11 ▶ if ( !$node ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($node) 0 11 11
1546 0 $self->warn(
1547 "cannot find $right in $tree ($branch $left..$right)\n"
1548 );
1549 0 last;
1550 }
1551 11 ▶ if (/\(n=\s*(\S+)\s+s=\s*(\S+)\)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\(n=\s*(\S+)\s+s=\s*(\S+)\)/) 11 0 11
1552 11 $node->add_tag_value( 'n', $1 );
1553 11 $node->add_tag_value( 's', $2 );
1554 }
1555 11 $branch2node[$branch] = $right;
1556 }
1557 elsif (
1558 /^\s+(\d+)\s+([A-Z*])\s+(\S+)\s+\-\>\s+([A-Z*])\s+(\S+)?/)
1559 {
1560 45 my ( $site, $anc, $aprob, $derived, $dprob ) =
1561 ( $1, $2, $3, $4, $5 );
1562 45 ▶ if ( !$node ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($node) 0 45 45
1563 0 $self->warn("no branch line was previously parsed!");
1564 0 next;
1565 }
1566 45 my %c = (
1567 'site' => $site,
1568 'anc_aa' => $anc,
1569 'anc_prob' => $aprob,
1570 'derived_aa' => $derived,
1571 );
1572 45 ▶ $c{'derived_prob'} = $dprob if defined $dprob;
Branch: 1 branch
BranchTrueFalseTotal
if defined $dprob 28 17 45
1573 45 $node->add_tag_value( 'changes', \%c );
1574 }
1575 }
1576 }
1577 elsif (
1578 /^Overall\s+accuracy\s+of\s+the\s+(\d+)\s+ancestral\s+sequences:/)
1579 {
1580 0 my $line = $rstio->_readline;
1581 0 $line =~ s/^\s+//;
1582 0 $line =~ s/\s+$//;
1583 0 my @overall_site = split( /\s+/, $line );
1584  
1585 # skip next 2 lines, want the third
1586 0 for ( 1 .. 3 ) {
1587 0 $line = $rstio->_readline;
1588 }
1589 0 $line =~ s/^\s+//;
1590 0 $line =~ s/\s+$//;
1591 0 my @overall_seq = split( /\s+/, $line );
1592 0 ▶ if ( @overall_seq != @overall_site
Branch: 1 branch
BranchTrueFalseTotal
if (@overall_seq != @overall_site or @overall_seq != @seqs) 0 0 0
Condition0%0/3
@overall_seq != @overall_site or @overall_seq != @seqs
l!l&&r!l&&!r
000
MC/DC0%0/2
@overall_seq != @overall_site or @overall_seq != @seqs
@overall_seq != @overall_site @overall_seq != @seqs
Truth table0%0/3
A or B
A= @overall_seq != @overall_siteB= @overall_seq != @seqs
ABresult
1X1
011
000
1593 || @overall_seq != @seqs )
1594 {
1595 0 $self->warn(
1596 "out of sync somehow seqs, site scores don't match\n");
1597 0 $self->warn("@seqs @overall_seq @overall_site\n");
1598 }
1599 0 for (@seqs) {
1600 0 $_->description(
1601 sprintf(
1602 "overall_accuracy_site=%s overall_accuracy_seq=%s",
1603 shift @overall_site,
1604 shift @overall_seq
1605 )
1606 );
1607 }
1608 }
1609 elsif (m/^List of extant and reconstructed sequences/o) {
1610 3 my $seqcount = 0;
1611 3 ▶ while ( defined( $_ = $rstio->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $rstio->_readline)) 311 1 312
1612 311 ▶ last if (/^Overall accuracy of the/);
Branch: 1 branch
BranchTrueFalseTotal
if /^Overall accuracy of the/ 2 309 311
1613 309 ▶ if (/^\s+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s+$/) 61 248 309
1614 61 ▶ last if $seqcount && $seqcount == @seqs;
Branch: 1 branch
BranchTrueFalseTotal
if $seqcount and $seqcount == @seqs 0 61 61
Condition33%1/3
$seqcount and $seqcount == @seqs
!ll&&!rl&&r
6100
MC/DC0%0/2
$seqcount and $seqcount == @seqs
$seqcount $seqcount == @seqs
Truth table33%1/3
A and B
A= $seqcountB= $seqcount == @seqs
ABresult
0X0
100
111
1615 61 next;
1616 }
1617 248 ▶ if (/^\s*(\d+)\s+(\d+)\s+$/) { $seqcount = $1; next }
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*(\d+)\s+(\d+)\s+$/) 0 248 248
1618  
1619 # runmode = (0)
1620 # this should in fact be packed into a Bio::SimpleAlign object
1621 # instead of an array but we'll stay with this for now
1622 248 ▶ if (/^node/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^node/) 20 228 248
1623 20 my ( $name, $num, $seqstr ) = split( /\s+/, $_, 3 );
1624 20 $name .= $num;
1625 20 $seqstr =~ s/\s+//g; # remove whitespace
1626 20 ▶ unless (@firstseq) {
Branch: 1 branch
BranchTrueFalseTotal
if (@firstseq) { } 19 1 20
1627 1 @firstseq = split( //, $seqstr );
1628 1 push @seqs,
1629 Bio::LocatableSeq->new(
1630 -display_id => $name,
1631 -seq => $seqstr
1632 );
1633 }
1634 else {
1635 19 my $i = 0;
1636 19 my $v;
1637 19 ▶ while ( ( $v = index( $seqstr, '.', $i ) ) >= $i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($v = index($seqstr, ".", $i)) >= $i) 0 19 19
1638  
1639 # replace the '.' with the correct seq from the
1640 0 substr( $seqstr, $v, 1, $firstseq[$v] );
1641 0 $i = $v;
1642 }
1643 19 $self->debug("adding seq $seqstr\n");
1644 19 push @seqs,
1645 Bio::LocatableSeq->new(
1646 -display_id => $name,
1647 -seq => $seqstr
1648 );
1649 }
1650 }
1651 }
1652 3 $self->{'_rst'}->{'rctrted_seqs'} = \@seqs;
1653 }
1654 else {
1655 }
1656 }
1657 1 $self->{'_rst'}->{'trees'} = \@trees;
1658 1 return;
1659 }
1660  
1661 7 1;
1662  
1663 __END__
« Tools/Run/Phylo/PAML/Evolver.pm ↑ Summary Tools/Run/Phylo/PAML/Yn00.pm »