Archive Ensembl HomeArchive Ensembl Home
OntologyTermAdaptor.pm
Go to the documentation of this file.
00001 =head1 LICENSE
00002 
00003   Copyright (c) 1999-2012 The European Bioinformatics Institute and
00004   Genome Research Limited.  All rights reserved.
00005 
00006   This software is distributed under a modified Apache license.
00007   For license details, please see
00008 
00009     http://www.ensembl.org/info/about/code_licence.html
00010 
00011 =head1 CONTACT
00012 
00013   Please email comments or questions to the public Ensembl
00014   developers list at <dev@ensembl.org>.
00015 
00016   Questions may also be sent to the Ensembl help desk at
00017   <helpdesk@ensembl.org>.
00018 
00019 =cut
00020 
00021 =head1 NAME
00022 
00023 Bio::EnsEMBL::DBSQL::OntologyTermAdaptor
00024 
00025 =head1 SYNOPSIS
00026 
00027   my $goa =
00028     $registry->get_adaptor( 'Multi', 'Ontology', 'OntologyTerm' );
00029 
00030   my $term = $goa->fetch_by_accession('GO:0010885');
00031 
00032   my @children    = @{ $goa->fetch_all_by_parent_term($term) };
00033   my @descendants = @{ $goa->fetch_all_by_ancestor_term($term) };
00034 
00035   my @parents   = @{ $goa->fetch_all_by_child_term($term) };
00036   my @ancestors = @{ $goa->fetch_all_by_descendant_term($term) };
00037 
00038   my %ancestor_chart = %{ $goa->_fetch_ancestor_chart($term) };
00039 
00040 =head1 DESCRIPTION
00041 
00042 An abstract adaptor class for fetching ontology
00043 terms, creates Bio::EnsEMBL::OntologyTerm objects.
00044 
00045 =head1 METHODS
00046 
00047 =cut
00048 
00049 package Bio::EnsEMBL::DBSQL::OntologyTermAdaptor;
00050 
00051 use strict;
00052 use warnings;
00053 
00054 use DBI qw( :sql_types );
00055 
00056 use Bio::EnsEMBL::Utils::Exception qw( throw );
00057 use Bio::EnsEMBL::Utils::Scalar qw( assert_ref );
00058 
00059 use Bio::EnsEMBL::OntologyTerm;
00060 
00061 use base qw( Bio::EnsEMBL::DBSQL::BaseAdaptor );
00062 
00063 =head2 fetch_all_by_name
00064 
00065   Arg [1]       : String, name of term, or SQL pattern
00066   Arg [2]       : (optional) String, name of ontology
00067 
00068   Description   : Fetches ontology term(s) given a name, a synonym, or a
00069                   SQL pattern like "%splice_site%"
00070 
00071   Example       :
00072 
00073     my ($term) =
00074       @{ $ot_adaptor->fetch_by_name( 'DNA_binding_site', 'SO' ) };
00075 
00076     # Will find terms in both SO and GO:
00077     my @terms = @{ $ot_adaptor->fetch_by_name('%splice_site%') };
00078 
00079   Return type   : listref of Bio::EnsEMBL::OntologyTerm
00080 
00081 =cut
00082 
00083 sub fetch_all_by_name {
00084   my ( $this, $pattern, $ontology ) = @_;
00085 
00086   my $statement = q(
00087 SELECT DISTINCT
00088         term.term_id,
00089         term.accession,
00090         term.name,
00091         term.definition,
00092         term.subsets,
00093         ontology.namespace
00094 FROM    ontology
00095   JOIN  term USING (ontology_id)
00096   LEFT JOIN  synonym USING (term_id)
00097 WHERE   ( term.name LIKE ? OR synonym.name LIKE ? ));
00098 
00099   if ( defined($ontology) ) {
00100     $statement .= " AND ontology.name = ?";
00101   }
00102 
00103   my $sth = $this->prepare($statement);
00104   $sth->bind_param( 1, $pattern, SQL_VARCHAR );
00105   $sth->bind_param( 2, $pattern, SQL_VARCHAR );
00106 
00107   if ( defined($ontology) ) {
00108     $sth->bind_param( 3, $ontology, SQL_VARCHAR );
00109   }
00110 
00111   $sth->execute();
00112 
00113   my ( $dbid, $accession, $name, $definition, $subsets, $namespace );
00114   $sth->bind_columns(
00115      \( $dbid, $accession, $name, $definition, $subsets, $namespace ) );
00116 
00117   my @terms;
00118 
00119   while ( $sth->fetch() ) {
00120     $subsets ||= '';
00121 
00122     push @terms,
00123       Bio::EnsEMBL::OntologyTerm->new(
00124                                '-dbid'      => $dbid,
00125                                '-adaptor'   => $this,
00126                                '-accession' => $accession,
00127                                '-namespace' => $namespace,
00128                                '-subsets' => [ split( /,/, $subsets ) ],
00129                                '-name'    => $name,
00130                                '-definition' => $definition, );
00131   }
00132 
00133   return \@terms;
00134 } ## end sub fetch_all_by_name
00135 
00136 
00137 =head2 fetch_by_accession
00138 
00139   Arg [1]       : String
00140 
00141   Description   : Fetches an ontology term given an accession.
00142 
00143   Example       :
00144 
00145     my $term = $ot_adaptor->fetch_by_accession('GO:0030326');
00146 
00147   Return type   : Bio::EnsEMBL::OntologyTerm
00148 
00149 =cut
00150 
00151 sub fetch_by_accession {
00152   my ( $this, $accession ) = @_;
00153 
00154   my $statement = q(
00155 SELECT  term.term_id,
00156         term.name,
00157         term.definition,
00158         term.subsets,
00159         ontology.name,
00160         ontology.namespace
00161 FROM    ontology
00162   JOIN  term USING (ontology_id)
00163 WHERE   term.accession = ?);
00164 
00165   my $sth = $this->prepare($statement);
00166   $sth->bind_param( 1, $accession, SQL_VARCHAR );
00167 
00168   $sth->execute();
00169 
00170   my ( $dbid, $name, $definition, $subsets, $ontology, $namespace );
00171   $sth->bind_columns(
00172       \( $dbid, $name, $definition, $subsets, $ontology, $namespace ) );
00173 
00174   $sth->fetch();
00175   $subsets ||= '';
00176 
00177   my $term =
00178     Bio::EnsEMBL::OntologyTerm->new(
00179                     '-dbid'       => $dbid,
00180                     '-adaptor'    => $this,
00181                     '-accession'  => $accession,
00182                     '-ontology'   => $ontology,
00183                     '-namespace'  => $namespace,
00184                     '-subsets'    => [ split( /,/, $subsets ) ],
00185                     '-name'       => $name,
00186                     '-definition' => $definition,
00187                     '-synonyms' => $this->_fetch_synonyms_by_dbID($dbid)
00188     );
00189   $sth->finish();
00190 
00191   return $term;
00192 } ## end sub fetch_by_accession
00193 
00194 =head2 fetch_all_by_parent_term
00195 
00196   Arg [1]       : Bio::EnsEMBL::OntologyTerm
00197                   The term whose children terms should be fetched.
00198 
00199   Description   : Given a parent ontology term, returns a list of
00200                   its immediate children terms.
00201 
00202   Example       :
00203 
00204     my @children =
00205       @{ $ot_adaptor->fetch_all_by_parent_term($term) };
00206 
00207   Return type   : listref of Bio::EnsEMBL::OntologyTerm
00208 
00209 =cut
00210 
00211 sub fetch_all_by_parent_term {
00212   my ( $this, $term ) = @_;
00213 
00214   assert_ref( $term, 'Bio::EnsEMBL::OntologyTerm' );
00215 
00216   my @terms;
00217 
00218   if ( !$term->{'child_terms_fetched'} ) {
00219     my $statement = q(
00220 SELECT  child_term.term_id,
00221         child_term.accession,
00222         child_term.name,
00223         child_term.definition,
00224         child_term.subsets,
00225         rt.name
00226 FROM    term child_term
00227   JOIN  relation ON (relation.child_term_id = child_term.term_id)
00228   JOIN  relation_type rt USING (relation_type_id)
00229 WHERE   relation.parent_term_id = ?);
00230 
00231     my $sth = $this->prepare($statement);
00232     $sth->bind_param( 1, $term->dbID(), SQL_INTEGER );
00233 
00234     $sth->execute();
00235 
00236     my ( $dbid, $accession, $name, $definition, $subsets, $relation );
00237     $sth->bind_columns(
00238       \( $dbid, $accession, $name, $definition, $subsets, $relation ) );
00239 
00240     while ( $sth->fetch() ) {
00241       $subsets ||= '';
00242 
00243       my $child_term =
00244         Bio::EnsEMBL::OntologyTerm->new(
00245                                '-dbid'      => $dbid,
00246                                '-adaptor'   => $this,
00247                                '-accession' => $accession,
00248                                '-ontology'  => $term->{'ontology'},
00249                                '-namespace' => $term->{'namespace'},
00250                                '-subsets' => [ split( /,/, $subsets ) ],
00251                                '-name'    => $name,
00252                                '-definition' => $definition, );
00253 
00254       push( @terms,                              $child_term );
00255       push( @{ $term->{'children'}{$relation} }, $child_term );
00256     }
00257 
00258     $term->{'child_terms_fetched'} = 1;
00259   } else {
00260     foreach my $relation ( values( %{ $term->{'children'} } ) ) {
00261       push( @terms, @{$relation} );
00262     }
00263   }
00264 
00265   return \@terms;
00266 } ## end sub fetch_all_by_parent_term
00267 
00268 =head2 fetch_all_by_ancestor_term
00269 
00270   Arg [1]       : Bio::EnsEMBL::OntologyTerm
00271                   The term whose descendant terms should be fetched.
00272 
00273   Description   : Given a parent ontology term, returns a list of
00274                   all its descendant terms, down to and including
00275                   any leaf terms.  Relations of the type 'is_a' and
00276                   'part_of' are followed.
00277 
00278   Example       :
00279 
00280     my @descendants =
00281       @{ $ot_adaptor->fetch_all_by_ancestor_term($term) };
00282 
00283   Return type   : listref of Bio::EnsEMBL::OntologyTerm
00284 
00285 =cut
00286 
00287 sub fetch_all_by_ancestor_term {
00288   my ( $this, $term ) = @_;
00289 
00290   assert_ref( $term, 'Bio::EnsEMBL::OntologyTerm' );
00291 
00292   my $statement = q(
00293 SELECT DISTINCT
00294         child_term.term_id,
00295         child_term.accession,
00296         child_term.name,
00297         child_term.definition,
00298         child_term.subsets
00299 FROM    term child_term
00300   JOIN  closure ON (closure.child_term_id = child_term.term_id)
00301 WHERE   closure.parent_term_id = ?
00302   AND   closure.distance > 0
00303 ORDER BY closure.distance, child_term.accession);
00304 
00305   my $sth = $this->prepare($statement);
00306   $sth->bind_param( 1, $term->dbID(), SQL_INTEGER );
00307 
00308   $sth->execute();
00309 
00310   my ( $dbid, $accession, $name, $definition, $subsets );
00311   $sth->bind_columns(
00312                  \( $dbid, $accession, $name, $definition, $subsets ) );
00313 
00314   my @terms;
00315 
00316   while ( $sth->fetch() ) {
00317     $subsets ||= '';
00318 
00319     push( @terms,
00320           Bio::EnsEMBL::OntologyTerm->new(
00321                                '-dbid'      => $dbid,
00322                                '-adaptor'   => $this,
00323                                '-accession' => $accession,
00324                                '-ontology'  => $term->{'ontology'},
00325                                '-namespace' => $term->{'namespace'},
00326                                '-subsets' => [ split( /,/, $subsets ) ],
00327                                '-name'    => $name,
00328                                '-definition' => $definition, ) );
00329   }
00330 
00331   return \@terms;
00332 } ## end sub fetch_all_by_ancestor_term
00333 
00334 =head2 fetch_all_by_child_term
00335 
00336   Arg [1]       : Bio::EnsEMBL::OntologyTerm
00337                   The term whose parent terms should be fetched.
00338 
00339   Description   : Given a child ontology term, returns a list of
00340                   its immediate parent terms.
00341 
00342   Example       :
00343 
00344     my @parents = @{ $ot_adaptor->fetch_all_by_child_term($term) };
00345 
00346   Return type   : listref of Bio::EnsEMBL::OntologyTerm
00347 
00348 =cut
00349 
00350 sub fetch_all_by_child_term {
00351   my ( $this, $term ) = @_;
00352 
00353   assert_ref( $term, 'Bio::EnsEMBL::OntologyTerm' );
00354 
00355   my @terms;
00356 
00357   if ( !$term->{'parent_terms_fetched'} ) {
00358     my $statement = q(
00359 SELECT  parent_term.term_id,
00360         parent_term.accession,
00361         parent_term.name,
00362         parent_term.definition,
00363         parent_term.subsets,
00364         rt.name
00365 FROM    term parent_term
00366   JOIN  relation ON (relation.parent_term_id = parent_term.term_id)
00367   JOIN  relation_type rt USING (relation_type_id)
00368 WHERE   relation.child_term_id = ?);
00369 
00370     my $sth = $this->prepare($statement);
00371     $sth->bind_param( 1, $term->dbID(), SQL_INTEGER );
00372 
00373     $sth->execute();
00374 
00375     my ( $dbid, $accession, $name, $definition, $subsets, $relation );
00376     $sth->bind_columns(
00377       \( $dbid, $accession, $name, $definition, $subsets, $relation ) );
00378 
00379     while ( $sth->fetch() ) {
00380       $subsets ||= '';
00381 
00382       my $parent_term =
00383         Bio::EnsEMBL::OntologyTerm->new(
00384                                '-dbid'      => $dbid,
00385                                '-adaptor'   => $this,
00386                                '-accession' => $accession,
00387                                '-ontology'  => $term->{'ontology'},
00388                                '-namespace' => $term->{'namespace'},
00389                                '-subsets' => [ split( /,/, $subsets ) ],
00390                                '-name'    => $name,
00391                                '-definition' => $definition, );
00392 
00393       push( @terms,                             $parent_term );
00394       push( @{ $term->{'parents'}{$relation} }, $parent_term );
00395     }
00396 
00397     $term->{'parent_terms_fetched'} = 1;
00398   } else {
00399     foreach my $relation ( values( %{ $term->{'parents'} } ) ) {
00400       push( @terms, @{$relation} );
00401     }
00402   }
00403 
00404   return \@terms;
00405 } ## end sub fetch_all_by_child_term
00406 
00407 =head2 fetch_all_by_descendant_term
00408 
00409   Arg [1]       : Bio::EnsEMBL::OntologyTerm
00410                   The term whose ancestor terms should be fetched.
00411 
00412   Arg [2]       : (optional) String
00413                   The subset within the ontolgy to which the query
00414                   should be restricted.  The subset may be specified as
00415                   a SQL pattern, e.g., "%goslim%" (but "goslim%" might
00416                   not do what you expect), or as a specific subset name,
00417                   e.g., "goslim_generic".
00418 
00419   Arg [3]       : (optional) Boolean
00420                   If true (non-zero), only return the closest
00421                   term(s).  If this argument is true, and the
00422                   previous argument is left undefined, this method
00423                   will return the parent(s) of the given term.
00424 
00425   Description   : Given a child ontology term, returns a list of
00426                   all its ancestor terms, up to and including any
00427                   root term.  Relations of the type 'is_a' and
00428                   'part_of' are followed.  Optionally, only terms in
00429                   a given subset of the ontology may be returned,
00430                   and additionally one may ask to only get the
00431                   closest term(s) to the given child term.
00432 
00433   Example       :
00434 
00435     my @ancestors =
00436       @{ $ot_adaptor->fetch_all_by_descendant_term($term) };
00437 
00438   Return type   : listref of Bio::EnsEMBL::OntologyTerm
00439 
00440 =cut
00441 
00442 sub fetch_all_by_descendant_term {
00443   my ( $this, $term, $subset, $closest_only ) = @_;
00444 
00445   assert_ref( $term, 'Bio::EnsEMBL::OntologyTerm' );
00446 
00447   $closest_only ||= 0;
00448 
00449   my $statement = q(
00450 SELECT DISTINCT
00451         parent_term.term_id,
00452         parent_term.accession,
00453         parent_term.name,
00454         parent_term.definition,
00455         parent_term.subsets,
00456         closure.distance
00457 FROM    term parent_term
00458   JOIN  closure ON (closure.parent_term_id = parent_term.term_id)
00459 WHERE   closure.child_term_id = ?
00460   AND   closure.distance > 0);
00461 
00462   if ( defined($subset) ) {
00463     if ( index( $subset, '%' ) != -1 ) {
00464       $statement .= q(
00465   AND   parent_term.subsets LIKE ?);
00466     } else {
00467       $statement .= q(
00468   AND   FIND_IN_SET(?, parent_term.subsets) > 0);
00469     }
00470   }
00471 
00472   $statement .= q(
00473 ORDER BY closure.distance, parent_term.accession);
00474 
00475   my $sth = $this->prepare($statement);
00476   $sth->bind_param( 1, $term->dbID(), SQL_INTEGER );
00477 
00478   if ( defined($subset) ) {
00479     $sth->bind_param( 2, $subset, SQL_VARCHAR );
00480   }
00481 
00482   $sth->execute();
00483 
00484   my ( $dbid, $accession, $name, $definition, $subsets, $distance );
00485   $sth->bind_columns(
00486       \( $dbid, $accession, $name, $definition, $subsets, $distance ) );
00487 
00488   my @terms;
00489   my $min_distance;
00490 
00491   while ( $sth->fetch() ) {
00492     $subsets ||= '';
00493     $min_distance ||= $distance;
00494 
00495     if ( !$closest_only || $distance == $min_distance ) {
00496       push( @terms,
00497             Bio::EnsEMBL::OntologyTerm->new(
00498                                '-dbid'      => $dbid,
00499                                '-adaptor'   => $this,
00500                                '-accession' => $accession,
00501                                '-ontology'  => $term->{'ontology'},
00502                                '-namespace' => $term->{'namespace'},
00503                                '-subsets' => [ split( /,/, $subsets ) ],
00504                                '-name'    => $name,
00505                                '-definition' => $definition, ) );
00506     } else {
00507       $sth->finish();
00508       last;
00509     }
00510   }
00511 
00512   return \@terms;
00513 } ## end sub fetch_all_by_descendant_term
00514 
00515 sub _fetch_synonyms_by_dbID {
00516   my ( $this, $dbID ) = @_;
00517 
00518   my $statement = q(
00519 SELECT  synonym.name
00520 FROM    synonym
00521 WHERE   synonym.term_id = ?);
00522 
00523   my $sth = $this->prepare($statement);
00524   $sth->bind_param( 1, $dbID, SQL_INTEGER );
00525 
00526   $sth->execute();
00527 
00528   my $synonym;
00529   $sth->bind_col( 1, \$synonym );
00530 
00531   my @synonyms;
00532   while ( $sth->fetch() ) {
00533     push( @synonyms, $synonym );
00534   }
00535 
00536   return \@synonyms;
00537 }
00538 
00539 
00540 
00541 =head2 _fetch_ancestor_chart
00542 
00543   Arg [1]       : Bio::EnsEMBL::OntologyTerm
00544                   The term whose ancestor terms should be fetched.
00545 
00546   Description   : Given a child ontology term, returns a hash
00547                   structure containing its ancestor terms, up to and
00548                   including any root term.  Relations of the type
00549                   'is_a' and 'part_of' are included.
00550 
00551   Example       :
00552 
00553     my %chart = %{ $ot_adaptor->_fetch_ancestor_chart($term) };
00554 
00555   Return type   : A reference to a hash structure like this:
00556 
00557     {
00558       'GO:XXXXXXX' => {
00559         'term' =>           # ref to Bio::EnsEMBL::OntologyTerm object
00560         'is_a'    => [...], # listref of Bio::EnsEMBL::OntologyTerm
00561         'part_of' => [...], # listref of Bio::EnsEMBL::OntologyTerm
00562       },
00563       'GO:YYYYYYY' => {
00564         # Similarly for all ancestors,
00565         # and including the query term itself.
00566       }
00567     }
00568 
00569 =cut
00570 
00571 sub _fetch_ancestor_chart {
00572   my ( $this, $term ) = @_;
00573 
00574   assert_ref( $term, 'Bio::EnsEMBL::OntologyTerm' );
00575 
00576   my $statement = q(
00577 SELECT  subparent_term.term_id,
00578         parent_term.term_id,
00579         relation_type.name
00580 FROM    closure
00581   JOIN  relation
00582     ON (relation.parent_term_id = closure.parent_term_id
00583       AND relation.child_term_id = closure.subparent_term_id)
00584   JOIN  relation_type USING (relation_type_id)
00585   JOIN  term subparent_term
00586     ON (subparent_term.term_id = closure.subparent_term_id)
00587   JOIN  term parent_term ON (parent_term.term_id = closure.parent_term_id)
00588 WHERE   closure.child_term_id = ?
00589 ORDER BY closure.distance);
00590 
00591   my $sth = $this->prepare($statement);
00592   $sth->bind_param( 1, $term->dbID(), SQL_INTEGER );
00593 
00594   $sth->execute();
00595 
00596   my ( $subparent_id, $parent_id, $relation );
00597   $sth->bind_columns( \( $subparent_id, $parent_id, $relation ) );
00598 
00599   my %id_chart;
00600   my %acc_chart;
00601 
00602   while ( $sth->fetch() ) {
00603     if ( !exists( $id_chart{$parent_id} ) ) {
00604       $id_chart{$parent_id} = {};
00605     }
00606     push( @{ $id_chart{$subparent_id}{$relation} }, $parent_id );
00607   }
00608 
00609   my @terms = @{ $this->fetch_all_by_dbID_list( [ keys(%id_chart) ] ) };
00610 
00611   foreach my $term (@terms) {
00612     $id_chart{ $term->dbID() }{'term'}       = $term;
00613     $acc_chart{ $term->accession() }{'term'} = $term;
00614   }
00615 
00616   foreach my $term (@terms) {
00617     my $accession = $term->accession();
00618     my $dbID      = $term->dbID();
00619 
00620     foreach my $relation ( keys( %{ $id_chart{$dbID} } ) ) {
00621       if ( $relation eq 'term' ) { next }
00622 
00623       foreach my $id ( @{ $id_chart{$dbID}{$relation} } ) {
00624         push( @{ $acc_chart{$accession}{$relation} },
00625               $id_chart{$id}{'term'} );
00626       }
00627     }
00628   }
00629 
00630   return \%acc_chart;
00631 } ## end sub _fetch_ancestor_chart
00632 
00633 #-----------------------------------------------------------------------
00634 # Useful public methods that implement functionality not properly
00635 # provided by the parent class Bio::EnsEMBL::DBSQL::BaseAdaptor.
00636 
00637 sub fetch_by_dbID {
00638   my ( $this, $dbid ) = @_;
00639 
00640   my $statement = q(
00641 SELECT  term.accession,
00642         term.name,
00643         term.definition,
00644         term.subsets,
00645         ontology.name,
00646         ontology.namespace
00647 FROM    ontology
00648   JOIN  term USING (ontology_id)
00649 WHERE   term.term_id = ?);
00650 
00651   my $sth = $this->prepare($statement);
00652   $sth->bind_param( 1, $dbid, SQL_INTEGER );
00653 
00654   $sth->execute();
00655 
00656   my ( $accession, $name, $definition, $subsets, $ontology,
00657        $namespace );
00658   $sth->bind_columns(
00659       \( $accession, $name, $definition, $subsets, $ontology, $namespace
00660       ) );
00661 
00662   $sth->fetch();
00663   $subsets ||= '';
00664 
00665   my $term =
00666     Bio::EnsEMBL::OntologyTerm->new(
00667                     '-dbid'       => $dbid,
00668                     '-adaptor'    => $this,
00669                     '-accession'  => $accession,
00670                     '-ontology'   => $ontology,
00671                     '-namespace'  => $namespace,
00672                     '-subsets'    => [ split( /,/, $subsets ) ],
00673                     '-name'       => $name,
00674                     '-definition' => $definition,
00675                     '-synonyms' => $this->_fetch_synonyms_by_dbID($dbid)
00676     );
00677   $sth->finish();
00678 
00679   return $term;
00680 } ## end sub fetch_by_dbID
00681 
00682 sub fetch_all_by_dbID_list {
00683   my ( $this, $dbids ) = @_;
00684 
00685   if ( !@{$dbids} ) { return [] }
00686 
00687   my $stmt = q(
00688 SELECT  term.term_id,
00689         term.accession,
00690         term.name,
00691         term.definition,
00692         term.subsets,
00693         ontology.name,
00694         ontology.namespace
00695 FROM    ontology
00696   JOIN  term USING (ontology_id)
00697 WHERE   term.term_id IN (%s));
00698 
00699   my $statement = sprintf(
00700     $stmt,
00701     join(
00702       ',',
00703       map {
00704         $this->dbc()->db_handle()->quote( $_, SQL_INTEGER )
00705         } @{$dbids} ) );
00706 
00707   my $sth = $this->prepare($statement);
00708 
00709   $sth->execute();
00710 
00711   my ( $dbid, $accession, $name, $definition, $subsets, $ontology,
00712        $namespace );
00713   $sth->bind_columns( \( $dbid,    $accession, $name, $definition,
00714                          $subsets, $ontology,  $namespace ) );
00715 
00716   my @terms;
00717 
00718   while ( $sth->fetch() ) {
00719     $subsets ||= '';
00720 
00721     push( @terms,
00722           Bio::EnsEMBL::OntologyTerm->new(
00723                                '-dbid'      => $dbid,
00724                                '-adaptor'   => $this,
00725                                '-accession' => $accession,
00726                                '-ontology'  => $ontology,
00727                                '-namespace' => $namespace,
00728                                '-subsets' => [ split( /,/, $subsets ) ],
00729                                '-name'    => $name,
00730                                '-definition' => $definition, ) );
00731   }
00732 
00733   return \@terms;
00734 } ## end sub fetch_all_by_dbID_list
00735 
00736 sub fetch_all {
00737   my ($this) = @_;
00738 
00739   my $statement = q(
00740 SELECT  term.term_id,
00741         term.accession,
00742         term.name,
00743         term.definition,
00744         term.subsets,
00745         ontology.name,
00746         ontology.namespace
00747 FROM    ontology
00748   JOIN  term USING (ontology_id));
00749 
00750   my $sth = $this->prepare($statement);
00751   $sth->execute();
00752 
00753   my ( $dbid, $accession, $name, $definition, $subsets, $ontology,
00754        $namespace );
00755   $sth->bind_columns( \( $dbid,    $accession, $name, $definition,
00756                          $subsets, $ontology,  $namespace ) );
00757 
00758   my @terms;
00759 
00760   while ( $sth->fetch() ) {
00761     $subsets ||= '';
00762 
00763     push( @terms,
00764           Bio::EnsEMBL::OntologyTerm->new(
00765                                '-dbid'      => $dbid,
00766                                '-adaptor'   => $this,
00767                                '-accession' => $accession,
00768                                '-ontology'  => $ontology,
00769                                '-namespace' => $namespace,
00770                                '-subsets' => [ split( /,/, $subsets ) ],
00771                                '-name'    => $name,
00772                                '-definition' => $definition ) );
00773   }
00774 
00775   return \@terms;
00776 } ## end sub fetch_all
00777 
00778 1;