Phylo/Matrices/Character.pm

filter: Statementstmt 70.3% 38 / 54 Branchbran 16.6% 3 / 18 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 94.1% 16 / 17 Podpod 100% 5 / 5 totaltotal 60.1% 62 / 103 CC 12 SCAR 24.5
CC
12
Cov
53%
set_codonpos
34.6
to_xml
12.0
set_weight
8.3
CRAP 11.6
« Phylo/Project.pm ↑ Summary Phylo/Treedrawer/Png.pm »
1 package Bio::Phylo::Matrices::Character;
2 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use base 'Bio::Phylo::Matrices::TypeSafeData';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use Bio::Phylo::Factory;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use Bio::Phylo::Util::CONSTANT qw'_CHARACTER_ _CHARACTERS_ _NS_BIOPHYLO_ /looks_like/';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use Bio::Phylo::Util::Exceptions 'throw';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 10 my $fac = Bio::Phylo::Factory->new;
10  
11 =head1 NAME
12  
13 Bio::Phylo::Matrices::Character - A character (column) in a matrix
14  
15 =head1 SYNOPSIS
16  
17 # No direct usage
18  
19 =head1 DESCRIPTION
20  
21 Objects of this type represent a single character in a matrix. By default, a
22 matrix will adjust the number of such objects it requires automatically as its
23 contents grow or shrink. The main function, at present, for objects of this
24 type is to facilitate NeXML serialization of characters and their annotations.
25  
26 =head1 METHODS
27  
28 =head2 MUTATORS
29  
30 =over
31  
32 =item set_weight()
33  
34 Type : Mutator
35 Title : set_weight
36 Usage : $character->set_weight(2);
37 Function: Sets character weight
38 Returns : $self
39 Args : A number
40  
41 =cut
42  
43 22 ▶sub set_weight : Clonable {
Subroutine set_weight: called CC=4 SCAR=21.1
Pod documented
44 22 my ( $self, $weight ) = @_;
45 22 ▶ if ( looks_like_number $weight ) {
Branch: 2 branches
BranchTrueFalseTotal
if (&looks_like_number($weight)) { } 0 22 22
elsif (defined $weight) { } 0 22 22
46 0 ▶ if ( my ($meta) = @{ $self->get_meta('bp:charWeight') } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($meta) = @{$self->get_meta('bp:charWeight');}) { } 0 0 0
47 0 $meta->set_triple( 'bp:charWeight' => $weight );
48 }
49 else {
50 0 $self->add_meta(
51 $fac->create_meta(
52 '-namespaces' => { 'bp' => _NS_BIOPHYLO_ },
53 '-triple' => { 'bp:charWeight' => $weight },
54 )
55 );
56 }
57 }
58 elsif ( defined $weight ) {
59 0 throw 'BadNumber' => "'$weight' is not a number";
60 }
61 22 return $self;
62 10 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64 =item set_codonpos()
65  
66 Type : Mutator
67 Title : set_codonpos
68 Usage : $character->set_codonpos(2);
69 Function: Sets codon position for the column
70 Returns : $self
71 Args : A number
72  
73 =cut
74  
75 22 ▶sub set_codonpos : Clonable {
Subroutine set_codonpos: called CC=7 SCAR=35.4
Pod documented
76 22 my ( $self, $codonpos ) = @_;
77 22 ▶ if ( $codonpos ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($codonpos) 0 22 22
78 0 ▶ if ( $codonpos == 1 || $codonpos == 2 || $codonpos == 3 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($codonpos == 1 or $codonpos == 2 or $codonpos == 3) { } 0 0 0
elsif (defined $codonpos) { } 0 0 0
Condition0%0/6
$codonpos == 1 or $codonpos == 2 or $codonpos == 3
l!l&&r!l&&!r
000
$codonpos == 1 or $codonpos == 2
l!l&&r!l&&!r
000
MC/DC0%0/3
$codonpos == 1 or $codonpos == 2 or $codonpos == 3
$codonpos == 1 $codonpos == 2 $codonpos == 3
Truth table0%0/4
A or B or C
A= $codonpos == 1B= $codonpos == 2C= $codonpos == 3
ABCresult
1XX1
01X1
0011
0000
79 0 ▶ if ( my ($meta) = @{ $self->get_meta('bp:codonPos') } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($meta) = @{$self->get_meta('bp:codonPos');}) { } 0 0 0
80 0 $meta->set_triple( 'bp:codonPos' => $codonpos );
81 }
82 else {
83 0 $self->add_meta(
84 $fac->create_meta(
85 '-namespaces' => { 'bp' => _NS_BIOPHYLO_ },
86 '-triple' => { 'bp:codonPos' => $codonpos },
87 )
88 );
89 }
90 }
91 elsif ( defined $codonpos ) {
92 0 throw 'BadNumber' => "'$codonpos' is not a valid 1-based codon position";
93 }
94 }
95 22 return $self;
96 10 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
97  
98 =back
99  
100 =head2 ACCESSORS
101  
102 =over
103  
104 =item get_weight()
105  
106 Type : Accessor
107 Title : get_weight
108 Usage : my $weight = $character->get_weight();
109 Function: Gets character weight
110 Returns : A number (default is 1)
111 Args : NONE
112  
113 =cut
114  
115 22 ▶sub get_weight {
Subroutine get_weight: called CC=1 SCAR=0.0
Pod documented
116 22 shift->get_meta_object('bp:charWeight');
117 }
118  
119 =item get_codonpos()
120  
121 Type : Mutator
122 Title : get_codonpos
123 Usage : my $pos = $character->get_codonpos;
124 Function: Gets codon position for the column
125 Returns : 1, 2, 3 or undef
126 Args : None
127  
128 =cut
129  
130 22 ▶sub get_codonpos {
Subroutine get_codonpos: called CC=1 SCAR=0.0
Pod documented
131 22 shift->get_meta_object('bp:codonPos');
132 }
133  
134 =back
135  
136 =head2 SERIALIZERS
137  
138 =over
139  
140 =item to_xml()
141  
142 Serializes characters to nexml format.
143  
144 Type : Format convertor
145 Title : to_xml
146 Usage : my $xml = $characters->to_xml;
147 Function: Converts characters object into a nexml element structure.
148 Returns : Nexml block (SCALAR).
149 Args : NONE
150  
151 =cut
152  
153 0 ▶sub to_xml {
Subroutine to_xml: not called CC=3 SCAR=24.8
Pod documented
154 0 my $self = shift;
155 0 ▶ if ( my $to = $self->get_type_object ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $to = $self->get_type_object) 0 0 0
156 0 ▶ if ( $to->get_type !~ m/continuous/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($to->get_type =~ /continuous/i) 0 0 0
157 0 $self->set_attributes( 'states' => $to->get_xml_id );
158 }
159 }
160 0 return $self->SUPER::to_xml;
161 }
162 205 ▶sub _validate { 1 }
Subroutine _validate: called CC=1 SCAR=0.0
163 322 ▶sub _container { _CHARACTERS_ }
Subroutine _container: called CC=1 SCAR=0.0
164 231 ▶sub _type { _CHARACTER_ }
Subroutine _type: called CC=1 SCAR=0.0
165 38 ▶sub _tag { 'char' }
Subroutine _tag: called CC=1 SCAR=0.0
166  
167 =back
168  
169 =cut
170  
171 # podinherit_insert_token
172  
173 =head1 SEE ALSO
174  
175 There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo>
176 for any user or developer questions and discussions.
177  
178 =over
179  
180 =item L<Bio::Phylo::Matrices::TypeSafeData>
181  
182 This object inherits from L<Bio::Phylo::Matrices::TypeSafeData>, so the
183 methods defined therein are also applicable to characters objects
184 objects.
185  
186 =item L<Bio::Phylo::Manual>
187  
188 Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>.
189  
190 =back
191  
192 =head1 CITATION
193  
194 If you use Bio::Phylo in published research, please cite it:
195  
196 B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen>
197 and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl.
198 I<BMC Bioinformatics> B<12>:63.
199 L<http://dx.doi.org/10.1186/1471-2105-12-63>
200  
201 =cut
202  
203 10 1;
« Phylo/Project.pm ↑ Summary Phylo/Treedrawer/Png.pm »