Skip to content
Snippets Groups Projects
Commit 991a724a authored by Andy Yates's avatar Andy Yates
Browse files

[ENSCORESW-691]. Adding the ability to query by retired seq region ids.

Other schemas may need this which do not go through a process of removing
old/retired seq region ids in favour of their new ids. When querying by a slice
this is automatically delt with. When fetching by an ID you now need to
force the search on.
parent fff35314
No related branches found
No related tags found
No related merge requests found
......@@ -805,7 +805,7 @@ sub fetch_by_name {
=cut
sub fetch_by_seq_region_id {
my ( $self, $seq_region_id, $start, $end, $strand ) = @_;
my ( $self, $seq_region_id, $start, $end, $strand, $check_prior_ids ) = @_;
my $arr = $self->{'sr_id_cache'}->{$seq_region_id};
my ( $name, $length, $cs, $cs_id );
......@@ -823,7 +823,19 @@ sub fetch_by_seq_region_id {
$sth->bind_param( 1, $seq_region_id, SQL_INTEGER );
$sth->execute();
if ( $sth->rows() == 0 ) { return undef }
if ( $sth->rows() == 0 ) {
# This could have been an old seq region id so see if we can
# translate it into a more recent version.
if($check_prior_ids) {
my $csa = $self->db()->get_CoordSystemAdaptor();
if(exists $csa->{_external_seq_region_mapping}->{$seq_region_id}) {
my $new_seq_region_id = $csa->{_external_seq_region_mapping}->{$seq_region_id};
# No need to pass check prior ids flag because it's a 1 step relationship
return $self->fetch_by_seq_region_id($new_seq_region_id, $start, $end, $strand);
}
}
return undef;
}
( $name, $cs_id, $length ) = $sth->fetchrow_array();
$sth->finish();
......
......@@ -508,5 +508,41 @@ is($chr_one_slice->assembly_exception_type(), 'REF', 'Ensuring reference regions
}
}
# Test alternative region mappings from fetch_by_seq_region_id()
{
my $current_slice = $slice_adaptor->fetch_by_region('chromosome', $CHR, $START, $END);
my $alternative_seq_region_id = 1;
#Get the alternative seq region id. Expect nothing
ok(! defined $slice_adaptor->fetch_by_seq_region_id($alternative_seq_region_id), 'Asking for a non-existent ID results in no slice returned');
#Save the tables and add the mapping values in
my @tables = ('seq_region_mapping', 'mapping_set');
$multi_db->save('core', @tables);
my $ms_sql = 'insert into mapping_set (mapping_set_id, internal_schema_build, external_schema_build) values (?,?,?)';
$db->dbc->sql_helper->execute_update(-SQL => $ms_sql, -PARAMS => [1, $db->_get_schema_build(), 'oldbuild']);
my $srm_sql = 'insert into seq_region_mapping (mapping_set_id, internal_seq_region_id, external_seq_region_id) values (?,?,?)';
$db->dbc->sql_helper->execute_update(-SQL => $srm_sql, -PARAMS => [1, $current_slice->get_seq_region_id(), $alternative_seq_region_id]);
#Force a refresh in CSA
delete $db->get_CoordSystemAdaptor->{$_} for qw/_internal_seq_region_mapping _external_seq_region_mapping/;
$db->get_CoordSystemAdaptor->_cache_seq_region_mapping();
my $alternative_slice = $slice_adaptor->fetch_by_seq_region_id($alternative_seq_region_id);
ok(!defined $alternative_slice, 'Cannot retrieve the alternative slice without asking to look at alternatives');
$alternative_slice = $slice_adaptor->fetch_by_seq_region_id($alternative_seq_region_id, undef, undef, undef, 1); #don't care about start,end,strand
ok(defined $alternative_slice, 'Got a slice after asking for it');
cmp_ok($current_slice->get_seq_region_id(), '==', $alternative_slice->get_seq_region_id(), 'Seq region IDs should be equivalent even though query seq_region_id was different');
#Restore & force a refresh
$multi_db->restore('core', @tables);
delete $db->get_CoordSystemAdaptor->{$_} for qw/_internal_seq_region_mapping _external_seq_region_mapping/;
$db->get_CoordSystemAdaptor->_cache_seq_region_mapping();
# Just checking we are back to normal
$alternative_slice = $slice_adaptor->fetch_by_seq_region_id($alternative_seq_region_id);
ok(!defined $alternative_slice, 'Cannot retrieve the alternative slice post restore');
}
done_testing();
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