<commit_before>=head1 NAME

NestedSetAdaptor - DESCRIPTION of Object

=head1 SYNOPSIS

=head1 DESCRIPTION

=head1 CONTACT

  Contact <NAME> on implemetation/design detail: <EMAIL>
  Contact <NAME> on EnsEMBL in general: <EMAIL>

=head1 APPENDIX

The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _

=cut

package Bio::EnsEMBL::Compara::DBSQL::NCBITaxonAdaptor;

use strict;
use Bio::EnsEMBL::Utils::Exception qw(throw warning deprecate);
use Bio::EnsEMBL::Compara::NCBITaxon;

use Bio::EnsEMBL::Compara::DBSQL::NestedSetAdaptor;
our @ISA = qw(Bio::EnsEMBL::Compara::DBSQL::NestedSetAdaptor);


sub fetch_node_by_taxon_id {
  my ($self, $taxon_id) = @_;
  my $constraint = "WHERE t.taxon_id = $taxon_id";
  my ($node) = @{$self->_generic_fetch($constraint)};
  return $node;
}


sub fetch_parent_for_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 $constraint = "WHERE t.taxon_id = " . $node->_parent_id;
  my ($parent) = @{$self->_generic_fetch($constraint)};
  return $parent;
}



##################################
#
# subclass override methods
#
##################################

sub tables {
  my $self = shift;
  return [['ncbi_taxa_nodes', 't'],
          ['ncbi_taxa_names', 'n']
         ];
}


sub columns {
  my $self = shift;
  return ['t.taxon_id as node_id',
          't.parent_id',
          't.left_index',
          't.right_index',
          't.rank',
          'n.name'
          ];
}


sub default_where_clause {
  my $self = shift;
  return "t.taxon_id = n.taxon_id and n.name_class='scientific name'";
}


sub create_instance_from_rowhash {
  my $self = shift;
  my $rowhash = shift;
  
  my $node = $self->cache_fetch_by_id($rowhash->{'node_id'});
  return $node if($node);
  
  $node = new Bio::EnsEMBL::Compara::NCBITaxon;
  $self->init_instance_from_rowhash($node, $rowhash);
  
  $self->cache_add_object($node);

  return $node;
}


sub init_instance_from_rowhash {
  my $self = shift;
  my $node = shift;
  my $rowhash = shift;
  
  $self->SUPER::init_instance_from_rowhash($node, $rowhash);

  $node->name($rowhash->{'name'});
  $node->rank($rowhash->{'rank'});  
  # print("  create node : ", $node, " : "); $node->print_node;
  
  return $node;
}



1;<commit_msg>added methods:   fetch_node_by_name   fetch_node_by_genome_db_id added loading of all names into metadata tags of taxon objects<commit_after>=head1 NAME

NestedSetAdaptor - DESCRIPTION of Object

=head1 SYNOPSIS

=head1 DESCRIPTION

=head1 CONTACT

  Contact <NAME> on implemetation/design detail: <EMAIL>
  Contact <NAME> on EnsEMBL in general: <EMAIL>

=head1 APPENDIX

The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _

=cut

package Bio::EnsEMBL::Compara::DBSQL::NCBITaxonAdaptor;

use strict;
use Bio::EnsEMBL::Utils::Exception qw(throw warning deprecate);
use Bio::EnsEMBL::Compara::NCBITaxon;

use Bio::EnsEMBL::Compara::DBSQL::NestedSetAdaptor;
our @ISA = qw(Bio::EnsEMBL::Compara::DBSQL::NestedSetAdaptor);


sub fetch_node_by_taxon_id {
  my ($self, $taxon_id) = @_;
  my $constraint = "WHERE t.taxon_id = $taxon_id";
  my ($node) = @{$self->_generic_fetch($constraint)};
  return $node;
}

sub fetch_node_by_name {
  my ($self, $name) = @_;
  my $constraint = "WHERE n.name = $name";
  my ($node) = @{$self->_generic_fetch($constraint)};
  return $node;
}

sub fetch_node_by_genome_db_id {
  my ($self, $gdbID) = @_;
  my $constraint = "JOIN genome_db gdb ON ( t.taxon_id = gdb.taxon_id) 
                    WHERE gdb.genome_db_id=$gdbID";
  my ($node) = @{$self->_generic_fetch($constraint)};
  return $node;
}


sub fetch_parent_for_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 $constraint = "WHERE t.taxon_id = " . $node->_parent_id;
  my ($parent) = @{$self->_generic_fetch($constraint)};
  return $parent;
}



##################################
#
# subclass override methods
#
##################################

sub tables {
  my $self = shift;
  return [['ncbi_taxa_nodes', 't'],
          ['ncbi_taxa_names', 'n']
         ];
}


sub columns {
  my $self = shift;
  return ['t.taxon_id as node_id',
          't.parent_id',
          't.left_index',
          't.right_index',
          't.rank',
          'n.name'
          ];
}


sub default_where_clause {
  my $self = shift;
  return "t.taxon_id = n.taxon_id and n.name_class='scientific name'";
}


sub create_instance_from_rowhash {
  my $self = shift;
  my $rowhash = shift;
  
  my $node = $self->cache_fetch_by_id($rowhash->{'node_id'});
  return $node if($node);
  
  $node = new Bio::EnsEMBL::Compara::NCBITaxon;
  $self->init_instance_from_rowhash($node, $rowhash);
  $self->_load_tagvalues($node);
  
  #$self->cache_add_object($node);

  return $node;
}


sub init_instance_from_rowhash {
  my $self = shift;
  my $node = shift;
  my $rowhash = shift;
  
  $self->SUPER::init_instance_from_rowhash($node, $rowhash);

  $node->name($rowhash->{'name'});
  $node->rank($rowhash->{'rank'});
  $node->distance_to_parent(0.1);  
  # print("  create node : ", $node, " : "); $node->print_node;
  
  return $node;
}

sub _load_tagvalues {
  my $self = shift;
  my $node = shift;
  
  unless($node->isa('Bio::EnsEMBL::Compara::NCBITaxon')) {
    throw("set arg must be a [Bio::EnsEMBL::Compara::NCBITaxon] not a $node");
  }

  my $sth = $self->prepare("SELECT name_class, name from ncbi_taxa_names where taxon_id=?");
  $sth->execute($node->node_id);  
  while (my ($tag, $value) = $sth->fetchrow_array()) {
    $node->add_tag($tag,$value);
  }
  $sth->finish;
}


1;
{'fraction_non_alphanumeric': 0.17951353203151765, 'fraction_numerical': 0.002398081534772182, 'mean_word_length': 4.081810269799826, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6956010', 'n_tokens_mistral': 2286, 'n_tokens_neox': 2173, 'n_words': 455}