Commit 016d40c8 authored by Graham McVicker's avatar Graham McVicker
Browse files

make use of meta_coord.max_length to further optomize generated feature queries

parent 552faa71
......@@ -491,6 +491,10 @@ sub _slice_fetch {
if($feat_cs->equals($slice_cs)) {
# no mapping is required if this is the same coord system
my $max_len =
$mcc->fetch_max_length_by_CoordSystem_feature_type($feat_cs,$tab_name);
my $constraint = $orig_constraint;
my $sr_id = $self->db->get_SliceAdaptor->get_seq_region_id($slice);
......@@ -499,6 +503,13 @@ sub _slice_fetch {
"${tab_syn}.seq_region_id = $sr_id AND " .
"${tab_syn}.seq_region_start <= $slice_end AND " .
"${tab_syn}.seq_region_end >= $slice_start";
if($max_len) {
my $min_start = $slice_start - $max_len;
$constraint .=
" AND ${tab_syn}.seq_region_start >= $min_start";
}
my $fs = $self->generic_fetch($constraint,undef,$slice);
# features may still have to have coordinates made relative to slice
......@@ -540,6 +551,10 @@ sub _slice_fetch {
} else {
# do multiple split queries using start / end constraints
my $max_len =
$mcc->fetch_max_length_by_CoordSystem_feature_type($feat_cs,
$tab_name);
my $len = @coords;
for(my $i = 0; $i < $len; $i++) {
my $constraint = $orig_constraint;
......@@ -548,6 +563,13 @@ sub _slice_fetch {
"${tab_syn}.seq_region_id = " . $ids[$i] . " AND " .
"${tab_syn}.seq_region_start <= " . $coords[$i]->end() . " AND ".
"${tab_syn}.seq_region_end >= " . $coords[$i]->start();
if($max_len) {
my $min_start = $coords[$i]->start() - $max_len;
$constraint .=
" AND ${tab_syn}.seq_region_start >= $min_start";
}
my $fs = $self->generic_fetch($constraint,$mapper,$slice);
$fs = _remap($fs, $mapper, $slice);
......
......@@ -24,12 +24,13 @@ sub new {
# and cache them
#
my $sth = $self->prepare
('SELECT table_name, coord_system_id FROM meta_coord');
('SELECT table_name, coord_system_id, max_length FROM meta_coord');
$sth->execute();
while(my ($table_name, $cs_id) = $sth->fetchrow_array()) {
while(my ($table_name, $cs_id, $max_length) = $sth->fetchrow_array()) {
$self->{'_feature_cache'}->{lc($table_name)} ||= [];
push @{$self->{'_feature_cache'}->{lc($table_name)}}, $cs_id;
$self->{'_max_len_cache'}->{$cs_id}->{lc($table_name)} = $max_length;
}
$sth->finish();
......@@ -49,7 +50,7 @@ sub new {
the API to perform queries to these tables and to ensure that
features are only stored in appropriate coordinate systems.
Returntype : listref of Bio::EnsEMBL::CoordSystem objects
Exceptions : none
Exceptions : throw if name argument not provided
Caller : BaseFeatureAdaptor
=cut
......@@ -84,6 +85,36 @@ sub fetch_all_CoordSystems_by_feature_type {
=head2 fetch_max_length_by_CoordSystem_feature_type
Arg [1] : Bio::EnsEMBL::CoordSystem $cs
Arg [2] : string $table
Example : $max_len =
$mcc->fetch_max_length_by_CoordSystem_feature_type($cs,'gene');
Description: Returns the maximum length of features of a given type in
a given coordinate system.
Returntype : int or undef
Exceptions : throw on incorrect argument
Caller : BaseFeatureAdaptor
=cut
sub fetch_max_length_by_CoordSystem_feature_type {
my $self = shift;
my $cs = shift;
my $table = shift;
if(!ref($cs) || !$cs->isa('Bio::EnsEMBL::CoordSystem')) {
throw('Bio::EnsEMBL::CoordSystem argument expected');
}
throw("Table name argument is required") unless $table;
return $self->{'_max_len_cache'}->{$cs->dbID()}->{lc($table)};
}
=head2 add_feature_type
......
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