Bio::Tools::CodonTable::is_start_codon: check in case of ambiguous codons (#266)
[bioperl-live.git] / lib / Bio / Annotation / TypeManager.pm
blobf6b258c5ec809ef704c4dfc93e60bb5912df82b9
2 # BioPerl module for Bio::Annotation::TypeManager
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Ewan Birney <birney@ebi.ac.uk>
8 # Copyright Ewan Birney
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
14 =head1 NAME
16 Bio::Annotation::TypeManager - Manages types for annotation collections
18 =head1 SYNOPSIS
20 # default type manager
22 $tm = Bio::Annotation::TypeManager->new();
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";
27 if( !$tm->is_valid($key,$object) ) {
28 $self->throw("Invalid object for key $key");
31 =head1 DESCRIPTION
33 Manages types for annotation collections.
35 =head1 FEEDBACK
37 =head2 Mailing Lists
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.
44 bioperl-l@bioperl.org
46 =head2 Support
48 Please direct usage questions or support issues to the mailing list:
50 I<bioperl-l@bioperl.org>
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.
57 =head2 Reporting Bugs
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:
63 https://github.com/bioperl/bioperl-live/issues
65 =head1 AUTHOR - Ewan Birney
67 Email birney@ebi.ac.uk
69 =head1 APPENDIX
71 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
73 =cut
76 # Let the code begin...
79 package Bio::Annotation::TypeManager;
81 use strict;
83 # Object preamble - inherits from Bio::Root::Root
87 use base qw(Bio::Root::Root);
88 # new() can be inherited from Bio::Root::Root
90 =head2 new
92 Title : new
93 Usage :
94 Function:
95 Example :
96 Returns :
97 Args :
100 =cut
102 sub new{
103 my ($class,@args) = @_;
105 my $self = $class->SUPER::new(@args);
107 $self->{'_type'} = {};
109 $self->_add_type_map('reference',"Bio::Annotation::Reference");
110 $self->_add_type_map('comment',"Bio::Annotation::Comment");
111 $self->_add_type_map('dblink',"Bio::Annotation::DBLink");
113 return $self;
117 =head2 type_for_key
119 Title : type_for_key
120 Usage :
121 Function:
122 Example :
123 Returns :
124 Args :
127 =cut
129 sub type_for_key{
130 my ($self,$key) = @_;
132 $key = $key->name() if ref($key) && $key->isa("Bio::Ontology::TermI");
133 return $self->{'_type'}->{$key};
137 =head2 is_valid
139 Title : is_valid
140 Usage :
141 Function:
142 Example :
143 Returns :
144 Args :
147 =cut
149 sub is_valid{
150 my ($self,$key,$object) = @_;
152 if( !defined $object || !ref $object ) {
153 $self->throw("Cannot type an object [$object]!");
156 if( !$object->isa($self->type_for_key($key)) ) {
157 return 0;
158 } else {
159 return 1;
164 =head2 _add_type_map
166 Title : _add_type_map
167 Usage :
168 Function:
169 Example :
170 Returns :
171 Args :
174 =cut
176 sub _add_type_map{
177 my ($self,$key,$type) = @_;
179 $key = $key->name() if ref($key) && $key->isa("Bio::Ontology::TermI");
180 $self->{'_type'}->{$key} = $type;