Bio::EnsEMBL::ExternalData::Family::DBSQL FamilyMemberAdaptor
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvsRaw content
Summary
FamilyAdaptor - DESCRIPTION of Object
  This object represents a database of protein families.
Package variables
No package variables defined.
Included modules
Bio::EnsEMBL::DBSQL::BaseAdaptor
Bio::EnsEMBL::ExternalData::Family::FamilyMember
Inherit
Bio::EnsEMBL::DBSQL::BaseAdaptor
Synopsis
Description
Methods
_fetch_family_members
No description
Code
fetch_by_dbIDDescriptionCode
fetch_by_dbname
No description
Code
fetch_by_dbname_taxon
No description
Code
fetch_by_family_dbname
No description
Code
fetch_by_family_dbname_taxon
No description
Code
fetch_by_family_id
No description
Code
fetch_by_stable_idDescriptionCode
get_dbname_by_external_db_id
No description
Code
get_external_db_id_by_dbname
No description
Code
storeDescriptionCode
updateDescriptionCode
Methods description
fetch_by_dbIDcode    nextTop
 Title   : fetch_by_dbID
Usage : $memberadaptor->fetch_by_dbID($id);
Function: fetches a FamilyMember given its internal database identifier
Example : $memberadaptor->fetch_by_dbID(1)
Returns : a Bio::EnsEMBL::ExternalData::Family::FamilyMember object if found,
undef otherwise
Args : an integer
fetch_by_stable_idcodeprevnextTop
 Title   : fetch_by_stable_id
Usage : $memberadaptor->fetch_by_stable_id($stable_id);
Function: fetches a FamilyMember given its stable identifier
(external_member_id)
Example : $db->fetch_by_stable_id('ENSG00000000009');
Returns : a array ref of Bio::EnsEMBL::ExternalData::Family::FamilyMembers
IMPORTANT: this method returns an array reference because the
stable_id could not be unique
i.e. the same member maybe part of more than one family
Args : an EnsEMBL Gene/Peptide stable id (e.g. ENSG00000000009) or
an Accession Number (e.g.O35622)
storecodeprevnextTop
  Arg [1]    : int family_id 
Arg [2] : Bio::EnsEMBL::ExternalData::Family::FamilyMember $member
Example : $member_id = $family_member_adaptor->store($family_id, $member);
Description: Stores a family member object in the database. On success the
family member id is returned
Returntype : int
Exceptions : thrown if incorrect argument supplied
Caller : general
updatecodeprevnextTop
  Arg [1]    : Bio::EnsEMBL::ExternalData::Family::FamilyMember
