Commit db0a3394 authored by Daniel Rios's avatar Daniel Rios
Browse files

modified to allow mapping between external and internal seq_region_ids

parent 7ed68160
......@@ -163,7 +163,7 @@ sub fetch_all_by_Slice_and_score {
sub fetch_all_by_Slice_constraint {
my($self, $slice, $constraint, $logic_name) = @_;
my @result;
my @result = ();
if(!ref($slice) || !$slice->isa("Bio::EnsEMBL::Slice")) {
throw("Bio::EnsEMBL::Slice argument expected.");
......@@ -352,7 +352,8 @@ sub _slice_fetch {
} else {
$sr_id = $self->db()->get_SliceAdaptor()->get_seq_region_id($slice);
}
#if there is mapping information, use the external_seq_region_id to get features
my $sr_id = $self->get_seq_region_id_external($sr_id);
$constraint .= " AND " if($constraint);
$constraint .=
"${tab_syn}.seq_region_id = $sr_id AND " .
......@@ -400,7 +401,6 @@ sub _slice_fetch {
my $id_str = join(',', @ids);
$constraint .= " AND " if($constraint);
$constraint .= "${tab_syn}.seq_region_id IN ($id_str)";
my $fs = $self->generic_fetch($constraint, $mapper, $slice);
$fs = $self->_remap( $fs, $mapper, $slice );
......@@ -427,7 +427,6 @@ sub _slice_fetch {
$constraint .=
" AND ${tab_syn}.seq_region_start >= $min_start";
}
my $fs = $self->generic_fetch($constraint,$mapper,$slice);
$fs = $self->_remap( $fs, $mapper, $slice );
......@@ -442,6 +441,22 @@ sub _slice_fetch {
}
#for a given seq_region_id, gets the one used in an external database, if present, otherwise, returns the internal one
sub get_seq_region_id_external{
my $self = shift;
my $sr_id = shift;
return (exists $self->db->get_CoordSystemAdaptor->{'_internal_seq_region_mapping'}->{$sr_id} ? $self->db->get_CoordSystemAdaptor->{'_internal_seq_region_mapping'}->{$sr_id} : $sr_id);
}
#for a given seq_region_id and coord_system, gets the one used in the internal (core) database
sub get_seq_region_id_internal{
my $self = shift;
my $sr_id = shift;
return (exists $self->db->get_CoordSystemAdaptor->{'_external_seq_region_mapping'}->{$sr_id} ? $self->db->get_CoordSystemAdaptor->{'_external_seq_region_mapping'}->{$sr_id} : $sr_id);
}
#
# Helper function containing some common feature storing functionality
......
......@@ -150,6 +150,12 @@ sub new {
$self->{'_is_sequence_level'} = {};
$self->{'_is_default_version'} = {};
#cache to store the seq_region_mapping information
#from internal->external
$self->{'_internal_seq_region_mapping'} = {};
#from external->internal
$self->{'_external_seq_region_mapping'} = {};
my $sth = $self->prepare(
'SELECT coord_system_id, name, rank, version, attrib ' .
'FROM coord_system');
......@@ -191,10 +197,31 @@ sub new {
$self->_cache_mapping_paths;
$self->_cache_seq_region_mapping;
return $self;
}
#this cache will load the information from the seq_region_table, if any, to allow mapping
#between internal and external seq_region_id
sub _cache_seq_region_mapping{
my $self = shift;
#for a given core database, will return the schema_build information
my $schema_build = $self->db->_get_schema_build();
#prepare the query to get relation for the current database being used
my $sql = 'SELECT s.internal_seq_region_id, s.external_seq_region_id from seq_region_mapping s, mapping_set ms where ms.mapping_set_id = s.mapping_set_id and ms.schema_build="'.$schema_build.'"';
#load the cache:
foreach my $row (@{$self->db->dbc->db_handle->selectall_arrayref($sql)}){
#the internal->external
$self->{'_internal_seq_region_mapping'}->{$row->[0]} = $row->[1];
#the external->internal
$self->{'_external_seq_region_mapping'}->{$row->[1]} = $row->[0];
}
#and return
return;
}
sub _cache_mapping_paths{
#
# Retrieve a list of available mappings from the meta table.
......
......@@ -662,6 +662,25 @@ sub get_SeqRegionCache {
}
#convenient method to retrieve the schema_build version for the database being used
sub _get_schema_build{
my ($self) = @_;
#avoided using dnadb by default to avoid obfuscation of behaviour
my @dbname = split/_/, $self->dbc->dbname();
#warn "dbname is $schema_build";
my $schema_build = pop @dbname;
$schema_build = pop(@dbname).'_'.$schema_build;
return $schema_build;
}
=head2 dnadb
Title : dnadb
......
......@@ -374,8 +374,9 @@ sub _objs_from_sth {
$dta->fetch_by_dbID($density_type_id);
#get the slice object
#need to get the internal_seq_region, if present
$seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
my $slice = $slice_hash{"ID:".$seq_region_id};
if(!$slice) {
$slice = $sa->fetch_by_seq_region_id($seq_region_id);
$slice_hash{"ID:".$seq_region_id} = $slice;
......
......@@ -542,6 +542,9 @@ sub _objs_from_sth {
}
FEATURE: while($sth->fetch()) {
#need to get the internal_seq_region, if present
$seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
my $slice = $slice_hash{"ID:".$seq_region_id};
my $dest_mapper = $mapper;
......
......@@ -1376,6 +1376,9 @@ sub _objs_from_sth {
#get the canonical_transcript object
my $canonical_transcript = $ta->fetch_by_dbID($canonical_transcript_id);
#need to get the internal_seq_region, if present
$seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
my $slice = $slice_hash{"ID:".$seq_region_id};
if(!$slice) {
......
......@@ -117,6 +117,9 @@ sub _objs_from_sth {
\$seq_region_end, \$band, \$stain);
while ( $sth->fetch() ) {
#need to get the internal_seq_region, if present
$seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
my $slice = $slice_cache{$seq_region_id} ||=
$slice_adaptor->fetch_by_seq_region_id($seq_region_id);
......
......@@ -398,6 +398,8 @@ sub _objs_from_sth {
}
$current = $misc_feature_id;
#need to get the internal_seq_region, if present
$seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
my $slice = $slice_hash{"ID:".$seq_region_id};
if (!$slice) {
......
......@@ -327,6 +327,8 @@ sub _objs_from_sth {
my $analysis = $analysis_hash{$analysis_id} ||= $aa->fetch_by_dbID($analysis_id);
# Get the slice object
#need to get the internal_seq_region, if present
$seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
my $slice = $slice_hash{'ID:'.$seq_region_id};
if (!$slice) {
......
......@@ -42,6 +42,7 @@ use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
use Bio::EnsEMBL::PredictionExon;
use Bio::EnsEMBL::Utils::Exception qw( warning throw deprecate );
@ISA = qw( Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor );
......@@ -347,6 +348,8 @@ sub _objs_from_sth {
}
FEATURE: while($sth->fetch()) {
#need to get the internal_seq_region, if present
$seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
my $slice = $slice_hash{"ID:".$seq_region_id};
my $dest_mapper = $mapper;
......
......@@ -319,7 +319,8 @@ sub _objs_from_sth {
#get the analysis object
my $analysis = $analysis_hash{$analysis_id} ||=
$aa->fetch_by_dbID($analysis_id);
#need to get the internal_seq_region, if present
$seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
my $slice = $slice_hash{"ID:".$seq_region_id};
if(!$slice) {
......
......@@ -242,7 +242,8 @@ sub _objs_from_sth {
#get the analysis object
my $analysis = $analysis_hash{$analysis_id} ||=
$aa->fetch_by_dbID($analysis_id);
#need to get the internal_seq_region, if present
$seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
my $slice = $slice_hash{"ID:".$seq_region_id};
if(!$slice) {
......
......@@ -229,6 +229,8 @@ sub _objs_from_sth {
my $analysis = $analysis_hash{$analysis_id} ||=
$aa->fetch_by_dbID($analysis_id);
#need to get the internal_seq_region, if present
$seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
#get the slice object
my $slice = $slice_hash{"ID:".$seq_region_id};
......
......@@ -1195,7 +1195,8 @@ sub _objs_from_sth {
#get the analysis object
my $analysis = $analysis_hash{$analysis_id} ||=
$aa->fetch_by_dbID($analysis_id);
#need to get the internal_seq_region, if present
$seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
my $slice = $slice_hash{"ID:".$seq_region_id};
my $dest_mapper = $mapper;
......
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