File Coverage

blib/lib/Bio/PhyloRole.pm
Criterion Covered Total %
statement 50 61 81.9
branch 12 16 75.0
condition 7 20 35.0
subroutine 13 14 92.8
pod 6 6 100.0
total 88 117 75.2


line stmt bran cond sub pod time code
1             package Bio::PhyloRole;
2 57     57   318 use strict;
  57         101  
  57         1430  
3 57     57   337 use warnings;
  57         186  
  57         1404  
4 57     57   336 use base 'Bio::Phylo::Identifiable';
  57         165  
  57         14662  
5 57     57   17061 use Data::Dumper;
  57         229839  
  57         3086  
6 57     57   10222 use Bio::Phylo::Util::CONSTANT '/looks_like/';
  57         116  
  57         10653  
7 57     57   369 use Bio::Phylo::Identifiable; # for storing unique IDs inside an instance
  57         93  
  57         1244  
8 57     57   258 use Bio::Phylo::Util::Exceptions 'throw'; # defines exception classes and throws
  57         103  
  57         2124  
9 57     57   14370 use Bio::Phylo::Util::Logger; # for logging, like log4perl/log4j
  57         158  
  57         29289  
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             sub get_nexus_name {
82 3201     3201 1 4925 my ($self,$no_internal) = @_;
83 3201 100       6909 my $name = $no_internal ? $self->get_name : $self->get_internal_name;
84 3201 50       5520 if ( $name ) {
85 3201 50 33     8302 if ( $name =~ /\s/ && $name !~ /^'.+'$/ ) {
86 0         0 $name =~ s/\s/_/g;
87             }
88 3201 100 66     7860 if ( $name =~ /(?:\-|\^|\*|\(|\)|{|}|\[|\]|\+|=|;|:|"|\\|<|>|\/|,)/
89             && $name !~ /^'.+'$/ )
90             {
91 49         109 $name = "'${name}'";
92             }
93 3201 50 66     6687 if ( $name =~ /'/ && $name !~ /^".+"$/ && $name !~ /^'.+'$/ ) {
      66        
94 0         0 $name = "\"${name}\"";
95             }
96             }
97 3201         6772 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             sub get_internal_name {
115 1480     1480 1 1966 my $self = shift;
116 1480 100       3077 if ( my $name = $self->get_name ) {
117 1341         2937 return $name;
118             }
119             else {
120 139         258 my $internal_name = ref $self;
121 139         633 $internal_name =~ s/.*:://;
122 139         339 $internal_name .= $self->get_id;
123 139         460 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             sub get {
149 544     544 1 1230 my ( $self, $var ) = @_;
150 544 100       1581 if ( $self->can($var) ) {
151 534         1205 return $self->$var;
152             }
153             else {
154 10         22 my $ref = ref $self;
155 10         45 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             sub to_string {
174 0     0 1 0 my $self = shift;
175 0         0 my $class = ref $self;
176 0         0 my $id = $self->get_id;
177 0         0 my $internal_name = $self->get_internal_name;
178 0   0     0 my $name = $self->get_name || '';
179 0   0     0 my $score = $self->get_score || '';
180 0   0     0 my $desc = $self->get_desc || '';
181 0   0     0 my $gen = Dumper($self->get_generic) || '';
182 0         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             sub VERBOSE {
213 12     12 1 958 my $class = shift;
214 12 50       54 if (@_) {
215 12         62 my %opt = looks_like_hash @_;
216 12         66 Bio::Phylo::Util::Logger::VERBOSE(%opt);
217              
218             }
219 12         40 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             sub CITATION {
237 1     1 1 3 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             1;