Example :
Description: Updates the attributes of a family member that has already been
stored in the database. This is useful to update attributes
such as a the alignment string which may have been calculated
after the families were alreated created. On success this
method returns the dbID of the updated member
Returntype : int
Exceptions : thrown if incorrect argument is provided
thrown if the member to be updated does not have a dbID
Caller : general
Methods code
_fetch_family_membersdescriptionprevnextTop
sub _fetch_family_members {
  my ($self, $constraint) = @_;

  my $q = "SELECT fm.family_member_id, fm.family_id, fm.external_db_id, 
                  fm.external_member_id, fm.taxon_id, fm.alignment, ex.name
           FROM family_members fm, external_db ex
           WHERE ex.external_db_id = fm.external_db_id";

  if($constraint) {
    $q .= " AND $constraint";
  }

  my $sth = $self->prepare($q);
  $sth->execute();
 
  my ($family_member_id, $family_id, $external_db_id, $external_member_id,
      $taxon_id, $alignment_string, $external_db_name);

  $sth->bind_columns(\$family_member_id,\$ family_id,\$ external_db_id,\$ 
		    external_member_id,\$ taxon_id,\$ alignment_string,\$
		    external_db_name);

  my @members;
  while($sth->fetch) {
    my $member = new Bio::EnsEMBL::ExternalData::Family::FamilyMember();
    $member->adaptor($self);
    $member->dbID($family_member_id);
    $member->family_id($family_id);
    $member->external_db_id($external_db_id);
    $member->database($external_db_name);
    $member->stable_id($external_member_id);
    $member->taxon_id($taxon_id);
    $member->alignment_string($alignment_string);
    push @members, $member;
  }

  return\@ members;
}
fetch_by_dbIDdescriptionprevnextTop
sub fetch_by_dbID {
  my ($self, $dbID) = @_;

  $self->throw("dbID arg is required\n") unless ($dbID);

  my $constraint = "fm.family_member_id = $dbID";

  my $members = $self->_fetch_family_members($constraint);

  return undef if(!@$members);

  return $members->[0];
}
fetch_by_dbnamedescriptionprevnextTop
sub fetch_by_dbname {
  my ($self,$dbname) = @_;

  $self->throw("dbname arg is required\n") unless ($dbname);

  my $constraint = "ex.name = '$dbname'";

  return $self->_fetch_family_members($constraint);
}
fetch_by_dbname_taxondescriptionprevnextTop
sub fetch_by_dbname_taxon {
  my ($self,$dbname,$taxon_id) = @_;

  $self->throw("dbname and taxon_id args are required") 
    unless($dbname && $taxon_id);

  my $constraint = "ex.name = '$dbname' and fm.taxon_id = $taxon_id";

  return $self->_fetch_family_members($constraint);
}
fetch_by_family_dbnamedescriptionprevnextTop
sub fetch_by_family_dbname {
  my ($self,$family_id,$dbname) = @_;

  $self->throw("family_id and dbname args are required") 
    unless($family_id && $dbname);

  my $constraint = "fm.family_id = $family_id and ex.name = '$dbname'";
  
  return $self->_fetch_family_members($constraint);
}
fetch_by_family_dbname_taxondescriptionprevnextTop
sub fetch_by_family_dbname_taxon {
  my ($self,$family_id,$dbname,$taxon_id) = @_;

  $self->throw("family_id, dbname and taxon_id args are required") 
    unless ($family_id && $dbname && $taxon_id);
  
  my $constraint = "fm.family_id = $family_id 
                    AND ex.name = '$dbname'
                    AND fm.taxon_id = $taxon_id";

  return $self->_fetch_family_members($constraint);
}
fetch_by_family_iddescriptionprevnextTop
sub fetch_by_family_id {
  my ($self, $family_id) = @_;

  $self->throw("family_id arg is required\n") unless ($family_id);

  my $constraint = "fm.family_id = $family_id";

  return $self->_fetch_family_members($constraint);
}
fetch_by_stable_iddescriptionprevnextTop
sub fetch_by_stable_id {
    my ($self, $stable_id) = @_; 

    $self->throw("stable_id arg is required") unless ($stable_id);

    my $constraint = "fm.external_member_id = '$stable_id'";

    return $self->_fetch_family_members($constraint);
}
get_dbname_by_external_db_iddescriptionprevnextTop
sub get_dbname_by_external_db_id {
  my ($self, $external_db_id) = @_;

  $self->throw("Should give a defined external_db_id as argument\n") 
    unless (defined $external_db_id);

  my $q = "SELECT name FROM external_db WHERE external_db_id = ?";
  $q = $self->prepare($q);
  $q->execute($external_db_id);
  my $rowhash = $q->fetchrow_hashref;

  return $rowhash->{name};
}
get_external_db_id_by_dbnamedescriptionprevnextTop
sub get_external_db_id_by_dbname {
  my ($self, $dbname) = @_;

  $self->throw("Should give a defined databasename as argument\n") 
    unless (defined $dbname);

  my $q = "SELECT external_db_id FROM external_db WHERE name = ?";
  $q = $self->prepare($q);
  $q->execute($dbname);
  my $rowhash = $q->fetchrow_hashref;

  return $rowhash->{external_db_id};
}
storedescriptionprevnextTop
sub store {
  my ($self,$family_id,$member) = @_;
  
  unless($member->isa('Bio::EnsEMBL::ExternalData::Family::FamilyMember')) {
    $self->throw(
      "member arg must be a [Bio::EnsEMBL::ExternalData::Family::FamilyMember]"
    . "not a $member");
  }

  my $sth = 
    $self->prepare("INSERT INTO family_members (family_id, external_db_id, 
                                taxon_id, external_member_id,
                                alignment) 
                    VALUES (?,?,?,?,?)");

  $sth->execute($family_id, 
		$member->external_db_id, 
		$member->taxon_id,
		$member->primary_id,
		$member->alignment_string);

  $member->dbID( $sth->{'mysql_insertid'} );
  $member->adaptor($self);
  if (defined $member->taxon) {
    $self->db->get_TaxonAdaptor->store_if_needed($member->taxon);
  }
  return $member->dbID;
}
updatedescriptionprevnextTop
sub update {
  my ($self, $member) = @_;

  unless($member->isa('Bio::EnsEMBL::ExternalData::Family::FamilyMember')) {
    $self->throw(
      "member arg must be a [Bio::EnsEMBL::ExternalData::Family::FamilyMember".
      "not a [$member]");
  }

  unless($member->dbID) {
    $self->throw("Family member does not have a dbID and cannot be updated");
  }

  my $sth = 
    $self->prepare("UPDATE family_members 
                    SET    family_id = ?, 
                           external_db_id = ?, 
                           external_member_id = ?, 
                           taxon_id = ?, 
                           alignment = ?
                    WHERE  family_member_id = ?");

  $sth->execute($member->family_id, $member->external_db_id, 
                $member->primary_id, $member->taxon_id, 
                $member->alignment_string, $member->dbID);

  return $member->dbID;
}


1;
}
General documentation
CONTACTTop
APPENDIXTop