Skip to content
Snippets Groups Projects
Commit afc25421 authored by Nathan Johnson's avatar Nathan Johnson
Browse files

fetch_all_by_name - Replaced fuzzy matching logic with simple like

parent 76b92b4a
No related branches found
Tags cvs/release/ensemblgenomes/19-72
No related merge requests found
...@@ -123,12 +123,8 @@ sub ontology { ...@@ -123,12 +123,8 @@ sub ontology {
Arg [1] : String - Name of term Arg [1] : String - Name of term
Arg [2] : int - Fuzzy match flag: Description : Fetches an ontology term(s) given a name, which may
1 = Try with spaces and underscores or none contain MySQL wildcards i.e. _ or %
2 = Pre/Append wildcards
3 = Both of the above
Description : Fetches an ontology term(s) given a name.
Example : Example :
...@@ -139,37 +135,7 @@ sub ontology { ...@@ -139,37 +135,7 @@ sub ontology {
=cut =cut
sub fetch_all_by_name { sub fetch_all_by_name {
my ( $this, $name, $fuzzy) = @_; my ( $this, $name) = @_;
#fetch_all because term-ontolgy does not have unique key
#And fuzzy may bring back >1 term
#Case insensitivity is implicit due to table character collection
my ($name_clause, $name_string);
if(! $fuzzy){
$name_clause = 'term.name = ?';
$name_string = $name;
}
elsif($fuzzy == 2){
$name_clause = ' term.name like ?';
$name_string = "\%${name}\%";
}
elsif($fuzzy < 4){
#$fuzzy == 3
$name_clause = ' term.name rlike ?';
($name_string = $name) =~ s/[\s_]+/\[ _\]*/g;
#no need for .* at flanks as this is the default rlike behaviour
if($fuzzy == 1){
$name_string = "^${name_string}\$";
}
}
else{
throw("Fuzzy match level can only be set to 1, 2 or 3 not $fuzzy");
}
my $statement = q( my $statement = q(
SELECT term.term_id, SELECT term.term_id,
...@@ -182,7 +148,7 @@ FROM ontology, ...@@ -182,7 +148,7 @@ FROM ontology,
term term
WHERE ontology.name = ? WHERE ontology.name = ?
AND ontology.ontology_id = term.ontology_id AND ontology.ontology_id = term.ontology_id
AND ).$name_clause; AND term.name like ?');
my $sth = $this->prepare($statement); my $sth = $this->prepare($statement);
$sth->bind_param( 1, $this->{'ontology'}, SQL_VARCHAR ); $sth->bind_param( 1, $this->{'ontology'}, SQL_VARCHAR );
......
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