Bio::EnsEMBL::Compara::DBSQL ProteinTreeAdaptor
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvsRaw content
Summary
ProteinTreeAdaptor - DESCRIPTION of Object
Package variables
No package variables defined.
Included modules
Bio::EnsEMBL::Compara::AlignedMember
Bio::EnsEMBL::Compara::DBSQL::MemberAdaptor
Bio::EnsEMBL::Compara::DBSQL::NestedSetAdaptor
Bio::EnsEMBL::Compara::ProteinTree
Bio::EnsEMBL::Utils::Exception qw ( throw warning )
Inherit
Bio::EnsEMBL::Compara::DBSQL::NestedSetAdaptor
Synopsis
Description
Methods
_fetch_sequence_by_id
No description
Code
_load_tagvalues
No description
Code
_objs_from_sth
No description
Code
_store_tagvalue
No description
Code
columns
No description
Code
create_instance_from_rowhash
No description
Code
default_where_clause
No description
Code
delete_flattened_leaf
No description
Code
delete_node
No description
Code
delete_node_and_under
No description
Code
delete_nodes_not_in_tree
No description
Code
delete_tag
No description
Code
fetch_AlignedMember_by_member_id_mlssIDDescriptionCode
fetch_AlignedMember_by_member_id_root_idDescriptionCode
fetch_by_Member_root_idDescriptionCode
fetch_gene_for_peptide_member_id
No description
Code
fetch_longest_peptide_member_for_gene_member_id
No description
Code
fetch_peptides_for_gene_member_id
No description
Code
init_instance_from_rowhash
No description
Code
left_join_clause
No description
Code
merge_nodes
No description
Code
store
No description
Code
store_node
No description
Code
tables
No description
Code
update_node
No description
Code
Methods description
fetch_AlignedMember_by_member_id_mlssIDcode    nextTop
  Arg[1]     : int member_id of a peptide member (longest translation)
Arg[2] : [optional] int clusterset_id (def. 0)
Example :
my $aligned_member = $proteintree_adaptor-> fetch_AlignedMember_by_member_id_mlssID ( $member->get_longest_peptide_Member->member_id, $mlssID ); Description: Fetches from the database the protein_tree that contains the member_id Returntype : Bio::EnsEMBL::Compara::AlignedMember Exceptions : Caller :
fetch_AlignedMember_by_member_id_root_idcodeprevnextTop
  Arg[1]     : int member_id of a peptide member (longest translation)
Arg[2] : [optional] int clusterset_id (def. 0)
Example :
my $aligned_member = $proteintree_adaptor-> fetch_AlignedMember_by_member_id_root_id ( $member->get_longest_peptide_Member->member_id ); Description: Fetches from the database the protein_tree that contains the member_id Returntype : Bio::EnsEMBL::Compara::AlignedMember Exceptions : Caller :
fetch_by_Member_root_idcodeprevnextTop
  Arg[1]     : Bio::EnsEMBL::Compara::Member
