diff --git a/modules/Bio/EnsEMBL/DBSQL/ProteinFeatureAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/ProteinFeatureAdaptor.pm index 0ca989431d24966fcb2a60e67ebc29a653791ad4..093c0eba90ca30ce72ea8c8efbf396171cc63174 100755 --- a/modules/Bio/EnsEMBL/DBSQL/ProteinFeatureAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/ProteinFeatureAdaptor.pm @@ -49,7 +49,7 @@ use strict; use Bio::EnsEMBL::DBSQL::BaseAdaptor; use Bio::EnsEMBL::ProteinFeature; use Bio::EnsEMBL::Utils::Exception qw(throw deprecate warning); - +use Data::Dumper; use vars qw(@ISA); @ISA = qw(Bio::EnsEMBL::DBSQL::BaseAdaptor); @@ -300,5 +300,71 @@ sub fetch_all_by_feature_and_dbID { return \@out; } + +sub save { + + my ($self, $features) = @_; + + my @feats = @$features; + throw("Must call save with features") if( scalar(@feats) == 0 ); + +# my @tabs = $self->_tables; +# my ($tablename) = @{$tabs[0]}; + my $tablename = 'protein_feature'; + + my $db = $self->db(); + my $analysis_adaptor = $db->get_AnalysisAdaptor(); + + my $sql = qq{INSERT INTO $tablename (translation_id, seq_start, seq_end, hit_start, hit_end, hit_id, analysis_id, score, evalue, perc_ident, extra_data) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}; + + my $sth = $self->prepare($sql); + + foreach my $feat ( @feats ) { + if( !ref $feat || !$feat->isa("Bio::EnsEMBL::ProteinFeature") ) { + throw("feature must be a Bio::EnsEMBL::ProteinFeature,". " not a [".ref($feat)."]."); + } + + if($feat->is_stored($db)) { + warning("ProteinFeature [".$feat->dbID."] is already stored" . + " in this database."); + next; + } + + my $hstart = defined $feat->hstart ? $feat->hstart : $feat->start ; + my $hend = defined $feat->hend ? $feat->hend : $feat->end; + + if(!defined($feat->analysis)) { + throw("An analysis must be attached to the features to be stored."); + } + + #store the analysis if it has not been stored yet + if(!$feat->analysis->is_stored($db)) { + $analysis_adaptor->store($feat->analysis()); + } + + my $original = $feat; + my $extra_data = $feat->extra_data ? $self->dump_data($feat->extra_data) : ''; + + $sth->bind_param(1,$feat->translation_id,SQL_INTEGER); + $sth->bind_param(2,$feat->start,SQL_INTEGER); + $sth->bind_param(3,$feat->end,SQL_INTEGER); + $sth->bind_param(4,$hstart,SQL_INTEGER); + $sth->bind_param(5,$hend,SQL_INTEGER); + $sth->bind_param(6,$feat->hseqname,SQL_VARCHAR); + $sth->bind_param(7,$feat->analysis->dbID,SQL_INTEGER); + $sth->bind_param(8,$feat->score,SQL_DOUBLE); + $sth->bind_param(9,$feat->p_value,SQL_DOUBLE); + $sth->bind_param(10,$feat->percent_id,SQL_FLOAT); + $sth->bind_param(11,$extra_data,SQL_LONGVARCHAR); + + $sth->execute(); + $original->dbID($sth->{'mysql_insertid'}); + $original->adaptor($self); + } + + $sth->finish(); +} + + 1;