Commit 8048b47b authored by Magali Ruffier's avatar Magali Ruffier
Browse files

ENSCORESW-308: added support for is_obsolete

parent 8d9096bc
...@@ -81,7 +81,7 @@ use base qw( Bio::EnsEMBL::DBSQL::BaseAdaptor ); ...@@ -81,7 +81,7 @@ use base qw( Bio::EnsEMBL::DBSQL::BaseAdaptor );
=cut =cut
sub fetch_all_by_name { sub fetch_all_by_name {
my ( $this, $pattern, $ontology ) = @_; my ( $this, $pattern, $ontology, $include_obsolete ) = @_;
my $statement = q( my $statement = q(
SELECT DISTINCT SELECT DISTINCT
...@@ -91,6 +91,7 @@ SELECT DISTINCT ...@@ -91,6 +91,7 @@ SELECT DISTINCT
term.definition, term.definition,
term.subsets, term.subsets,
term.is_root, term.is_root,
term.is_obsolete,
ontology.name, ontology.name,
ontology.namespace ontology.namespace
FROM ontology FROM ontology
...@@ -101,6 +102,7 @@ WHERE ( term.name LIKE ? OR synonym.name LIKE ? )); ...@@ -101,6 +102,7 @@ WHERE ( term.name LIKE ? OR synonym.name LIKE ? ));
if ( defined($ontology) ) { if ( defined($ontology) ) {
$statement .= " AND ontology.name = ?"; $statement .= " AND ontology.name = ?";
} }
$statement .= " AND term.is_obsolete = 0" unless $include_obsolete;
my $sth = $this->prepare($statement); my $sth = $this->prepare($statement);
$sth->bind_param( 1, $pattern, SQL_VARCHAR ); $sth->bind_param( 1, $pattern, SQL_VARCHAR );
...@@ -112,9 +114,9 @@ WHERE ( term.name LIKE ? OR synonym.name LIKE ? )); ...@@ -112,9 +114,9 @@ WHERE ( term.name LIKE ? OR synonym.name LIKE ? ));
$sth->execute(); $sth->execute();
my ( $dbid, $accession, $name, $definition, $subsets, $is_root, $namespace ); my ( $dbid, $accession, $name, $definition, $subsets, $is_root, $is_obsolete, $namespace );
$sth->bind_columns( $sth->bind_columns(
\( $dbid, $accession, $name, $definition, $subsets, $is_root, $ontology, $namespace ) ); \( $dbid, $accession, $name, $definition, $subsets, $is_root, $is_obsolete, $ontology, $namespace ) );
my @terms; my @terms;
...@@ -127,6 +129,7 @@ WHERE ( term.name LIKE ? OR synonym.name LIKE ? )); ...@@ -127,6 +129,7 @@ WHERE ( term.name LIKE ? OR synonym.name LIKE ? ));
'-adaptor' => $this, '-adaptor' => $this,
'-accession' => $accession, '-accession' => $accession,
'-is_root' => $is_root, '-is_root' => $is_root,
'-is_obsolete' => $is_obsolete,
'-ontology' => $ontology, '-ontology' => $ontology,
'-namespace' => $namespace, '-namespace' => $namespace,
'-subsets' => [ split( /,/, $subsets ) ], '-subsets' => [ split( /,/, $subsets ) ],
...@@ -156,7 +159,7 @@ WHERE ( term.name LIKE ? OR synonym.name LIKE ? )); ...@@ -156,7 +159,7 @@ WHERE ( term.name LIKE ? OR synonym.name LIKE ? ));
=cut =cut
sub fetch_by_accession { sub fetch_by_accession {
my ( $this, $accession ) = @_; my ( $this, $accession, $include_obsolete ) = @_;
my $statement = q( my $statement = q(
SELECT term.term_id, SELECT term.term_id,
...@@ -165,20 +168,23 @@ SELECT term.term_id, ...@@ -165,20 +168,23 @@ SELECT term.term_id,
term.definition, term.definition,
term.subsets, term.subsets,
term.is_root, term.is_root,
term.is_obsolete,
ontology.name, ontology.name,
ontology.namespace ontology.namespace
FROM ontology FROM ontology
JOIN term USING (ontology_id) JOIN term USING (ontology_id)
WHERE term.accession = ?); WHERE term.accession = ?);
$statement .= " AND term.is_obsolete = 0" unless $include_obsolete;
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, $is_root, $ontology, $namespace ); my ( $dbid, $name, $definition, $subsets, $is_root, $is_obsolete, $ontology, $namespace );
$sth->bind_columns( $sth->bind_columns(
\( $dbid, $accession, $name, $definition, $subsets, $is_root, $ontology, $namespace ) ); \( $dbid, $accession, $name, $definition, $subsets, $is_root, $is_obsolete, $ontology, $namespace ) );
$sth->fetch(); $sth->fetch();
...@@ -193,6 +199,7 @@ WHERE term.accession = ?); ...@@ -193,6 +199,7 @@ WHERE term.accession = ?);
'-adaptor' => $this, '-adaptor' => $this,
'-accession' => $accession, '-accession' => $accession,
'-is_root' => $is_root, '-is_root' => $is_root,
'-is_obsolete'=> $is_obsolete,
'-ontology' => $ontology, '-ontology' => $ontology,
'-namespace' => $namespace, '-namespace' => $namespace,
'-subsets' => [ split( /,/, $subsets ) ], '-subsets' => [ split( /,/, $subsets ) ],
...@@ -223,7 +230,7 @@ WHERE term.accession = ?); ...@@ -223,7 +230,7 @@ WHERE term.accession = ?);
=cut =cut
sub fetch_all_by_parent_term { sub fetch_all_by_parent_term {
my ( $this, $term, $ontology ) = @_; my ( $this, $term, $ontology, $include_obsolete ) = @_;
assert_ref( $term, 'Bio::EnsEMBL::OntologyTerm' ); assert_ref( $term, 'Bio::EnsEMBL::OntologyTerm' );
...@@ -237,6 +244,7 @@ SELECT child_term.term_id, ...@@ -237,6 +244,7 @@ SELECT child_term.term_id,
child_term.definition, child_term.definition,
child_term.subsets, child_term.subsets,
child_term.is_root, child_term.is_root,
child_term.is_obsolete,
rt.name rt.name
FROM term child_term FROM term child_term
JOIN relation ON (relation.child_term_id = child_term.term_id) JOIN relation ON (relation.child_term_id = child_term.term_id)
...@@ -245,6 +253,8 @@ FROM term child_term ...@@ -245,6 +253,8 @@ FROM term child_term
WHERE relation.parent_term_id = ? WHERE relation.parent_term_id = ?
AND ontology.name = ?); AND ontology.name = ?);
$statement .= " AND child_term.is_obsolete = 0" unless $include_obsolete;
my $sth = $this->prepare($statement); my $sth = $this->prepare($statement);
$sth->bind_param( 1, $term->dbID(), SQL_INTEGER ); $sth->bind_param( 1, $term->dbID(), SQL_INTEGER );
...@@ -256,9 +266,9 @@ WHERE relation.parent_term_id = ? ...@@ -256,9 +266,9 @@ WHERE relation.parent_term_id = ?
$sth->execute(); $sth->execute();
my ( $dbid, $accession, $name, $definition, $subsets, $is_root, $relation ); my ( $dbid, $accession, $name, $definition, $subsets, $is_root, $is_obsolete, $relation );
$sth->bind_columns( $sth->bind_columns(
\( $dbid, $accession, $name, $definition, $subsets, $is_root, $relation ) ); \( $dbid, $accession, $name, $definition, $subsets, $is_root, $is_obsolete, $relation ) );
while ( $sth->fetch() ) { while ( $sth->fetch() ) {
$subsets ||= ''; $subsets ||= '';
...@@ -269,6 +279,7 @@ WHERE relation.parent_term_id = ? ...@@ -269,6 +279,7 @@ WHERE relation.parent_term_id = ?
'-adaptor' => $this, '-adaptor' => $this,
'-accession' => $accession, '-accession' => $accession,
'-is_root' => $is_root, '-is_root' => $is_root,
'-is_obsolete' => $is_obsolete,
'-ontology' => $term->{'ontology'}, '-ontology' => $term->{'ontology'},
'-namespace' => $term->{'namespace'}, '-namespace' => $term->{'namespace'},
'-subsets' => [ split( /,/, $subsets ) ], '-subsets' => [ split( /,/, $subsets ) ],
...@@ -322,7 +333,8 @@ SELECT DISTINCT ...@@ -322,7 +333,8 @@ SELECT DISTINCT
child_term.name, child_term.name,
child_term.definition, child_term.definition,
child_term.subsets, child_term.subsets,
child_term.is_root child_term.is_root,
child_term.is_obsolete
FROM term child_term FROM term child_term
JOIN closure ON (closure.child_term_id = child_term.term_id) JOIN closure ON (closure.child_term_id = child_term.term_id)
JOIN ontology ON (closure.ontology_id = ontology.ontology_id) JOIN ontology ON (closure.ontology_id = ontology.ontology_id)
...@@ -340,9 +352,9 @@ ORDER BY closure.distance, child_term.accession); ...@@ -340,9 +352,9 @@ ORDER BY closure.distance, child_term.accession);
$sth->bind_param( 2, $ontology, SQL_VARCHAR ); $sth->bind_param( 2, $ontology, SQL_VARCHAR );
$sth->execute(); $sth->execute();
my ( $dbid, $accession, $name, $definition, $subsets, $is_root ); my ( $dbid, $accession, $name, $definition, $subsets, $is_root, $is_obsolete );
$sth->bind_columns( $sth->bind_columns(
\( $dbid, $accession, $name, $definition, $subsets, $is_root ) ); \( $dbid, $accession, $name, $definition, $subsets, $is_root, $is_obsolete ) );
my @terms; my @terms;
...@@ -355,6 +367,7 @@ ORDER BY closure.distance, child_term.accession); ...@@ -355,6 +367,7 @@ ORDER BY closure.distance, child_term.accession);
'-adaptor' => $this, '-adaptor' => $this,
'-accession' => $accession, '-accession' => $accession,
'-is_root' => $is_root, '-is_root' => $is_root,
'-is_obsolete' => $is_obsolete,
'-ontology' => $term->{'ontology'}, '-ontology' => $term->{'ontology'},
'-namespace' => $term->{'namespace'}, '-namespace' => $term->{'namespace'},
'-subsets' => [ split( /,/, $subsets ) ], '-subsets' => [ split( /,/, $subsets ) ],
...@@ -398,6 +411,7 @@ SELECT parent_term.term_id, ...@@ -398,6 +411,7 @@ SELECT parent_term.term_id,
parent_term.definition, parent_term.definition,
parent_term.subsets, parent_term.subsets,
parent_term.is_root, parent_term.is_root,
parent_term.is_obsolete,
rt.name rt.name
FROM term parent_term FROM term parent_term
JOIN relation ON (relation.parent_term_id = parent_term.term_id) JOIN relation ON (relation.parent_term_id = parent_term.term_id)
...@@ -416,9 +430,9 @@ WHERE relation.child_term_id = ? ...@@ -416,9 +430,9 @@ WHERE relation.child_term_id = ?
$sth->execute(); $sth->execute();
my ( $dbid, $accession, $name, $definition, $subsets, $is_root, $relation ); my ( $dbid, $accession, $name, $definition, $subsets, $is_root, $is_obsolete, $relation );
$sth->bind_columns( $sth->bind_columns(
\( $dbid, $accession, $name, $definition, $subsets, $is_root, $relation ) ); \( $dbid, $accession, $name, $definition, $subsets, $is_root, $is_obsolete, $relation ) );
while ( $sth->fetch() ) { while ( $sth->fetch() ) {
$subsets ||= ''; $subsets ||= '';
...@@ -429,6 +443,7 @@ WHERE relation.child_term_id = ? ...@@ -429,6 +443,7 @@ WHERE relation.child_term_id = ?
'-adaptor' => $this, '-adaptor' => $this,
'-accession' => $accession, '-accession' => $accession,
'-is_root' => $is_root, '-is_root' => $is_root,
'-is_obsolete' => $is_obsolete,
'-ontology' => $term->{'ontology'}, '-ontology' => $term->{'ontology'},
'-namespace' => $term->{'namespace'}, '-namespace' => $term->{'namespace'},
'-subsets' => [ split( /,/, $subsets ) ], '-subsets' => [ split( /,/, $subsets ) ],
...@@ -506,6 +521,7 @@ SELECT DISTINCT ...@@ -506,6 +521,7 @@ SELECT DISTINCT
parent_term.definition, parent_term.definition,
parent_term.subsets, parent_term.subsets,
parent_term.is_root, parent_term.is_root,
parent_term.is_obsolete,
closure.distance closure.distance
FROM term parent_term FROM term parent_term
JOIN closure ON (closure.parent_term_id = parent_term.term_id) JOIN closure ON (closure.parent_term_id = parent_term.term_id)
...@@ -543,9 +559,9 @@ ORDER BY closure.distance, parent_term.accession); ...@@ -543,9 +559,9 @@ ORDER BY closure.distance, parent_term.accession);
$sth->execute(); $sth->execute();
my ( $dbid, $accession, $name, $definition, $subsets, $is_root, $distance ); my ( $dbid, $accession, $name, $definition, $subsets, $is_root, $is_obsolete, $distance );
$sth->bind_columns( $sth->bind_columns(
\( $dbid, $accession, $name, $definition, $subsets, $is_root, $distance ) ); \( $dbid, $accession, $name, $definition, $subsets, $is_root, $is_obsolete, $distance ) );
my @terms; my @terms;
my $min_distance; my $min_distance;
...@@ -561,6 +577,7 @@ ORDER BY closure.distance, parent_term.accession); ...@@ -561,6 +577,7 @@ ORDER BY closure.distance, parent_term.accession);
'-adaptor' => $this, '-adaptor' => $this,
'-accession' => $accession, '-accession' => $accession,
'-is_root' => $is_root, '-is_root' => $is_root,
'-is_obsolete' => $is_obsolete,
'-ontology' => $term->{'ontology'}, '-ontology' => $term->{'ontology'},
'-namespace' => $term->{'namespace'}, '-namespace' => $term->{'namespace'},
'-subsets' => [ split( /,/, $subsets ) ], '-subsets' => [ split( /,/, $subsets ) ],
...@@ -707,7 +724,7 @@ ORDER BY closure.distance); ...@@ -707,7 +724,7 @@ ORDER BY closure.distance);
# provided by the parent class Bio::EnsEMBL::DBSQL::BaseAdaptor. # provided by the parent class Bio::EnsEMBL::DBSQL::BaseAdaptor.
sub fetch_by_dbID { sub fetch_by_dbID {
my ( $this, $dbid ) = @_; my ( $this, $dbid, $include_obsolete ) = @_;
my $statement = q( my $statement = q(
SELECT term.term_id, SELECT term.term_id,
...@@ -716,21 +733,24 @@ SELECT term.term_id, ...@@ -716,21 +733,24 @@ SELECT term.term_id,
term.definition, term.definition,
term.subsets, term.subsets,
term.is_root, term.is_root,
term.is_obsolete,
ontology.name, ontology.name,
ontology.namespace ontology.namespace
FROM ontology FROM ontology
JOIN term USING (ontology_id) JOIN term USING (ontology_id)
WHERE term.term_id = ?); WHERE term.term_id = ?);
$statement .= " AND term.is_obsolete = 0" unless $include_obsolete;
my $sth = $this->prepare($statement); my $sth = $this->prepare($statement);
$sth->bind_param( 1, $dbid, SQL_INTEGER ); $sth->bind_param( 1, $dbid, SQL_INTEGER );
$sth->execute(); $sth->execute();
my ( $accession, $name, $definition, $subsets, $is_root, $ontology, my ( $accession, $name, $definition, $subsets, $is_root, $is_obsolete, $ontology,
$namespace ); $namespace );
$sth->bind_columns( $sth->bind_columns(
\( $dbid, $accession, $name, $definition, $subsets, $is_root, $ontology, $namespace \( $dbid, $accession, $name, $definition, $subsets, $is_root, $is_obsolete, $ontology, $namespace
) ); ) );
$sth->fetch(); $sth->fetch();
...@@ -745,6 +765,7 @@ WHERE term.term_id = ?); ...@@ -745,6 +765,7 @@ WHERE term.term_id = ?);
'-adaptor' => $this, '-adaptor' => $this,
'-accession' => $accession, '-accession' => $accession,
'-is_root' => $is_root, '-is_root' => $is_root,
'-is_obsolete' => $is_obsolete,
'-ontology' => $ontology, '-ontology' => $ontology,
'-namespace' => $namespace, '-namespace' => $namespace,
'-subsets' => [ split( /,/, $subsets ) ], '-subsets' => [ split( /,/, $subsets ) ],
...@@ -758,7 +779,7 @@ WHERE term.term_id = ?); ...@@ -758,7 +779,7 @@ WHERE term.term_id = ?);
} ## end sub fetch_by_dbID } ## end sub fetch_by_dbID
sub fetch_all_by_dbID_list { sub fetch_all_by_dbID_list {
my ( $this, $dbids ) = @_; my ( $this, $dbids, $include_obsolete ) = @_;
if ( !@{$dbids} ) { return [] } if ( !@{$dbids} ) { return [] }
...@@ -769,6 +790,7 @@ SELECT term.term_id, ...@@ -769,6 +790,7 @@ SELECT term.term_id,
term.definition, term.definition,
term.subsets, term.subsets,
term.is_root, term.is_root,
term.is_obsolete,
ontology.name, ontology.name,
ontology.namespace ontology.namespace
FROM ontology FROM ontology
...@@ -783,14 +805,16 @@ WHERE term.term_id IN (%s)); ...@@ -783,14 +805,16 @@ WHERE term.term_id IN (%s));
$this->dbc()->db_handle()->quote( $_, SQL_INTEGER ) $this->dbc()->db_handle()->quote( $_, SQL_INTEGER )
} @{$dbids} ) ); } @{$dbids} ) );
$statement .= " AND term.is_obsolete = 0" unless $include_obsolete;
my $sth = $this->prepare($statement); my $sth = $this->prepare($statement);
$sth->execute(); $sth->execute();
my ( $dbid, $accession, $name, $definition, $subsets, $is_root, $ontology, my ( $dbid, $accession, $name, $definition, $subsets, $is_root, $is_obsolete, $ontology,
$namespace ); $namespace );
$sth->bind_columns( \( $dbid, $accession, $name, $definition, $sth->bind_columns( \( $dbid, $accession, $name, $definition,
$subsets, $is_root, $ontology, $namespace ) ); $subsets, $is_root, $is_obsolete, $ontology, $namespace ) );
my @terms; my @terms;
...@@ -803,6 +827,7 @@ WHERE term.term_id IN (%s)); ...@@ -803,6 +827,7 @@ WHERE term.term_id IN (%s));
'-adaptor' => $this, '-adaptor' => $this,
'-accession' => $accession, '-accession' => $accession,
'-is_root' => $is_root, '-is_root' => $is_root,
'-is_obsolete' => $is_obsolete,
'-ontology' => $ontology, '-ontology' => $ontology,
'-namespace' => $namespace, '-namespace' => $namespace,
'-subsets' => [ split( /,/, $subsets ) ], '-subsets' => [ split( /,/, $subsets ) ],
...@@ -845,6 +870,7 @@ SELECT term.term_id, ...@@ -845,6 +870,7 @@ SELECT term.term_id,
term.definition, term.definition,
term.subsets, term.subsets,
term.is_root, term.is_root,
term.is_obsolete,
ontology.name, ontology.name,
ontology.namespace ontology.namespace
FROM ontology FROM ontology
...@@ -861,10 +887,10 @@ FROM ontology ...@@ -861,10 +887,10 @@ FROM ontology
} }
$sth->execute(); $sth->execute();
my ( $dbid, $accession, $name, $definition, $subsets, $is_root, $ontology, my ( $dbid, $accession, $name, $definition, $subsets, $is_root, $is_obsolete, $ontology,
$namespace ); $namespace );
$sth->bind_columns( \( $dbid, $accession, $name, $definition, $sth->bind_columns( \( $dbid, $accession, $name, $definition,
$subsets, $is_root, $ontology, $namespace ) ); $subsets, $is_root, $is_obsolete, $ontology, $namespace ) );
my @terms; my @terms;
...@@ -877,6 +903,7 @@ FROM ontology ...@@ -877,6 +903,7 @@ FROM ontology
'-adaptor' => $this, '-adaptor' => $this,
'-accession' => $accession, '-accession' => $accession,
'-is_root' => $is_root, '-is_root' => $is_root,
'-is_obsolete' => $is_obsolete,
'-ontology' => $ontology, '-ontology' => $ontology,
'-namespace' => $namespace, '-namespace' => $namespace,
'-subsets' => [ split( /,/, $subsets ) ], '-subsets' => [ split( /,/, $subsets ) ],
...@@ -892,7 +919,7 @@ FROM ontology ...@@ -892,7 +919,7 @@ FROM ontology
sub fetch_all { sub fetch_all {
my ($this) = @_; my ($this, $include_obsolete) = @_;
my $statement = q( my $statement = q(
SELECT term.term_id, SELECT term.term_id,
...@@ -901,18 +928,21 @@ SELECT term.term_id, ...@@ -901,18 +928,21 @@ SELECT term.term_id,
term.definition, term.definition,
term.subsets, term.subsets,
term.is_root, term.is_root,
term.is_obsolete,
ontology.name, ontology.name,
ontology.namespace ontology.namespace
FROM ontology FROM ontology
JOIN term USING (ontology_id)); JOIN term USING (ontology_id));
$statement .= " AND term.is_obsolete = 0" unless $include_obsolete;
my $sth = $this->prepare($statement); my $sth = $this->prepare($statement);
$sth->execute(); $sth->execute();
my ( $dbid, $accession, $name, $definition, $subsets, $is_root, $ontology, my ( $dbid, $accession, $name, $definition, $subsets, $is_root, $is_obsolete, $ontology,
$namespace ); $namespace );
$sth->bind_columns( \( $dbid, $accession, $name, $definition, $sth->bind_columns( \( $dbid, $accession, $name, $definition,
$subsets, $is_root, $ontology, $namespace ) ); $subsets, $is_root, $is_obsolete, $ontology, $namespace ) );
my @terms; my @terms;
...@@ -925,6 +955,7 @@ FROM ontology ...@@ -925,6 +955,7 @@ FROM ontology
'-adaptor' => $this, '-adaptor' => $this,
'-accession' => $accession, '-accession' => $accession,
'-is_root' => $is_root, '-is_root' => $is_root,
'-is_obsolete' => $is_obsolete,
'-ontology' => $ontology, '-ontology' => $ontology,
'-namespace' => $namespace, '-namespace' => $namespace,
'-subsets' => [ split( /,/, $subsets ) ], '-subsets' => [ split( /,/, $subsets ) ],
......
...@@ -99,9 +99,9 @@ sub new { ...@@ -99,9 +99,9 @@ sub new {
my $this = $proto->SUPER::new(@_); my $this = $proto->SUPER::new(@_);
my ( $accession, $ontology, $namespace, $name, $definition, $is_root, $subsets ) my ( $accession, $ontology, $namespace, $name, $definition, $is_root, $is_obsolete, $subsets )
= rearrange( [ 'ACCESSION', 'ONTOLOGY', 'NAMESPACE', 'NAME', = rearrange( [ 'ACCESSION', 'ONTOLOGY', 'NAMESPACE', 'NAME',
'DEFINITION', 'IS_ROOT', 'SUBSETS' ], 'DEFINITION', 'IS_ROOT', 'IS_OBSOLETE', 'SUBSETS' ],
@_ ); @_ );
$this->{'accession'} = $accession; $this->{'accession'} = $accession;
...@@ -110,6 +110,7 @@ sub new { ...@@ -110,6 +110,7 @@ sub new {
$this->{'name'} = $name; $this->{'name'} = $name;
$this->{'definition'} = $definition; $this->{'definition'} = $definition;
$this->{'is_root'} = $is_root; $this->{'is_root'} = $is_root;
$this->{'is_obsolete'}= $is_obsolete;
$this->{'subsets'} = [ @{$subsets} ]; $this->{'subsets'} = [ @{$subsets} ];
$this->{'child_terms_fetched'} = 0; $this->{'child_terms_fetched'} = 0;
...@@ -220,6 +221,24 @@ sub is_root { ...@@ -220,6 +221,24 @@ sub is_root {
return $this->{'is_root'}; return $this->{'is_root'};
}