Bio-EnsEMBL

 view release on metacpan or  search on metacpan

lib/Bio/EnsEMBL/DBSQL/ProteinFeatureAdaptor.pm  view on Meta::CPAN

									  -TRANSLATION_ID  => $pf_hash_ref->{translation_id},
									  -CIGAR_STRING => $cigar_string,
									  -ALIGN_TYPE => $align_type
									  );
} ## end sub fetch_by_dbID

=head2 store

  Arg [1]    : Bio::EnsEMBL::ProteinFeature $feature
               The feature to be stored
  Arg [2]    : int $translation_id
            
  Example    : $protein_feature_adaptor->store($protein_feature);
  Description: Stores a protein feature in the database
  Returntype : int - the new internal identifier of the stored protein feature
  Exceptions : thrown if arg is not a Bio::EnsEMBL:
  Caller     : none
  Status     : Stable

=cut

sub store {
  my ($self, $feature, $translation_id) = @_;

  if (!ref($feature) || !$feature->isa('Bio::EnsEMBL::ProteinFeature')) {
    throw("ProteinFeature argument is required");
  }

  my $db = $self->db();

  if ($feature->is_stored($db)) {
    warning("ProteinFeature " . $feature->dbID() . " is already stored in " . "this database - not storing again");
  }

  my $analysis = $feature->analysis();
  if (!defined($analysis)) {
    throw("Feature doesn't have analysis. Can't write to database");
  }
  if (!$analysis->is_stored($db)) {
    $db->get_AnalysisAdaptor->store($analysis);
  }

  my $insert_ignore = $self->insert_ignore_clause();
  my @insert_cols = $self->_tbl_columns(1);  # skip pk - protein_feature_id

  my @insert_values = map { '?' } @insert_cols;
  my $insert_stmt = "${insert_ignore} INTO protein_feature (". (join ',', @insert_cols) .  ') VALUES (' . (join ',',  @insert_values) . ')';

  my $sth = $self->prepare($insert_stmt);

  my $i = 0;
  $sth->bind_param(++$i, $translation_id,        SQL_INTEGER);
  $sth->bind_param(++$i, $feature->start,        SQL_INTEGER);
  $sth->bind_param(++$i, $feature->end,          SQL_INTEGER);
  $sth->bind_param(++$i, $feature->hstart,       SQL_INTEGER);
  $sth->bind_param(++$i, $feature->hend,         SQL_INTEGER);
  $sth->bind_param(++$i, $feature->hseqname,     SQL_VARCHAR);
  $sth->bind_param(++$i, $analysis->dbID,        SQL_INTEGER);
  $sth->bind_param(++$i, $feature->score,        SQL_DOUBLE);
  $sth->bind_param(++$i, $feature->p_value,      SQL_DOUBLE);
  $sth->bind_param(++$i, $feature->percent_id,   SQL_FLOAT);
  $sth->bind_param(++$i, $feature->external_data,      SQL_VARCHAR);
  $sth->bind_param(++$i, $feature->hdescription, SQL_LONGVARCHAR);

  if ($self->schema_version > 92) {
    $sth->bind_param(++$i, $feature->cigar_string,      SQL_VARCHAR);
    $sth->bind_param(++$i, $feature->align_type,      SQL_VARCHAR);
  }

  $sth->execute();

  if (defined($sth->err) && $sth->err eq 0){ # is a warning if 0 and defined
      warning('SQL warning : ' . $sth->errstr ."\n");
  }
 
  my $dbID = $self->last_insert_id('protein_feature_id', undef, 'protein_feature');

  $feature->adaptor($self);
  $feature->dbID($dbID);

  $sth->finish();

  return $dbID;
} ## end sub store

sub _tables {
  my $self = shift;

  return (['protein_feature', 'pf'], ['interpro', 'ip'], ['xref', 'x']);
}

sub _left_join {
  return (['interpro', "pf.hit_name = ip.id"], ['xref', "x.dbprimary_acc = ip.interpro_ac"]);
}

# return columns from protein_feature table
sub _tbl_columns {
  my ($self, $skip_pk) = @_;
  $skip_pk = defined $skip_pk ? $skip_pk : 0;

  my @columns = qw(
                  protein_feature_id
                  translation_id
                  seq_start
                  seq_end
                  hit_start
                  hit_end
                  hit_name
                  analysis_id
                  score
                  evalue
                  perc_ident
                  external_data
                  hit_description
  );

  $self->schema_version > 92 and push @columns, ('cigar_line', 'align_type');
  shift @columns if $skip_pk;
  return @columns;
}



( run in 1.077 second using v1.01-cache-2.11-cpan-39bf76dae61 )