Commit 1289dac2 authored by Graham McVicker's avatar Graham McVicker
Browse files

Added remove method for database feature removal to the BaseFeatureAdaptor

parent aef7c979
......@@ -247,7 +247,7 @@ sub transform{
sub dbID{
my ($self, $arg) = @_;
if($arg){
if(defined $arg){
$self->{_database_id} = $arg;
}
......
......@@ -586,6 +586,48 @@ sub store{
}
=head2 remove
Arg [1] : A feature $feature
Example : $feature_adaptor->remove($feature);
Description: This removes a feature from the database. The table the
feature is removed from is defined by the abstract method
_tablename, and the primary key of the table is assumed
to be _tablename() . '_id'. The feature argument must
be an object implementing the dbID method, and for the
feature to be removed from the datasbase a dbID value must
be returned.
Returntype : none
Exceptions : thrown if $feature arg does not implement dbID(), or if
$feature->dbID is not a true value
Caller : general
=cut
sub remove {
my ($self, $feature) = @_;
unless($feature->can('dbID')) {
$self->throw("Feature [$feature] does not implement method dbID");
}
unless($feature->dbID) {
$self->warn("BaseFeatureAdaptor::remove - dbID not defined - " .
"feature could not be removed");
}
my $table = $self->_tablename();
my $sth = $self->prepare("DELETE FROM $table WHERE ${table}_id = ?");
$sth->execute($feature->dbID());
#unset the feature dbID
$feature->dbID('');
return;
}
=head2 _tablename
Args : none
......@@ -629,7 +671,7 @@ sub _columns {
}
=head2 _obj_from_hashref
=head2 _objs_from_sth
Arg [1] : DBI::row_hashref $hashref containing key-value pairs
for each of the columns specified by the _columns method
......@@ -643,7 +685,7 @@ sub _columns {
=cut
sub _obj_from_hashref {
sub _objs_from_sth {
my $self = shift;
$self->throw("abstract method _obj_from_hashref not defined by implementing"
......
......@@ -120,7 +120,7 @@ sub store {
my $tablename = $self->_tablename();
if( scalar(@sf) == 0 ) {
$self->throw("Must call store with contig_id then sequence features");
$self->throw("Must call store with sequence features");
}
my $sth = $self->prepare("
......
......@@ -52,7 +52,7 @@ use vars qw(@ISA);
Arg [1] : string $constraint
Arg [2] : string $logic_name
Example :
Example : none
Description: Overrides the Bio::EnsEMBL::DNAAlignFeatureAdaptor generic_fetch
method. Normally requests will still be forwarded to the
core (primary) database with the exception of requests that
......@@ -76,12 +76,85 @@ sub generic_fetch {
return $est_adaptor->generic_fetch($constraint, $logic_name);
}
}
#use the core adaptor
return $self->{'_primary_adaptor'}->generic_fetch($constraint, $logic_name);
}
=head2 store
Arg [1] : Bio::EnsEMBL::DnaDnaAlignFeature $feature
Example : none
Description: overrides the store method to ensure that the est database
is used to store ex_e2g_features
Returntype : see DnaAlignFeatureAdaptor::store
Exceptions : none
Caller : general
=cut
sub store {
my ($self, @sfs) = @_;
my $est_features = [];
my $core_features = [];
my $est_db = $self->db()->get_db_adaptor('est');
if(defined $est_db) {
foreach my $f (@sfs) {
if($f->analysis() && $f->analysis()->logic_name() eq 'ex_e2g_feat') {
push @$est_features, $f;
} else {
push @$core_features, $f;
}
#forward request to the EST db
my $est_adaptor = $est_db->get_DnaAlignFeatureAdaptor();
if(scalar @$est_features) {
$est_adaptor->store(@$est_features);
}
if(scalar @$core_features) {
$self->{'_primary_adaptor'}->store(@$core_features);
}
}
}
#use the core adaptor
return $self->{'_primary_adaptor'}->store(@sfs);
}
=head2 remove
Arg [1] : Bio::EnsEMBL::DnaDnaAlignFeature $feature
Example : none
Description: overrides the remove method to ensure that the est database
is used to remove ex_e2g_features
Returntype : none
Exceptions : none
Caller : general
=cut
sub remove {
my ($self, $feature) = @_;
if($feature && $feature->analysis &&
$feature->analysis()->logic_name() eq 'ex_e2g_feat') {
my $est_db = $self->db()->get_db_adaptor('est');
if(defined $est_db) {
#forward request to the EST db
my $est_adaptor = $est_db->get_DnaAlignFeatureAdaptor();
return $est_adaptor->remove($feature);
}
}
#use the core adaptor
return $self->{'_primary_adaptor'}->remove($feature);
}
......
......@@ -69,7 +69,7 @@ sub get_RepeatConsensus {
sub dbID {
my( $self, $db_id ) = @_;
if ($db_id) {
if (defined $db_id) {
$self->{'_db_id'} = $db_id;
}
return $self->{'_db_id'};
......
......@@ -77,7 +77,7 @@ sub display_label{
sub dbID{
my ($self, $arg) = @_;
if($arg){
if(defined $arg){
$self->{_database_id} = $arg;
}
......
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