Phylo/Parsers/Nexus.pm

filter: Statementstmt 82.6% 568 / 687 Branchbran 71.0% 213 / 300 Conditioncond 59.4% 116 / 195 MC/DCmcdc 45.0% 55 / 122 Subroutinesub 85.1% 46 / 54 Podpod n/a totaltotal 73.4% 998 / 1358 CC 240 SCAR 30.9
CC
240
Cov
76%
_semicolon
55.5
_tokenize
45.4
_resolve_ambig
44.2
CRAP 22.0
« Phylo/Unparsers/Phyloxml.pm ↑ Summary Phylo/Matrices/Datatype/Mixed.pm »
1 package Bio::Phylo::Parsers::Nexus;
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use base 'Bio::Phylo::Parsers::Abstract';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Bio::Phylo::Factory;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Bio::Phylo::IO 'parse';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Bio::Phylo::Util::CONSTANT qw':objecttypes looks_like_instance';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Bio::Phylo::Util::Exceptions 'throw';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # TODO: handle mixed? distances, splits, bipartitions
11 6 my $TAXA = _TAXA_;
12 6 my $MATRIX = _MATRIX_;
13  
14 # useful regular expressions
15 6 my $COMMENT = qr|^\[|; # crude, only checks first char, use after tokenizing!
16 6 my $QUOTES_OR_BRACKETS =
17 qr/[\[\]'"]/mox; # catch all for opening/closing square brackets and quotes
18 6 my $OPENING_QUOTE_OR_BRACKET =
19 qr/^(.*?)([\['"].*)$/mox; # capturing regex for opening sq. br. & q.
20  
21 # this is a dispatch table whose sub references are invoked
22 # during parsing. the keys match the tokens upon which the
23 # respective subs are called. Underscored (private) fields are for parsing
24 # context. The fields of this table comprise the default state of the
25 # parser object.
26 6 my %defaults = (
27 '_lines' => undef,
28 '_current' => undef,
29 '_previous' => undef,
30 '_begin' => undef,
31 '_ntax' => undef,
32 '_nchar' => undef,
33 '_gap' => undef,
34 '_missing' => undef,
35 '_i' => undef,
36 '_tree' => undef,
37 '_trees' => undef,
38 '_treename' => undef,
39 '_treestart' => undef,
40 '_row' => undef,
41 '_matrixtype' => undef,
42 '_found' => 0,
43 '_linemode' => 0,
44 '_taxlabels' => [],
45 '_tokens' => [],
46 '_context' => [],
47 '_translate' => [],
48 '_symbols' => [],
49 '_charlabels' => [],
50 '_statelabels' => [],
51 '_charstatelabels' => [],
52 '_tmpstatelabels' => [],
53 '_comments' => [],
54 '_treenames' => [],
55 '_matrixrowlabels' => [],
56 '_matrix' => {},
57 '_charset' => {},
58 '_taxset' => {},
59 'begin' => \&_begin,
60 'taxa' => \&_taxa,
61 'title' => \&_title,
62 'dimensions' => \&_dimensions,
63 'ntax' => \&_ntax,
64 'taxlabels' => \&_taxlabels,
65 'blockid' => \&_blockid,
66 'data' => \&_data,
67 'characters' => \&_characters,
68 'codons' => \&_codons,
69 'nchar' => \&_nchar,
70 'format' => \&_format,
71 'datatype' => \&_datatype,
72 'matchchar' => \&_matchchar,
73 'gap' => \&_gap,
74 'missing' => \&_missing,
75 'charlabels' => \&_charlabels,
76 'statelabels' => \&_statelabels,
77 'charstatelabels' => \&_charstatelabels,
78 'symbols' => \&_symbols,
79 'items' => \&_items,
80 'matrix' => \&_matrix,
81 'charset' => \&_charset,
82 'taxset' => \&_taxset,
83 'trees' => \&_trees,
84 'translate' => \&_translate,
85 'tree' => \&_tree,
86 'utree' => \&_tree,
87 'end' => \&_end,
88 'endblock' => \&_end,
89 '#nexus' => \&_nexus,
90 'link' => \&_link,
91 ';' => \&_semicolon,
92 'interleave' => \&_interleave,
93 );
94  
95 =head1 NAME
96  
97 Bio::Phylo::Parsers::Nexus - Parser used by Bio::Phylo::IO, no serviceable parts inside
98  
99 =head1 DESCRIPTION
100  
101 This module parses nexus files. It is called by the L<Bio::Phylo::IO> module,
102 there is no direct usage. The parser can handle files and strings with multiple
103 tree, taxon, and characters blocks whose links are defined using Mesquite's
104 "TITLE = 'some_name'" and "LINK TAXA = 'some_name'" tokens.
105  
106 The parser returns a reference to an array containing one or more taxa, trees
107 and matrices objects. Nexus comments are stripped, private nexus blocks (and the
108 'assumptions' block) are skipped. It currently doesn't handle 'mixed' data.
109  
110 =begin comment
111  
112 Type : Constructor
113 Title : _new
114 Usage : my $nexus = Bio::Phylo::Parsers::Nexus->_new;
115 Function: Initializes a Bio::Phylo::Parsers::Nexus object.
116 Returns : A Bio::Phylo::Parsers::Nexus object.
117 Args : none.
118  
119 =end comment
120  
121 =cut
122  
123 15 ▶sub _process_defaults {
Subroutine _process_defaults: called CC=4 SCAR=13.9
124 15 my $self = shift;
125 15 for my $key ( keys %defaults ) {
126 990 ▶ if ( looks_like_instance( $defaults{$key}, 'ARRAY' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (&looks_like_instance($defaults{$key}, 'ARRAY')) { } 180 810 990
elsif (&looks_like_instance($defaults{$key}, 'HASH')) { } 45 765 810
127 180 $self->{$key} = [];
128 }
129 elsif ( looks_like_instance( $defaults{$key}, 'HASH' ) ) {
130 45 $self->{$key} = {};
131 }
132 else {
133 765 $self->{$key} = $defaults{$key};
134 }
135 }
136 15 return $self;
137 }
138  
139 =begin comment
140  
141 Type : Wrapper
142 Title : _from_handle(\*FH)
143 Usage : $nexus->_from_handle(\*FH);
144 Function: Does all the parser magic, from a file handle
145 Returns : ARRAY
146 Args : \*FH = file handle
147  
148 =end comment
149  
150 =cut
151  
152 15 ▶sub _parse {
Subroutine _parse: called CC=17 SCAR=30.2
153 15 my $self = shift;
154 15 $self->_process_defaults;
155 15 $self->_logger->info("going to parse nexus data");
156 15 $self->{'_lines'} = $self->_stringify(@_);
157 15 $self->{'_tokens'} = $self->_tokenize( $self->{'_lines'} );
158  
159 # iterate over tokens, dispatch methods from %{ $self } table
160 # This is the meat of the parsing, from here everything else is called.
161 15 $self->_logger->info("tokenized and split data, going to parse blocks");
162 15 my $i = 0;
163 15 my $private_block;
164 15 my $token_queue = [ undef, undef, undef ];
165 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
166 15 TOKEN_LINE: for my $token_line ( @{ $self->{'_tokens'} } ) {
167 313 ▶ if ( not $self->{'_linemode'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->{'_linemode'}) { } 265 48 313
elsif ($self->{'_linemode'}) { } 48 0 48
168 265 RAW_TOKEN: for my $raw_token ( @{$token_line} ) {
169 1060 ▶ if ( $raw_token =~ qr/^\[/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raw_token =~ qr/^\[/) 10 1050 1060
170 10 push @{ $self->{'_comments'} }, $raw_token;
171 10 next RAW_TOKEN;
172 }
173 1050 my $lower_case_token = lc($raw_token);
174 1050 push @$token_queue, $lower_case_token;
175 1050 shift @$token_queue;
176 1050 ▶ if ( exists $self->{$lower_case_token} and not $private_block )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{$lower_case_token} and not $private_block) { } 415 635 1050
elsif ($self->{'_current'} and not $private_block) { } 634 2 636
Condition66%2/3
exists $self->{$lower_case_token} and not $private_block
!ll&&!rl&&r
6350415
MC/DC50%1/2
exists $self->{$lower_case_token} and not $private_block
exists $self->{$lower_case_token} not $private_block
Truth table66%2/3
A and not(B)
A= exists $self->{$lower_case_token}B= not $private_block
ABresult
0X0
100
111
177 {
178 415 ▶ if ( ref $self->{$lower_case_token} eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{$lower_case_token} eq "CODE") 415 0 415
179 415 $self->{'_previous'} = $self->{'_current'};
180 415 $self->{'_current'} = $lower_case_token;
181  
182 # pull code ref from dispatch table
183 415 my $c = $self->{$lower_case_token};
184  
185 # invoke as object method
186 415 $self->$c($raw_token);
187 414 next RAW_TOKEN;
188 }
189 }
190 ▶ elsif ( $self->{'_current'} and not $private_block ) {
Condition66%2/3
$self->{"_current"} and not $private_block
!ll&&!rl&&r
10634
MC/DC50%1/2
$self->{"_current"} and not $private_block
$self->{"_current"} not $private_block
Truth table66%2/3
A and not(B)
A= $self->{"_current"}B= not $private_block
ABresult
0X0
100
111
191 634 my $c = $self->{ $self->{'_current'} };
192 634 $self->$c($raw_token);
193 634 next RAW_TOKEN;
194 }
195  
196 # $self->{'_begin'} is switched 'on' by &_begin(), and 'off'
197 # again by any one of the appropriate subsequent tokens, i.e.
198 # taxa, data, characters and trees
199 1 ▶ if ( $self->{'_begin'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_begin"} and not exists $self->{$lower_case_token} and not $private_block) 0 1 1
Condition33%2/6
$self->{"_begin"} and not exists $self->{$lower_case_token} and not $private_block
!ll&&!rl&&r
100
$self->{"_begin"} and not exists $self->{$lower_case_token}
!ll&&!rl&&r
100
MC/DC0%0/3
$self->{"_begin"} and not exists $self->{$lower_case_token} and not $private_block
$self->{"_begin"} not exists $self->{$lower_case_token} not $private_block
Truth table25%1/4
A and not(B) and not(C)
A= $self->{"_begin"}B= not exists $self->{$lower_case_token}C= not $private_block
ABCresult
0XX0
10X0
1100
1111
200 and not exists $self->{$lower_case_token}
201 and not $private_block )
202 {
203 0 $private_block = $raw_token;
204 0 next RAW_TOKEN;
205 }
206  
207 # jump over private block content
208 1 ▶ if ( $private_block
Branch: 1 branch
BranchTrueFalseTotal
if ($private_block and $token_queue->[-2] eq 'end' and $token_queue->[-1] eq ';') { } 0 1 1
Condition33%2/6
$private_block and $token_queue->[-2] eq "end" and $token_queue->[-1] eq ";"
!ll&&!rl&&r
100
$private_block and $token_queue->[-2] eq "end"
!ll&&!rl&&r
100
MC/DC0%0/3
$private_block and $token_queue->[-2] eq "end" and $token_queue->[-1] eq ";"
$private_block $token_queue->[-2] eq "end" $token_queue->[-1] eq ";"
Truth table25%1/4
A and B and C
A= $private_blockB= $token_queue->[-2] eq "end"C= $token_queue->[-1] eq ";"
ABCresult
0XX0
10X0
1100
1111
209 and $token_queue->[-2] eq 'end'
210 and $token_queue->[-1] eq ';' )
211 {
212 0 $private_block = 0;
213 0 $self->_logger->info(
214 "Skipped private $private_block block");
215 0 next RAW_TOKEN;
216 }
217 else {
218 1 next RAW_TOKEN;
219 }
220 }
221 }
222 elsif ( $self->{'_linemode'} ) {
223 48 my $c = $self->{ $self->{'_current'} };
224 48 push @{$token_queue}, $token_line;
225 48 shift @$token_queue;
226 48 $self->$c($token_line);
227 47 next TOKEN_LINE;
228 }
229 }
230 13 return $self->_post_process(@_);
231 }
232  
233 # makes array reference of strings, one string per line, from input
234 # file handle or string;
235 15 ▶sub _stringify {
Subroutine _stringify: called CC=2 SCAR=6.9
236 15 my $self = shift;
237 15 $self->_logger->info("going to split nexus data on lines");
238 15 my %opts = @_;
239 15 my @lines;
240 15 my $handle = $self->_handle;
241 15 ▶ while (<$handle>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $handle)) 435 15 450
242 435 my $line = $_;
243 435 push @lines, grep { /\S/ } split( /\n|\r|\r\n/, $line );
244 435 $self->_logger->debug("read line: $line");
245 }
246 15 return \@lines;
247 }
248  
249 =begin comment
250  
251 Type : Method
252 Title : _tokenize()
253 Usage : $nexus->_tokenize($lines);
254 Function: Tokenizes lines in $lines array ref
255 Returns : Two dimensional ARRAY
256 Args : An array ref of lines (e.g. read from an input file);
257 Comments: This method accepts an array ref holding lines that may contain
258 single quotes, double quotes or square brackets. Line breaks and
259 spaces inside these quoted/bracketed fragments are ignored, otherwise
260 it is split, e.g.:
261  
262 [
263 [ '#NEXUS' ],
264 [ 'BEGIN TAXA; [taxablock comment]' ],
265 [ 'DIMENSIONS NTAX=3;' ],
266 [ 'TAXLABELS "Taxon \' A" \'Taxon B\' TAXON[comment]C' ],
267 ...etc...
268 ]
269  
270 becomes:
271 [
272 [ '#NEXUS' ],
273 [
274 'BEGIN',
275 'TAXA',
276 ';',
277 '[taxablock comment]'
278 ],
279 [
280 'DIMENSIONS',
281 'NTAX',
282 '=',
283 '3',
284 ';'
285 ],
286 [
287 'TAXLABELS',
288 '"Taxon \' A"',
289 '\'Taxon B\'',
290 'TAXON',
291 '[comment]',
292 'C'
293 ],
294 ...etc...
295 ]
296  
297  
298 =end comment
299  
300 =cut
301  
302 15 ▶sub _tokenize {
Subroutine _tokenize: called CC=39 SCAR=38.1
303 15 my ( $self, $lines ) = @_;
304 15 $self->_logger->info("going to split lines on tokens");
305 15 my ( $extract, $INSIDE_QUOTE, $continue ) = ( '', 0, 0 );
306 15 my ( @tokens, @split );
307 15 my $CLOSING_BRACKET_MIDLINE = qr/^.*?(\])(.*)$/mox;
308 15 my $CONTEXT_QB_AT_START = qr/^([\['"])(.*)$/mox;
309 15 my $CONTEXT_CLOSER;
310 my $QuoteContext; # either " ' or [
311 15 my $QuoteStartLine;
312 15 my $LineCount = 0;
313 15 my %CLOSE_CHAR = (
314 '"' => '"',
315 "'" => "'",
316 '[' => ']',
317 );
318 15 my %INVERSE_CLOSE_CHAR = (
319 '"' => '"',
320 "'" => "'",
321 ']' => '[',
322 ')' => '(',
323 );
324  
325 # tokenize
326 15 LINE: for my $line ( @{$lines} ) {
327 379 $LineCount++;
328 379 ▶ TOKEN: while ( $line =~ /\S/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\S/) 408 11 419
329  
330 # line in file has no quoting/bracketing characters, and
331 # is no extension of a quoted/bracketed fragment starting
332 # on a previous line
333 408 ▶ if ( $line !~ $QUOTES_OR_BRACKETS && !$INSIDE_QUOTE ) {
Branch: 5 branches
BranchTrueFalseTotal
if (not $line =~ /$QUOTES_OR_BRACKETS/mx || $INSIDE_QUOTE) { } 332 76 408
elsif ($line =~ /$OPENING_QUOTE_OR_BRACKET/mx and not $INSIDE_QUOTE) { } 20 56 76
elsif (not $line =~ /$CONTEXT_CLOSER/ and $INSIDE_QUOTE) { } 30 26 56
elsif ($line =~ /$CONTEXT_QB_AT_START/ and $INSIDE_QUOTE) { } 20 6 26
elsif ($line =~ /$CONTEXT_CLOSER/ and $INSIDE_QUOTE) { } 6 0 6
Condition100%3/3
$line =~ /$QUOTES_OR_BRACKETS/mx || $INSIDE_QUOTE
l!l&&r!l&&!r
5224332
MC/DC100%2/2
$line =~ /$QUOTES_OR_BRACKETS/mx || $INSIDE_QUOTE
$line =~ /$QUOTES_OR_BRACKETS/mx $INSIDE_QUOTE
Truth table100%3/3
A || B
A= $line =~ /$QUOTES_OR_BRACKETS/mxB= $INSIDE_QUOTE
ABresult
1X1
011
000
334 332 ▶ if ($continue) {
Branch: 1 branch
BranchTrueFalseTotal
if ($continue) { } 20 312 332
335 20 push @{ $tokens[-1] }, $line;
336 20 $continue = 0;
337 }
338 else {
339 312 push @tokens, [$line];
340 }
341 332 my $logline = join( ' ', @{ $tokens[-1] } );
342 332 chomp($logline);
343 332 $self->_logger->debug("Tokenized line $LineCount: $logline");
344 332 next LINE;
345 }
346  
347 # line in file has opening quoting/bracketing characters, and
348 # is no extension of a quoted/bracketed fragment starting
349 # on a previous line
350 ▶ elsif ( $line =~ $OPENING_QUOTE_OR_BRACKET && !$INSIDE_QUOTE ) {
Condition100%3/3
$line =~ /$OPENING_QUOTE_OR_BRACKET/mx and not $INSIDE_QUOTE
!ll&&!rl&&r
272920
MC/DC100%2/2
$line =~ /$OPENING_QUOTE_OR_BRACKET/mx and not $INSIDE_QUOTE
$line =~ /$OPENING_QUOTE_OR_BRACKET/mx not $INSIDE_QUOTE
Truth table100%3/3
A and not(B)
A= $line =~ /$OPENING_QUOTE_OR_BRACKET/mxB= not $INSIDE_QUOTE
ABresult
0X0
100
111
351 20 my ( $start, $quoted ) = ( $1, $2 );
352 20 push @tokens, [$start];
353 20 $line = $quoted;
354 20 $extract = $quoted;
355 20 $INSIDE_QUOTE++;
356 20 $continue = 1;
357 20 $QuoteContext = substr( $quoted, 0, 1 );
358 20 $self->_logger->debug("Line $LineCount contains $QuoteContext");
359 20 $QuoteStartLine = $LineCount;
360 20 $CONTEXT_QB_AT_START = qr/^(\Q$QuoteContext\E)(.*)$/;
361 20 my $context_closer = $CLOSE_CHAR{$QuoteContext};
362 20 $CONTEXT_CLOSER = qr/^(.*?)(\Q$context_closer\E)(.*)$/;
363 20 next TOKEN;
364 }
365  
366 # line in file has no quoting/bracketing characters, and
367 # is an extension of a quoted/bracketed fragment starting
368 # on a previous line
369 ▶ elsif ( $line !~ $CONTEXT_CLOSER && $INSIDE_QUOTE ) {
Condition66%2/3
not $line =~ /$CONTEXT_CLOSER/ and $INSIDE_QUOTE
!ll&&!rl&&r
26030
MC/DC50%1/2
not $line =~ /$CONTEXT_CLOSER/ and $INSIDE_QUOTE
not $line =~ /$CONTEXT_CLOSER/ $INSIDE_QUOTE
Truth table66%2/3
not(A) and B
A= not $line =~ /$CONTEXT_CLOSER/B= $INSIDE_QUOTE
ABresult
0X0
100
111
370 30 $self->_logger->debug(
371 "Line $LineCount extends quote or comment");
372 30 $extract .= $line;
373 30 next LINE;
374 }
375 ▶ elsif ( $line =~ $CONTEXT_QB_AT_START && $INSIDE_QUOTE ) {
Condition66%2/3
$line =~ /$CONTEXT_QB_AT_START/ and $INSIDE_QUOTE
!ll&&!rl&&r
6020
MC/DC50%1/2
$line =~ /$CONTEXT_QB_AT_START/ and $INSIDE_QUOTE
$line =~ /$CONTEXT_QB_AT_START/ $INSIDE_QUOTE
Truth table66%2/3
A and B
A= $line =~ /$CONTEXT_QB_AT_START/B= $INSIDE_QUOTE
ABresult
0X0
100
111
376 20 my ( $q, $remainder ) = ( $1, $1 . $2 );
377 20 ▶ if ( $q eq '"' || $q eq "'" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($q eq '"' or $q eq q[']) { } 9 11 20
elsif ($q eq '[') { } 11 0 11
Condition100%3/3
$q eq "\"" or $q eq "'"
l!l&&r!l&&!r
5411
MC/DC100%2/2
$q eq "\"" or $q eq "'"
$q eq "\"" $q eq "'"
Truth table100%3/3
A or B
A= $q eq "\""B= $q eq "'"
ABresult
1X1
011
000
378 9 ▶ if ( $remainder =~ m/^($q[^$q]*?$q)(.*)$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($remainder =~ /^(${q}[^$q]*?$q)(.*)$/) { } 9 0 9
elsif ($remainder =~ /^${q}[^$q]*$/) { } 0 0 0
379 9 $self->_logger->debug(
380 "Line $LineCount closes $INVERSE_CLOSE_CHAR{$q} with $q"
381 );
382 9 push @{ $tokens[-1] }, ($1);
383 9 $line = $2;
384 9 $INSIDE_QUOTE--;
385 9 next TOKEN;
386 }
387 elsif ( $remainder =~ m/^$q[^$q]*$/ ) {
388 0 $extract .= $line;
389 0 $continue = 1;
390 0 next LINE;
391 }
392 }
393 elsif ( $q eq '[' ) {
394 11 for my $i ( 1 .. length($line) ) {
395 830 ▶ $INSIDE_QUOTE++ if substr( $line, $i, 1 ) eq '[';
Branch: 1 branch
BranchTrueFalseTotal
if substr($line, $i, 1) eq "[" 3 827 830
396 830 ▶ if ( $i and !$INSIDE_QUOTE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i and not $INSIDE_QUOTE) 8 822 830
Condition66%2/3
$i and not $INSIDE_QUOTE
!ll&&!rl&&r
08228
MC/DC50%1/2
$i and not $INSIDE_QUOTE
$i not $INSIDE_QUOTE
Truth table66%2/3
A and not(B)
A= $iB= not $INSIDE_QUOTE
ABresult
0X0
100
111
397 8 push @{ $tokens[-1] }, substr( $line, 0, $i );
398 8 my $logqc = substr( $line, ( $i - 1 ), 1 );
399 8 $self->_logger->debug(
400 "Line $LineCount closes $INVERSE_CLOSE_CHAR{$logqc} with $logqc"
401 );
402 8 $line = substr( $line, $i );
403 8 next TOKEN;
404 }
405 822 ▶ $INSIDE_QUOTE-- if substr( $line, $i, 1 ) eq ']';
Branch: 1 branch
BranchTrueFalseTotal
if substr($line, $i, 1) eq "]" 11 811 822
406 }
407 3 $extract = $line;
408 3 $continue = 1;
409 3 next LINE;
410 }
411 }
412 ▶ elsif ( $line =~ $CONTEXT_CLOSER && $INSIDE_QUOTE ) {
Condition33%1/3
$line =~ /$CONTEXT_CLOSER/ and $INSIDE_QUOTE
!ll&&!rl&&r
006
MC/DC0%0/2
$line =~ /$CONTEXT_CLOSER/ and $INSIDE_QUOTE
$line =~ /$CONTEXT_CLOSER/ $INSIDE_QUOTE
Truth table33%1/3
A and B
A= $line =~ /$CONTEXT_CLOSER/B= $INSIDE_QUOTE
ABresult
0X0
100
111
413 6 my ( $start, $q, $remainder ) = ( $1, $2, $3 );
414 6 $self->_logger->debug(
415 "Line $LineCount closes $INVERSE_CLOSE_CHAR{$q} with $q");
416 6 ▶ $start = $extract . $start if $continue;
Branch: 1 branch
BranchTrueFalseTotal
if $continue 6 0 6
417 6 ▶ if ( $q eq '"' or $q eq "'" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($q eq '"' or $q eq q[']) { } 0 6 6
elsif ($q eq ']') { } 6 0 6
Condition33%1/3
$q eq "\"" or $q eq "'"
l!l&&r!l&&!r
006
MC/DC0%0/2
$q eq "\"" or $q eq "'"
$q eq "\"" $q eq "'"
Truth table33%1/3
A or B
A= $q eq "\""B= $q eq "'"
ABresult
1X1
011
000
418 0 push @{ $tokens[-1] }, $start;
419 0 $line = $remainder;
420 0 next TOKEN;
421 }
422 elsif ( $q eq ']' ) {
423 6 for my $i ( 0 .. length($line) ) {
424 414 ▶ $INSIDE_QUOTE++ if substr( $line, $i, 1 ) eq '[';
Branch: 1 branch
BranchTrueFalseTotal
if substr($line, $i, 1) eq "[" 3 411 414
425 414 ▶ if ( $i and !$INSIDE_QUOTE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i and not $INSIDE_QUOTE) 3 411 414
Condition100%3/3
$i and not $INSIDE_QUOTE
!ll&&!rl&&r
64053
MC/DC100%2/2
$i and not $INSIDE_QUOTE
$i not $INSIDE_QUOTE
Truth table100%3/3
A and not(B)
A= $iB= not $INSIDE_QUOTE
ABresult
0X0
100
111
426 3 my $segment = substr( $line, 0, $i );
427 3 ▶ if ($continue) {
Branch: 1 branch
BranchTrueFalseTotal
if ($continue) { } 3 0 3
428 3 push @{ $tokens[-1] }, $extract . $segment;
429 }
430 else {
431 0 push @{ $tokens[-1] }, $segment;
432 }
433 3 $line = substr( $line, $i );
434 3 next TOKEN;
435 }
436 411 ▶ $INSIDE_QUOTE-- if substr( $line, $i, 1 ) eq ']';
Branch: 1 branch
BranchTrueFalseTotal
if substr($line, $i, 1) eq "]" 6 405 411
437 }
438 3 ▶ if ($continue) {
Branch: 1 branch
BranchTrueFalseTotal
if ($continue) { } 3 0 3
439 3 $extract .= $line;
440 }
441 else {
442 0 $extract = $line;
443 }
444 3 $continue = 1;
445 3 next LINE;
446 }
447 }
448 }
449 }
450  
451 # an exception here means that an opening quote symbol " ' [
452 # ($QuoteContext) was encountered at input file/string line $QuoteStartLine.
453 # This can happen if any of these symbols is used in an illegal
454 # way, e.g. by using double quotes as gap symbols in matrices.
455 15 ▶ if ($INSIDE_QUOTE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INSIDE_QUOTE) 0 15 15
456 0 throw 'BadArgs' =>
457 "Unbalanced $QuoteContext starting at line $QuoteStartLine";
458 }
459  
460 # final split: non-quoted/bracketed fragments are split on whitespace,
461 # others are preserved verbatim
462 $self->_logger->info(
463 15 "going to split non-quoted/commented fragments on whitespace");
464 15 foreach my $line (@tokens) {
465 332 my @line;
466 332 foreach my $word (@$line) {
467 372 ▶ if ( $word !~ $QUOTES_OR_BRACKETS ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $word =~ /$QUOTES_OR_BRACKETS/mx) { } 352 20 372
468 352 $word =~ s/(=|;|,)/ $1 /g;
469 352 push @line, grep { /\S/ } split /\s+/, $word;
470 }
471 else {
472 20 push @line, $word;
473 }
474 }
475 332 push @split, \@line;
476 }
477 15 return \@split;
478 }
479  
480 # link matrices and forests to taxa
481 13 ▶sub _post_process {
Subroutine _post_process: called CC=11 SCAR=25.3
482 13 my $self = shift;
483 13 my $taxa = [];
484 13 foreach my $block ( @{ $self->{'_context'} } ) {
485 26 ▶ if ( $block->_type == $TAXA ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($block->_type == $TAXA) { } 13 13 26
elsif ($block->_type != $TAXA and $block->can('set_taxa')) { } 13 0 13
486 13 push @{$taxa}, $block;
487 }
488 ▶ elsif ( $block->_type != $TAXA and $block->can('set_taxa') ) {
Condition33%1/3
$block->_type != $TAXA and $block->can("set_taxa")
!ll&&!rl&&r
0013
MC/DC0%0/2
$block->_type != $TAXA and $block->can("set_taxa")
$block->_type != $TAXA $block->can("set_taxa")
Truth table33%1/3
A and B
A= $block->_type != $TAXAB= $block->can("set_taxa")
ABresult
0X0
100
111
489 13 ▶ if ( $taxa->[-1]
Branch: 1 branch
BranchTrueFalseTotal
if ($taxa->[-1] and $taxa->[-1]->can("_type") == $TAXA and not $block->get_taxa) 0 13 13
Condition33%2/6
$taxa->[-1] and $taxa->[-1]->can("_type") == $TAXA and not $block->get_taxa
!ll&&!rl&&r
1300
$taxa->[-1] and $taxa->[-1]->can("_type") == $TAXA
!ll&&!rl&&r
0130
MC/DC0%0/3
$taxa->[-1] and $taxa->[-1]->can("_type") == $TAXA and not $block->get_taxa
$taxa->[-1] $taxa->[-1]->can("_type") == $TAXA not $block->get_taxa
Truth table25%1/4
A and B and not(C)
A= $taxa->[-1]B= $taxa->[-1]->can("_type") == $TAXAC= not $block->get_taxa
ABCresult
0XX0
10X0
1100
1111
490 and $taxa->[-1]->can('_type') == $TAXA
491 and not $block->get_taxa )
492 {
493 0 $block->set_taxa( $taxa->[-1] ); # XXX exception here?
494 }
495 }
496 }
497 13 my $blocks = $self->{'_context'};
498  
499 # initialize object, note we have to
500 # force data type references to be empty
501 13 @{$taxa} = ();
502 13 for my $key ( keys %defaults ) {
503 858 ▶ if ( looks_like_instance( $defaults{$key}, 'ARRAY' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (&looks_like_instance($defaults{$key}, 'ARRAY')) { } 156 702 858
elsif (&looks_like_instance($defaults{$key}, 'HASH')) { } 39 663 702
504 156 $self->{$key} = [];
505 }
506 elsif ( looks_like_instance( $defaults{$key}, 'HASH' ) ) {
507 39 $self->{$key} = {};
508 }
509 else {
510 663 $self->{$key} = $defaults{$key};
511 }
512 }
513 13 return @{$blocks};
514 }
515  
516 =begin comment
517  
518 The following subs are called by the dispatch table stored in the object when
519 their respective tokens are encountered.
520  
521 =end comment
522  
523 =cut
524  
525 14 ▶sub _nexus {
Subroutine _nexus: called CC=2 SCAR=7.1
526 14 my $self = shift;
527 14 ▶ if ( uc( $_[0] ) eq '#NEXUS' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (uc $_[0] eq "#NEXUS") 14 0 14
528 14 $self->_logger->info("found nexus token");
529 }
530 }
531  
532 43 ▶sub _begin {
Subroutine _begin: called CC=1 SCAR=0.0
533 43 my $self = shift;
534 43 $self->{'_begin'} = 1;
535 }
536  
537 18 ▶sub _taxa {
Subroutine _taxa: called CC=2 SCAR=6.9
538 18 my $self = shift;
539 18 ▶ if ( $self->{'_begin'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_begin'}) { } 13 5 18
540 13 my $taxa = $self->_factory->create_taxa;
541 13 push @{ $self->{'_context'} }, $taxa;
542 13 $self->_logger->info("starting taxa block");
543 13 $self->{'_begin'} = 0;
544 }
545 else {
546 5 $self->{'_current'} = 'link'; # because of 'link taxa = blah' construct
547 }
548 }
549  
550 17 ▶sub _charset {
Subroutine _charset: called CC=8 SCAR=20.8
551 17 my $self = shift;
552 17 my $token = shift;
553
554 # first thing after the CHARSET token is the set name
555 17 ▶ if ( $token !~ /CHARSET/i && ! $self->{'_charset'}->{'name'} ) {
Branch: 4 branches
BranchTrueFalseTotal
if (not $token =~ /CHARSET/i || $self->{'_charset'}{'name'}) { } 2 15 17
elsif ($token =~ /^\(/) { } 1 14 15
elsif (defined $self->{'_charset'}{'matrix'} and not $self->{'_charset'}{'matrix'} and not $token =~ /(?:\(?CHARACTERS|=)/i) { } 1 13 14
elsif ($token =~ /(?:\d+|-)/) { } 8 5 13
Condition100%3/3
$token =~ /CHARSET/i || $self->{'_charset'}{'name'}
l!l&&r!l&&!r
2132
MC/DC100%2/2
$token =~ /CHARSET/i || $self->{'_charset'}{'name'}
$token =~ /CHARSET/i $self->{'_charset'}{'name'}
Truth table100%3/3
A || B
A= $token =~ /CHARSET/iB= $self->{'_charset'}{'name'}
ABresult
1X1
011
000
556 2 $self->{'_charset'}->{'name'} = $token;
557 2 $self->{'_charset'}->{'range'} = [];
558 }
559
560 # then there might be a mesquite-style matrix reference, e.g. (CHARACTERS = matrix_name)
561 elsif ( $token =~ m/^\(/ ) {
562 1 $self->{'_charset'}->{'matrix'} = '';
563 }
564 ▶ elsif ( defined $self->{'_charset'}->{'matrix'} && ! $self->{'_charset'}->{'matrix'} && $token !~ /(?:\(?CHARACTERS|=)/i ) {
Condition100%6/6
defined $self->{"_charset"}{"matrix"} and not $self->{"_charset"}{"matrix"} and not $token =~ /(?:\(?CHARACTERS|=)/i
!ll&&!rl&&r
1211
defined $self->{"_charset"}{"matrix"} and not $self->{"_charset"}{"matrix"}
!ll&&!rl&&r
752
MC/DC100%3/3
defined $self->{"_charset"}{"matrix"} and not $self->{"_charset"}{"matrix"} and not $token =~ /(?:\(?CHARACTERS|=)/i
defined $self->{"_charset"}{"matrix"} not $self->{"_charset"}{"matrix"} not $token =~ /(?:\(?CHARACTERS|=)/i
Truth table100%4/4
A and not(B) and not(C)
A= defined $self->{"_charset"}{"matrix"}B= not $self->{"_charset"}{"matrix"}C= not $token =~ /(?:\(?CHARACTERS|=)/i
ABCresult
0XX0
10X0
1100
1111
565 1 $token =~ s/\)$//;
566 1 $self->{'_charset'}->{'matrix'} = $token;
567 }
568
569 # then come the indices
570 elsif ( $token =~ /(?:\d+|-)/ ) {
571 8 push @{ $self->{'_charset'}->{'range'} }, $token;
572 }
573 }
574  
575 19 ▶sub _taxset {
Subroutine _taxset: called CC=8 SCAR=20.8
576 19 my $self = shift;
577 19 my $token = shift;
578
579 # first thing after the TAXSET token is the set name
580 19 ▶ if ( $token !~ /TAXSET/i && ! $self->{'_taxset'}->{'name'} ) {
Branch: 4 branches
BranchTrueFalseTotal
if (not $token =~ /TAXSET/i || $self->{'_taxset'}{'name'}) { } 2 17 19
elsif ($token =~ /^\(/) { } 1 16 17
elsif (defined $self->{'_taxset'}{'taxa'} and not $self->{'_taxset'}{'taxa'} and not $token =~ /(?:\(?TAXA|=)/) { } 1 15 16
elsif ($token =~ /(?:\d+|-)/) { } 10 5 15
Condition100%3/3
$token =~ /TAXSET/i || $self->{'_taxset'}{'name'}
l!l&&r!l&&!r
2152
MC/DC100%2/2
$token =~ /TAXSET/i || $self->{'_taxset'}{'name'}
$token =~ /TAXSET/i $self->{'_taxset'}{'name'}
Truth table100%3/3
A || B
A= $token =~ /TAXSET/iB= $self->{'_taxset'}{'name'}
ABresult
1X1
011
000
581 2 $self->{'_taxset'}->{'name'} = $token;
582 2 $self->{'_taxset'}->{'range'} = [];
583 }
584
585 # then there might be a mesquite-style taxa reference, e.g. (TAXA = matrix_name)
586 elsif ( $token =~ m/^\(/ ) {
587 1 $self->{'_taxset'}->{'taxa'} = '';
588 }
589 ▶ elsif ( defined $self->{'_taxset'}->{'taxa'} && ! $self->{'_taxset'}->{'taxa'} && $token !~ /(?:\(?TAXA|=)/ ) {
Condition100%6/6
defined $self->{"_taxset"}{"taxa"} and not $self->{"_taxset"}{"taxa"} and not $token =~ /(?:\(?TAXA|=)/
!ll&&!rl&&r
1411
defined $self->{"_taxset"}{"taxa"} and not $self->{"_taxset"}{"taxa"}
!ll&&!rl&&r
862
MC/DC100%3/3
defined $self->{"_taxset"}{"taxa"} and not $self->{"_taxset"}{"taxa"} and not $token =~ /(?:\(?TAXA|=)/
defined $self->{"_taxset"}{"taxa"} not $self->{"_taxset"}{"taxa"} not $token =~ /(?:\(?TAXA|=)/
Truth table100%4/4
A and not(B) and not(C)
A= defined $self->{"_taxset"}{"taxa"}B= not $self->{"_taxset"}{"taxa"}C= not $token =~ /(?:\(?TAXA|=)/
ABCresult
0XX0
10X0
1100
1111
590 1 $token =~ s/\)$//;
591 1 $self->{'_taxset'}->{'taxa'} = $token;
592 }
593
594 # then come the indices
595 elsif ( $token =~ /(?:\d+|-)/ ) {
596 10 push @{ $self->{'_taxset'}->{'range'} }, $token;
597 }
598 }
599  
600 0 ▶sub _interleave {
Subroutine _interleave: not called CC=3 SCAR=24.8
601 0 my $self = shift;
602 0 my $token = shift;
603 0 $self->_logger->info("perhaps we'll need to parse interleaved");
604 0 ▶ if ( defined $token and uc($token) eq 'NO' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $token and uc $token eq "NO") 0 0 0
Condition0%0/3
defined $token and uc $token eq "NO"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $token and uc $token eq "NO"
defined $token uc $token eq "NO"
Truth table0%0/3
A and B
A= defined $tokenB= uc $token eq "NO"
ABresult
0X0
100
111
605 0 $self->_logger->info("no, we don't need to parse interleaved");
606 }
607 }
608  
609 25 ▶sub _title {
Subroutine _title: called CC=4 SCAR=14.0
610 25 my $self = shift;
611 25 my $token = shift;
612 25 ▶ if ( defined $token and uc($token) ne 'TITLE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $token and uc $token ne "TITLE") 11 14 25
Condition66%2/3
defined $token and uc $token ne "TITLE"
!ll&&!rl&&r
01411
MC/DC50%1/2
defined $token and uc $token ne "TITLE"
defined $token uc $token ne "TITLE"
Truth table66%2/3
A and B
A= defined $tokenB= uc $token ne "TITLE"
ABresult
0X0
100
111
613 11 my $title = $token;
614 11 ▶ if ( not $self->_current->get_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_current->get_name) 11 0 11
615 11 $self->_current->set_name($title);
616 11 $self->_logger->info("block has title '$title'");
617 }
618 }
619 }
620  
621 2 ▶sub _link {
Subroutine _link: called CC=7 SCAR=34.2
622 2 my $self = shift;
623 2 my $token = shift;
624 2 ▶ if ( defined $token and $token !~ m/^(?:LINK|TAXA|=)$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $token and not $token =~ /^(?:LINK|TAXA|=)$/i) 0 2 2
Condition33%1/3
defined $token and not $token =~ /^(?:LINK|TAXA|=)$/i
!ll&&!rl&&r
020
MC/DC0%0/2
defined $token and not $token =~ /^(?:LINK|TAXA|=)$/i
defined $token not $token =~ /^(?:LINK|TAXA|=)$/i
Truth table33%1/3
A and not(B)
A= defined $tokenB= not $token =~ /^(?:LINK|TAXA|=)$/i
ABresult
0X0
100
111
625 0 my $link = $token;
626 0 ▶ if ( not $self->_current->get_taxa ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_current->get_taxa) 0 0 0
627 0 foreach my $block ( @{ $self->{'_context'} } ) {
628 0 ▶ if ( $block->get_name and $block->get_name eq $link ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($block->get_name and $block->get_name eq $link) 0 0 0
Condition0%0/3
$block->get_name and $block->get_name eq $link
!ll&&!rl&&r
000
MC/DC0%0/2
$block->get_name and $block->get_name eq $link
$block->get_name $block->get_name eq $link
Truth table0%0/3
A and B
A= $block->get_nameB= $block->get_name eq $link
ABresult
0X0
100
111
629 0 $self->_current->set_taxa($block);
630 0 last;
631 }
632 }
633 $self->_logger->info(
634 0 "block links to taxa block with title '$link'");
635 }
636 }
637 }
638  
639 22 ▶sub _dimensions {
Subroutine _dimensions: called CC=1 SCAR=0.0
640  
641 #my $self = shift;
642 }
643  
644 39 ▶sub _ntax {
Subroutine _ntax: called CC=3 SCAR=11.0
645 39 my $self = shift;
646 39 ▶ if ( defined $_[0] and $_[0] =~ m/^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and $_[0] =~ /^\d+$/) 13 26 39
Condition66%2/3
defined $_[0] and $_[0] =~ /^\d+$/
!ll&&!rl&&r
02613
MC/DC50%1/2
defined $_[0] and $_[0] =~ /^\d+$/
defined $_[0] $_[0] =~ /^\d+$/
Truth table66%2/3
A and B
A= defined $_[0]B= $_[0] =~ /^\d+$/
ABresult
0X0
100
111
647 13 $self->{'_ntax'} = shift;
648 13 my $ntax = $self->{'_ntax'};
649 13 $self->_logger->info("number of taxa: $ntax");
650 }
651 }
652  
653 72 ▶sub _taxlabels {
Subroutine _taxlabels: called CC=5 SCAR=16.6
654 72 my $self = shift;
655 72 ▶ if ( defined $_[0] and uc( $_[0] ) ne 'TAXLABELS' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_[0] and uc $_[0] ne 'TAXLABELS') { } 59 13 72
elsif (defined $_[0] and uc $_[0] eq 'TAXLABELS') { } 13 0 13
Condition66%2/3
defined $_[0] and uc $_[0] ne "TAXLABELS"
!ll&&!rl&&r
01359
MC/DC50%1/2
defined $_[0] and uc $_[0] ne "TAXLABELS"
defined $_[0] uc $_[0] ne "TAXLABELS"
Truth table66%2/3
A and B
A= defined $_[0]B= uc $_[0] ne "TAXLABELS"
ABresult
0X0
100
111
656 59 my $taxon = shift;
657 59 $self->_logger->debug("taxon: $taxon");
658 59 push @{ $self->{'_taxlabels'} }, $taxon;
659 }
660 ▶ elsif ( defined $_[0] and uc( $_[0] ) eq 'TAXLABELS' ) {
Condition33%1/3
defined $_[0] and uc $_[0] eq "TAXLABELS"
!ll&&!rl&&r
0013
MC/DC0%0/2
defined $_[0] and uc $_[0] eq "TAXLABELS"
defined $_[0] uc $_[0] eq "TAXLABELS"
Truth table33%1/3
A and B
A= defined $_[0]B= uc $_[0] eq "TAXLABELS"
ABresult
0X0
100
111
661 $self->_current->set_generic(
662 13 'nexus_comments' => $self->{'_comments'} );
663 13 $self->{'_comments'} = [];
664 13 $self->_logger->info("starting taxlabels");
665 }
666 }
667  
668 0 ▶sub _blockid {
Subroutine _blockid: not called CC=3 SCAR=24.8
669 0 my $self = shift;
670 0 ▶ if ( defined $_[0] and uc( $_[0] ) ne 'BLOCKID' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and uc $_[0] ne "BLOCKID") 0 0 0
Condition0%0/3
defined $_[0] and uc $_[0] ne "BLOCKID"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[0] and uc $_[0] ne "BLOCKID"
defined $_[0] uc $_[0] ne "BLOCKID"
Truth table0%0/3
A and B
A= defined $_[0]B= uc $_[0] ne "BLOCKID"
ABresult
0X0
100
111
671 0 my $blockid = shift;
672 0 $self->_logger->debug("blockid: $blockid");
673 0 $self->_current->set_generic( 'blockid' => $blockid );
674 }
675 }
676  
677 0 ▶sub _data {
Subroutine _data: not called CC=2 SCAR=17.9
678 0 my $self = shift;
679 0 ▶ if ( $self->{'_begin'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_begin"}) 0 0 0
680 0 $self->{'_begin'} = 0;
681 0 push @{ $self->{'_context'} }, $self->_factory->create_matrix;
682 0 $self->_logger->info("starting data block");
683 }
684 }
685  
686 9 ▶sub _characters {
Subroutine _characters: called CC=2 SCAR=7.0
687 9 my $self = shift;
688 9 ▶ if ( $self->{'_begin'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_begin"}) 9 0 9
689 9 $self->{'_begin'} = 0;
690 9 push @{ $self->{'_context'} }, $self->_factory->create_matrix;
691 9 $self->_logger->info("starting characters block");
692 }
693 }
694  
695 27 ▶sub _nchar {
Subroutine _nchar: called CC=3 SCAR=11.0
696 27 my $self = shift;
697 27 ▶ if ( defined $_[0] and $_[0] =~ m/^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and $_[0] =~ /^\d+$/) 9 18 27
Condition66%2/3
defined $_[0] and $_[0] =~ /^\d+$/
!ll&&!rl&&r
0189
MC/DC50%1/2
defined $_[0] and $_[0] =~ /^\d+$/
defined $_[0] $_[0] =~ /^\d+$/
Truth table66%2/3
A and B
A= defined $_[0]B= $_[0] =~ /^\d+$/
ABresult
0X0
100
111
698 9 $self->{'_nchar'} = shift;
699 9 my $nchar = $self->{'_nchar'};
700 9 $self->_logger->info("number of characters: $nchar");
701 }
702 }
703  
704 9 ▶sub _format {
Subroutine _format: called CC=1 SCAR=0.0
705  
706 #my $self = shift;
707 }
708  
709 27 ▶sub _datatype {
Subroutine _datatype: called CC=3 SCAR=11.0
710 27 my $self = shift;
711 27 ▶ if ( defined $_[0] and $_[0] !~ m/^(?:DATATYPE|=)/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and not $_[0] =~ /^(?:DATATYPE|=)/i) 9 18 27
Condition66%2/3
defined $_[0] and not $_[0] =~ /^(?:DATATYPE|=)/i
!ll&&!rl&&r
0189
MC/DC50%1/2
defined $_[0] and not $_[0] =~ /^(?:DATATYPE|=)/i
defined $_[0] not $_[0] =~ /^(?:DATATYPE|=)/i
Truth table66%2/3
A and not(B)
A= defined $_[0]B= not $_[0] =~ /^(?:DATATYPE|=)/i
ABresult
0X0
100
111
712 9 my $datatype = shift;
713 9 $self->_current->set_type($datatype);
714 9 $self->_logger->info("datatype: $datatype");
715 }
716 }
717  
718 0 ▶sub _matchchar {
Subroutine _matchchar: not called CC=3 SCAR=24.8
719 0 my $self = shift;
720 0 ▶ if ( defined $_[0] and $_[0] !~ m/^(?:MATCHCHAR|=)/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and not $_[0] =~ /^(?:MATCHCHAR|=)/i) 0 0 0
Condition0%0/3
defined $_[0] and not $_[0] =~ /^(?:MATCHCHAR|=)/i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[0] and not $_[0] =~ /^(?:MATCHCHAR|=)/i
defined $_[0] not $_[0] =~ /^(?:MATCHCHAR|=)/i
Truth table0%0/3
A and not(B)
A= defined $_[0]B= not $_[0] =~ /^(?:MATCHCHAR|=)/i
ABresult
0X0
100
111
721 0 my $matchchar = shift;
722 0 $self->_current->set_matchchar($matchchar);
723 0 $self->_logger->info("matchchar: $matchchar");
724 }
725 }
726  
727 0 ▶sub _items {
Subroutine _items: not called CC=1 SCAR=0.0
728  
729 #my $self = shift;
730 }
731  
732 27 ▶sub _gap {
Subroutine _gap: called CC=3 SCAR=11.0
733 27 my $self = shift;
734 27 ▶ if ( $_[0] !~ m/^(?:GAP|=)/i and !$self->{'_gap'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $_[0] =~ /^(?:GAP|=)/i || $self->{"_gap"}) 9 18 27
Condition66%2/3
$_[0] =~ /^(?:GAP|=)/i || $self->{'_gap'}
l!l&&r!l&&!r
1809
MC/DC50%1/2
$_[0] =~ /^(?:GAP|=)/i || $self->{'_gap'}
$_[0] =~ /^(?:GAP|=)/i $self->{'_gap'}
Truth table66%2/3
A || B
A= $_[0] =~ /^(?:GAP|=)/iB= $self->{'_gap'}
ABresult
1X1
011
000
735 9 $self->{'_gap'} = shift;
736 9 my $gap = $self->{'_gap'};
737 9 $self->_current->set_gap($gap);
738 9 $self->_logger->info("gap character: $gap");
739 9 undef $self->{'_gap'};
740 }
741 }
742  
743 27 ▶sub _missing {
Subroutine _missing: called CC=3 SCAR=11.0
744 27 my $self = shift;
745 27 ▶ if ( $_[0] !~ m/^(?:MISSING|=)/i and !$self->{'_missing'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $_[0] =~ /^(?:MISSING|=)/i || $self->{"_missing"}) 9 18 27
Condition66%2/3
$_[0] =~ /^(?:MISSING|=)/i || $self->{'_missing'}
l!l&&r!l&&!r
1809
MC/DC50%1/2
$_[0] =~ /^(?:MISSING|=)/i || $self->{'_missing'}
$_[0] =~ /^(?:MISSING|=)/i $self->{'_missing'}
Truth table66%2/3
A || B
A= $_[0] =~ /^(?:MISSING|=)/iB= $self->{'_missing'}
ABresult
1X1
011
000
746 9 $self->{'_missing'} = shift;
747 9 my $missing = $self->{'_missing'};
748 9 $self->_current->set_missing($missing);
749 9 $self->_logger->info("missing character: $missing");
750 9 undef $self->{'_missing'};
751 }
752 }
753  
754 15 ▶sub _symbols {
Subroutine _symbols: called CC=3 SCAR=11.0
755 15 my $self = shift;
756 15 ▶ if ( $_[0] !~ m/^(?:SYMBOLS|=)$/i and $_[0] =~ m/^"?(.+)"?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $_[0] =~ /^(?:SYMBOLS|=)$/i and $_[0] =~ /^"?(.+)"?$/) 5 10 15
Condition66%2/3
not $_[0] =~ /^(?:SYMBOLS|=)$/i and $_[0] =~ /^"?(.+)"?$/
!ll&&!rl&&r
1005
MC/DC50%1/2
not $_[0] =~ /^(?:SYMBOLS|=)$/i and $_[0] =~ /^"?(.+)"?$/
not $_[0] =~ /^(?:SYMBOLS|=)$/i $_[0] =~ /^"?(.+)"?$/
Truth table66%2/3
not(A) and B
A= not $_[0] =~ /^(?:SYMBOLS|=)$/iB= $_[0] =~ /^"?(.+)"?$/
ABresult
0X0
100
111
757 5 my $sym = $1;
758 5 $sym =~ s/"//g;
759 5 my @syms = grep { /\S+/ } split /\s+/, $sym;
760 5 push @{ $self->{'_symbols'} }, @syms;
761 5 $self->_logger->debug("recorded character state symbols '@syms'");
762 }
763 }
764  
765 0 ▶sub _charlabels {
Subroutine _charlabels: not called CC=3 SCAR=24.8
766 0 my $self = shift;
767 0 ▶ if ( defined $_[0] and uc $_[0] ne 'CHARLABELS' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and uc $_[0] ne "CHARLABELS") 0 0 0
Condition0%0/3
defined $_[0] and uc $_[0] ne "CHARLABELS"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[0] and uc $_[0] ne "CHARLABELS"
defined $_[0] uc $_[0] ne "CHARLABELS"
Truth table0%0/3
A and B
A= defined $_[0]B= uc $_[0] ne "CHARLABELS"
ABresult
0X0
100
111
768 0 push @{ $self->{'_charlabels'} }, shift;
769 }
770 }
771  
772 18 ▶sub _charstatelabels {
Subroutine _charstatelabels: called CC=3 SCAR=11.0
773 18 my $self = shift;
774 18 my $token = shift;
775 18 $self->_logger->debug($token);
776 18 ▶ if ( defined $token and uc $token ne 'CHARSTATELABELS' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $token and uc $token ne "CHARSTATELABELS") 16 2 18
Condition66%2/3
defined $token and uc $token ne "CHARSTATELABELS"
!ll&&!rl&&r
0216
MC/DC50%1/2
defined $token and uc $token ne "CHARSTATELABELS"
defined $token uc $token ne "CHARSTATELABELS"
Truth table66%2/3
A and B
A= defined $tokenB= uc $token ne "CHARSTATELABELS"
ABresult
0X0
100
111
777 16 push @{ $self->{'_charstatelabels'} }, $token;
778 }
779 }
780  
781 0 ▶sub _statelabels {
Subroutine _statelabels: not called CC=4 SCAR=30.0
782 0 my $self = shift;
783 0 my $token = shift;
784 0 ▶ if ( defined $token and uc $token ne 'STATELABELS' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $token and uc $token ne "STATELABELS") 0 0 0
Condition0%0/3
defined $token and uc $token ne "STATELABELS"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $token and uc $token ne "STATELABELS"
defined $token uc $token ne "STATELABELS"
Truth table0%0/3
A and B
A= defined $tokenB= uc $token ne "STATELABELS"
ABresult
0X0
100
111
785 0 ▶ if ( $token eq ',' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq ',') { } 0 0 0
786 0 my $tmpstatelabels = $self->{'_tmpstatelabels'};
787 0 my $index = shift @{$tmpstatelabels};
788 0 $self->{'_statelabels'}->[ $index - 1 ] = $tmpstatelabels;
789 0 $self->{'_tmpstatelabels'} = [];
790 }
791 else {
792 0 push @{ $self->{'_tmpstatelabels'} }, $token;
793 }
794 }
795 }
796  
797 # for data type, character labels, state labels
798 57 ▶sub _add_matrix_metadata {
Subroutine _add_matrix_metadata: called CC=8 SCAR=28.6
799 57 my $self = shift;
800 57 $self->_logger->info("adding matrix metadata");
801 57 ▶ if ( not defined $self->{'_matrixtype'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_matrixtype"}) 9 48 57
802 9 $self->{'_matrixtype'} = $self->_current->get_type;
803 9 ▶ if ( @{ $self->{'_charlabels'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"_charlabels"};}) 0 9 9
804 0 $self->_current->set_charlabels( $self->{'_charlabels'} );
805 0 $self->_logger->debug("adding character labels");
806 }
807 9 ▶ if ( @{ $self->{'_statelabels'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"_statelabels"};}) 0 9 9
808 0 $self->_current->set_statelabels( $self->{'_statelabels'} );
809 0 $self->_logger->debug("adding state labels");
810 }
811 9 ▶ if ( my @symbols = @{ $self->{'_symbols'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@symbols) = @{$self->{"_symbols"};}) 0 9 9
812 0 $self->_logger->debug("updating state lookup table");
813 0 my $to = $self->_current->get_type_object;
814 0 my $lookup = $to->get_lookup;
815 0 ▶ if ($lookup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lookup) 0 0 0
816 0 for my $sym (@symbols) {
817 0 ▶ if ( not exists $lookup->{$sym} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $lookup->{$sym}) 0 0 0
818 0 $lookup->{$sym} = [$sym];
819 }
820 }
821 }
822 }
823 }
824 57 return $self;
825 }
826  
827 48 ▶sub _add_tokens_to_row {
Subroutine _add_tokens_to_row: called CC=13 SCAR=28.7
828 48 my ( $self, $tokens ) = @_;
829 48 my $rowname;
830 48 for my $token ( @{$tokens} ) {
831 90 $self->_logger->debug("token: $token");
832 90 ▶ last if $token eq ';';
Branch: 1 branch
BranchTrueFalseTotal
if $token eq ";" 9 81 90
833  
834 # mesquite sometimes writes multiline (but not interleaved)
835 # matrix rows (harrumph).
836 81 ▶ if ( not defined $rowname and $token !~ $COMMENT ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $rowname || $token =~ /$COMMENT/) { } 39 42 81
elsif (defined $rowname and not $token =~ /$COMMENT/) { } 42 0 42
Condition66%2/3
defined $rowname || $token =~ /$COMMENT/
l!l&&r!l&&!r
42039
MC/DC50%1/2
defined $rowname || $token =~ /$COMMENT/
defined $rowname $token =~ /$COMMENT/
Truth table66%2/3
A || B
A= defined $rownameB= $token =~ /$COMMENT/
ABresult
1X1
011
000
837 39 my $taxa;
838 39 ▶ if ( $taxa = $self->_current->get_taxa ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($taxa = $self->_current->get_taxa) { } 0 39 39
elsif ($taxa = $self->_find_last_seen_taxa_block) { } 39 0 39
839 0 ▶ if ( my $taxon = $taxa->get_by_name($token) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $taxon = $taxa->get_by_name($token)) { } 0 0 0
840 0 $rowname = $token;
841 }
842 else {
843 0 $rowname = $self->{'_matrixrowlabels'}->[-1];
844 }
845 }
846 elsif ( $taxa = $self->_find_last_seen_taxa_block ) {
847 39 ▶ if ( my $taxon = $taxa->get_by_name($token) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $taxon = $taxa->get_by_name($token)) { } 39 0 39
848 39 $rowname = $token;
849 }
850 else {
851 0 $rowname = $self->{'_matrixrowlabels'}->[-1];
852 }
853 }
854 else {
855 0 $rowname = $token;
856 }
857 39 ▶ if ( not exists $self->{'_matrix'}->{$rowname} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_matrix"}{$rowname}) 39 0 39
858 39 $self->{'_matrix'}->{$rowname} = [];
859 39 push @{ $self->{'_matrixrowlabels'} }, $rowname;
860 }
861 }
862 ▶ elsif ( defined $rowname and $token !~ $COMMENT ) {
Condition33%1/3
defined $rowname and not $token =~ /$COMMENT/
!ll&&!rl&&r
0042
MC/DC0%0/2
defined $rowname and not $token =~ /$COMMENT/
defined $rowname not $token =~ /$COMMENT/
Truth table33%1/3
A and not(B)
A= defined $rownameB= not $token =~ /$COMMENT/
ABresult
0X0
100
111
863 42 my $row = $self->{'_matrix'}->{$rowname};
864 42 ▶ if ( $self->{'_matrixtype'} =~ m/^continuous$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_matrixtype'} =~ /^continuous$/i) { } 6 36 42
865 6 push @{$row}, split( /\s+/, $token );
866 }
867 else {
868 36 push @{$row}, split( //, $token );
869 }
870 }
871 }
872 }
873  
874 85 ▶sub _find_last_seen_taxa_block {
Subroutine _find_last_seen_taxa_block: called CC=5 SCAR=16.1
875 85 my $self = shift;
876 85 my $name = shift;
877 85 ▶ for ( my $i = $#{ $self->{'_context'} } ; $i >= 0 ; $i-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 180 2 182
878 180 ▶ if ( $self->{'_context'}->[$i]->_type == $TAXA ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_context"}[$i]->_type == $TAXA) 84 96 180
879 84 ▶ if ( $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) { } 2 82 84
880 2 ▶ if ( $self->{'_context'}->[$i]->get_name eq $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_context"}[$i]->get_name eq $name) 1 1 2
881 1 return $self->{'_context'}->[$i];
882 }
883 }
884 else {
885 82 return $self->{'_context'}->[$i];
886 }
887 }
888 }
889 2 return;
890 }
891  
892 4 ▶sub _find_last_seen_matrix {
Subroutine _find_last_seen_matrix: called CC=5 SCAR=16.3
893 4 my $self = shift;
894 4 my $name = shift;
895 4 ▶ for ( my $i = $#{ $self->{'_context'} } ; $i >= 0 ; $i-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 5 0 5
896 5 ▶ if ( $self->{'_context'}->[$i]->_type == $MATRIX ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_context"}[$i]->_type == $MATRIX) 5 0 5
897 5 ▶ if ( $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) { } 2 3 5
898 2 ▶ if ( $self->{'_context'}->[$i]->get_name eq $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_context"}[$i]->get_name eq $name) 1 1 2
899 1 return $self->{'_context'}->[$i];
900 }
901 }
902 else {
903 3 return $self->{'_context'}->[$i];
904 }
905 }
906 }
907 0 return;
908 }
909  
910 74 ▶sub _set_taxon {
Subroutine _set_taxon: called CC=2 SCAR=9.2
911 74 my ( $self, $obj, $taxa ) = @_;
912  
913 # first case: a taxon by $obj's name already exists
914 74 ▶ if ( my $taxon = $taxa->get_by_name( $obj->get_name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $taxon = $taxa->get_by_name($obj->get_name)) { } 74 0 74
915 74 $obj->set_taxon($taxon);
916 74 return $self;
917 }
918  
919 # second case: no taxon by $obj's name exists yet
920 else {
921 0 my $taxon = $self->_factory->create_taxon( '-name' => $obj->get_name );
922 0 $taxa->insert($taxon);
923 0 $obj->set_taxon($taxon);
924 0 return $self;
925 }
926 }
927  
928 132 ▶sub _resolve_taxon {
Subroutine _resolve_taxon: called CC=4 SCAR=13.9
929 132 my ( $self, $obj ) = @_;
930 132 my $container = $self->_current;
931  
932 # first case: the object is actually already
933 # linked to a taxon
934 132 ▶ if ( my $taxon = $obj->get_taxon ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $taxon = $obj->get_taxon) 88 44 132
935 88 return $self;
936 }
937  
938 # second case: the container is already linked
939 # to a taxa block, but the object isn't
940 44 ▶ if ( my $taxa = $container->get_taxa ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $taxa = $container->get_taxa) 30 14 44
941 30 $self->_set_taxon( $obj, $taxa );
942 }
943  
944 # third case: the container isn't explicitly linked,
945 # but a taxa block has been seen
946 44 ▶ if ( my $taxa = $self->_find_last_seen_taxa_block ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $taxa = $self->_find_last_seen_taxa_block) { } 42 2 44
947 42 $container->set_taxa($taxa);
948 42 $self->_set_taxon( $obj, $taxa );
949 }
950  
951 # final case: no taxa block exists
952 else {
953 2 my $taxa = $container->make_taxa;
954 2 pop @{ $self->{'_context'} };
955 2 push @{ $self->{'_context'} }, $taxa, $container;
956 2 $self->_set_taxon( $obj, $taxa );
957 }
958 }
959  
960 39 ▶sub _resolve_ambig {
Subroutine _resolve_ambig: called CC=11 SCAR=37.9
961 39 my ( $self, $datum, $chars ) = @_;
962 39 my %brackets = (
963 '(' => ')',
964 '{' => '}',
965 );
966 39 my $to = $datum->get_type_object;
967 39 my @resolved;
968 39 my $in_set = 0;
969 39 my @set;
970 my $close;
971 39 for my $c ( @{$chars} ) {
972  
973 228 ▶ if ( not $in_set and not exists $brackets{$c} ) {
Branch: 4 branches
BranchTrueFalseTotal
if (not $in_set || exists $brackets{$c}) { } 228 0 228
elsif (not $in_set and exists $brackets{$c}) { } 0 0 0
elsif ($in_set and $c ne $close) { } 0 0 0
elsif ($in_set and $c eq $close) { } 0 0 0
Condition33%1/3
$in_set || exists $brackets{$c}
l!l&&r!l&&!r
00228
MC/DC0%0/2
$in_set || exists $brackets{$c}
$in_set exists $brackets{$c}
Truth table33%1/3
A || B
A= $in_setB= exists $brackets{$c}
ABresult
1X1
011
000
974 228 ▶ push @resolved, $c if defined $c;
Branch: 1 branch
BranchTrueFalseTotal
if defined $c 228 0 228
975 }
976 ▶ elsif ( not $in_set and exists $brackets{$c} ) {
Condition0%0/3
not $in_set and exists $brackets{$c}
!ll&&!rl&&r
000
MC/DC0%0/2
not $in_set and exists $brackets{$c}
not $in_set exists $brackets{$c}
Truth table0%0/3
not(A) and B
A= not $in_setB= exists $brackets{$c}
ABresult
0X0
100
111
977 0 $in_set++;
978 0 $close = $brackets{$c};
979 }
980 ▶ elsif ( $in_set and $c ne $close ) {
Condition0%0/3
$in_set and $c ne $close
!ll&&!rl&&r
000
MC/DC0%0/2
$in_set and $c ne $close
$in_set $c ne $close
Truth table0%0/3
A and B
A= $in_setB= $c ne $close
ABresult
0X0
100
111
981 0 push @set, $c;
982 }
983 ▶ elsif ( $in_set and $c eq $close ) {
Condition0%0/3
$in_set and $c eq $close
!ll&&!rl&&r
000
MC/DC0%0/2
$in_set and $c eq $close
$in_set $c eq $close
Truth table0%0/3
A and B
A= $in_setB= $c eq $close
ABresult
0X0
100
111
984 0 push @resolved, $to->get_symbol_for_states(@set);
985 0 @set = ();
986 0 $in_set = 0;
987 0 $close = undef;
988 }
989 }
990 39 return \@resolved;
991 }
992  
993 0 ▶sub _codons {
Subroutine _codons: not called CC=2 SCAR=17.9
994 0 my $self = shift;
995 0 $self->_logger->info(shift);
996 0 ▶ if ( $self->{'_begin'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_begin"}) 0 0 0
997 0 $self->{'_begin'} = 0;
998 }
999 }
1000  
1001 57 ▶sub _matrix {
Subroutine _matrix: called CC=11 SCAR=24.6
1002 57 my $self = shift;
1003 57 my $token = shift;
1004 57 $self->_add_matrix_metadata;
1005  
1006 # first token: 'MATRIX', i.e. we're just starting to parse
1007 # the actual matrix. Here we need to switch to "linemode",
1008 # so that subsequently tokens will be array references (all
1009 # the tokens on a line). This is so that we can handle
1010 # interleaved matrices, which unfortunately need line breaks
1011 # in them.
1012 57 ▶ if ( not looks_like_instance( $token, 'ARRAY' ) and uc($token) eq 'MATRIX' )
Branch: 3 branches
BranchTrueFalseTotal
if (not &looks_like_instance($token, 'ARRAY') and uc $token eq 'MATRIX') { } 9 48 57
elsif (&looks_like_instance($token, 'ARRAY') and not grep({/^;$/;} @{$token;})) { } 39 9 48
elsif (&looks_like_instance($token, 'ARRAY') and grep {/^;$/;} @{$token;}) { } 9 0 9
Condition66%2/3
not &looks_like_instance($token, "ARRAY") and uc $token eq "MATRIX"
!ll&&!rl&&r
4809
MC/DC50%1/2
not &looks_like_instance($token, "ARRAY") and uc $token eq "MATRIX"
not &looks_like_instance($token, "ARRAY") uc $token eq "MATRIX"
Truth table66%2/3
not(A) and B
A= not &looks_like_instance($token, "ARRAY")B= uc $token eq "MATRIX"
ABresult
0X0
100
111
1013 {
1014 9 $self->{'_linemode'} = 1;
1015 9 $self->_logger->info("starting matrix");
1016 9 return;
1017 }
1018  
1019 # a row inside the matrix, after adding tokens to row, nothing
1020 # else to do
1021 ▶ elsif ( looks_like_instance( $token, 'ARRAY' )
Condition66%2/3
&looks_like_instance($token, "ARRAY") and not grep({/^;$/;} @{$token;})
!ll&&!rl&&r
0939
MC/DC50%1/2
&looks_like_instance($token, "ARRAY") and not grep({/^;$/;} @{$token;})
&looks_like_instance($token, "ARRAY") not grep({/^;$/;} @{$token;})
Truth table66%2/3
A and not(B)
A= &looks_like_instance($token, "ARRAY")B= not grep({/^;$/;} @{$token;})
ABresult
0X0
100
111
1022 90 and not grep { /^;$/ } @{$token} )
1023 {
1024 39 $self->_add_tokens_to_row($token);
1025 39 $self->_logger->info("adding tokens to row");
1026 39 return;
1027 }
1028  
1029 # the last row of the matrix, after adding tokens to row,
1030 # instantiate & populate datum objects, link against taxa
1031 # objects
1032 ▶ elsif ( looks_like_instance( $token, 'ARRAY' )
Condition33%1/3
&looks_like_instance($token, "ARRAY") and grep {/^;$/;} @{$token;}
!ll&&!rl&&r
009
MC/DC0%0/2
&looks_like_instance($token, "ARRAY") and grep {/^;$/;} @{$token;}
&looks_like_instance($token, "ARRAY") grep {/^;$/;} @{$token;}
Truth table33%1/3
A and B
A= &looks_like_instance($token, "ARRAY")B= grep {/^;$/;} @{$token;}
ABresult
0X0
100
111
1033 9 and grep { /^;$/ } @{$token} )
1034 {
1035 9 $self->_add_tokens_to_row($token);
1036  
1037 # link to taxa
1038 9 for my $row ( @{ $self->{'_matrixrowlabels'} } ) {
1039  
1040 # create new datum
1041 39 my $datum = $self->_factory->create_datum(
1042 '-type_object' => $self->_current->get_type_object,
1043 '-name' => $row,
1044 );
1045 my $char =
1046 39 $self->_resolve_ambig( $datum, $self->{'_matrix'}->{$row} );
1047 39 $datum->set_char($char);
1048  
1049 # insert new datum in matrix
1050 39 $self->_current->insert($datum);
1051  
1052 # link to taxon
1053 39 $self->_resolve_taxon($datum);
1054 39 my ( $length, $seq ) = ( $datum->get_length, $datum->get_char );
1055 39 $self->_logger->info("parsed $length characters for ${row}: $seq");
1056 }
1057  
1058 # Let's avoid these!
1059 9 ▶ if ( $self->_current->get_nchar != $self->{'_nchar'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_current->get_nchar != $self->{'_nchar'}) { } 1 8 9
elsif (defined $self->{'_ntax'} and $self->_current->get_ntax != $self->{'_ntax'}) { } 0 16 16
1060 my ( $obs, $exp ) =
1061 1 ( $self->_current->get_nchar, $self->{'_nchar'} );
1062 1 _bad_format("Observed and expected nchar mismatch: $obs vs. $exp");
1063 }
1064  
1065 # ntax is only defined for "data" blocks (which have ntax token),
1066 # not for "characters" blocks (which should match up with taxa block)
1067 ▶ elsif ( defined $self->{'_ntax'}
Condition33%1/3
defined $self->{"_ntax"} and $self->_current->get_ntax != $self->{"_ntax"}
!ll&&!rl&&r
800
MC/DC0%0/2
defined $self->{"_ntax"} and $self->_current->get_ntax != $self->{"_ntax"}
defined $self->{"_ntax"} $self->_current->get_ntax != $self->{"_ntax"}
Truth table33%1/3
A and B
A= defined $self->{"_ntax"}B= $self->_current->get_ntax != $self->{"_ntax"}
ABresult
0X0
100
111
1068 and $self->_current->get_ntax != $self->{'_ntax'} )
1069 {
1070 0 my ( $obs, $exp ) = ( $self->_current->get_ntax, $self->{'_ntax'} );
1071 0 _bad_format("Observed and expected ntax mismatch: $obs vs. $exp");
1072 }
1073  
1074 # XXX matrix clean up here
1075 8 $self->{'_ntax'} = undef;
1076 8 $self->{'_nchar'} = undef;
1077 8 $self->{'_matrixtype'} = undef;
1078 8 $self->{'_matrix'} = {};
1079 8 $self->{'_matrixrowlabels'} = [];
1080 8 $self->{'_linemode'} = 0;
1081 }
1082 }
1083  
1084 2 ▶sub _bad_format {
Subroutine _bad_format: called CC=1 SCAR=0.0
1085 2 throw 'BadFormat' => shift;
1086 }
1087 408 ▶sub _current { shift->{'_context'}->[-1] }
Subroutine _current: called CC=1 SCAR=0.0
1088  
1089 5 ▶sub _trees {
Subroutine _trees: called CC=2 SCAR=7.0
1090 5 my $self = shift;
1091 5 ▶ if ( $self->{'_begin'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_begin"}) 5 0 5
1092 5 $self->{'_begin'} = 0;
1093 5 $self->{'_trees'} = '';
1094 5 $self->{'_treenames'} = [];
1095 5 push @{ $self->{'_context'} }, $self->_factory->create_forest;
1096 5 $self->_logger->info("starting trees block");
1097 }
1098 }
1099  
1100 171 ▶sub _translate {
Subroutine _translate: called CC=9 SCAR=22.1
1101 171 my $self = shift;
1102 171 my $i = $self->{'_i'};
1103 171 ▶ if ( $i && $i == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i and $i == 1) 5 166 171
Condition100%3/3
$i and $i == 1
!ll&&!rl&&r
115515
MC/DC100%2/2
$i and $i == 1
$i $i == 1
Truth table100%3/3
A and B
A= $iB= $i == 1
ABresult
0X0
100
111
1104 { # actually, $i can be 0 according to BayesPhylogenies translation table
1105 5 $self->_logger->info("starting translation table");
1106 }
1107 171 ▶ if ( !defined($i) && $_[0] =~ m/^\d+$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $i and $_[0] =~ /^\d+$/) { } 57 114 171
elsif (defined $i and exists $self->{'_translate'}[$i] and not defined $self->{'_translate'}[$i] and $_[0] ne ';') { } 57 114 171
Condition100%3/3
not defined $i and $_[0] =~ /^\d+$/
!ll&&!rl&&r
575757
MC/DC100%2/2
not defined $i and $_[0] =~ /^\d+$/
not defined $i $_[0] =~ /^\d+$/
Truth table100%3/3
not(A) and B
A= not defined $iB= $_[0] =~ /^\d+$/
ABresult
0X0
100
111
1108 57 $self->{'_i'} = shift;
1109 57 $self->{'_translate'}->[ $self->{'_i'} ] = undef;
1110 }
1111 ▶ elsif (defined($i)
Condition66%6/9
defined $i and exists $self->{"_translate"}[$i] and not defined $self->{"_translate"}[$i] and $_[0] ne ";"
!ll&&!rl&&r
57057
defined $i and exists $self->{"_translate"}[$i] and not defined $self->{"_translate"}[$i]
!ll&&!rl&&r
57057
defined $i and exists $self->{"_translate"}[$i]
!ll&&!rl&&r
57057
MC/DC25%1/4
defined $i and exists $self->{"_translate"}[$i] and not defined $self->{"_translate"}[$i] and $_[0] ne ";"
defined $i exists $self->{"_translate"}[$i] not defined $self->{"_translate"}[$i] $_[0] ne ";"
Truth table40%2/5
A and B and not(C) and D
A= defined $iB= exists $self->{"_translate"}[$i]C= not defined $self->{"_translate"}[$i]D= $_[0] ne ";"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1112 && exists $self->{'_translate'}->[$i]
1113 && !defined $self->{'_translate'}->[$i]
1114 && $_[0] ne ';' )
1115 {
1116 57 $self->{'_translate'}->[$i] = $_[0];
1117 57 $self->_logger->debug("Translation: $i => $_[0]");
1118 57 $self->{'_i'} = undef;
1119 }
1120 }
1121  
1122 212 ▶sub _tree {
Subroutine _tree: called CC=12 SCAR=24.9
1123 212 my $self = shift;
1124 212 ▶ if ( not $self->{'_treename'} and $_[0] !~ m/^(U?TREE|\*)$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_treename"} or $_[0] =~ /^(U?TREE|\*)$/i) 13 199 212
Condition100%3/3
$self->{"_treename"} or $_[0] =~ /^(U?TREE|\*)$/i
l!l&&r!l&&!r
1861313
MC/DC100%2/2
$self->{"_treename"} or $_[0] =~ /^(U?TREE|\*)$/i
$self->{"_treename"} $_[0] =~ /^(U?TREE|\*)$/i
Truth table100%3/3
A or B
A= $self->{"_treename"}B= $_[0] =~ /^(U?TREE|\*)$/i
ABresult
1X1
011
000
1125 13 $self->{'_treename'} = $_[0];
1126 }
1127 212 ▶ if ( $_[0] eq '=' and not $self->{'_treestart'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] eq "=" and not $self->{"_treestart"}) 13 199 212
Condition66%2/3
$_[0] eq "=" and not $self->{"_treestart"}
!ll&&!rl&&r
199013
MC/DC50%1/2
$_[0] eq "=" and not $self->{"_treestart"}
$_[0] eq "=" not $self->{"_treestart"}
Truth table66%2/3
A and not(B)
A= $_[0] eq "="B= not $self->{"_treestart"}
ABresult
0X0
100
111
1128 13 $self->{'_treestart'} = 1;
1129 }
1130 212 ▶ if ( $_[0] ne '=' and $self->{'_treestart'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] ne "=" and $self->{"_treestart"}) 173 39 212
Condition100%3/3
$_[0] ne "=" and $self->{"_treestart"}
!ll&&!rl&&r
1326173
MC/DC100%2/2
$_[0] ne "=" and $self->{"_treestart"}
$_[0] ne "=" $self->{"_treestart"}
Truth table100%3/3
A and B
A= $_[0] ne "="B= $self->{"_treestart"}
ABresult
0X0
100
111
1131 173 $self->{'_tree'} .= $_[0];
1132 }
1133  
1134 # tr/// returns # of replacements, hence can be used to check
1135 # tree description is balanced
1136 212 ▶ if ( $self->{'_treestart'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_treestart"} and $self->{"_tree"} and $self->{"_tree"} =~ tr/(// == $self->{"_tree"} =~ tr/)//) 13 199 212
Condition100%6/6
$self->{"_treestart"} and $self->{"_tree"} and $self->{"_tree"} =~ tr/(// == $self->{"_tree"} =~ tr/)//
!ll&&!rl&&r
3916013
$self->{"_treestart"} and $self->{"_tree"}
!ll&&!rl&&r
2613173
MC/DC100%3/3
$self->{"_treestart"} and $self->{"_tree"} and $self->{"_tree"} =~ tr/(// == $self->{"_tree"} =~ tr/)//
$self->{"_treestart"} $self->{"_tree"} $self->{"_tree"} =~ tr/(// == $self->{"_tree"} =~ tr/)//
Truth table100%4/4
A and B and C
A= $self->{"_treestart"}B= $self->{"_tree"}C= $self->{"_tree"} =~ tr/(// == $self->{"_tree"} =~ tr/)//
ABCresult
0XX0
10X0
1100
1111
1137 and $self->{'_tree'}
1138 and $self->{'_tree'} =~ tr/(/(/ == $self->{'_tree'} =~ tr/)/)/ )
1139 {
1140 13 my $translated = $self->{'_tree'};
1141 13 my $translate = $self->{'_translate'};
1142 13 ▶ my $start =
Branch: 1 branch
BranchTrueFalseTotal
exists $translate->[0] ? : 1 12 13
1143 exists $translate->[0]
1144 ? 0
1145 : 1; # BayesPhylogenies starts translation table w. 0
1146 13 for my $i ( $start .. $#{$translate} ) {
1147 93 $translated =~ s/(\(|,)$i(,|\)|:)/$1$translate->[$i]$2/;
1148 }
1149 my ( $logtreename, $logtree ) =
1150 13 ( $self->{'_treename'}, $self->{'_tree'} );
1151 13 $self->_logger->info("tree: $logtreename string: $logtree");
1152 13 $self->{'_trees'} .= $translated . ';';
1153 13 push @{ $self->{'_treenames'} }, $self->{'_treename'};
1154  
1155 # XXX tree cleanup here
1156 13 $self->{'_treestart'} = 0;
1157 13 $self->{'_tree'} = undef;
1158 13 $self->{'_treename'} = undef;
1159 }
1160 }
1161  
1162 33 ▶sub _end {
Subroutine _end: called CC=7 SCAR=19.5
1163 33 my $self = shift;
1164 33 $self->{'_translate'} = [];
1165 33 ▶ if ( uc $self->{'_previous'} eq ';' and $self->{'_trees'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (uc $self->{"_previous"} eq ";" and $self->{"_trees"}) 5 28 33
Condition100%3/3
uc $self->{"_previous"} eq ";" and $self->{"_trees"}
!ll&&!rl&&r
8205
MC/DC100%2/2
uc $self->{"_previous"} eq ";" and $self->{"_trees"}
uc $self->{"_previous"} eq ";" $self->{"_trees"}
Truth table100%3/3
A and B
A= uc $self->{"_previous"} eq ";"B= $self->{"_trees"}
ABresult
0X0
100
111
1166 5 my $forest = $self->_current;
1167 my $trees = parse(
1168 '-format' => 'newick',
1169 5 '-string' => $self->{'_trees'},
1170 '-as_project' => 0
1171 );
1172 5 for my $tree ( @{ $trees->get_entities } ) {
1173 13 $forest->insert($tree);
1174 }
1175  
1176 # set tree names
1177 5 for my $i ( 0 .. $#{ $self->{'_treenames'} } ) {
1178 13 $forest->get_by_index($i)->set_name( $self->{'_treenames'}->[$i] );
1179 }
1180  
1181 # link tips to taxa
1182 5 for my $tree ( @{ $forest->get_entities } ) {
1183 13 for my $tip ( @{ $tree->get_terminals } ) {
1184 93 $self->_resolve_taxon($tip);
1185 }
1186 }
1187  
1188 # XXX trees cleanup here
1189 5 $self->{'_trees'} = '';
1190 5 $self->{'_treenames'} = [];
1191 }
1192 }
1193  
1194 189 ▶sub _semicolon {
Subroutine _semicolon: called CC=38 SCAR=40.2
1195 189 my $self = shift;
1196 189 ▶ if ( uc $self->{'_previous'} eq 'MATRIX' ) {
Branch: 8 branches
BranchTrueFalseTotal
if (uc $self->{'_previous'} eq 'MATRIX') { } 0 189 189
elsif (uc $self->{'_previous'} eq 'CHARSET') { } 2 187 189
elsif (uc $self->{'_previous'} eq 'CHARSTATELABELS') { } 2 185 187
elsif (uc $self->{'_previous'} eq 'TAXSET') { } 2 183 185
elsif (uc $self->{'_previous'} eq 'TAXLABELS') { } 13 170 183
elsif (uc $self->{'_previous'} eq 'SYMBOLS') { } 5 165 170
elsif (uc $self->{'_previous'} eq 'CHARLABELS') { } 0 165 165
elsif (uc $self->{'_previous'} eq 'STATELABELS') { } 0 165 165
1197 0 $self->{'_matrixtype'} = undef;
1198 0 $self->{'_matrix'} = {};
1199 0 $self->{'_charlabels'} = [];
1200 0 $self->{'_statelabels'} = [];
1201 0 $self->{'_linemode'} = 0;
1202 0 ▶ if ( not $self->_current->get_ntax ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_current->get_ntax) 0 0 0
1203 0 my $taxon = {};
1204 0 foreach my $row ( @{ $self->_current->get_entities } ) {
1205 0 $taxon->{ $row->get_taxon }++;
1206 }
1207 0 my $ntax = scalar keys %{$taxon};
1208 }
1209 }
1210
1211 # finalize character set
1212 elsif ( uc $self->{'_previous'} eq 'CHARSET' ) {
1213 2 my $matrix = $self->_find_last_seen_matrix( $self->{'_charset'}->{'matrix'} );
1214 2 my $characters = $matrix->get_characters;
1215 2 my $set = $self->_factory->create_set( '-name' => $self->{'_charset'}->{'name'} );
1216 2 $characters->add_set($set);
1217 2 my $range = $self->{'_charset'}->{'range'};
1218 2 my @range;
1219 2 ▶ if ( ref($range) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $range eq "ARRAY") 2 0 2
1220 2 ▶ while ( @{ $range } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$range;}) 4 2 6
1221 4 my $index = shift @{ $range };
1222 4 ▶ if ( $range->[0] && $range->[0] eq '-' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($range->[0] and $range->[0] eq '-') { } 2 2 4
Condition66%2/3
$range->[0] and $range->[0] eq "-"
!ll&&!rl&&r
202
MC/DC50%1/2
$range->[0] and $range->[0] eq "-"
$range->[0] $range->[0] eq "-"
Truth table66%2/3
A and B
A= $range->[0]B= $range->[0] eq "-"
ABresult
0X0
100
111
1223 2 shift @{ $range };
1224 2 my $end = shift @{ $range };
1225 2 push @range, ( $index - 1 ) .. ( $end - 1 );
1226 }
1227 else {
1228 2 push @range, ( $index - 1 );
1229 }
1230 }
1231 2 for my $i ( @range ) {
1232 6 my $character = $characters->get_by_index($i);
1233 6 ▶ if ( $character ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($character) { } 6 0 6
1234 6 $characters->add_to_set($character,$set);
1235 }
1236 else {
1237 0 throw 'API' => "No character at index $i";
1238 }
1239 }
1240 }
1241 2 $self->{'_charset'} = {};
1242 }
1243
1244 # finalize character state labels
1245 elsif ( uc $self->{'_previous'} eq 'CHARSTATELABELS' ) {
1246 2 my $matrix = $self->_find_last_seen_matrix;
1247 2 my @labels = @{ $self->{'_charstatelabels'} };
1248 2 ▶ if ( $matrix->get_type =~ m/continuous/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($matrix->get_type =~ /continuous/i) { } 1 1 2
1249 1 my @charlabels;
1250 1 my $charnum = 1;
1251 1 ▶ while (@labels) {
Branch: 1 branch
BranchTrueFalseTotal
if (@labels) 2 1 3
1252
1253 # expecting an index at the beginning of the statement
1254 2 my $index = shift @labels;
1255 2 ▶ $index != $charnum && _bad_format( "Expecting character number $charnum, observed $index in CHARSTATELABELS" );
Branch: 1 branch
BranchTrueFalseTotal
$index != $charnum and _bad_format("Expecting character number $charnum, observed $index in CHARSTATELABELS") 0 2 2
1256
1257 # then the character label
1258 2 push @charlabels, shift @labels;
1259
1260 # then a comma
1261 2 ▶ if ( @labels ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@labels) 1 1 2
1262 1 ▶ $labels[0] eq ',' ? shift @labels : _bad_format( "Expecting , observed $labels[0] in CHARSTATELABELS" );
Branch: 1 branch
BranchTrueFalseTotal
$labels[0] eq ',' ? : 1 0 1
1263 }
1264 2 $charnum++;
1265 }
1266 1 $matrix->set_charlabels(\@charlabels);
1267 1 $self->{'_charstatelabels'} = [];
1268 }
1269 else {
1270 1 my ( @charlabels, @statelabels );
1271 1 my $charnum = 1;
1272 1 ▶ while (@labels) {
Branch: 1 branch
BranchTrueFalseTotal
if (@labels) 2 1 3
1273
1274 # expecting an index at the beginning of the statement
1275 2 my $index = shift @labels;
1276 2 ▶ $index != $charnum && _bad_format( "Expecting character number $charnum, observed $index in CHARSTATELABELS" );
Branch: 1 branch
BranchTrueFalseTotal
$index != $charnum and _bad_format("Expecting character number $charnum, observed $index in CHARSTATELABELS") 0 2 2
1277
1278 # then the character label
1279 2 push @charlabels, shift @labels;
1280
1281 # then a forward slash
1282 2 my $slash = shift @labels;
1283 2 ▶ $slash ne '/' && _bad_format( "Expecting /, observed $slash in CHARSTATELABELS" );
Branch: 1 branch
BranchTrueFalseTotal
$slash ne "/" and _bad_format("Expecting /, observed $slash in CHARSTATELABELS") 0 2 2
1284
1285 # then a list of state labels
1286 2 my @stateset;
1287 2 ▶ push @stateset, shift @labels while(@labels and $labels[0] ne ',');
Branch: 1 branch
BranchTrueFalseTotal
@labels and $labels[0] ne "," and do { push @stateset, shift @labels } 4 2 6
Condition100%3/3
@labels and $labels[0] ne ","
!ll&&!rl&&r
114
MC/DC100%2/2
@labels and $labels[0] ne ","
@labels $labels[0] ne ","
Truth table100%3/3
A and B
A= @labelsB= $labels[0] ne ","
ABresult
0X0
100
111
1288 2 push @statelabels, \@stateset;
1289
1290 # then a comma
1291 2 ▶ if ( @labels ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@labels) 1 1 2
1292 1 ▶ $labels[0] eq ',' ? shift @labels : _bad_format( "Expecting , observed $labels[0] in CHARSTATELABELS" );
Branch: 1 branch
BranchTrueFalseTotal
$labels[0] eq ',' ? : 1 0 1
1293 }
1294 2 $charnum++;
1295 }
1296 1 $matrix->set_charlabels(\@charlabels);
1297 1 $matrix->set_statelabels(\@statelabels);
1298 1 $self->{'_charstatelabels'} = [];
1299 }
1300 }
1301
1302 # finalize taxon set
1303 elsif ( uc $self->{'_previous'} eq 'TAXSET' ) {
1304 2 my $taxa = $self->_find_last_seen_taxa_block( $self->{'_taxset'}->{'taxa'} );
1305 2 my $set = $self->_factory->create_set( '-name' => $self->{'_taxset'}->{'name'} );
1306 2 $taxa->add_set($set);
1307 2 my $range = $self->{'_taxset'}->{'range'};
1308 2 my @range;
1309 2 ▶ while ( @{ $range } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$range;}) 6 2 8
1310 6 my $index = shift @{ $range };
1311 6 ▶ if ( $range->[0] && $range->[0] eq '-' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($range->[0] and $range->[0] eq '-') { } 2 4 6
Condition100%3/3
$range->[0] and $range->[0] eq "-"
!ll&&!rl&&r
222
MC/DC100%2/2
$range->[0] and $range->[0] eq "-"
$range->[0] $range->[0] eq "-"
Truth table100%3/3
A and B
A= $range->[0]B= $range->[0] eq "-"
ABresult
0X0
100
111
1312 2 shift @{ $range };
1313 2 my $end = shift @{ $range };
1314 2 push @range, ( $index - 1 ) .. ( $end - 1 );
1315 }
1316 else {
1317 4 push @range, ( $index - 1 );
1318 }
1319 }
1320 2 for my $i ( @range ) {
1321 8 my $taxon = $taxa->get_by_index($i);
1322 8 ▶ if ( $taxon ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($taxon) { } 8 0 8
1323 8 $taxa->add_to_set($taxon,$set);
1324 }
1325 else {
1326 0 _bad_format( "No taxon at index $i" );
1327 }
1328 }
1329 2 $self->{'_taxset'} = {};
1330 }
1331
1332 # finalize taxa labels
1333 elsif ( uc $self->{'_previous'} eq 'TAXLABELS' ) {
1334 13 foreach my $name ( @{ $self->{'_taxlabels'} } ) {
1335 59 my $taxon = $self->_factory->create_taxon( '-name' => $name );
1336 59 $self->_current->insert($taxon);
1337 }
1338 13 ▶ if ( $self->_current->get_ntax != $self->{'_ntax'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_current->get_ntax != $self->{"_ntax"}) 1 12 13
1339 _bad_format(
1340 sprintf(
1341 'Mismatch between observed and expected ntax: %d vs %d',
1342 1 $self->_current->get_ntax, $self->{'_ntax'}
1343 )
1344 );
1345 }
1346  
1347 # XXX taxa cleanup here
1348 12 $self->{'_ntax'} = undef;
1349 12 $self->{'_taxlabels'} = [];
1350 }
1351
1352 # finalize symbols list
1353 elsif ( uc $self->{'_previous'} eq 'SYMBOLS' ) {
1354 5 my $logsymbols = join( ' ', @{ $self->{'_symbols'} } );
1355 5 $self->_logger->info("symbols: $logsymbols");
1356 5 $self->{'_symbols'} = [];
1357 }
1358
1359 # finalize character labels
1360 elsif ( uc $self->{'_previous'} eq 'CHARLABELS' ) {
1361 0 ▶ if ( @{ $self->{'_charlabels'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"_charlabels"};}) 0 0 0
1362 0 my $logcharlabels = join( ' ', @{ $self->{'_charlabels'} } );
1363 0 $self->_logger->info("charlabels: $logcharlabels");
1364 }
1365 }
1366
1367 # finalize state labels
1368 elsif ( uc $self->{'_previous'} eq 'STATELABELS' ) {
1369 0 ▶ if ( @{ $self->{'_statelabels'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"_statelabels"};}) 0 0 0
1370 0 my $logstatelabels = join( ' ', @{ $self->{'_statelabels'} } );
1371 0 $self->_logger->info("statelabels: $logstatelabels");
1372 }
1373 }
1374 }
1375  
1376 # podinherit_insert_token
1377  
1378 =head1 SEE ALSO
1379  
1380 There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo>
1381 for any user or developer questions and discussions.
1382  
1383 =over
1384  
1385 =item L<Bio::Phylo::IO>
1386  
1387 The nexus parser is called by the L<Bio::Phylo::IO> object. Look there for
1388 examples of file parsing and manipulation.
1389  
1390 =item L<Bio::Phylo::Manual>
1391  
1392 Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>.
1393  
1394 =back
1395  
1396 =head1 CITATION
1397  
1398 If you use Bio::Phylo in published research, please cite it:
1399  
1400 B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen>
1401 and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl.
1402 I<BMC Bioinformatics> B<12>:63.
1403 L<http://dx.doi.org/10.1186/1471-2105-12-63>
1404  
1405 =cut
1406  
1407 6 1;
« Phylo/Unparsers/Phyloxml.pm ↑ Summary Phylo/Matrices/Datatype/Mixed.pm »