Bio-EnsEMBL

 view release on metacpan or  search on metacpan

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

               - we should have a much more structured system than this.
  Returntype : listref of strings (Interpro_acc:description)
  Exceptions : none 
  Caller     : domainview
  Status     : Stable

=cut

sub get_Interpro_by_geneid {
  my ($self, $gene_stable_id) = @_;

  my $sql = qq(
  SELECT    i.interpro_ac,
            x.description
  FROM      transcript t,
            translation tl,
            protein_feature pf,
            interpro i,
            xref x,
            gene g
  WHERE     g.stable_id = ?
    AND     t.gene_id = g.gene_id
    AND     t.is_current = 1
    AND     tl.transcript_id = t.transcript_id
    AND     tl.translation_id = pf.translation_id
    AND     i.id = pf.hit_name
    AND     i.interpro_ac = x.dbprimary_acc);

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

  $sth->bind_param(1, $gene_stable_id, SQL_VARCHAR);

  $sth->execute;

  my @out;
  my %h;
  while ((my $arr = $sth->fetchrow_arrayref())) {
    if ($h{$arr->[0]}) { next; }
    $h{$arr->[0]} = 1;
    my $string = $arr->[0] . ":" . $arr->[1];
    push(@out, $string);
  }

  return \@out;
} ## end sub get_Interpro_by_geneid

=head2 update

  Arg [1]    : Bio::EnsEMBL::Gene $gene
               The gene to update
  Example    : $gene_adaptor->update($gene);
  Description: Updates the type, analysis, display_xref, is_current and
               description of a gene in the database.
  Returntype : None
  Exceptions : thrown if the $gene is not a Bio::EnsEMBL::Gene
  Caller     : general
  Status     : Stable

=cut

sub update {
  my ($self, $gene) = @_;
  my $update = 0;

  if (!defined $gene || !ref $gene || !$gene->isa('Bio::EnsEMBL::Gene')) {
    throw("Must update a gene object, not a $gene");
  }

  # Get old canonical transcript id
  my $sth = $self->prepare("SELECT canonical_transcript_id FROM gene WHERE gene_id=?");
  $sth->execute($gene->dbID());
  my ($old_canonical_transcript_id) = $sth->fetchrow_array();
  $sth->finish();

  my $update_gene_sql = qq(
       UPDATE gene
          SET stable_id = ?,
              biotype = ?,
              analysis_id = ?,
              display_xref_id = ?,
              description = ?,
              is_current = ?,
              canonical_transcript_id = ?,
              version = ?
        WHERE gene_id = ?
  );

  my $display_xref = $gene->display_xref();
  my $display_xref_id;

  if ($display_xref && $display_xref->dbID()) {
    $display_xref_id = $display_xref->dbID();
  } else {
    $display_xref_id = undef;
  }

  $sth = $self->prepare($update_gene_sql);

  $sth->bind_param(1, $gene->stable_id(),      SQL_VARCHAR);
  $sth->bind_param(2, $gene->get_Biotype->name, SQL_VARCHAR);
  $sth->bind_param(3, $gene->analysis->dbID(), SQL_INTEGER);
  $sth->bind_param(4, $display_xref_id,        SQL_INTEGER);
  $sth->bind_param(5, $gene->description(),    SQL_VARCHAR);
  $sth->bind_param(6, $gene->is_current(),     SQL_TINYINT);

  if (defined($gene->canonical_transcript())) {
    $sth->bind_param(7, $gene->canonical_transcript()->dbID(), SQL_INTEGER);
  } else {
    $sth->bind_param(7, 0, SQL_INTEGER);
  }
  $sth->bind_param(8, $gene->version(), SQL_TINYINT);
  $sth->bind_param(9, $gene->dbID(), SQL_INTEGER);

  $sth->execute();

  if (defined($gene->canonical_transcript())) {
    my $transcript_adaptor = $self->db()->get_TranscriptAdaptor();
    $transcript_adaptor->update_canonical_attribute($gene->canonical_transcript()->dbID(), $old_canonical_transcript_id);
  }

} ## end sub update


=head2 update_coords

  Arg [1]    : Bio::EnsEMBL::Gene $gene
               The gene to update
  Example    : $gene_adaptor->update_coords($gene);
  Description: In the event of a transcript being removed, coordinates for the Gene
               need to be reset, but update() does not do this. update_coords 
               fills this niche
  Returntype : None
  Exceptions : thrown if the $gene is not supplied
  Caller     : general

=cut

sub update_coords {
  my ($self, $gene) = @_;
  throw('Must have a gene to update in order to update it') unless ($gene);
  $gene->recalculate_coordinates;
  my $update_sql = qq(
    UPDATE gene
       SET seq_region_start = ?,
           seq_region_end = ?
       WHERE gene_id = ?
    );
  my $sth = $self->prepare($update_sql);
  $sth->bind_param(1, $gene->seq_region_start);
  $sth->bind_param(2, $gene->seq_region_end);
  $sth->bind_param(3, $gene->dbID);
  $sth->execute();
}

# _objs_from_sth

#  Arg [1]    : StatementHandle $sth
#  Arg [2]    : Bio::EnsEMBL::AssemblyMapper $mapper
#  Arg [3]    : Bio::EnsEMBL::Slice $dest_slice
#  Description: PROTECTED implementation of abstract superclass method.
#               responsible for the creation of Genes
#  Returntype : listref of Bio::EnsEMBL::Genes in target coordinate system
#  Exceptions : none
#  Caller     : internal
#  Status     : Stable

sub _objs_from_sth {
  my ($self, $sth, $mapper, $dest_slice) = @_;

  #
  # This code is ugly because an attempt has been made to remove as many
  # function calls as possible for speed purposes.  Thus many caches and
  # a fair bit of gymnastics is used.
  #

  my $sa             = $self->db()->get_SliceAdaptor();
  my $aa             = $self->db()->get_AnalysisAdaptor();
  my $dbEntryAdaptor = $self->db()->get_DBEntryAdaptor();

  my @genes;
  my %analysis_hash;
  my %slice_hash;
  my %sr_name_hash;
  my %sr_cs_hash;

  my (
    $gene_id,                 $seq_region_id,     $seq_region_start,
    $seq_region_end,          $seq_region_strand, $analysis_id,
    $biotype,                 $display_xref_id,   $gene_description,
    $source,                  $is_current,
    $canonical_transcript_id, $stable_id,         $version,
    $created_date,            $modified_date,     $xref_display_label,
    $xref_primary_acc,        $xref_description,  $xref_version,
    $external_db,             $external_status,   $external_release,
    $external_db_name,        $info_type,         $info_text
  );

  $sth->bind_columns(\(



( run in 0.477 second using v1.01-cache-2.11-cpan-f56aa216473 )