File Coverage

blib/lib/Bio/PhyloRole.pm
Criterion Covered Total %
statement 47 58 81.0
branch 12 16 75.0
condition 7 20 35.0
subroutine 12 13 92.3
pod 6 6 100.0
total 84 113 74.3


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