Skip to content
Snippets Groups Projects
Commit d1f1115b authored by Andreas Kusalananda Kähäri's avatar Andreas Kusalananda Kähäri
Browse files

Remove accidentally re-added new() and ontology() methods.

Make fetch_by_name() take an optional second argument (ontology name).

Make fetch_by_name() also look at synonyms.
parent 8753ad8b
No related branches found
No related tags found
No related merge requests found
...@@ -60,82 +60,25 @@ use Bio::EnsEMBL::OntologyTerm; ...@@ -60,82 +60,25 @@ 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_all_by_name =head2 fetch_all_by_name
Arg [1] : String - Name of term Arg [1] : String, name of term, or SQL pattern
Arg [2] : (optional) String, name of ontology
Description : Fetches an ontology term(s) given a name, which may Description : Fetches ontology term(s) given a name, a synonym, or a
contain MySQL wildcards i.e. _ or % SQL pattern like "%splice_site"
Example : Example :
my ($term) = @{$ot_adaptor->fetch_by_name('DNA_binding_site')}; my ($term) =
@{ $ot_adaptor->fetch_by_name( 'DNA_binding_site', 'SO' ) };
Return type : ARRAYREF of Bio::EnsEMBL::OntologyTerm Objects Return type : listref of Bio::EnsEMBL::OntologyTerm
=cut =cut
sub fetch_all_by_name { sub fetch_all_by_name {
my ( $this, $name) = @_; my ( $this, $pattern, $ontology ) = @_;
my $statement = q( my $statement = q(
SELECT term.term_id, SELECT term.term_id,
...@@ -145,43 +88,49 @@ SELECT term.term_id, ...@@ -145,43 +88,49 @@ SELECT term.term_id,
term.subsets, term.subsets,
ontology.namespace ontology.namespace
FROM ontology, FROM ontology,
term term,
WHERE ontology.name = ? synonym
AND ontology.ontology_id = term.ontology_id WHERE ontology.ontology_id = term.ontology_id
AND term.name like ?); AND synonym.term_id = term.term_id
AND ( term.name LIKE ? OR synonym.name LIKE ? )
);
if ( defined($ontology) ) {
$statement .= "AND ontology.name = ?";
}
my $sth = $this->prepare($statement); my $sth = $this->prepare($statement);
$sth->bind_param( 1, $this->{'ontology'}, SQL_VARCHAR ); $sth->bind_param( 1, $pattern, SQL_VARCHAR );
$sth->bind_param( 2, $name, SQL_VARCHAR ); $sth->bind_param( 2, $pattern, SQL_VARCHAR );
if ( defined($ontology) ) {
$sth->bind_param( 3, $this->{'ontology'}, SQL_VARCHAR );
}
$sth->execute(); $sth->execute();
my ( $dbid, $accession, $term_name, $definition, $subsets, $namespace ); my ( $dbid, $accession, $name, $definition, $subsets, $namespace );
$sth->bind_columns( $sth->bind_columns(
\( $dbid, $accession, $term_name, $definition, $subsets, $namespace ) ); \( $dbid, $accession, $name, $definition, $subsets, $namespace ) );
my @terms; my @terms;
while ( $sth->fetch ) {
$subsets ||= '';
while($sth->fetch){ push @terms,
Bio::EnsEMBL::OntologyTerm->new(
$subsets ||= ''; '-dbid' => $dbid,
push @terms, Bio::EnsEMBL::OntologyTerm->new '-adaptor' => $this,
( '-accession' => $accession,
'-dbid' => $dbid, '-namespace' => $namespace,
'-adaptor' => $this, '-subsets' => [ split( /,/, $subsets ) ],
'-accession' => $accession, '-name' => $name,
'-namespace' => $namespace, '-definition' => $definition );
'-subsets' => [ split( /,/, $subsets ) ],
'-name' => $term_name,
'-definition' => $definition
);
} }
$sth->finish();
return \@terms; return \@terms;
} ## end sub fetch_by_name } ## end sub fetch_all_by_name
=head2 fetch_by_accession =head2 fetch_by_accession
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment