diff --git a/modules/Bio/EnsEMBL/OntologyXref.pm b/modules/Bio/EnsEMBL/OntologyXref.pm index cab5ef69ecce06b9345022f116aa29bf63ef4db1..1c81d431bc183c615928a4cff293ee3b5d434391 100644 --- a/modules/Bio/EnsEMBL/OntologyXref.pm +++ b/modules/Bio/EnsEMBL/OntologyXref.pm @@ -64,9 +64,40 @@ identifier but with different evidence tags. For this reason a single package Bio::EnsEMBL::OntologyXref; use strict; +use warnings; use base qw( Bio::EnsEMBL::DBEntry ); +require Bio::EnsEMBL::Registry; + +=head2 get_OntologyTerm + + Example : $ontology_xref->get_OntologyTerm(); + Description: Queries the OntologyTermAdaptor for a term which is the same + as the primary id of this object. This method requires a + OntologyDBAdaptor to be available in the Bio::EnsEMBL::Registry. + If you have loaded data from an Ensembl release using + Bio::EnsEMBL::Registry->load_registry_from_db() then this should + work. + Returntype : Bio::EnsEMBL::OntologyTerm + Exceptions : None + Caller : general + Status : Experimantal + +=cut + + +sub get_OntologyTerm { + my ($self) = @_; + my $dbas = Bio::EnsEMBL::Registry->get_all_DBAdaptors(-GROUP => 'ontology'); + foreach my $ontology_dba (@{$dbas}) { + my $ota = $ontology_dba->get_OntologyTermAdaptor(); + my $term = $ota->fetch_by_accession($self->primary_id()); + return $term if $term; + } + return; +} + =head2 add_linkage_type Arg [1] : string $value diff --git a/modules/t/ontologyTerm.t b/modules/t/ontologyTerm.t index 029809f9005db5f38a5b105fc6716da4fc32cd43..e5116c369486ff3adecf2593bfbbc59c3226975e 100644 --- a/modules/t/ontologyTerm.t +++ b/modules/t/ontologyTerm.t @@ -14,21 +14,21 @@ use Bio::EnsEMBL::Translation; use Bio::EnsEMBL::Gene; use Bio::EnsEMBL::DnaDnaAlignFeature; -# switch on the debug prints +# switch on the note prints our $verbose = 0; -debug("Startup test"); +note("Startup test"); ok(1); my $multi = Bio::EnsEMBL::Test::MultiTestDB->new('ontology'); my $odb = $multi->get_DBAdaptor("ontology"); -debug("Ontology database instatiated"); +note("Ontology database instatiated"); ok($odb); my $human = Bio::EnsEMBL::Test::MultiTestDB->new(); my $db = $human->get_DBAdaptor("core"); -debug("Test database instatiated"); +note("Test database instatiated"); ok($db); my $go_adaptor = $odb->get_OntologyTermAdaptor(); @@ -69,6 +69,16 @@ is(@{$go_roots}, 1, "Found go roots"); my $efo_roots = $go_adaptor->fetch_all_roots('efo'); is(@{$efo_roots}, 0, "Found no efo roots"); +#Now go back to the OntologyXref & see if we can do the reverse lookup +{ + my $go_db_links = $genes->[0]->get_all_DBLinks('GO'); + foreach my $dbentry (@{$go_db_links}) { + my $term = $dbentry->get_OntologyTerm(); + my $direct_term = $go_adaptor->fetch_by_accession($dbentry->primary_id()); + is_deeply($term, $direct_term, 'Fetching the OntologyTerm from the OntologyXref should match the same object from OntologyTermAdaptor'); + } +} + done_testing();