Commit a38ef046 authored by Magali Ruffier's avatar Magali Ruffier
Browse files

ENSCORESW-2399: check perfect match before wildcard

parent 027bb9fa
......@@ -302,25 +302,36 @@ sub fetch_by_region {
$syn_sql .= "AND cs.version = '" . $version . "' ";
}
my $syn_sql_sth = $self->prepare($syn_sql);
my $escaped_seq_region_name = $seq_region_name;
my $escape_char = $self->dbc->db_handle->get_info(14);
$escaped_seq_region_name =~ s/([_%])/$escape_char$1/g;
$syn_sql_sth->bind_param(1, "$escaped_seq_region_name%", SQL_VARCHAR);
$syn_sql_sth->bind_param(1, $seq_region_name, SQL_VARCHAR);
$syn_sql_sth->bind_param(2, $self->species_id(), SQL_INTEGER);
$syn_sql_sth->execute();
my ($new_name, $new_coord_system, $new_version);
$syn_sql_sth->bind_columns( \$new_name, \$new_coord_system, \$new_version);
if($syn_sql_sth->fetch){
$syn_sql_sth->finish;
if ((not defined($cs)) || ($cs->name eq $new_coord_system && $cs->version eq $new_version)) {
return $self->fetch_by_region($new_coord_system, $new_name, $start, $end, $strand, $new_version, $no_fuzz);
} elsif ($cs->name ne $new_coord_system) {
warning("Searched for a known feature on coordinate system: ".$cs->dbID." but found it on: ".$new_coord_system.
"\n No result returned, consider searching without coordinate system or use toplevel.");
return;
}
} else {
# Try wildcard searching if no exact synonym was found
$syn_sql_sth = $self->prepare($syn_sql);
my $escaped_seq_region_name = $seq_region_name;
my $escape_char = $self->dbc->db_handle->get_info(14);
$escaped_seq_region_name =~ s/([_%])/$escape_char$1/g;
$syn_sql_sth->bind_param(1, "$escaped_seq_region_name%", SQL_VARCHAR);
$syn_sql_sth->bind_param(2, $self->species_id(), SQL_INTEGER);
$syn_sql_sth->execute();
$syn_sql_sth->bind_columns( \$new_name, \$new_coord_system, \$new_version);
if($syn_sql_sth->fetch){
if ((not defined($cs)) || ($cs->name eq $new_coord_system && $cs->version eq $new_version)) {
return $self->fetch_by_region($new_coord_system, $new_name, $start, $end, $strand, $new_version, $no_fuzz);
} elsif ($cs->name ne $new_coord_system) {
warning("Searched for a known feature on coordinate system: ".$cs->dbID." but found it on: ".$new_coord_system.
"\n No result returned, consider searching without coordinate system or use toplevel.");
return;
}
}
}
$syn_sql_sth->finish;
......
......@@ -474,14 +474,14 @@ $multi->restore();
$multi->save("core", 'seq_region_synonym');
$slice = $slice_adaptor->fetch_by_region('chromosome', 1, 1, 10);
$slice = $slice_adaptor->fetch_by_region('chromosome', 5, 1, 10);
@alt_names = @{$slice->get_all_synonyms()};
is(@alt_names, 0, "No altnames returned");
$slice->add_synonym("1ish");
$slice->add_synonym("5ish");
@alt_names = @{$slice->get_all_synonyms()};
......@@ -492,7 +492,7 @@ foreach my $syn (@alt_names){
}
$slice = $slice_adaptor->fetch_by_region('chromosome', 1, 1, 10);
$slice = $slice_adaptor->fetch_by_region('chromosome', 5, 1, 10);
@alt_names = @{$slice->get_all_synonyms()};
......@@ -513,7 +513,7 @@ $multi->restore();
# test fetch_all on synonym adaptor
my $all_synonyms = $syn_adap->fetch_all();
is(@$all_synonyms, 3, 'fetch_all on synonym adaptor');
is(@$all_synonyms, 5, 'fetch_all on synonym adaptor');
#Test assembly exception type on HAP
......
......@@ -555,6 +555,9 @@ ok($slice->seq_region_name =~ /$clone_name\.\d+/);
is($chr_syn_slice->seq_region_name(), '20', 'Ensuring slice is Chr20 as expected');
$chr_syn_slice = $slice_adaptor->fetch_by_region('toplevel', 'chrx');
is($chr_syn_slice->seq_region_name(), 'X', 'Ensuring slice is ChrX as expected');
$syn_slice = $slice_adaptor->fetch_by_region('toplevel', 'chr1');
is($syn_slice->seq_region_name(), '1', 'Ensuring chr1 is 1, and not 10');
}
#{
......
1 469283 alt_20 \N
2 469283 anoth_20 4200
3 469293 chrx 11000
4 469272 chr10 11000
5 469271 chr1 11000
Markdown is supported
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