Skip to content
Snippets Groups Projects
Commit cc91660c authored by Graham McVicker's avatar Graham McVicker
Browse files

more work on AttributeAdaptor, still incomplete

parent 227ae696
No related branches found
No related tags found
No related merge requests found
......@@ -78,32 +78,40 @@ sub new {
=head2 fetch_all_by_MiscFeature
Arg [1] : none, string, int, Bio::EnsEMBL::Example $formal_parameter_name
Additional description lines
list, listref, hashref
Example : ( optional )
Description: testable description
Returntype : none, txt, int, float, Bio::EnsEMBL::Example
Exceptions : none
Caller : object::methodname or just methodname
Arg [1] : Bio::EnsEMBL::MiscFeature $mf
Example : @attributes = @{$attrib_adaptor->fetch_all_by_MiscFeature($mf)};
Description: Fetches all attributes for a given MiscFeature
Returntype : Bio::EnsEMBL::Attribute
Exceptions : throw if incorrect arguments
throw if provided MiscFeature does not have a dbID
Caller : MiscFeature
=cut
sub fetch_all_by_MiscFeature {
my $self = shift;
my $mf = shift;
}
=head2 fetch_all_by_Slice
Arg [1] : none, string, int, Bio::EnsEMBL::Example $formal_parameter_name
Additional description lines
list, listref, hashref
Example : ( optional )
Description: testable description
Returntype : none, txt, int, float, Bio::EnsEMBL::Example
Exceptions : none
Caller : object::methodname or just methodname
Arg [1] : Bio::EnsEMBL::Slice $slice
Example : @attributes = @{$attrib_adaptor->fetch_all_by_Slice($slice)};
Description: Fetches all attributes for a given sequence region (which the
passed in slice is on)
Returntype : Bio::EnsEMBL::Attribute
Exceptions : throw if incorrect arguments
throw if cannot get seq_region_id from provided Slice
Caller : Slice
=cut
sub fetch_all_by_Slice {
my $self = shift;
my $slice = shift;
}
=head2 fetch_all_types
......@@ -127,49 +135,54 @@ sub fetch_all_types {
=head2 store_on_Slice
Arg [1] : Bio::EnsEMBL::Slice $slice
Example : ( optional )
Description: testable description
Returntype : none, txt, int, float, Bio::EnsEMBL::Example
Exceptions : none
Caller : object::methodname or just methodname
Arg [2] : listref of Bio::EnsEMBL::Attribute objects $attribs
Example : $attribute_adaptor->store_on_Slice($slice, \@attribs);
Description: Stores a set of attributes on a sequence region given a
Slice object which is on the seq_region for which attributes are
being stored.
Returntype : none
Exceptions : throw if $slice argument not provided
Caller : general
=cut
sub store_on_Slice {
my $self = shift;
my $slice = shift;
my $self = shift;
my $slice = shift;
my $attribs = shift;
# need to access directly to prevent lazy loading
my $attributes = $slice->{'???????'};
if(!ref($slice) || !$slice->isa('Bio::EnsEMBL::Slice')) {
throw("Slice argument expected.");
}
if( ! defined $attributes ) {
return;
if(ref($attribs) ne 'ARRAY') {
throw("Reference to list of Bio::EnsEMBL::Attribute objects " .
"argument expected.");
}
my $seq_region_id = $slice->get_seq_region_id();
if( ! defined $seq_region_id ) {
throw( );
if(!$seq_region_id) {
throw("Could not get seq_region_id for provided slice: " $slice->name());
}
my $sth = $self->prepare( "INSERT into seq_region_attrib ".
"SET seq_region_id = ?, attrib_type_id = ?, ".
"value = ? " );
"SET seq_region_id = ?, attrib_type_id = ?, ".
"value = ? " );
for my $attrib ( @$attributes ) {
my $attrib_id = $self->_store_type( $attrib );
$sth->excute( $seq_region_id, $attrib_id, $attrib->value() );
foreach my $at ( @$attribs ) {
if(!ref($at) && $at->isa('Bio::EnsEMBL::Attribute')) {
throw("Reference to list of Bio::EnsEMBL::Attribute objects " .
"argument expected.");
}
my $atid = $self->_store_type( $at );
$sth->execute( $seq_region_id, $attrib_id, $attrib->value() );
}
return;
}
......@@ -178,40 +191,49 @@ sub store_on_Slice {
=head2 store_on_MiscFeature
Arg [1] : Bio::EnsEMBL::MiscFeature $feature
Example : $attribute_adaptor->store_on_MiscFeature( $my_misc_feature )
Example : $attribute_adaptor->store_on_MiscFeature($my_misc_feature,
$attributes)
Description: Stores all the attributes on the misc feature.
Will duplicate things if called twice.
Returntype : none
Exceptions : on database problems.
Exceptions : throw on incorrect arguments
throw if provided feature is not stored in this database
Caller : general, MiscFeatureAdaptor
=cut
sub store_on_MiscFeature {
my $self = shift;
my $feature = shift;
# need to access directly to prevent lazy loading
my $attributes = $feature->{'attributes'};
my $self = shift;
my $feature = shift;
my $attributes = shift;
if( ! defined $attributes ) {
return;
if(!ref($feature) || !$feature->isa('Bio::EnsEMBL::MiscFeature')) {
throw("MiscFeature argument expected");
}
my $feature_id = $feature->dbID();
if(ref($attributes) ne 'ARRAY') {
throw("Reference to list of Bio::EnsEMBL::Attribute objects argument " .
"expected");
}
if( ! defined $feature_id ) {
throw("dbID in feature is not set.".
"Need to store feature before storeing attributes.\n" );
my $db = $self->db();
if(!$feature->is_stored($db)) {
throw("MiscFeature is not stored in this DB - cannot store attributes.");
}
my $feature_id = $feature->dbID();
my $sth = $self->prepare( "INSERT into misc_attrib ".
"SET misc_feature_id = ?, attrib_type_id = ?, ".
"value = ? " );
for my $attrib ( @$attributes ) {
my $attrib_id = $self->_store_type( $attrib );
$sth->excute( $feature_id, $attrib_id, $attrib->value() );
if(!ref($at) && $at->isa('Bio::EnsEMBL::Attribute')) {
throw("Reference to list of Bio::EnsEMBL::Attribute objects " .
"argument expected.");
}
my $atid = $self->_store_type( $attrib );
$sth->execute( $feature_id, $atid, $attrib->value() );
}
return;
......@@ -225,7 +247,6 @@ sub _store_type {
my $self = shift;
my $attrib = shift;
my $sth = $self->prepare
("INSERT IGNORE INTO attrib_type set code = ?, name = ?, ".
"description = ?" );
......@@ -236,7 +257,7 @@ sub _store_type {
$sth->finish();
if( $self->db->db_handle->{'mysql_info'} == 0 ){
if( $self->db->db_handle->{'mysql_info'} == 0 ) {
# the insert failed because the code is already stored
$sth = $self->prepare
("SELECT attrib_type_id FROM attrib_type " .
......@@ -248,7 +269,7 @@ sub _store_type {
if(!$atid) {
throw("Could not store or fetch attrib_type code [$code]\n" .
"Wrong permissions?");
"Wrong database user/permissions?");
}
}
......
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