PhyloRole.pm

filter: Statementstmt 82.2% 51 / 62 Branchbran 75.0% 12 / 16 Conditioncond 35.0% 7 / 20 MC/DCmcdc 9.0% 1 / 11 Subroutinesub 92.8% 13 / 14 Podpod 100% 6 / 6 totaltotal 69.7% 90 / 129 CC 17 SCAR 23.1
CC
17
Cov
71%
to_string
30.0
get_nexus_name
13.1
VERBOSE
2.0
CRAP 10.1
« Phylo/NeXML/DOM/Element/Libxml.pm ↑ Summary Phylo/Forest/DrawTreeRole.pm »
1 package Bio::PhyloRole;
2 57 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 57 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 57 ▶use base 'Bio::Phylo::Identifiable';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 57 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 57 ▶use Bio::Phylo::Util::CONSTANT '/looks_like/';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 57 ▶use Bio::Phylo::Identifiable; # for storing unique IDs inside an instance
Subroutine BEGIN: called CC=1 SCAR=0.0
8 57 ▶use Bio::Phylo::Util::Exceptions 'throw'; # defines exception classes and throws
Subroutine BEGIN: called CC=1 SCAR=0.0
9 57 ▶use Bio::Phylo::Util::Logger; # for logging, like log4perl/log4j
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Bio::PhyloRole - Extra behaviours for the base class
14  
15 =head1 SYNOPSIS
16  
17 # Actually, you would almost never use this module directly. This is
18 # the base class for other modules.
19 use Bio::Phylo;
20
21 # sets global verbosity to 'error'
22 Bio::Phylo->VERBOSE( -level => Bio::Phylo::Util::Logger::ERROR );
23
24 # sets verbosity for forest ojects to 'debug'
25 Bio::Phylo->VERBOSE(
26 -level => Bio::Phylo::Util::Logger::DEBUG,
27 -class => 'Bio::Phylo::Forest'
28 );
29
30 # prints version, including SVN revision number
31 print Bio::Phylo->VERSION;
32
33 # prints suggested citation
34 print Bio::Phylo->CITATION;
35  
36 =head1 DESCRIPTION
37  
38 This is the base class for the Bio::Phylo package for phylogenetic analysis using
39 object-oriented perl5. In this file, methods are defined that are performed by other
40 objects in the Bio::Phylo release that inherit from this base class (which you normally
41 wouldn't use directly).
42  
43 For general information on how to use Bio::Phylo, consult the manual
44 (L<Bio::Phylo::Manual>).
45  
46 If you come here because you are trying to debug a problem you run into in
47 using Bio::Phylo, you may be interested in the "exceptions" system as discussed
48 in L<Bio::Phylo::Util::Exceptions>. In addition, you may find the logging system
49 in L<Bio::Phylo::Util::Logger> of use to localize problems.
50  
51 =head1 METHODS
52  
53 =head2 ACCESSORS
54  
55 =over
56  
57 =item get_nexus_name()
58  
59 Gets invocant's name, modified to be safely used in nexus files. This means that:
60  
61 =item names with spaces in them that aren't 'single quoted' have their spaces replaced
62 with underscores
63  
64 =item names with any of the following characters in them are single quoted:
65 -^*(){}[]+=;:"\<>/,
66  
67 =item names with single quotes inside them (i.e. not around them) are "double quoted"
68  
69 Type : Accessor
70 Title : get_nexus_name
71 Usage : my $name = $obj->get_nexus_name;
72 Function: Returns the object's name.
73 Returns : A string
74 Args : (Optional) if provided a true value, the returned name may be the null
75 string, in cases where no name for the object has been set. The default
76 value (i.e. if no argument was provided) is to return an autogenerated
77 name for any anonymous object.
78  
79 =cut
80  
81 3237 ▶ sub get_nexus_name {
Subroutine get_nexus_name: called CC=10 SCAR=25.7
Pod documented
82 3237 my ($self,$no_internal) = @_;
83 3237 ▶ my $name = $no_internal ? $self->get_name : $self->get_internal_name;
Branch: 1 branch
BranchTrueFalseTotal
$no_internal ? : 3154 83 3237
84 3237 ▶ if ( $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) 3237 0 3237
85 3237 ▶ if ( $name =~ /\s/ && $name !~ /^'.+'$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\s/ and not $name =~ /^'.+'$/) 0 3237 3237
Condition33%1/3
$name =~ /\s/ and not $name =~ /^'.+'$/
!ll&&!rl&&r
323700
MC/DC0%0/2
$name =~ /\s/ and not $name =~ /^'.+'$/
$name =~ /\s/ not $name =~ /^'.+'$/
Truth table33%1/3
A and not(B)
A= $name =~ /\s/B= not $name =~ /^'.+'$/
ABresult
0X0
100
111
86 0 $name =~ s/\s/_/g;
87 }
88 3237 ▶ if ( $name =~ /(?:\-|\^|\*|\(|\)|{|}|\[|\]|\+|=|;|:|"|\\|<|>|\/|,)/
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ m<(?:\-|\^|\*|\(|\)|{|}|\[|\]|\+|=|;|:|"|\\|<|>|/|,)> and not $name =~ /^'.+'$/) 49 3188 3237
Condition66%2/3
$name =~ m<(?:\-|\^|\*|\(|\)|{|}|\[|\]|\+|=|;|:|"|\\|<|>|/|,)> and not $name =~ /^'.+'$/
!ll&&!rl&&r
3188049
MC/DC50%1/2
$name =~ m<(?:\-|\^|\*|\(|\)|{|}|\[|\]|\+|=|;|:|"|\\|<|>|/|,)> and not $name =~ /^'.+'$/
$name =~ m<(?:\-|\^|\*|\(|\)|{|}|\[|\]|\+|=|;|:|"|\\|<|>|/|,)> not $name =~ /^'.+'$/
Truth table66%2/3
A and not(B)
A= $name =~ m<(?:\-|\^|\*|\(|\)|{|}|\[|\]|\+|=|;|:|"|\\|<|>|/|,)>B= not $name =~ /^'.+'$/
ABresult
0X0
100
111
89 && $name !~ /^'.+'$/ )
90 {
91 49 $name = "'${name}'";
92 }
93 3237 ▶ if ( $name =~ /'/ && $name !~ /^".+"$/ && $name !~ /^'.+'$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /'/ and not $name =~ /^".+"$/ and not $name =~ /^'.+'$/) 0 3237 3237
Condition66%4/6
$name =~ /'/ and not $name =~ /^".+"$/ and not $name =~ /^'.+'$/
!ll&&!rl&&r
3179580
$name =~ /'/ and not $name =~ /^".+"$/
!ll&&!rl&&r
3179058
MC/DC0%0/3
$name =~ /'/ and not $name =~ /^".+"$/ and not $name =~ /^'.+'$/
$name =~ /'/ not $name =~ /^".+"$/ not $name =~ /^'.+'$/
Truth table50%2/4
A and not(B) and not(C)
A= $name =~ /'/B= not $name =~ /^".+"$/C= not $name =~ /^'.+'$/
ABCresult
0XX0
10X0
1100
1111
94 0 $name = "\"${name}\"";
95 }
96 }
97 3237 return $name;
98 }
99  
100 =item get_internal_name()
101  
102 Gets invocant's 'fallback' name (possibly autogenerated).
103  
104 Type : Accessor
105 Title : get_internal_name
106 Usage : my $name = $obj->get_internal_name;
107 Function: Returns the object's name (if none was set, the name
108 is a combination of the $obj's class and its UID).
109 Returns : A string
110 Args : None
111  
112 =cut
113  
114 1480 ▶ sub get_internal_name {
Subroutine get_internal_name: called CC=2 SCAR=6.9
Pod documented
115 1480 my $self = shift;
116 1480 ▶ if ( my $name = $self->get_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = $self->get_name) { } 1341 139 1480
117 1341 return $name;
118 }
119 else {
120 139 my $internal_name = ref $self;
121 139 $internal_name =~ s/.*:://;
122 139 $internal_name .= $self->get_id;
123 139 return $internal_name;
124 }
125 }
126  
127 =back
128  
129 =head2 PACKAGE METHODS
130  
131 =over
132  
133 =item get()
134  
135 Attempts to execute argument string as method on invocant.
136  
137 Type : Accessor
138 Title : get
139 Usage : my $treename = $tree->get('get_name');
140 Function: Alternative syntax for safely accessing
141 any of the object data; useful for
142 interpolating runtime $vars.
143 Returns : (context dependent)
144 Args : a SCALAR variable, e.g. $var = 'get_name';
145  
146 =cut
147  
148 544 ▶ sub get {
Subroutine get: called CC=2 SCAR=6.9
Pod documented
149 544 my ( $self, $var ) = @_;
150 544 ▶ if ( $self->can($var) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can($var)) { } 534 10 544
151 534 return $self->$var;
152 }
153 else {
154 10 my $ref = ref $self;
155 10 throw 'UnknownMethod' => "sorry, a '$ref' can't '$var'";
156 }
157 }
158  
159 =item to_string()
160  
161 Serializes object to general purpose string
162  
163 Type : Serializer
164 Title : to_string()
165 Usage : print $obj->to_string();
166 Function: Serializes object to general purpose string
167 Returns : String
168 Args : None
169 Comments: This is YAML
170  
171 =cut
172  
173 0 ▶ sub to_string {
Subroutine to_string: not called CC=5 SCAR=34.0
Pod documented
174 0 my $self = shift;
175 0 my $class = ref $self;
176 0 my $id = $self->get_id;
177 0 my $internal_name = $self->get_internal_name;
178 0 ▶ my $name = $self->get_name || '';
Condition0%0/2
$self->get_name || ''
l!l
00
MC/DC0%0/1
$self->get_name || ''
$self->get_name
Truth table0%0/2
A
A= $self->get_name
Aresult
11
00
179 0 ▶ my $score = $self->get_score || '';
Condition0%0/2
$self->get_score || ''
l!l
00
MC/DC0%0/1
$self->get_score || ''
$self->get_score
Truth table0%0/2
A
A= $self->get_score
Aresult
11
00
180 0 ▶ my $desc = $self->get_desc || '';
Condition0%0/2
$self->get_desc || ''
l!l
00
MC/DC0%0/1
$self->get_desc || ''
$self->get_desc
Truth table0%0/2
A
A= $self->get_desc
Aresult
11
00
181 0 ▶ my $gen = Dumper($self->get_generic) || '';
Condition0%0/2
Dumper($self->get_generic) || ''
l!l
00
MC/DC0%0/1
Dumper($self->get_generic) || ''
Dumper($self->get_generic)
Truth table0%0/2
A
A= Dumper($self->get_generic)
Aresult
11
00
182 0 return <<"SERIALIZED_OBJECT";
183 class: $class
184 id: $id
185 internal_name: $internal_name
186 name: $name
187 score: $score
188 desc: $desc
189 generic: $gen
190 SERIALIZED_OBJECT
191 }
192  
193 =item VERBOSE()
194  
195 Getter and setter for the verbosity level. Refer to L<Bio::Phylo::Util::Logger> for more
196 info on available verbosity levels.
197  
198 Type : Accessor
199 Title : VERBOSE()
200 Usage : Bio::Phylo->VERBOSE( -level => $level )
201 Function: Sets/gets verbose level
202 Returns : Verbose level
203 Args : -level => $level
204 Comments:
205  
206 =cut
207  
208 # Verbosity is mostly handled by the logger, actually. This method
209 # is just here for backward compatibility (and ease of use).
210 # TODO have a facility to turn log levels (warn/error/fatal) into
211 # throws
212 12 ▶ sub VERBOSE {
Subroutine VERBOSE: called CC=2 SCAR=7.0
Pod documented
213 12 my $class = shift;
214 12 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 12 0 12
215 12 my %opt = looks_like_hash @_;
216 12 Bio::Phylo::Util::Logger::VERBOSE(%opt);
217  
218 }
219 12 return $Bio::Phylo::Util::Logger::VERBOSE;
220 }
221  
222 =item CITATION()
223  
224 Returns suggested citation.
225  
226 Type : Accessor
227 Title : CITATION
228 Usage : $phylo->CITATION;
229 Function: Returns suggested citation.
230 Returns : Returns suggested citation.
231 Args : None
232 Comments:
233  
234 =cut
235  
236 1 ▶ sub CITATION {
Subroutine CITATION: called CC=1 SCAR=0.0
Pod documented
237 1 return <<'CITATION';
238 Rutger A Vos, Jason Caravas, Klaas Hartmann, Mark A Jensen and Chase Miller, 2011.
239 Bio::Phylo - phyloinformatic analysis using Perl. BMC Bioinformatics 12:63.
240 doi:10.1186/1471-2105-12-63
241 CITATION
242 }
243  
244 =back
245  
246 =head1 SEE ALSO
247  
248 There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo>
249 for any user or developer questions and discussions.
250  
251 Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>
252  
253 =head1 CITATION
254  
255 If you use Bio::Phylo in published research, please cite it:
256  
257 B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen>
258 and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl.
259 I<BMC Bioinformatics> B<12>:63.
260 L<http://dx.doi.org/10.1186/1471-2105-12-63>
261  
262 =cut
263  
264 57 1;
« Phylo/NeXML/DOM/Element/Libxml.pm ↑ Summary Phylo/Forest/DrawTreeRole.pm »