Arg[2] : [optional] int clusterset_id (def. 1)
Example : $protein_tree = $proteintree_adaptor->fetch_by_Member_root_id($member);
Description: Fetches from the database the protein_tree that contains the member Returntype : Bio::EnsEMBL::Compara::ProteinTree Exceptions : Caller :
Methods code
_fetch_sequence_by_iddescriptionprevnextTop
sub _fetch_sequence_by_id {
  my $self = shift;
  return $self->db->get_MemberAdaptor->_fetch_sequence_by_id(@_);
}
_load_tagvaluesdescriptionprevnextTop
sub _load_tagvalues {
  my $self = shift;
  my $node = shift;
  
  unless($node->isa('Bio::EnsEMBL::Compara::NestedSet')) {
    throw("set arg must be a [Bio::EnsEMBL::Compara::NestedSet] not a $node");
  }

  my $sth = $self->prepare("SELECT tag,value from protein_tree_tag where node_id=?");
  $sth->execute($node->node_id);  
  while (my ($tag, $value) = $sth->fetchrow_array()) {
    $node->add_tag($tag,$value);
  }
  $sth->finish;
}
_objs_from_sthdescriptionprevnextTop
sub _objs_from_sth {
  my ($self, $sth) = @_;
  my $node_list = [];

  while(my $rowhash = $sth->fetchrow_hashref) {
    my $node = $self->create_instance_from_rowhash($rowhash);        
    push @$node_list, $node;
  }

  return $node_list;
}
_store_tagvaluedescriptionprevnextTop
sub _store_tagvalue {
  my $self = shift;
  my $node_id = shift;
  my $tag = shift;
  my $value = shift;
  
  $value="" unless(defined($value));

  my $sql = "INSERT ignore into protein_tree_tag (node_id,tag) values ($node_id,\"$tag\")";
  #print("$sql\n");
$self->dbc->do($sql); $sql = "UPDATE protein_tree_tag set value=\"$value\" where node_id=$node_id and tag=\"$tag\""; #print("$sql\n");
$self->dbc->do($sql); } ##################################
#
# subclass override methods
#
##################################
}
columnsdescriptionprevnextTop
sub columns {
  my $self = shift;
  return ['t.node_id',
          't.parent_id',
          't.root_id',
          't.left_index',
          't.right_index',
          't.distance_to_parent',
          
          'tm.cigar_line',
          'tm.cigar_start',
          'tm.cigar_end',

          @{Bio::EnsEMBL::Compara::DBSQL::MemberAdaptor->columns()}
          ];
}
create_instance_from_rowhashdescriptionprevnextTop
sub create_instance_from_rowhash {
  my $self = shift;
  my $rowhash = shift;
  
  my $node;  
  if($rowhash->{'member_id'}) {
    $node = new Bio::EnsEMBL::Compara::AlignedMember;    
  } else {
    $node = new Bio::EnsEMBL::Compara::ProteinTree;
  }
  
  $self->init_instance_from_rowhash($node, $rowhash);
  return $node;
}
default_where_clausedescriptionprevnextTop
sub default_where_clause {
  return "";
}
delete_flattened_leafdescriptionprevnextTop
sub delete_flattened_leaf {
  my $self = shift;
  my $node = shift;
  
  my $node_id = $node->node_id;
  #print("delete node $node_id\n");
# $self->dbc->do("UPDATE protein_tree_node dn, protein_tree_node n SET ".
# "n.parent_id = dn.parent_id WHERE n.parent_id=dn.node_id AND dn.node_id=$node_id");
$self->dbc->do("DELETE from protein_tree_node WHERE node_id = $node_id"); $self->dbc->do("DELETE from protein_tree_tag WHERE node_id = $node_id"); $self->dbc->do("DELETE from protein_tree_member WHERE node_id = $node_id");
}
delete_nodedescriptionprevnextTop
sub delete_node {
  my $self = shift;
  my $node = shift;
  
  my $node_id = $node->node_id;
  #print("delete node $node_id\n");
$self->dbc->do("UPDATE protein_tree_node dn, protein_tree_node n SET ". "n.parent_id = dn.parent_id WHERE n.parent_id=dn.node_id AND dn.node_id=$node_id"); $self->dbc->do("DELETE from protein_tree_node WHERE node_id = $node_id"); $self->dbc->do("DELETE from protein_tree_tag WHERE node_id = $node_id"); $self->dbc->do("DELETE from protein_tree_member WHERE node_id = $node_id");
}
delete_node_and_underdescriptionprevnextTop
sub delete_node_and_under {
  my $self = shift;
  my $node = shift;

  my @all_subnodes = $node->get_all_subnodes;
  foreach my $subnode (@all_subnodes) {
    my $subnode_id = $subnode->node_id;
    $self->dbc->do("DELETE from protein_tree_node WHERE node_id = $subnode_id");
    $self->dbc->do("DELETE from protein_tree_tag WHERE node_id = $subnode_id");
    $self->dbc->do("DELETE from protein_tree_member WHERE node_id = $subnode_id");
  }
  my $node_id = $node->node_id;
  $self->dbc->do("DELETE from protein_tree_node WHERE node_id = $node_id");
  $self->dbc->do("DELETE from protein_tree_tag WHERE node_id = $node_id");
  $self->dbc->do("DELETE from protein_tree_member WHERE node_id = $node_id");
}

