Phylo/Matrices/DatumRole.pm

filter: Statementstmt 31.2% 131 / 419 Branchbran 18.4% 28 / 152 Conditioncond 3.4% 3 / 86 MC/DCmcdc 0.0% 0 / 52 Subroutinesub 38.1% 24 / 63 Podpod 43.7% 21 / 48 totaltotal 25.2% 207 / 820 CC 130 SCAR 44.9
CC
130
Cov
25%
to_dom
380.0
to_xml
272.0
new_from_bioperl
132.0
CRAP 89.5
« Phylo/Unparsers/Nwmsrdf.pm ↑ Summary Phylo/Unparsers/Nexml.pm »
1 package Bio::Phylo::Matrices::DatumRole;
2 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use Bio::Phylo::Util::MOP;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use base qw'Bio::Phylo::Matrices::TypeSafeData Bio::Phylo::Taxa::TaxonLinker';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use Bio::Phylo::Util::OptionalInterface 'Bio::Seq';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use Bio::Phylo::Util::Exceptions 'throw';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use Bio::Phylo::Util::CONSTANT qw':objecttypes /looks_like/';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use Bio::Phylo::NeXML::Writable;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use Bio::Phylo::Factory;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 my $LOADED_WRAPPERS = 0;
12 {
13 16 my $fac = Bio::Phylo::Factory->new;
14 16 my $logger = __PACKAGE__->get_logger;
15 16 my $TYPE_CONSTANT = _DATUM_;
16 16 my $CONTAINER_CONSTANT = _MATRIX_;
17 #{
18 #my @fields = \( my ( %weight, %position, %annotations ) );
19 #}
20  
21 =head1 NAME
22  
23 Bio::Phylo::Matrices::DatumRole - Extra behaviours for a character state sequence
24  
25 =head1 SYNOPSIS
26  
27 use Bio::Phylo::Factory;
28 my $fac = Bio::Phylo::Factory->new;
29  
30 # instantiating a datum object...
31 my $datum = $fac->create_datum(
32 -name => 'Tooth comb size,
33 -type => 'STANDARD',
34 -desc => 'number of teeth in lower jaw comb',
35 -pos => 1,
36 -weight => 2,
37 -char => [ 6 ],
38 );
39  
40 # ...and linking it to a taxon object
41 my $taxon = $fac->create_taxon(
42 -name => 'Lemur_catta'
43 );
44 $datum->set_taxon( $taxon );
45  
46 # instantiating a matrix...
47 my $matrix = $fac->create_matrix;
48  
49 # ...and insert datum in matrix
50 $matrix->insert($datum);
51  
52 =head1 DESCRIPTION
53  
54 The datum object models a single observation or a sequence of observations,
55 which can be linked to a taxon object.
56  
57 =head1 METHODS
58  
59 =head2 CONSTRUCTOR
60  
61 =over
62  
63 =item new()
64  
65 Datum object constructor.
66  
67 Type : Constructor
68 Title : new
69 Usage : my $datum = Bio::Phylo::Matrices::Datum->new;
70 Function: Instantiates a Bio::Phylo::Matrices::Datum
71 object.
72 Returns : A Bio::Phylo::Matrices::Datum object.
73 Args : None required. Optional:
74 -taxon => $taxon,
75 -weight => 0.234,
76 -type => DNA,
77 -pos => 2,
78  
79 =cut
80  
81 724 ▶ sub new : Constructor {
Subroutine new: called CC=3 SCAR=22.8
Pod documented
82  
83 # could be child class
84 724 my $class = shift;
85  
86 # notify user
87 724 $logger->info("constructor called for '$class'");
88 724 ▶ if ( not $LOADED_WRAPPERS ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($LOADED_WRAPPERS) 14 710 724
89 0 ▶ eval do { local $/; <DATA> };
Subroutine accession_number: not called CC=1 SCAR=6.6
Subroutine alphabet: not called CC=1 SCAR=6.6
Subroutine annotation: not called CC=1 SCAR=6.6
Subroutine can_call_new: not called CC=1 SCAR=6.6
Subroutine desc: not called CC=2 SCAR=17.5
Subroutine display_id: not called CC=1 SCAR=6.6
Subroutine end: not called CC=3 SCAR=24.3
Subroutine feature_count: not called CC=1 SCAR=6.6
Subroutine get_SeqFeatures: not called CC=1 SCAR=6.6
Subroutine get_all_SeqFeatures: not called CC=1 SCAR=6.6
Subroutine get_nse: not called CC=6 SCAR=36.8
Subroutine id: not called CC=1 SCAR=6.6
Subroutine is_circular: not called CC=1 SCAR=6.6
Subroutine length: not called CC=1 SCAR=6.6
Subroutine meta_names: not called CC=5 SCAR=33.4
Subroutine moltype: not called CC=1 SCAR=6.6
Subroutine primary_id: not called CC=1 SCAR=6.6
Subroutine primary_seq: not called CC=1 SCAR=6.6
Subroutine revcom: not called CC=1 SCAR=6.6
Subroutine seq: not called CC=1 SCAR=6.6
Subroutine species: not called CC=1 SCAR=6.6
Subroutine start: not called CC=2 SCAR=17.5
Subroutine strand: not called CC=2 SCAR=17.5
Subroutine subseq: not called CC=11 SCAR=48.2
Subroutine translate: not called CC=1 SCAR=6.6
Subroutine trunc: not called CC=1 SCAR=6.6
Subroutine write_GFF: not called CC=1 SCAR=6.6
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Branch: 17 branches
BranchTrueFalseTotal
if (defined $desc) 0 0 0
if (defined $end) 0 0 0
if (defined $end) { } 0 0 0
unless defined $self->id 0 0 0
unless defined $self->start 0 0 0
unless defined $self->end 0 0 0
unless $_ eq $DEFAULT_NAME 0 0 0
if $names->{$DEFAULT_NAME} 0 0 0
if (defined $start) 0 0 0
if (defined $strand) 0 0 0
if (ref $start and $start->isa('Bio::LocationI')) { } 0 0 0
elsif (defined $start and defined $end) { } 0 0 0
if ($subloc->strand < 0) 0 0 0
if ($start > $end) 0 0 0
if ($start <= 0) 0 0 0
if ($end > $self->length) 0 0 0
if (defined $replace) { } 0 0 0
Condition0%0/12
$char1 ||= "/"
l!l
00
$char2 ||= "-"
l!l
00
$self->get_generic('meta') || {}
l!l
00
ref $start and $start->isa("Bio::LocationI")
!ll&&!rl&&r
000
defined $start and defined $end
!ll&&!rl&&r
000
MC/DC0%0/1
$char1 ||= "/"
$char1
MC/DC0%0/1
$char2 ||= "-"
$char2
MC/DC0%0/1
$self->get_generic('meta') || {}
$self->get_generic('meta')
MC/DC0%0/2
ref $start and $start->isa("Bio::LocationI")
ref $start $start->isa("Bio::LocationI")
MC/DC0%0/2
defined $start and defined $end
defined $start defined $end
Truth table0%0/2
A
A= $char1
Aresult
11
00
Truth table0%0/2
A
A= $char2
Aresult
11
00
Truth table0%0/2
A
A= $self->get_generic('meta')
Aresult
11
00
Truth table0%0/3
A and B
A= ref $startB= $start->isa("Bio::LocationI")
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $startB= defined $end
ABresult
0X0
100
111
90 14 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 14 14
91 14 $LOADED_WRAPPERS++;
92 }
93  
94 # go up inheritance tree, eventually get an ID
95 724 my $self = $class->SUPER::new(
96 @_,
97 '-listener' => \&_update_characters,
98 );
99 724 return $self;
100 16 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
101  
102 =item new_from_bioperl()
103  
104 Datum constructor from Bio::Seq argument.
105  
106 Type : Constructor
107 Title : new_from_bioperl
108 Usage : my $datum =
109 Bio::Phylo::Matrices::Datum->new_from_bioperl($seq);
110 Function: Instantiates a
111 Bio::Phylo::Matrices::Datum object.
112 Returns : A Bio::Phylo::Matrices::Datum object.
113 Args : A Bio::Seq (or similar) object
114  
115 =cut
116  
117 0 ▶ sub new_from_bioperl {
Subroutine new_from_bioperl: not called CC=11 SCAR=48.8
Pod documented
118 0 my ( $class, $seq, @args ) = @_;
119  
120 # want $seq type-check here? Allowable: is-a Bio::PrimarySeq,
121 # Bio::LocatableSeq /maj
122 0 ▶ my $type = $seq->alphabet || $seq->_guess_alphabet || 'dna';
Condition0%0/5
$seq->alphabet || $seq->_guess_alphabet || 'dna'
l!l
00
$seq->alphabet or $seq->_guess_alphabet
l!l&&r!l&&!r
000
MC/DC0%0/2
$seq->alphabet || $seq->_guess_alphabet || 'dna'
$seq->alphabet $seq->_guess_alphabet
Truth table0%0/3
A or B
A= $seq->alphabetB= $seq->_guess_alphabet
ABresult
1X1
011
000
123 0 my $self = $class->new( '-type' => $type, @args );
124  
125 # copy seq string
126 0 my $seqstring = $seq->seq;
127 0 ▶ if ( $seqstring and $seqstring =~ /\S/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seqstring and $seqstring =~ /\S/) 0 0 0
Condition0%0/3
$seqstring and $seqstring =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
$seqstring and $seqstring =~ /\S/
$seqstring $seqstring =~ /\S/
Truth table0%0/3
A and B
A= $seqstringB= $seqstring =~ /\S/
ABresult
0X0
100
111
128 0 eval { $self->set_char($seqstring) };
129 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($@ and &looks_like_instance($@, "Bio::Phylo::Util::Exceptions::InvalidData")) 0 0 0
Condition0%0/3
$@ and &looks_like_instance($@, "Bio::Phylo::Util::Exceptions::InvalidData")
!ll&&!rl&&r
000
MC/DC0%0/2
$@ and &looks_like_instance($@, "Bio::Phylo::Util::Exceptions::InvalidData")
$@ &looks_like_instance($@, "Bio::Phylo::Util::Exceptions::InvalidData")
Truth table0%0/3
A and B
A= $@B= &looks_like_instance($@, "Bio::Phylo::Util::Exceptions::InvalidData")
ABresult
0X0
100
111
130 $@
131 and looks_like_instance(
132 $@, 'Bio::Phylo::Util::Exceptions::InvalidData'
133 )
134 )
135 {
136 0 $logger->error(
137 "\nAn exception of type Bio::Phylo::Util::Exceptions::InvalidData was caught\n\n"
138 . $@->description
139 . "\n\nThe BioPerl sequence object contains invalid data ($seqstring)\n"
140 . "I cannot store this string, I will continue instantiating an empty object.\n"
141 . "---------------------------------- STACK ----------------------------------\n"
142 . $@->trace->as_string
143 . "\n--------------------------------------------------------------------------"
144 );
145 }
146 }
147  
148 # copy name
149 0 my $name = $seq->display_id;
150 0 ▶ $self->set_name($name) if defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 0 0 0
151  
152 # copy desc
153 0 my $desc = $seq->desc;
154 0 ▶ $self->set_desc($desc) if defined $desc;
Branch: 1 branch
BranchTrueFalseTotal
if defined $desc 0 0 0
155  
156 # only Bio::LocatableSeq objs have these fields...
157 0 for my $field (qw(start end strand)) {
158 0 ▶ $self->$field( $seq->$field ) if $seq->can($field);
Branch: 1 branch
BranchTrueFalseTotal
if $seq->can($field) 0 0 0
159 }
160 0 return $self;
161 }
162  
163 =back
164  
165 =head2 MUTATORS
166  
167 =over
168  
169 =item set_char()
170  
171 Sets character state(s)
172  
173 Type : Mutator
174 Title : set_char
175 Usage : $datum->set_char($char);
176 Function: Assigns a datum's character value.
177 Returns : Modified object.
178 Args : The $char argument is checked against
179 the allowed ranges for the various
180 character types: IUPAC nucleotide (for
181 types of DNA|RNA|NUCLEOTIDE), IUPAC
182 single letter amino acid codes (for type
183 PROTEIN), integers (STANDARD) or any of perl's
184 decimal formats (CONTINUOUS). The $char can be:
185 * a single character;
186 * a string of characters;
187 * an array reference of characters;
188 * an array of characters;
189 Comments: Note that on assigning characters to a datum,
190 previously set annotations are removed.
191  
192 =cut
193  
194 713 ▶ sub set_char {
Subroutine set_char: called CC=7 SCAR=19.5
Pod documented
195 713 my $self = shift;
196 713 my $name = $self->get_internal_name;
197 713 ▶ my $length = ref $_[0] ? join( '', @{ $_[0] } ) : join( '', @_ );
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 69 644 713
198 713 $logger->info("setting $name $length chars '@_'");
199 713 my @data;
200 713 for my $arg (@_) {
201 713 ▶ if ( looks_like_instance( $arg, 'ARRAY' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_instance($arg, 'ARRAY')) { } 69 644 713
202 69 push @data, @{$arg};
203 }
204 else {
205 644 push @data, @{ $self->get_type_object->split($arg) };
206 }
207 }
208 713 my $missing = $self->get_missing;
209 713 ▶ my $position = $self->get_position || 1;
Condition50%1/2
$self->get_position || 1
l!l
0713
MC/DC0%0/1
$self->get_position || 1
$self->get_position
Truth table50%1/2
A
A= $self->get_position
Aresult
11
00
210 713 for ( 1 .. $position - 1 ) {
211 0 unshift @data, $missing;
212 }
213 713 my @char = @{ $self->get_entities }; # store old data for rollback
214 713 eval {
215 713 $self->clear;
216 713 $self->insert(@data);
217 };
218 713 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 7 706 713
219 7 $self->clear;
220 7 eval { $self->insert(@char) };
221 7 undef($@);
222 7 throw 'InvalidData' =>
223 sprintf( 'Invalid data for row %s (type %s: %s)',
224 $self->get_internal_name, $self->get_type, join( ' ', @data ) );
225 }
226 706 $self->set_annotations;
227 706 return $self;
228 }
229  
230 =back
231  
232 =head2 ACCESSORS
233  
234 =over
235  
236 =item get_matrix()
237  
238 Gets the matrix (if any) this datum belongs to
239  
240 Type : Accessor
241 Title : get_matrix
242 Usage : my $matrix = $datum->get_matrix;
243 Function: Retrieves the matrix the datum belongs to
244 Returns : Bio::Phylo::Matrices::Matrix
245 Args : NONE
246  
247 =cut
248  
249 133 ▶ sub get_matrix { shift->_get_container }
Subroutine get_matrix: called CC=1 SCAR=0.0
Pod documented
250  
251 =item get_char()
252  
253 Gets characters.
254  
255 Type : Accessor
256 Title : get_char
257 Usage : my $char = $datum->get_char;
258 Function: Retrieves a datum's character value.
259 Returns : In scalar context, returns a single
260 character, or a string of characters
261 (e.g. a DNA sequence, or a space
262 delimited series of continuous characters).
263 In list context, returns a list of characters
264 (of zero or more characters).
265 Args : NONE
266  
267 =cut
268  
269 1462 ▶ sub get_char {
Subroutine get_char: called CC=4 SCAR=13.9
Pod documented
270 1462 my $self = shift;
271 1462 my @data = @{ $self->get_entities };
272 1462 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 715 747 1462
273 715 ▶ return wantarray ? @data : $self->get_type_object->join( \@data );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 691 24 715
274 }
275 else {
276 747 ▶ return wantarray ? () : '';
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 747 0 747
277 }
278 }
279
280 =item get_unaligned_char()
281  
282 Gets unaligned characters, i.e. without gap or missing symbols
283  
284 Type : Accessor
285 Title : get_unaligned_char
286 Usage : my $char = $datum->get_unaligned_char;
287 Function: Retrieves a datum's unaligned character sequence
288 Returns : In scalar context, returns a single
289 character, or a string of characters
290 (e.g. a DNA sequence, or a space
291 delimited series of continuous characters).
292 In list context, returns a list of characters
293 (of zero or more characters).
294 Args : NONE
295  
296 =cut
297
298 0 ▶ sub get_unaligned_char {
Subroutine get_unaligned_char: not called CC=5 SCAR=34.0
Pod documented
299 0 my $self = shift;
300 0 my $gap = $self->get_gap;
301 0 my $missing = $self->get_missing;
302 0 my @char = $self->get_char;
303 0 ▶ my @data = grep { $_ ne $gap && $_ ne $missing } @char;
Condition0%0/3
$_ ne $gap && $_ ne $missing
!ll&&!rl&&r
000
MC/DC0%0/2
$_ ne $gap && $_ ne $missing
$_ ne $gap $_ ne $missing
Truth table0%0/3
A && B
A= $_ ne $gapB= $_ ne $missing
ABresult
0X0
100
111
304 0 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 0 0 0
305 0 ▶ return wantarray ? @data : $self->get_type_object->join( \@data );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
306 }
307 else {
308 0 ▶ return wantarray ? () : '';
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
309 }
310 }
311  
312 =item get_length()
313  
314 Gets invocant number of characters.
315  
316 Type : Accessor
317 Title : get_length
318 Usage : my $length = $datum->get_length;
319 Function: Retrieves a datum's length.
320 Returns : a SCALAR integer.
321 Args : NONE
322  
323 =cut
324  
325 623 ▶ sub get_length {
Subroutine get_length: called CC=3 SCAR=11.0
Pod documented
326 623 my $self = shift;
327 623 ▶ if ( my $matrix = $self->_get_container ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $matrix = $self->_get_container) { } 39 584 623
328 39 return $matrix->get_nchar;
329 }
330 else {
331 584 ▶ return scalar( @{ $self->get_entities } ) + ( $self->get_position || 1 ) - 1;
Condition50%1/2
$self->get_position || 1
l!l
0584
MC/DC0%0/1
$self->get_position || 1
$self->get_position
Truth table50%1/2
A
A= $self->get_position
Aresult
11
00
332 }
333 }
334  
335 =item get_by_index()
336  
337 Gets state at argument index.
338  
339 Type : Accessor
340 Title : get_by_index
341 Usage : my $val = $datum->get_by_index($i);
342 Function: Retrieves state at index $i.
343 Returns : a character state.
344 Args : INT
345  
346 =cut
347  
348 50 ▶ sub get_by_index {
Subroutine get_by_index: called CC=4 SCAR=14.5
Pod documented
349 50 my ( $self, $index ) = @_;
350 50 $logger->debug($index);
351 50 ▶ my $offset = ( $self->get_position || 1 ) - 1;
Condition50%1/2
$self->get_position || 1
l!l
050
MC/DC0%0/1
$self->get_position || 1
$self->get_position
Truth table50%1/2
A
A= $self->get_position
Aresult
11
00
352 50 ▶ return $self->get_type_object->get_missing if $offset > $index;
Branch: 1 branch
BranchTrueFalseTotal
if $offset > $index 0 50 50
353 50 my $val = $self->SUPER::get_by_index( $index - $offset );
354 50 ▶ return defined $val ? $val : $self->get_type_object->get_missing;
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 50 0 50
355 }
356  
357 =item get_index_of()
358  
359 Returns the index of the first occurrence of the
360 state observation in the datum or undef if the datum
361 doesn't contain the argument
362  
363 Type : Generic query
364 Title : get_index_of
365 Usage : my $i = $datum->get_index_of($state)
366 Function: Returns the index of the first occurrence of the
367 state observation in the datum or undef if the datum
368 doesn't contain the argument
369 Returns : An index or undef
370 Args : A contained object
371  
372 =cut
373  
374 0 ▶ sub get_index_of {
Subroutine get_index_of: not called CC=5 SCAR=34.0
Pod documented
375 0 my ( $self, $obj ) = @_;
376 0 my $is_numerical =
377 $self->get_type =~ m/^(Continuous|Standard|Restriction)$/;
378 0 my $i = 0;
379 0 for my $ent ( @{ $self->get_entities } ) {
380 0 ▶ if ($is_numerical) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_numerical) { } 0 0 0
381 0 ▶ return $i if $obj == $ent;
Branch: 1 branch
BranchTrueFalseTotal
if $obj == $ent 0 0 0
382 }
383 else {
384 0 ▶ return $i if $obj eq $ent;
Branch: 1 branch
BranchTrueFalseTotal
if $obj eq $ent 0 0 0
385 }
386 0 $i++;
387 }
388 0 return;
389 }
390  
391 =back
392  
393 =head2 TESTS
394  
395 =over
396  
397 =item can_contain()
398  
399 Tests if invocant can contain argument.
400  
401 Type : Test
402 Title : can_contain
403 Usage : &do_something if $datum->can_contain( @args );
404 Function: Tests if $datum can contain @args
405 Returns : BOOLEAN
406 Args : One or more arguments as can be provided to set_char
407  
408 =cut
409  
410 719 ▶ sub can_contain {
Subroutine can_contain: called CC=9 SCAR=38.8
Pod documented
411 719 my $self = shift;
412 719 my @data = @_;
413 719 ▶ if ( my $obj = $self->get_type_object ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $obj = $self->get_type_object) { } 719 0 719
414 719 ▶ if ( $obj->isa('Bio::Phylo::Matrices::Datatype::Mixed') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->isa('Bio::Phylo::Matrices::Datatype::Mixed')) { } 0 719 719
415 0 my @split;
416 0 for my $datum (@data) {
417 0 ▶ if ( looks_like_implementor( $datum, 'get_char' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (&looks_like_implementor($datum, 'get_char')) { } 0 0 0
elsif (&looks_like_instance($datum, 'ARRAY')) { } 0 0 0
418 0 my @tmp = $datum->get_char();
419 0 my $i = $datum->get_position() - 1;
420 0 for (@tmp) {
421 0 $split[ $i++ ] = $_;
422 }
423 }
424 elsif ( looks_like_instance( $datum, 'ARRAY' ) ) {
425 0 push @split, @{$datum};
426 }
427 else {
428 0 my $subtype = $obj->get_type_for_site( scalar(@split) );
429 0 push @split, @{ $subtype->split($datum) };
430 }
431 }
432  
433 #return 1;
434 0 for my $i ( 1 .. scalar(@split) ) {
435 0 my $subtype = $obj->get_type_for_site( $i - 1 );
436 0 ▶ next if $subtype->is_valid( $split[ $i - 1 ] );
Branch: 1 branch
BranchTrueFalseTotal
if $subtype->is_valid($split[$i - 1]) 0 0 0
437 0 throw 'InvalidData' => sprintf(
438 'Invalid char %s at pos %s for type %s',
439 $split[ $i - 1 ],
440 $i, $subtype->get_type,
441 );
442 }
443 0 return 1;
444 }
445 else {
446 719 return $obj->is_valid(@data);
447 }
448 }
449 else {
450 0 throw 'API' => "No associated type object found,\n"
451 . "this is a bug - please report - thanks";
452 }
453 }
454  
455 =back
456  
457 =head2 CALCULATIONS
458  
459 =over
460  
461 =item calc_state_counts()
462  
463 Calculates occurrences of states.
464  
465 Type : Calculation
466 Title : calc_state_counts
467 Usage : my %counts = %{ $datum->calc_state_counts };
468 Function: Calculates occurrences of states.
469 Returns : Hashref: keys are states, values are counts
470 Args : Optional - one or more states to focus on
471  
472 =cut
473  
474 23 ▶ sub calc_state_counts {
Subroutine calc_state_counts: called CC=7 SCAR=26.3
Pod documented
475 23 my $self = shift;
476  
477 # maybe there should be an option to bin continuous values
478 # in X categories, and return the frequencies of those? Anyway,
479 # Hennig86 seems to want continuous values to be counted as well,
480 # so not throwing an exception here.
481 #if ( $self->get_type =~ /^continuous$/i ) {
482 # throw 'BadArgs' => 'Matrix holds continuous values';
483 #}
484 23 my %counts;
485 23 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 23 23
486 0 my %focus = map { $_ => 1 } @_;
487 0 my @char = $self->get_char;
488 0 for my $c (@char) {
489 0 ▶ if ( exists $focus{$c} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $focus{$c}) 0 0 0
490 0 ▶ if ( not exists $counts{$c} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $counts{$c}) { } 0 0 0
491 0 $counts{$c} = 1;
492 }
493 else {
494 0 $counts{$c}++;
495 }
496 }
497 }
498 }
499 else {
500 23 my @char = $self->get_char;
501 23 for my $c (@char) {
502 101 ▶ if ( not exists $counts{$c} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $counts{$c}) { } 80 21 101
503 80 $counts{$c} = 1;
504 }
505 else {
506 21 $counts{$c}++;
507 }
508 }
509 }
510 23 return \%counts;
511 }
512  
513 =item calc_distance()
514  
515 Calculates the distance between the invocant and argument
516  
517 Type : Calculation
518 Title : calc_distance
519 Usage : my $dist = $datum1->calc_distance($datum2);
520 Function: Calculates pairwise distance
521 Returns : A number, the distance per site
522 Args : Another datum to calculate the distance to
523 Comments: Assumes the sequences are aligned. Calculates
524 substitutions / total non-missing and non-gapped sites.
525 =cut
526  
527 0 ▶ sub calc_distance {
Subroutine calc_distance: not called CC=7 SCAR=40.3
Pod documented
528 0 my ( $self, $other ) = @_;
529 0 my @c1 = $self->get_char;
530 0 my @c2 = $other->get_char;
531 0 my $t = $self->get_type_object;
532 0 my $m = $t->get_missing;
533 0 my $g = $t->get_gap;
534 0 my $subst = 0;
535 0 my $total = 0;
536 0 for my $i ( 0 .. $#c1 ) {
537 0 ▶ next if $c1[$i] eq $m or $c1[$i] eq $g or $c2[$i] eq $m or $c2[$i] eq $g;
Branch: 1 branch
BranchTrueFalseTotal
if $c1[$i] eq $m or $c1[$i] eq $g or $c2[$i] eq $m or $c2[$i] eq $g 0 0 0
Condition0%0/9
$c1[$i] eq $m or $c1[$i] eq $g or $c2[$i] eq $m or $c2[$i] eq $g
l!l&&r!l&&!r
000
$c1[$i] eq $m or $c1[$i] eq $g or $c2[$i] eq $m
l!l&&r!l&&!r
000
$c1[$i] eq $m or $c1[$i] eq $g
l!l&&r!l&&!r
000
MC/DC0%0/4
$c1[$i] eq $m or $c1[$i] eq $g or $c2[$i] eq $m or $c2[$i] eq $g
$c1[$i] eq $m $c1[$i] eq $g $c2[$i] eq $m $c2[$i] eq $g
Truth table0%0/5
A or B or C or D
A= $c1[$i] eq $mB= $c1[$i] eq $gC= $c2[$i] eq $mD= $c2[$i] eq $g
ABCDresult
1XXX1
01XX1
001X1
00011
00000
538 0 $subst += $c1[$i] ne $c2[$i];
539 0 $total++;
540 }
541 0 ▶ return $total ? $subst / $total : 9**9**9;
Branch: 1 branch
BranchTrueFalseTotal
$total ? : 0 0 0
542 }
543  
544 =item calc_state_frequencies()
545  
546 Calculates the frequencies of the states observed in the matrix.
547  
548 Type : Calculation
549 Title : calc_state_frequencies
550 Usage : my %freq = %{ $object->calc_state_frequencies() };
551 Function: Calculates state frequencies
552 Returns : A hash, keys are state symbols, values are frequencies
553 Args : Optional:
554 # if true, counts missing (usually the '?' symbol) as a state
555 # in the final tallies. Otherwise, missing states are ignored
556 -missing => 1
557 # if true, counts gaps (usually the '-' symbol) as a state
558 # in the final tallies. Otherwise, gap states are ignored
559 -gap => 1
560 Comments: Throws exception if matrix holds continuous values
561  
562 =cut
563  
564 5 ▶ sub calc_state_frequencies {
Subroutine calc_state_frequencies: called CC=6 SCAR=18.0
Pod documented
565 5 my $self = shift;
566 5 my $counts = $self->calc_state_counts;
567 5 my %args = looks_like_hash @_;
568 5 for my $arg (qw(missing gap)) {
569 10 ▶ if ( not exists $args{"-${arg}"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $args{"-$arg"}) 10 0 10
570 10 my $method = "get_${arg}";
571 10 my $symbol = $self->$method;
572 10 delete $counts->{$symbol};
573 }
574 }
575 5 my $total = 0;
576 5 $total += $_ for values %{$counts};
577 5 ▶ if ( $total > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($total > 0) 5 0 5
578 5 for my $state ( keys %{$counts} ) {
579 20 $counts->{$state} /= $total;
580 }
581 }
582 5 return $counts;
583 }
584  
585 =back
586  
587 =head2 METHODS
588  
589 =over
590  
591 =item reverse()
592  
593 Reverses contents.
594  
595 Type : Method
596 Title : reverse
597 Usage : $datum->reverse;
598 Function: Reverses a datum's contained characters
599 Returns : Returns modified $datum
600 Args : NONE
601  
602 =cut
603  
604 0 ▶ sub reverse {
Subroutine reverse: not called CC=1 SCAR=6.9
Pod documented
605 0 my $self = shift;
606 0 my @char = $self->get_char;
607 0 my @reversed = reverse(@char);
608 0 $self->set_char( \@reversed );
609 }
610  
611 =item concat()
612  
613 Appends argument to invocant.
614  
615 Type : Method
616 Title : reverse
617 Usage : $datum->concat($datum1);
618 Function: Appends $datum1 to $datum
619 Returns : Returns modified $datum
620 Args : NONE
621  
622 =cut
623  
624 0 ▶ sub concat {
Subroutine concat: not called CC=4 SCAR=30.0
Pod documented
625 0 my ( $self, @data ) = @_;
626 0 $logger->info("concatenating objects");
627 0 my @newchars;
628 0 my @self_chars = $self->get_char;
629 0 my $self_i = $self->get_position - 1;
630 0 my $self_j = $self->get_length - 1 + $self_i;
631 0 @newchars[ $self_i .. $self_j ] = @self_chars;
632 0 for my $datum (@data) {
633 0 my @chars = $datum->get_char;
634 0 my $i = $datum->get_position - 1;
635 0 my $j = $datum->get_length - 1 + $i;
636 0 @newchars[ $i .. $j ] = @chars;
637 }
638 0 my $missing = $self->get_missing;
639 0 for my $i ( 0 .. $#newchars ) {
640 0 ▶ $newchars[$i] = $missing if !defined $newchars[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newchars[$i] 0 0 0
641 }
642 0 $self->set_char( \@newchars );
643 }
644  
645 =item consense()
646  
647 Creates consensus sequence out of arguments
648  
649 Type : Method
650 Title : consense
651 Usage : my @chars = $datum->consense($datum1,...);
652 Function: Creates consensus sequence out of arguments
653 Returns : Returns @chars or $seq
654 Args : NONE
655  
656 =cut
657
658 0 ▶ sub consense {
Subroutine consense: not called CC=9 SCAR=45.0
Pod documented
659 0 my @data = @_;
660
661 # build two-dimensional array of character states
662 0 my @chars;
663 0 for my $datum ( @data ) {
664 0 my @char = $datum->get_char;
665 0 push @chars, \@char;
666 }
667
668 # get special symbols
669 0 my $length = $data[0]->get_length;
670 0 my $to = $data[0]->get_type_object;
671 0 my $m = $to->get_missing;
672 0 my $g = $to->get_gap;
673
674 # build result
675 0 my @result;
676 0 for my $i ( 0 .. ( $length - 1 ) ) {
677 0 my %col;
678
679 # get distinct states for column, ignore missing and gap
680 0 ROW: for my $row ( @chars ) {
681 0 my $c = $row->[$i];
682 0 ▶ next ROW if $c eq $m or $c eq $g;
Branch: 1 branch
BranchTrueFalseTotal
if $c eq $m or $c eq $g 0 0 0
Condition0%0/3
$c eq $m or $c eq $g
l!l&&r!l&&!r
000
MC/DC0%0/2
$c eq $m or $c eq $g
$c eq $m $c eq $g
Truth table0%0/3
A or B
A= $c eq $mB= $c eq $g
ABresult
1X1
011
000
683 0 $col{$c} = 1;
684 }
685
686 # get ambiguity symbol or missing
687 0 my @states = keys %col;
688 0 ▶ if ( @states ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@states) { } 0 0 0
689 0 ▶ push @result, $to->get_symbol_for_states(@states) || $m;
Condition0%0/3
$to->get_symbol_for_states(@states) || $m
l!l&&r!l&&!r
000
MC/DC0%0/2
$to->get_symbol_for_states(@states) || $m
$to->get_symbol_for_states(@states) $m
Truth table0%0/3
A || B
A= $to->get_symbol_for_states(@states)B= $m
ABresult
1X1
011
000
690 }
691 else {
692 0 push @result, $m;
693 }
694 }
695
696 # return result
697 0 ▶ return wantarray ? @result : $to->join(@result);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
698 }
699  
700 =begin comment
701  
702 Validates invocant data contents.
703  
704 Type : Method
705 Title : validate
706 Usage : $datum->validate;
707 Function: Validates character data contained by $datum
708 Returns : True or throws Bio::Phylo::Util::Exceptions::InvalidData
709 Args : NONE
710  
711 =end comment
712  
713 =cut
714  
715 752 ▶ sub _validate {
Subroutine _validate: called CC=2 SCAR=6.9
716 752 my $self = shift;
717 752 ▶ if ( !$self->get_type_object->is_valid($self) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->get_type_object->is_valid($self)) 3 749 752
718 3 throw 'InvalidData' => 'Invalid data!';
719 }
720 }
721  
722 =item to_xml()
723  
724 Serializes datum to nexml format.
725  
726 Type : Format convertor
727 Title : to_xml
728 Usage : my $xml = $datum->to_xml;
729 Function: Converts datum object into a nexml element structure.
730 Returns : Nexml block (SCALAR).
731 Args : -chars => [] # optional, an array ref of character IDs
732 -states => {} # optional, a hash ref of state IDs
733 -symbols => {} # optional, a hash ref of symbols
734 -special => {} # optional, a hash ref of special symbol IDs
735  
736 =cut
737  
738 0 ▶ sub to_xml {
Subroutine to_xml: not called CC=16 SCAR=56.1
Pod documented
739 0 my $self = shift;
740 0 my %args = looks_like_hash @_;
741 0 my $char_ids = $args{'-chars'};
742 0 my $state_ids = $args{'-states'};
743 0 my $special = $args{'-special'};
744 0 ▶ if ( my $taxon = $self->get_taxon ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $taxon = $self->get_taxon) 0 0 0
745 0 $self->set_attributes( 'otu' => $taxon->get_xml_id );
746 }
747 0 my @char = $self->get_char;
748 0 my ( $missing, $gap ) = ( $self->get_missing, $self->get_gap );
749 0 my $xml = $self->get_xml_tag;
750 0 ▶ if ( not $args{'-compact'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $args{'-compact'}) { } 0 0 0
751 0 for my $i ( 0 .. $#char ) {
752 0 my ( $c, $s );
753 0 ▶ if ( $missing ne $char[$i] and $gap ne $char[$i] ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($missing ne $char[$i] and $gap ne $char[$i]) { } 0 0 0
elsif ($missing eq $char[$i] or $gap eq $char[$i]) { } 0 0 0
Condition0%0/3
$missing ne $char[$i] and $gap ne $char[$i]
!ll&&!rl&&r
000
MC/DC0%0/2
$missing ne $char[$i] and $gap ne $char[$i]
$missing ne $char[$i] $gap ne $char[$i]
Truth table0%0/3
A and B
A= $missing ne $char[$i]B= $gap ne $char[$i]
ABresult
0X0
100
111
754 0 ▶ if ( $char_ids and $char_ids->[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char_ids and $char_ids->[$i]) { } 0 0 0
Condition0%0/3
$char_ids and $char_ids->[$i]
!ll&&!rl&&r
000
MC/DC0%0/2
$char_ids and $char_ids->[$i]
$char_ids $char_ids->[$i]
Truth table0%0/3
A and B
A= $char_idsB= $char_ids->[$i]
ABresult
0X0
100
111
755 0 $c = $char_ids->[$i];
756 }
757 else {
758 0 $c = $i;
759 }
760 0 ▶ if ( $state_ids and $state_ids->{ uc $char[$i] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state_ids and $$state_ids{uc $char[$i]}) { } 0 0 0
Condition0%0/3
$state_ids and $$state_ids{uc $char[$i]}
!ll&&!rl&&r
000
MC/DC0%0/2
$state_ids and $$state_ids{uc $char[$i]}
$state_ids $$state_ids{uc $char[$i]}
Truth table0%0/3
A and B
A= $state_idsB= $$state_ids{uc $char[$i]}
ABresult
0X0
100
111
761 0 $s = $state_ids->{ uc $char[$i] };
762 }
763 else {
764 0 $s = uc $char[$i];
765 }
766 }
767 ▶ elsif ( $missing eq $char[$i] or $gap eq $char[$i] ) {
Condition0%0/3
$missing eq $char[$i] or $gap eq $char[$i]
l!l&&r!l&&!r
000
MC/DC0%0/2
$missing eq $char[$i] or $gap eq $char[$i]
$missing eq $char[$i] $gap eq $char[$i]
Truth table0%0/3
A or B
A= $missing eq $char[$i]B= $gap eq $char[$i]
ABresult
1X1
011
000
768 0 ▶ if ( $char_ids and $char_ids->[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char_ids and $char_ids->[$i]) { } 0 0 0
Condition0%0/3
$char_ids and $char_ids->[$i]
!ll&&!rl&&r
000
MC/DC0%0/2
$char_ids and $char_ids->[$i]
$char_ids $char_ids->[$i]
Truth table0%0/3
A and B
A= $char_idsB= $char_ids->[$i]
ABresult
0X0
100
111
769 0 $c = $char_ids->[$i];
770 }
771 else {
772 0 $c = $i;
773 }
774 0 ▶ if ( $special and $special->{ $char[$i] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($special and $$special{$char[$i]}) { } 0 0 0
Condition0%0/3
$special and $$special{$char[$i]}
!ll&&!rl&&r
000
MC/DC0%0/2
$special and $$special{$char[$i]}
$special $$special{$char[$i]}
Truth table0%0/3
A and B
A= $specialB= $$special{$char[$i]}
ABresult
0X0
100
111
775 0 $s = $special->{ $char[$i] };
776 }
777 else {
778 0 $s = $char[$i];
779 }
780 }
781  
782 # $cell->set_attributes( 'char' => $c, 'state' => $s );
783 # $xml .= $cell->get_xml_tag(1);
784 0 $xml .= sprintf( '<cell char="%s" state="%s"/>', $c, $s );
785 }
786 }
787 else {
788 0 my @tmp = map { uc $_ } @char;
789 0 my $seq = Bio::Phylo::NeXML::Writable->new(
790 '-tag' => 'seq',
791 '-identifiable' => 0,
792 );
793 0 my $seq_text = $self->get_type_object->join( \@tmp );
794 0 $xml .=
795 $seq->get_xml_tag . "\n$seq_text\n" . "</" . $seq->get_tag . ">";
796 }
797 0 $xml .= sprintf( '</%s>', $self->get_tag );
798 0 return $xml;
799 }
800  
801 =item to_dom()
802  
803 Analog to to_xml.
804  
805 Type : Serializer
806 Title : to_dom
807 Usage : $datum->to_dom
808 Function: Generates a DOM subtree from the invocant
809 and its contained objects
810 Returns : an XML::LibXML::Element object
811 Args : none
812  
813 =cut
814  
815 0 ▶ sub to_dom {
Subroutine to_dom: not called CC=19 SCAR=59.4
Pod documented
816 0 my $self = shift;
817 0 my $dom = $_[0];
818 0 my @args = @_;
819  
820 # handle dom factory object...
821 0 ▶ if ( looks_like_instance( $dom, 'SCALAR' )
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_instance($dom, 'SCALAR') and $dom->_type == 18) { } 0 0 0
Condition0%0/3
&looks_like_instance($dom, "SCALAR") and $dom->_type == 18
!ll&&!rl&&r
000
MC/DC0%0/2
&looks_like_instance($dom, "SCALAR") and $dom->_type == 18
&looks_like_instance($dom, "SCALAR") $dom->_type == 18
Truth table0%0/3
A and B
A= &looks_like_instance($dom, "SCALAR")B= $dom->_type == 18
ABresult
0X0
100
111
822 && $dom->_type == _DOMCREATOR_ )
823 {
824 0 splice( @args, 0, 1 );
825 }
826 else {
827 0 $dom = $Bio::Phylo::NeXML::DOM::DOM;
828 0 ▶ unless ($dom) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dom) 0 0 0
829 0 throw 'BadArgs' => 'DOM factory object not provided';
830 }
831 }
832 ##### make sure argument handling works here....
833 0 my %args = looks_like_hash @args;
834 0 my $char_ids = $args{'-chars'};
835 0 my $state_ids = $args{'-states'};
836 0 my $special = $args{'-special'};
837 0 ▶ if ( my $taxon = $self->get_taxon ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $taxon = $self->get_taxon) 0 0 0
838 0 $self->set_attributes( 'otu' => $taxon->get_xml_id );
839 }
840 0 my @char = $self->get_char;
841 0 my ( $missing, $gap ) = ( $self->get_missing, $self->get_gap );
842 0 my $elt = $self->get_dom_elt($dom);
843 0 ▶ if ( not $args{'-compact'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $args{'-compact'}) { } 0 0 0
844 0 for my $i ( 0 .. $#char ) {
845 0 ▶ if ( $missing ne $char[$i] and $gap ne $char[$i] ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($missing ne $char[$i] and $gap ne $char[$i]) { } 0 0 0
elsif ($missing eq $char[$i] or $gap eq $char[$i]) { } 0 0 0
Condition0%0/3
$missing ne $char[$i] and $gap ne $char[$i]
!ll&&!rl&&r
000
MC/DC0%0/2
$missing ne $char[$i] and $gap ne $char[$i]
$missing ne $char[$i] $gap ne $char[$i]
Truth table0%0/3
A and B
A= $missing ne $char[$i]B= $gap ne $char[$i]
ABresult
0X0
100
111
846 0 my ( $c, $s );
847 0 ▶ if ( $char_ids and $char_ids->[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char_ids and $char_ids->[$i]) { } 0 0 0
Condition0%0/3
$char_ids and $char_ids->[$i]
!ll&&!rl&&r
000
MC/DC0%0/2
$char_ids and $char_ids->[$i]
$char_ids $char_ids->[$i]
Truth table0%0/3
A and B
A= $char_idsB= $char_ids->[$i]
ABresult
0X0
100
111
848 0 $c = $char_ids->[$i];
849 }
850 else {
851 0 $c = $i;
852 }
853 0 ▶ if ( $state_ids and $state_ids->{ uc $char[$i] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state_ids and $$state_ids{uc $char[$i]}) { } 0 0 0
Condition0%0/3
$state_ids and $$state_ids{uc $char[$i]}
!ll&&!rl&&r
000
MC/DC0%0/2
$state_ids and $$state_ids{uc $char[$i]}
$state_ids $$state_ids{uc $char[$i]}
Truth table0%0/3
A and B
A= $state_idsB= $$state_ids{uc $char[$i]}
ABresult
0X0
100
111
854 0 $s = $state_ids->{ uc $char[$i] };
855 }
856 else {
857 0 $s = uc $char[$i];
858 }
859 0 my $cell_elt = $dom->create_element( '-tag' => 'cell' );
860 0 $cell_elt->set_attributes( 'char' => $c );
861 0 $cell_elt->set_attributes( 'state' => $s );
862 0 $elt->set_child($cell_elt);
863 }
864 ▶ elsif ( $missing eq $char[$i] or $gap eq $char[$i] ) {
Condition0%0/3
$missing eq $char[$i] or $gap eq $char[$i]
l!l&&r!l&&!r
000
MC/DC0%0/2
$missing eq $char[$i] or $gap eq $char[$i]
$missing eq $char[$i] $gap eq $char[$i]
Truth table0%0/3
A or B
A= $missing eq $char[$i]B= $gap eq $char[$i]
ABresult
1X1
011
000
865 0 my ( $c, $s );
866 0 ▶ if ( $char_ids and $char_ids->[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char_ids and $char_ids->[$i]) { } 0 0 0
Condition0%0/3
$char_ids and $char_ids->[$i]
!ll&&!rl&&r
000
MC/DC0%0/2
$char_ids and $char_ids->[$i]
$char_ids $char_ids->[$i]
Truth table0%0/3
A and B
A= $char_idsB= $char_ids->[$i]
ABresult
0X0
100
111
867 0 $c = $char_ids->[$i];
868 }
869 else {
870 0 $c = $i;
871 }
872 0 ▶ if ( $special and $special->{ $char[$i] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($special and $$special{$char[$i]}) { } 0 0 0
Condition0%0/3
$special and $$special{$char[$i]}
!ll&&!rl&&r
000
MC/DC0%0/2
$special and $$special{$char[$i]}
$special $$special{$char[$i]}
Truth table0%0/3
A and B
A= $specialB= $$special{$char[$i]}
ABresult
0X0
100
111
873 0 $s = $special->{ $char[$i] };
874 }
875 else {
876 0 $s = $char[$i];
877 }
878 0 my $cell_elt = $dom->create_element( '-tag' => 'cell' );
879 0 $cell_elt->set_attributes( 'char' => $c );
880 0 $cell_elt->set_attributes( 'state' => $s );
881 0 $elt->set_child($cell_elt);
882 }
883 }
884 }
885 else {
886 0 my @tmp = map { uc $_ } @char;
887 0 my $seq = $self->get_type_object->join( \@tmp );
888 0 my $seq_elt = $dom->create_element( '-tag' => 'seq' );
889 #### create a text node here....
890 0 $seq_elt->set_text($seq);
891  
892 #$seq_elt->set_child( XML::LibXML::Text->new($seq) );
893 ####
894 0 $elt->set_child($seq_elt);
895 }
896 0 return $elt;
897 }
898  
899 =item copy_atts()
900  
901 Not implemented!
902  
903 =cut
904  
905 0 ▶ sub copy_atts { } # XXX not implemented
Subroutine copy_atts: not called CC=1 SCAR=0.0
Pod documented
906  
907 =item complement()
908  
909 Not implemented!
910  
911 =cut
912  
913 0 ▶ sub complement { } # XXX not implemented
Subroutine complement: not called CC=1 SCAR=0.0
Pod documented
914  
915 =item slice()
916  
917 Not implemented!
918  
919 =cut
920  
921 0 ▶ sub slice { # XXX not implemented
Subroutine slice: not called CC=1 SCAR=6.9
Pod documented
922 0 my $self = shift;
923 0 my $start = int $_[0];
924 0 my $end = int $_[1];
925 0 my @chars = $self->get_char;
926 0 my $pos = $self->get_position;
927 0 my $slice - $self->copy_atts;
928 }
929 1488 ▶ sub _type { $TYPE_CONSTANT }
Subroutine _type: called CC=1 SCAR=0.0
930 358 ▶ sub _container { $CONTAINER_CONSTANT }
Subroutine _container: called CC=1 SCAR=0.0
931 34 ▶ sub _tag { 'row' }
Subroutine _tag: called CC=1 SCAR=0.0
932
933 133 ▶ sub _update_characters {
Subroutine _update_characters: called CC=2 SCAR=8.1
934 133 my $self = shift;
935 133 ▶ if ( my $matrix = $self->get_matrix ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $matrix = $self->get_matrix) 0 133 133
936 0 $matrix->_update_characters;
937 }
938 }
939 }
940  
941 =back
942  
943 =cut
944  
945 # podinherit_insert_token
946  
947 =head1 SEE ALSO
948  
949 There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo>
950 for any user or developer questions and discussions.
951  
952 =over
953  
954 =item L<Bio::Phylo::Taxa::TaxonLinker>
955  
956 This object inherits from L<Bio::Phylo::Taxa::TaxonLinker>, so the methods
957 defined therein are also applicable to L<Bio::Phylo::Matrices::Datum> objects.
958  
959 =item L<Bio::Phylo::Matrices::TypeSafeData>
960  
961 This object inherits from L<Bio::Phylo::Matrices::TypeSafeData>, so the methods
962 defined therein are also applicable to L<Bio::Phylo::Matrices::Datum> objects.
963  
964 =item L<Bio::Phylo::Manual>
965  
966 Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>.
967  
968 =back
969  
970 =head1 CITATION
971  
972 If you use Bio::Phylo in published research, please cite it:
973  
974 B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen>
975 and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl.
976 I<BMC Bioinformatics> B<12>:63.
977 L<http://dx.doi.org/10.1186/1471-2105-12-63>
978  
979 =cut
980  
981 16 1;
982 __DATA__
« Phylo/Unparsers/Nwmsrdf.pm ↑ Summary Phylo/Unparsers/Nexml.pm »