19
# see documentation of methods
23
#make an ontology object manually. via OntologyIO
24
my $io = Bio::OntologyIO->new(
25
#params to fetch Cell Ontology here
27
my $cell_ontology = $io->next_ontology;
29
#this is a singleton that caches the fact that you've created
30
#a 'Cell Ontology' intance...
31
my $store = Bio::Ontology::OntologyStore->get_instance();
33
#...and it can hand you back a copy of it at any time.
34
my $cell_ontology_copy = $store->get_ontology('Cell Ontology');
41
my $store = Bio::Ontology::OntologyStore->get_instance();
42
#this use case allows the construction of an ontology on
43
#demand just by supplying the name.
44
my $ontology = $store->get_ontology('Sequence Ontology');
28
54
Ontology object. The latter would almost inevitably lead to memory
29
55
cycles, and would therefore potentially blow up an application.
31
As a user of Ontology objects and Term objects you almost certainly
32
will not need to deal with this module.
36
59
=head2 Mailing Lists
39
62
Bioperl modules. Send your comments and suggestions preferably to
40
63
the Bioperl mailing list. Your participation is much appreciated.
42
bioperl-l@bioperl.org - General discussion
43
http://bioperl.org/MailList.shtml - About the mailing lists
65
bioperl-l@bioperl.org - General discussion
66
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
45
68
=head2 Reporting Bugs
48
71
of the bugs and their resolution. Bug reports can be submitted via
51
http://bugzilla.bioperl.org/
74
http://bugzilla.open-bio.org/
53
76
=head1 AUTHOR - Hilmar Lapp
55
Email hlapp at gmx.net
59
Additional contributors names and emails here
78
Hilmar Lapp E<lt>hlapp@gmx.netE<gt>
79
Allen Day E<lt>allenday@ucla.eduE<gt>
72
92
package Bio::Ontology::OntologyStore;
76
95
# Object preamble - inherits from Bio::Root::Root
81
@ISA = qw(Bio::Root::Root );
97
use Bio::Ontology::DocumentRegistry;
100
use File::Spec::Functions;
103
use base qw(Bio::Root::Root);
83
105
# these are the static ontology stores by name and by identifier - there is
84
106
# only one of each in any application
85
107
my %ont_store_by_name = ();
86
108
my %ont_store_by_id = ();
110
'Gene Ontology' => 'Gene_Ontology'
87
112
# also, this is really meant as a singleton object, so we try to enforce it
88
113
my $instance = undef;
158
183
name, without dereferencing an object.
161
Returns : a L<Bio::Ontology::OntologyI> implementing object, or undef
186
Returns : a Bio::Ontology::OntologyI implementing object, or undef
162
187
if the query could not be satisfied
163
188
Args : Named parameters specifying the query. The following parameters
167
192
If both are specified, an implicit AND logical operator is
195
See L<Bio::Ontology::OntologyI>.
172
199
sub get_ontology{
173
my ($self,@args) = @_;
176
my ($name,$id) = $self->_rearrange([qw(NAME ID)], @args);
178
$ont = $ont_store_by_id{$id};
179
return unless $ont; # no AND can be satisfied in this case
182
my $o = $ont_store_by_name{$name};
183
if((! $ont) || ($ont->identifier() eq $o->identifier())) {
200
my ($self,@args) = @_;
203
my ($name,$id) = $self->_rearrange([qw(NAME ID)], @args);
205
$ont = $ont_store_by_id{$id};
206
return unless $ont; # no AND can be satisfied in this case
210
my $o = $ont_store_by_name{$name};
213
my $doc_registry = Bio::Ontology::DocumentRegistry->get_instance();
214
my($url,$def,$fmt) = $doc_registry->documents($name);
216
if(ref($url) eq 'ARRAY'){
217
my $io = Bio::OntologyIO->new(-url => $url,
222
$o = $io->next_ontology();
223
$ont_store_by_name{$name} = $o;
225
my $io = Bio::OntologyIO->new(-url => $url,
229
$o = $io->next_ontology;
230
$ont_store_by_name{$name} = $o;
234
if((! $ont) || ($ont->identifier() eq $o->identifier())) {
192
244
=head2 register_ontology
200
252
Returns : TRUE on success and FALSE otherwise
201
Args : the L<Bio::Ontology::OntologyI> object(s) to register
253
Args : the Bio::Ontology::OntologyI object(s) to register
255
See L<Bio::Ontology::OntologyI>.
206
sub register_ontology{
207
my ($self,@args) = @_;
259
sub register_ontology {
260
my ($self,@args) = @_;
262
foreach my $ont (@args) {
263
if(ref($ont) && $ont->isa('Bio::Ontology::OntologyI')){
264
$ont_store_by_name{$ont->name()} = $ont if $ont->name;
210
foreach my $ont (@args) {
211
268
if(! (ref($ont) && $ont->isa("Bio::Ontology::OntologyI"))) {
212
$self->throw((ref($ont) ? ref($ont) : $ont)." does not implement ".
213
"Bio::Ontology::OntologyI or is not an object");
269
$self->throw((ref($ont) ? ref($ont) : $ont)." does not implement ".
270
"Bio::Ontology::OntologyI or is not an object");
215
272
if($self->get_ontology(-name => $ont->name())) {
216
$self->warn("ontology with name \"".$ont->name().
217
"\" already exists in the store, ignoring new one");
273
$self->warn("ontology with name \"".$ont->name().
274
"\" already exists in the store, ignoring new one");
221
278
if($self->get_ontology(-id => $ont->identifier())) {
222
$self->warn("ontology with id \"".$ont->identifier().
223
"\" already exists in the store, ignoring new one");
279
$self->warn("ontology with id \"".$ont->identifier().
280
"\" already exists in the store, ignoring new one");
227
284
$ont_store_by_name{$ont->name()} = $ont;
228
285
$ont_store_by_id{$ont->identifier()} = $ont;
233
290
=head2 remove_ontology
237
294
Function: Remove the specified ontology from the store.
239
296
Returns : TRUE on success and FALSE otherwise
240
Args : the L<Bio::Ontology::OntologyI> implementing object(s)
297
Args : the Bio::Ontology::OntologyI implementing object(s)
241
298
to be removed from the store
300
See L<Bio::Ontology::OntologyI>.
318
=head2 guess_ontology()
320
Usage : my $ontology =
321
Bio::Ontology::OntologyStore->guess_ontology('GO:0000001');
322
Function: tries to guess which ontology a term identifier comes from,
323
loads it as necessary,
324
and returns it as a Bio::Ontology::Ontology object.
326
Returns : a Bio::Ontology::Ontology object, or warns and returns undef
327
Args : an ontology term identifier in XXXX:DDDDDDD format.
328
Guessing is based on the XXXX string before the colon.
335
my($prefix) = $id =~ /^(.+?):.+$/;
338
SO => 'Sequence Ontology',
339
SOFA => 'Sequence Ontology Feature Annotation',
340
GO => 'Gene Ontology',
343
return $prefix{$prefix} || undef;