sub add_feature_type
{ my $self = shift;
my $cs = shift;
my $table = lc(shift);
my $length = shift;
if(!ref($cs) || !$cs->isa('Bio::EnsEMBL::CoordSystem')) {
throw('CoordSystem argument is required.');
}
if(!$table) {
throw('Table argument is required.');
}
my $cs_ids = $self->{'_feature_cache'}->{$table} || [];
my ($exists) = grep {$cs->dbID() == $_} @$cs_ids;
if( $exists ) {
if( !$self->{'_max_len_cache'}->{$cs->dbID()}->{$table} ||
$self->{'_max_len_cache'}->{$cs->dbID()}->{$table} < $length ) {
my $sth = $self->prepare('UPDATE meta_coord ' .
"SET max_length = $length " .
'WHERE coord_system_id = ? ' .
'AND table_name = ? '.
"AND (max_length<$length ".
"OR max_length is null)");
$sth->execute( $cs->dbID(), $table );
$self->{'_max_len_cache'}->{$cs->dbID()}->{$table} = $length;
}
return;
}
my $sth = $self->prepare('INSERT IGNORE INTO meta_coord ' .
'SET coord_system_id = ?, ' .
'table_name = ?, ' .
'max_length = ? '
);
$sth->execute($cs->dbID, $table, $length );
$self->{'_feature_cache'}->{$table} ||= [];
push @{$self->{'_feature_cache'}->{$table}}, $cs->dbID();
$self->{'_max_len_cache'}->{$cs->dbID()}->{$table} = $length;
return;
}
1; } |
sub fetch_all_CoordSystems_by_feature_type
{ my $self = shift;
my $table = lc(shift);
throw('Name argument is required') unless $table;
if(!$self->{'_feature_cache'}->{$table}) {
return [];
}
my @cs_ids = @{$self->{'_feature_cache'}->{$table}};
my @coord_systems;
my $csa = $self->db->get_CoordSystemAdaptor();
foreach my $cs_id (@cs_ids) {
my $cs = $csa->fetch_by_dbID($cs_id);
if(!$cs) {
throw("meta_coord table refers to non-existant coord_system $cs_id");
}
push @coord_systems, $cs;
}
return\@ coord_systems; } |
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)}; } |
sub new
{ my $class = shift;
my $self = $class->SUPER::new(@_);
my @coord_systems =
@{ $self->db()->dnadb()->get_CoordSystemAdaptor->fetch_all() };
my @cs_ids;
foreach my $cs (@coord_systems) { push( @cs_ids, $cs->dbID() ) }
my $sth = $self->prepare(
'SELECT mc.table_name, mc.coord_system_id, mc.max_length '
. 'FROM meta_coord mc '
. 'WHERE mc.coord_system_id in ('
. join( ',', @cs_ids )
. ')' );
$sth->execute();
while ( my ( $table_name, $cs_id, $max_length ) =
$sth->fetchrow_array() )
{
$table_name = lc($table_name);
$self->{'_feature_cache'}->{$table_name} ||= [];
push( @{ $self->{'_feature_cache'}->{$table_name} }, $cs_id );
$self->{'_max_len_cache'}->{$cs_id}->{$table_name} = $max_length;
}
$sth->finish();
return $self;
}
} |