###################################
#
# tagging
#
###################################
}
delete_nodes_not_in_treedescriptionprevnextTop
sub delete_nodes_not_in_tree {
  my $self = shift;
  my $tree = shift;

  unless($tree->isa('Bio::EnsEMBL::Compara::NestedSet')) {
    throw("set arg must be a [Bio::EnsEMBL::Compara::NestedSet] not a $tree");
  }
  #print("delete_nodes_not_present under ", $tree->node_id, "\n");
my $dbtree = $self->fetch_node_by_node_id($tree->node_id); my @all_db_nodes = $dbtree->get_all_subnodes; foreach my $dbnode (@all_db_nodes) { next if($tree->find_node_by_node_id($dbnode->node_id)); $self->delete_node($dbnode); } $dbtree->release_tree;
}
delete_tagdescriptionprevnextTop
sub delete_tag {
  my $self = shift;
  my $node_id = shift;
  my $tag = shift;

  my $sql = "DELETE from protein_tree_tag where node_id=$node_id and tag=\"$tag\"";
  #print("$sql\n");
$self->dbc->do($sql);
}
fetch_AlignedMember_by_member_id_mlssIDdescriptionprevnextTop
sub fetch_AlignedMember_by_member_id_mlssID {
  my ($self, $member_id, $mlss_id) = @_;
    
  my $constraint = "WHERE tm.member_id = $member_id and m.member_id = $member_id";
  $constraint .= " AND tm.method_link_species_set_id = $mlss_id" if($mlss_id and $mlss_id>0);
  my ($node) = @{$self->_generic_fetch($constraint)};
  return $node;
}


###########################
# STORE methods
###########################
}
fetch_AlignedMember_by_member_id_root_iddescriptionprevnextTop
sub fetch_AlignedMember_by_member_id_root_id {
  my ($self, $member_id, $root_id) = @_;
    
  my $constraint = "WHERE tm.member_id = $member_id and m.member_id = $member_id";
  $constraint .= " AND t.root_id = $root_id" if($root_id and $root_id>0);
  my $final_clause = "order by tm.node_id desc";
  $self->final_clause($final_clause);
  my ($node) = @{$self->_generic_fetch($constraint)};
  return $node;
}
fetch_by_Member_root_iddescriptionprevnextTop
sub fetch_by_Member_root_id {
  my ($self, $member, $root_id) = @_;
  $root_id = $root_id || 1;

  my $aligned_member = $self->fetch_AlignedMember_by_member_id_root_id
    (
     $member->get_longest_peptide_Member->member_id,
     $root_id);
  return undef unless (defined $aligned_member);
  my $node = $aligned_member->subroot;
  return undef unless (defined $node);
  my $protein_tree = $self->fetch_node_by_node_id($node->node_id);

  return $protein_tree;
}
fetch_gene_for_peptide_member_iddescriptionprevnextTop
sub fetch_gene_for_peptide_member_id {
   my $self = shift;
  return $self->db->get_MemberAdaptor->fetch_gene_for_peptide_member_id(@_);
}
fetch_longest_peptide_member_for_gene_member_iddescriptionprevnextTop
sub fetch_longest_peptide_member_for_gene_member_id {
  my $self = shift;
  return $self->db->get_MemberAdaptor->fetch_longest_peptide_member_for_gene_member_id(@_);
}


