Commit c4921f02 authored by Andreas Kusalananda Kähäri's avatar Andreas Kusalananda Kähäri
Browse files

Do not use a special ontology adaptor for each and every ontology.

Asking for a a GOTerm adaptor, or a SOTerm adaptor, still works, but the
correct call to get_adaptor() should request an OntologyTerm adaptor.
parent 4c219bf2
...@@ -63,6 +63,7 @@ package Bio::EnsEMBL::DBSQL::GeneAdaptor; ...@@ -63,6 +63,7 @@ package Bio::EnsEMBL::DBSQL::GeneAdaptor;
use strict; use strict;
use Bio::EnsEMBL::Utils::Exception qw( deprecate throw warning ); use Bio::EnsEMBL::Utils::Exception qw( deprecate throw warning );
use Bio::EnsEMBL::Utils::Scalar qw( assert_ref );
use Bio::EnsEMBL::DBSQL::SliceAdaptor; use Bio::EnsEMBL::DBSQL::SliceAdaptor;
use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor; use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
use Bio::EnsEMBL::DBSQL::DBAdaptor; use Bio::EnsEMBL::DBSQL::DBAdaptor;
...@@ -811,10 +812,8 @@ sub fetch_all_by_external_name { ...@@ -811,10 +812,8 @@ sub fetch_all_by_external_name {
sub fetch_all_by_GOTerm { sub fetch_all_by_GOTerm {
my ( $self, $term ) = @_; my ( $self, $term ) = @_;
if ( !ref($term) assert_ref( $term, 'Bio::EnsEMBL::OntologyTerm' );
|| !$term->isa('Bio::EnsEMBL::OntologyTerm') if ( $term->ontology() ne 'GO' ) {
|| $term->ontology() ne 'GO' )
{
throw('Argument is not a GO term'); throw('Argument is not a GO term');
} }
...@@ -822,7 +821,7 @@ sub fetch_all_by_GOTerm { ...@@ -822,7 +821,7 @@ sub fetch_all_by_GOTerm {
my %unique_dbIDs; my %unique_dbIDs;
foreach my $accession ( map { $_->accession() } foreach my $accession ( map { $_->accession() }
( $term, @{ $term->descendants() } ) ) ( $term, @{ $term->descendants() } ) )
{ {
my @ids = my @ids =
$entryAdaptor->list_gene_ids_by_extids( $accession, 'GO' ); $entryAdaptor->list_gene_ids_by_extids( $accession, 'GO' );
...@@ -831,10 +830,11 @@ sub fetch_all_by_GOTerm { ...@@ -831,10 +830,11 @@ sub fetch_all_by_GOTerm {
my @result = @{ my @result = @{
$self->fetch_all_by_dbID_list( $self->fetch_all_by_dbID_list(
[ sort { $a <=> $b } keys(%unique_dbIDs) ] ) }; [ sort { $a <=> $b } keys(%unique_dbIDs) ]
) };
return \@result; return \@result;
} } ## end sub fetch_all_by_GOTerm
=head2 fetch_all_by_GOTerm_accession =head2 fetch_all_by_GOTerm_accession
...@@ -873,7 +873,7 @@ sub fetch_all_by_GOTerm_accession { ...@@ -873,7 +873,7 @@ sub fetch_all_by_GOTerm_accession {
my $goAdaptor = my $goAdaptor =
Bio::EnsEMBL::Registry->get_adaptor( 'Multi', 'Ontology', Bio::EnsEMBL::Registry->get_adaptor( 'Multi', 'Ontology',
'GOTerm' ); 'OntologyTerm' );
my $term = $goAdaptor->fetch_by_accession($accession); my $term = $goAdaptor->fetch_by_accession($accession);
......
...@@ -40,9 +40,9 @@ use base qw ( Bio::EnsEMBL::DBSQL::DBAdaptor ); ...@@ -40,9 +40,9 @@ use base qw ( Bio::EnsEMBL::DBSQL::DBAdaptor );
sub get_available_adaptors { sub get_available_adaptors {
return { return {
'GOTerm' => 'Bio::EnsEMBL::DBSQL::GOTermAdaptor', 'GOTerm' => 'Bio::EnsEMBL::DBSQL::OntologyTermAdaptor', #deprecated
'SOTerm' => 'Bio::EnsEMBL::DBSQL::SOTermAdaptor' 'SOTerm' => 'Bio::EnsEMBL::DBSQL::OntologyTermAdaptor', #deprecated
}; 'OntologyTerm' => 'Bio::EnsEMBL::DBSQL::OntologyTermAdaptor' };
} }
1; 1;
=head1 LICENSE =head1 LICENSE
Copyright (c) 1999-2011 The European Bioinformatics Institute and Copyright (c) 1999-2011 The European Bioinformatics Institute and
...@@ -25,7 +24,8 @@ Bio::EnsEMBL::DBSQL::OntologyTermAdaptor ...@@ -25,7 +24,8 @@ Bio::EnsEMBL::DBSQL::OntologyTermAdaptor
=head1 SYNOPSIS =head1 SYNOPSIS
my $goa = $registry->get_adaptor( 'Multi', 'Ontology', 'GOTerm' ); my $goa =
$registry->get_adaptor( 'Multi', 'Ontology', 'OntologyTerm' );
my $term = $goa->fetch_by_accession('GO:0010885'); my $term = $goa->fetch_by_accession('GO:0010885');
...@@ -41,8 +41,6 @@ Bio::EnsEMBL::DBSQL::OntologyTermAdaptor ...@@ -41,8 +41,6 @@ Bio::EnsEMBL::DBSQL::OntologyTermAdaptor
An abstract adaptor class for fetching ontology An abstract adaptor class for fetching ontology
terms, creates Bio::EnsEMBL::OntologyTerm objects. terms, creates Bio::EnsEMBL::OntologyTerm objects.
Specialized by Bio::EnsEMBL::DBSQL::GOTermAdaptor and
Bio::EnsEMBL::DBSQL::SOTermAdaptor
=head1 METHODS =head1 METHODS
...@@ -56,70 +54,12 @@ use warnings; ...@@ -56,70 +54,12 @@ use warnings;
use DBI qw( :sql_types ); use DBI qw( :sql_types );
use Bio::EnsEMBL::Utils::Exception qw( throw ); use Bio::EnsEMBL::Utils::Exception qw( throw );
use Bio::EnsEMBL::Utils::Scalar qw( assert_ref );
use Bio::EnsEMBL::OntologyTerm; use Bio::EnsEMBL::OntologyTerm;
use base qw( Bio::EnsEMBL::DBSQL::BaseAdaptor ); use base qw( Bio::EnsEMBL::DBSQL::BaseAdaptor );
=head2 new
Arg [1] : Bio::EnsEMBL::DBSQL::DBAdaptor
Argument required for parent class
Bio::EnsEMBL::DBSQL::BaseAdaptor.
Arg [2] : String
The particular ontology that this ontology adaptor
deals with.
Caller : Bio::EnsEMBL::DBSQL::GOTermAdaptor
Bio::EnsEMBL::DBSQL::SOTermAdaptor
Description : Creates an ontology term adaptor.
Example :
my $ot_adaptor =
Bio::EnsEMBL::DBSQL::OntologyTermAdaptor->new( $dba, 'GO' );
Return type : Bio::EnsEMBL::DBSQL::OntologyTermAdaptor
=cut
sub new {
my ( $proto, $dba, $ontology ) = @_;
if ( !ref($dba) || !$dba->isa('Bio::EnsEMBL::DBSQL::DBAdaptor') ) {
throw('First argument needs to be a '
. 'Bio::EnsEMBL::DBSQL::DBAdaptor object' );
}
my $this = $proto->SUPER::new($dba);
$this->{'ontology'} = $ontology;
return $this;
}
=head2 ontology
Arg : None
Description : Returns the name of the ontology which this
adaptor is used to retrieve terms for.
Example :
my $ontology = $ot_adaptor->ontology();
Return type : String
=cut
sub ontology {
my ($this) = @_;
return $this->{'ontology'};
}
=head2 fetch_by_accession =head2 fetch_by_accession
Arg [1] : String Arg [1] : String
...@@ -142,6 +82,7 @@ SELECT term.term_id, ...@@ -142,6 +82,7 @@ SELECT term.term_id,
term.name, term.name,
term.definition, term.definition,
term.subsets, term.subsets,
ontology.name,
ontology.namespace ontology.namespace
FROM ontology, FROM ontology,
term term
...@@ -149,25 +90,27 @@ WHERE ontology.ontology_id = term.ontology_id ...@@ -149,25 +90,27 @@ WHERE ontology.ontology_id = term.ontology_id
AND term.accession = ?); AND term.accession = ?);
my $sth = $this->prepare($statement); my $sth = $this->prepare($statement);
$sth->bind_param( 1, $accession, SQL_VARCHAR ); $sth->bind_param( 1, $accession, SQL_VARCHAR );
$sth->execute(); $sth->execute();
my ( $dbid, $name, $definition, $subsets, $namespace ); my ( $dbid, $name, $definition, $subsets, $ontology, $namespace );
$sth->bind_columns( $sth->bind_columns(
\( $dbid, $name, $definition, $subsets, $namespace ) ); \( $dbid, $name, $definition, $subsets, $ontology, $namespace ) );
$sth->fetch(); $sth->fetch();
$subsets ||= ''; $subsets ||= '';
my $term = Bio::EnsEMBL::OntologyTerm->new(
'-dbid' => $dbid, my $term =
'-adaptor' => $this, Bio::EnsEMBL::OntologyTerm->new(
'-accession' => $accession, '-dbid' => $dbid,
'-namespace' => $namespace, '-adaptor' => $this,
'-subsets' => [ split( /,/, $subsets ) ], '-accession' => $accession,
'-name' => $name, '-ontology' => $ontology,
'-definition' => $definition '-namespace' => $namespace,
); '-subsets' => [ split( /,/, $subsets ) ],
'-name' => $name,
'-definition' => $definition );
$sth->finish(); $sth->finish();
return $term; return $term;
...@@ -193,9 +136,7 @@ WHERE ontology.ontology_id = term.ontology_id ...@@ -193,9 +136,7 @@ WHERE ontology.ontology_id = term.ontology_id
sub fetch_all_by_parent_term { sub fetch_all_by_parent_term {
my ( $this, $term ) = @_; my ( $this, $term ) = @_;
if ( !ref($term) || !$term->isa('Bio::EnsEMBL::OntologyTerm') ) { assert_ref( $term, 'Bio::EnsEMBL::OntologyTerm' );
throw('Argument needs to be a Bio::EnsEMBL::OntologyTerm object');
}
my @terms; my @terms;
...@@ -226,22 +167,21 @@ WHERE relation.child_term_id = child_term.term_id ...@@ -226,22 +167,21 @@ WHERE relation.child_term_id = child_term.term_id
while ( $sth->fetch() ) { while ( $sth->fetch() ) {
$subsets ||= ''; $subsets ||= '';
my $child_term = Bio::EnsEMBL::OntologyTerm->new( my $child_term =
'-dbid' => $dbid, Bio::EnsEMBL::OntologyTerm->new(
'-adaptor' => $this, '-dbid' => $dbid,
'-accession' => $accession, '-adaptor' => $this,
'-namespace' => $term->{'namespace'}, '-accession' => $accession,
'-subsets' => [ split( /,/, $subsets ) ], '-ontology' => $term->{'ontology'},
'-name' => $name, '-namespace' => $term->{'namespace'},
'-definition' => $definition, '-subsets' => [ split( /,/, $subsets ) ],
); '-name' => $name,
'-definition' => $definition, );
push( @terms, $child_term ); push( @terms, $child_term );
push( @{ $term->{'children'}{$relation} }, $child_term ); push( @{ $term->{'children'}{$relation} }, $child_term );
} }
$sth->finish();
$term->{'child_terms_fetched'} = 1; $term->{'child_terms_fetched'} = 1;
} else { } else {
foreach my $relation ( values( %{ $term->{'children'} } ) ) { foreach my $relation ( values( %{ $term->{'children'} } ) ) {
...@@ -274,9 +214,7 @@ WHERE relation.child_term_id = child_term.term_id ...@@ -274,9 +214,7 @@ WHERE relation.child_term_id = child_term.term_id
sub fetch_all_by_ancestor_term { sub fetch_all_by_ancestor_term {
my ( $this, $term ) = @_; my ( $this, $term ) = @_;
if ( !ref($term) || !$term->isa('Bio::EnsEMBL::OntologyTerm') ) { assert_ref( $term, 'Bio::EnsEMBL::OntologyTerm' );
throw('Argument needs to be a Bio::EnsEMBL::OntologyTerm object');
}
my $statement = q( my $statement = q(
SELECT DISTINCT SELECT DISTINCT
...@@ -299,28 +237,25 @@ ORDER BY closure.distance, child_term.accession); ...@@ -299,28 +237,25 @@ ORDER BY closure.distance, child_term.accession);
my ( $dbid, $accession, $name, $definition, $subsets ); my ( $dbid, $accession, $name, $definition, $subsets );
$sth->bind_columns( $sth->bind_columns(
\( $dbid, $accession, $name, $definition, $subsets ) ); \( $dbid, $accession, $name, $definition, $subsets ) );
my @terms; my @terms;
while ( $sth->fetch() ) { while ( $sth->fetch() ) {
$subsets ||= ''; $subsets ||= '';
push( push( @terms,
@terms, Bio::EnsEMBL::OntologyTerm->new(
Bio::EnsEMBL::OntologyTerm->new( '-dbid' => $dbid,
'-dbid' => $dbid, '-adaptor' => $this,
'-adaptor' => $this, '-accession' => $accession,
'-accession' => $accession, '-ontology' => $term->{'ontology'},
'-namespace' => $term->{'namespace'}, '-namespace' => $term->{'namespace'},
'-subsets' => [ split( /,/, $subsets ) ], '-subsets' => [ split( /,/, $subsets ) ],
'-name' => $name, '-name' => $name,
'-definition' => $definition, '-definition' => $definition, ) );
) );
} }
$sth->finish();
return \@terms; return \@terms;
} ## end sub fetch_all_by_ancestor_term } ## end sub fetch_all_by_ancestor_term
...@@ -343,9 +278,7 @@ ORDER BY closure.distance, child_term.accession); ...@@ -343,9 +278,7 @@ ORDER BY closure.distance, child_term.accession);
sub fetch_all_by_child_term { sub fetch_all_by_child_term {
my ( $this, $term ) = @_; my ( $this, $term ) = @_;
if ( !ref($term) || !$term->isa('Bio::EnsEMBL::OntologyTerm') ) { assert_ref( $term, 'Bio::EnsEMBL::OntologyTerm' );
throw('Argument needs to be a Bio::EnsEMBL::OntologyTerm object');
}
my @terms; my @terms;
...@@ -376,22 +309,21 @@ WHERE relation.child_term_id = ? ...@@ -376,22 +309,21 @@ WHERE relation.child_term_id = ?
while ( $sth->fetch() ) { while ( $sth->fetch() ) {
$subsets ||= ''; $subsets ||= '';
my $parent_term = Bio::EnsEMBL::OntologyTerm->new( my $parent_term =
'-dbid' => $dbid, Bio::EnsEMBL::OntologyTerm->new(
'-adaptor' => $this, '-dbid' => $dbid,
'-accession' => $accession, '-adaptor' => $this,
'-namespace' => $term->{'namespace'}, '-accession' => $accession,
'-subsets' => [ split( /,/, $subsets ) ], '-ontology' => $term->{'ontology'},
'-name' => $name, '-namespace' => $term->{'namespace'},
'-definition' => $definition, '-subsets' => [ split( /,/, $subsets ) ],
); '-name' => $name,
'-definition' => $definition, );
push( @terms, $parent_term ); push( @terms, $parent_term );
push( @{ $term->{'parents'}{$relation} }, $parent_term ); push( @{ $term->{'parents'}{$relation} }, $parent_term );
} }
$sth->finish();
$term->{'parent_terms_fetched'} = 1; $term->{'parent_terms_fetched'} = 1;
} else { } else {
foreach my $relation ( values( %{ $term->{'parents'} } ) ) { foreach my $relation ( values( %{ $term->{'parents'} } ) ) {
...@@ -440,9 +372,7 @@ WHERE relation.child_term_id = ? ...@@ -440,9 +372,7 @@ WHERE relation.child_term_id = ?
sub fetch_all_by_descendant_term { sub fetch_all_by_descendant_term {
my ( $this, $term, $subset, $closest_only ) = @_; my ( $this, $term, $subset, $closest_only ) = @_;
if ( !ref($term) || !$term->isa('Bio::EnsEMBL::OntologyTerm') ) { assert_ref( $term, 'Bio::EnsEMBL::OntologyTerm' );
throw('Argument needs to be a Bio::EnsEMBL::OntologyTerm object');
}
$closest_only ||= 0; $closest_only ||= 0;
...@@ -484,7 +414,7 @@ ORDER BY closure.distance, parent_term.accession); ...@@ -484,7 +414,7 @@ ORDER BY closure.distance, parent_term.accession);
my ( $dbid, $accession, $name, $definition, $subsets, $distance ); my ( $dbid, $accession, $name, $definition, $subsets, $distance );
$sth->bind_columns( $sth->bind_columns(
\( $dbid, $accession, $name, $definition, $subsets, $distance ) ); \( $dbid, $accession, $name, $definition, $subsets, $distance ) );
my @terms; my @terms;
my $min_distance; my $min_distance;
...@@ -494,24 +424,22 @@ ORDER BY closure.distance, parent_term.accession); ...@@ -494,24 +424,22 @@ ORDER BY closure.distance, parent_term.accession);
$min_distance ||= $distance; $min_distance ||= $distance;
if ( !$closest_only || $distance == $min_distance ) { if ( !$closest_only || $distance == $min_distance ) {
push( push( @terms,
@terms, Bio::EnsEMBL::OntologyTerm->new(
Bio::EnsEMBL::OntologyTerm->new( '-dbid' => $dbid,
'-dbid' => $dbid, '-adaptor' => $this,
'-adaptor' => $this, '-accession' => $accession,
'-accession' => $accession, '-ontology' => $term->{'ontology'},
'-namespace' => $term->{'namespace'}, '-namespace' => $term->{'namespace'},
'-subsets' => [ split( /,/, $subsets ) ], '-subsets' => [ split( /,/, $subsets ) ],
'-name' => $name, '-name' => $name,
'-definition' => $definition, '-definition' => $definition, ) );
) );
} else { } else {
$sth->finish();
last; last;
} }
} }
$sth->finish();
return \@terms; return \@terms;
} ## end sub fetch_all_by_descendant_term } ## end sub fetch_all_by_descendant_term
...@@ -548,9 +476,7 @@ ORDER BY closure.distance, parent_term.accession); ...@@ -548,9 +476,7 @@ ORDER BY closure.distance, parent_term.accession);
sub _fetch_ancestor_chart { sub _fetch_ancestor_chart {
my ( $this, $term ) = @_; my ( $this, $term ) = @_;
if ( !ref($term) || !$term->isa('Bio::EnsEMBL::OntologyTerm') ) { assert_ref( $term, 'Bio::EnsEMBL::OntologyTerm' );
throw('Argument needs to be a Bio::EnsEMBL::OntologyTerm object');
}
my $statement = q( my $statement = q(
SELECT subparent_term.term_id, SELECT subparent_term.term_id,
...@@ -587,8 +513,6 @@ ORDER BY closure.distance); ...@@ -587,8 +513,6 @@ ORDER BY closure.distance);
push( @{ $id_chart{$subparent_id}{$relation} }, $parent_id ); push( @{ $id_chart{$subparent_id}{$relation} }, $parent_id );
} }
$sth->finish();
my @terms = @{ $this->fetch_all_by_dbID_list( [ keys(%id_chart) ] ) }; my @terms = @{ $this->fetch_all_by_dbID_list( [ keys(%id_chart) ] ) };
foreach my $term (@terms) { foreach my $term (@terms) {
...@@ -604,9 +528,8 @@ ORDER BY closure.distance); ...@@ -604,9 +528,8 @@ ORDER BY closure.distance);
if ( $relation eq 'term' ) { next } if ( $relation eq 'term' ) { next }
foreach my $id ( @{ $id_chart{$dbID}{$relation} } ) { foreach my $id ( @{ $id_chart{$dbID}{$relation} } ) {
push( push( @{ $acc_chart{$accession}{$relation} },
@{ $acc_chart{$accession}{$relation} }, $id_chart{$id}{'term'} );
$id_chart{$id}{'term'} );
} }
} }
} }
...@@ -626,6 +549,7 @@ SELECT term.accession, ...@@ -626,6 +549,7 @@ SELECT term.accession,
term.name, term.name,
term.definition, term.definition,
term.subsets, term.subsets,
ontology.name,
ontology.namespace ontology.namespace
FROM ontology, FROM ontology,
term term
...@@ -637,21 +561,25 @@ WHERE ontology.ontology_id = term.ontology_id ...@@ -637,21 +561,25 @@ WHERE ontology.ontology_id = term.ontology_id
$sth->execute(); $sth->execute();
my ( $accession, $name, $definition, $subsets, $namespace ); my ( $accession, $name, $definition, $subsets, $ontology,
$namespace );
$sth->bind_columns( $sth->bind_columns(
\( $accession, $name, $definition, $subsets, $namespace ) ); \( $accession, $name, $definition, $subsets, $ontology, $namespace
) );
$sth->fetch(); $sth->fetch();
$subsets ||= ''; $subsets ||= '';
my $term = Bio::EnsEMBL::OntologyTerm->new(
'-dbid' => $dbid, my $term =
'-adaptor' => $this, Bio::EnsEMBL::OntologyTerm->new(
'-accession' => $accession, '-dbid' => $dbid,
'-namespace' => $namespace, '-adaptor' => $this,
'-subsets' => [ split( /,/, $subsets ) ], '-accession' => $accession,
'-name' => $name, '-ontology' => $ontology,
'-definition' => $definition '-namespace' => $namespace,