Bio/Annotation/TypeManager.pm

filter: Statementstmt 92.5% 25 / 27 Branchbran 50.0% 4 / 8 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 69.4% 41 / 59 CC 8 SCAR 12.7
CC
8
Cov
73%
is_valid
5.6
type_for_key
3.5
_add_type_map
3.5
CRAP 3.5
« Bio/Factory/ObjectFactory.pm ↑ Summary Bio/SeqFeature/Gene/UTR.pm »
1 #
2 # BioPerl module for Bio::Annotation::TypeManager
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Ewan Birney <birney@ebi.ac.uk>
7 #
8 # Copyright Ewan Birney
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::Annotation::TypeManager - Manages types for annotation collections
17  
18 =head1 SYNOPSIS
19  
20 # default type manager
21  
22 $tm = Bio::Annotation::TypeManager->new();
23  
24 # $key is a string or a Bio::Ontology::TermI compliant object
25 print "The type for $key is ",$tm->type_for_key($key),"\n";
26  
27 if( !$tm->is_valid($key,$object) ) {
28 $self->throw("Invalid object for key $key");
29 }
30  
31 =head1 DESCRIPTION
32  
33 Manages types for annotation collections.
34  
35 =head1 FEEDBACK
36  
37 =head2 Mailing Lists
38  
39 User feedback is an integral part of the evolution of this
40 and other Bioperl modules. Send your comments and suggestions preferably
41 to one of the Bioperl mailing lists.
42 Your participation is much appreciated.
43  
44 bioperl-l@bioperl.org
45  
46 =head2 Support
47  
48 Please direct usage questions or support issues to the mailing list:
49  
50 I<bioperl-l@bioperl.org>
51  
52 rather than to the module maintainer directly. Many experienced and
53 reponsive experts will be able look at the problem and quickly
54 address it. Please include a thorough description of the problem
55 with code and data examples if at all possible.
56  
57 =head2 Reporting Bugs
58  
59 Report bugs to the Bioperl bug tracking system to help us keep track
60 the bugs and their resolution.
61 Bug reports can be submitted via the web:
62  
63 https://github.com/bioperl/bioperl-live/issues
64  
65 =head1 AUTHOR - Ewan Birney
66  
67 Email birney@ebi.ac.uk
68  
69 =head1 APPENDIX
70  
71 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
72  
73 =cut
74  
75  
76 # Let the code begin...
77  
78  
79 package Bio::Annotation::TypeManager;
80 315 $Bio::Annotation::TypeManager::VERSION = '1.7.8';
81 315 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83 # Object preamble - inherits from Bio::Root::Root
84  
85  
86  
87 315 ▶use base qw(Bio::Root::Root);
Subroutine BEGIN: called CC=1 SCAR=0.0
88 # new() can be inherited from Bio::Root::Root
89  
90 =head2 new
91  
92 Title : new
93 Usage :
94 Function:
95 Example :
96 Returns :
97 Args :
98  
99  
100 =cut
101  
102 2185 ▶sub new{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
103 2185 my ($class,@args) = @_;
104  
105 2185 my $self = $class->SUPER::new(@args);
106  
107 2185 $self->{'_type'} = {};
108  
109 2185 $self->_add_type_map('reference',"Bio::Annotation::Reference");
110 2185 $self->_add_type_map('comment',"Bio::Annotation::Comment");
111 2185 $self->_add_type_map('dblink',"Bio::Annotation::DBLink");
112  
113 2185 return $self;
114 }
115  
116  
117 =head2 type_for_key
118  
119 Title : type_for_key
120 Usage :
121 Function:
122 Example :
123 Returns :
124 Args :
125  
126  
127 =cut
128  
129 9486 ▶sub type_for_key{
Subroutine type_for_key: called CC=3 SCAR=12.5
Pod documented
130 9486 my ($self,$key) = @_;
131  
132 9486 ▶ $key = $key->name() if ref($key) && $key->isa("Bio::Ontology::TermI");
Branch: 1 branch
BranchTrueFalseTotal
if ref $key and $key->isa("Bio::Ontology::TermI") 0 9486 9486
Condition33%1/3
ref $key and $key->isa("Bio::Ontology::TermI")
!ll&&!rl&&r
948600
MC/DC0%0/2
ref $key and $key->isa("Bio::Ontology::TermI")
ref $key $key->isa("Bio::Ontology::TermI")
Truth table33%1/3
A and B
A= ref $keyB= $key->isa("Bio::Ontology::TermI")
ABresult
0X0
100
111
133 9486 return $self->{'_type'}->{$key};
134 }
135  
136  
137 =head2 is_valid
138  
139 Title : is_valid
140 Usage :
141 Function:
142 Example :
143 Returns :
144 Args :
145  
146  
147 =cut
148  
149 3659 ▶sub is_valid{
Subroutine is_valid: called CC=4 SCAR=17.2
Pod documented
150 3659 my ($self,$key,$object) = @_;
151  
152 3659 ▶ if( !defined $object || !ref $object ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $object and ref $object) 0 3659 3659
Condition33%1/3
defined $object and ref $object
!ll&&!rl&&r
003659
MC/DC0%0/2
defined $object and ref $object
defined $object ref $object
Truth table33%1/3
A and B
A= defined $objectB= ref $object
ABresult
0X0
100
111
153 0 $self->throw("Cannot type an object [$object]!");
154 }
155  
156 3659 ▶ if( !$object->isa($self->type_for_key($key)) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $object->isa($self->type_for_key($key))) { } 0 3659 3659
157 0 return 0;
158 } else {
159 3659 return 1;
160 }
161 }
162  
163  
164 =head2 _add_type_map
165  
166 Title : _add_type_map
167 Usage :
168 Function:
169 Example :
170 Returns :
171 Args :
172  
173  
174 =cut
175  
176 8723 ▶sub _add_type_map{
Subroutine _add_type_map: called CC=3 SCAR=12.5
177 8723 my ($self,$key,$type) = @_;
178  
179 8723 ▶ $key = $key->name() if ref($key) && $key->isa("Bio::Ontology::TermI");
Branch: 1 branch
BranchTrueFalseTotal
if ref $key and $key->isa("Bio::Ontology::TermI") 0 8723 8723
Condition33%1/3
ref $key and $key->isa("Bio::Ontology::TermI")
!ll&&!rl&&r
872300
MC/DC0%0/2
ref $key and $key->isa("Bio::Ontology::TermI")
ref $key $key->isa("Bio::Ontology::TermI")
Truth table33%1/3
A and B
A= ref $keyB= $key->isa("Bio::Ontology::TermI")
ABresult
0X0
100
111
180 8723 $self->{'_type'}->{$key} = $type;
181 }
182  
183 315 1;
« Bio/Factory/ObjectFactory.pm ↑ Summary Bio/SeqFeature/Gene/UTR.pm »