1;
}
fetch_peptides_for_gene_member_iddescriptionprevnextTop
sub fetch_peptides_for_gene_member_id {
  my $self = shift;
  return $self->db->get_MemberAdaptor->fetch_peptides_for_gene_member_id(@_);
}
init_instance_from_rowhashdescriptionprevnextTop
sub init_instance_from_rowhash {
  my $self = shift;
  my $node = shift;
  my $rowhash = shift;
  
  #SUPER is NestedSetAdaptor
$self->SUPER::init_instance_from_rowhash($node, $rowhash); if($rowhash->{'member_id'}) { Bio::EnsEMBL::Compara::DBSQL::MemberAdaptor->init_instance_from_rowhash($node, $rowhash); $node->cigar_line($rowhash->{'cigar_line'}); # cigar_start and cigar_end does not need to be set.
# $node->cigar_start($rowhash->{'cigar_start'});
# $node->cigar_end($rowhash->{'cigar_end'});
} # print(" create node : ", $node, " : "); $node->print_node;
$node->adaptor($self); return $node; } ##########################################################
#
# explicit method forwarding to MemberAdaptor
#
##########################################################
}
left_join_clausedescriptionprevnextTop
sub left_join_clause {
  return "left join protein_tree_member tm on t.node_id = tm.node_id left join member m on tm.member_id = m.member_id";
}
merge_nodesdescriptionprevnextTop
sub merge_nodes {
  my ($self, $node1, $node2) = @_;

  unless($node1->isa('Bio::EnsEMBL::Compara::NestedSet')) {
    throw("set arg must be a [Bio::EnsEMBL::Compara::NestedSet] not a $node1");
  }
  
  # printf("MERGE children from parent %d => %d\n", $node2->node_id, $node1->node_id);
my $sth = $self->prepare("UPDATE protein_tree_node SET parent_id=?, WHERE parent_id=?"); $sth->execute($node1->node_id, $node2->node_id); $sth->finish; $sth = $self->prepare("DELETE from protein_tree_node WHERE node_id=?"); $sth->execute($node2->node_id); $sth->finish;
}
storedescriptionprevnextTop
sub store {
  my ($self, $node) = @_;

  unless($node->isa('Bio::EnsEMBL::Compara::NestedSet')) {
    throw("set arg must be a [Bio::EnsEMBL::Compara::NestedSet] not a $node");
  }
  
  $self->store_node($node);
  
  # recursively do all the children
my $children = $node->children; foreach my $child_node (@$children) { $self->store($child_node); } return $node->node_id;
}
store_nodedescriptionprevnextTop
sub store_node {
  my ($self, $node) = @_;

  unless($node->isa('Bio::EnsEMBL::Compara::NestedSet')) {
    throw("set arg must be a [Bio::EnsEMBL::Compara::NestedSet] not a $node");
  }
  
  if($node->adaptor and 
     $node->adaptor->isa('Bio::EnsEMBL::Compara::DBSQL::NestedSetAdaptor') and
     $node->adaptor eq $self) 
  {
    #already stored so just update
return $self->update_node($node); } my $parent_id = 0; my $root_id = 0; if($node->parent) { $parent_id = $node->parent->node_id ; $root_id = $node->root->node_id; } #printf("inserting parent_id = %d, root_id = %d\n", $parent_id, $root_id);
my $sth = $self->prepare("INSERT INTO protein_tree_node (parent_id, root_id, left_index, right_index, distance_to_parent) VALUES (?,?,?,?,?)"); $sth->execute($parent_id, $root_id, $node->left_index, $node->right_index, $node->distance_to_parent); $node->node_id( $sth->{'mysql_insertid'} ); #printf(" new node_id %d\n", $node->node_id);
$node->adaptor($self); $sth->finish; if($node->isa('Bio::EnsEMBL::Compara::AlignedMember')) { $sth = $self->prepare("INSERT ignore INTO protein_tree_member (node_id, member_id, method_link_species_set_id, cigar_line) VALUES (?,?,?,?)"); $sth->execute($node->node_id, $node->member_id, $node->method_link_species_set_id, $node->cigar_line); $sth->finish; } return $node->node_id;
}
tablesdescriptionprevnextTop
sub tables {
  my $self = shift;
  return [['protein_tree_node', 't']];
}
update_nodedescriptionprevnextTop
sub update_node {
  my ($self, $node) = @_;

  unless($node->isa('Bio::EnsEMBL::Compara::NestedSet')) {
    throw("set arg must be a [Bio::EnsEMBL::Compara::NestedSet] not a $node");
  }
  
  my $parent_id = 0;
  if($node->parent) {
    $parent_id = $node->parent->node_id ;
  }

  my $sth = $self->prepare("UPDATE protein_tree_node SET
                              parent_id=?,
                              left_index=?,
                              right_index=?,
                              distance_to_parent=? 
                            WHERE node_id=?");
  $sth->execute($parent_id, $node->left_index, $node->right_index, 
                $node->distance_to_parent, $node->node_id);

  $node->adaptor($self);
  $sth->finish;

  if($node->isa('Bio::EnsEMBL::Compara::AlignedMember')) {
    my $sql = "UPDATE protein_tree_member SET ". 
              "cigar_line='". $node->cigar_line . "'";
    $sql .= ", cigar_start=" . $node->cigar_start if($node->cigar_start);              
    $sql .= ", cigar_end=" . $node->cigar_end if($node->cigar_end);              
    $sql .= ", method_link_species_set_id=" . $node->method_link_species_set_id if($node->method_link_species_set_id);              
    $sql .= " WHERE node_id=". $node->node_id;
    $self->dbc->do($sql);
  }
}
General documentation
CONTACTTop
  Contact Jessica Severin on implemetation/design detail: jessica@ebi.ac.uk
Contact Ewan Birney on EnsEMBL in general: birney@sanger.ac.uk
APPENDIXTop
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _