<commit_before>=head1 LICENSE                                                                                                                                                                                
  Copyright (c) 1999-2011 The European Bioinformatics Institute and
  Genome Research Limited.  All rights reserved.

  This software is distributed under a modified Apache license.
  For license details, please see

   http://www.ensembl.org/info/about/code_licence.html

=head1 CONTACT

  Please email comments or questions to the public Ensembl
  developers list at <<EMAIL>>.

  Questions may also be sent to the Ensembl help desk at
  <<EMAIL>>.

=head1 NAME

Bio::EnsEMBL::Compara::DBSQL::CAFEGeneFamilyAdaptor

=head1 SYNOPSIS


=head1 DESCRIPTION

  CAFEGeneFamilyAdaptor - Information about CAFE gene families


=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::CAFEGeneFamilyAdaptor;

use strict;
use Data::Dumper;
use Bio::EnsEMBL::Utils::Exception qw/throw warning/;
use Bio::EnsEMBL::Compara::CAFEGeneFamily;

use base ('Bio::EnsEMBL::Compara::DBSQL::NestedSetAdaptor');

sub fetch_all {
    my ($self, $lca) = @_;

    my $constraint = "stn.node_id = str.root_id";

    if (defined $lca) {
        my $sth = $self->prepare("SELECT node_id FROM species_tree_node_tag WHERE tag ='taxon_id' AND value = ?");
        $sth->execute($lca);
        my ($lca_id) = $sth->fetchrow_array();
        $constraint .= " AND cgf.lca_id = $lca_id";
    }

    return $self->generic_fetch($constraint);
}

sub fetch_by_GeneTree {
    my ($self, $geneTree) = @_;
    unless ($geneTree->isa('Bio::EnsEMBL::Compara::GeneTree')) {
        throw("set arg must be a [Bio::EnsEMBL::Compara::GeneTree] not a $geneTree");
    }
    my $node_id = $geneTree->root_id();

    return $self->fetch_by_gene_tree_root_id($node_id);
}

sub fetch_by_gene_tree_root_id {
    my ($self, $gene_tree_root_id) = @_;
    unless (defined $gene_tree_root_id) {
        throw("gene_tree_root_id must be defined");
    }
    my $constraint = "cgf.gene_tree_root_id = $gene_tree_root_id AND str.root_id = stn.root_id";
    my $trees = $self->generic_fetch($constraint);

    if (scalar @$trees > 1) {
        throw ("Too many trees returned by fetch_by_gene_tree_root_id (only 1 expected)\n");
    }
    return $trees->[0];
}

sub fetch_all_children_for_node {
    my ($self, $node) = @_;

    my $gene_tree_root_id = $node->gene_tree_root_id();

    my $constraint = "parent_id = " . $node->node_id;<commit_msg>fixed bug in fetch_by_gene_tree_root_id (wrong constraint)<commit_after>=head1 LICENSE                                                                                                                                                                                
  Copyright (c) 1999-2011 The European Bioinformatics Institute and
  Genome Research Limited.  All rights reserved.

  This software is distributed under a modified Apache license.
  For license details, please see

   http://www.ensembl.org/info/about/code_licence.html

=head1 CONTACT

  Please email comments or questions to the public Ensembl
  developers list at <<EMAIL>>.

  Questions may also be sent to the Ensembl help desk at
  <<EMAIL>>.

=head1 NAME

Bio::EnsEMBL::Compara::DBSQL::CAFEGeneFamilyAdaptor

=head1 SYNOPSIS


=head1 DESCRIPTION

  CAFEGeneFamilyAdaptor - Information about CAFE gene families


=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::CAFEGeneFamilyAdaptor;

use strict;
use Data::Dumper;
use Bio::EnsEMBL::Utils::Exception qw/throw warning/;
use Bio::EnsEMBL::Compara::CAFEGeneFamily;

use base ('Bio::EnsEMBL::Compara::DBSQL::NestedSetAdaptor');

sub fetch_all {
    my ($self, $lca) = @_;

    my $constraint = "stn.node_id = str.root_id";

    if (defined $lca) {
        my $sth = $self->prepare("SELECT node_id FROM species_tree_node_tag WHERE tag ='taxon_id' AND value = ?");
        $sth->execute($lca);
        my ($lca_id) = $sth->fetchrow_array();
        $constraint .= " AND cgf.lca_id = $lca_id";
    }

    return $self->generic_fetch($constraint);
}

sub fetch_by_GeneTree {
    my ($self, $geneTree) = @_;
    unless ($geneTree->isa('Bio::EnsEMBL::Compara::GeneTree')) {
        throw("set arg must be a [Bio::EnsEMBL::Compara::GeneTree] not a $geneTree");
    }
    my $node_id = $geneTree->root_id();

    return $self->fetch_by_gene_tree_root_id($node_id);
}

sub fetch_by_gene_tree_root_id {
    my ($self, $gene_tree_root_id) = @_;
    unless (defined $gene_tree_root_id) {
        throw("gene_tree_root_id must be defined");
    }
    my $constraint = "cgf.gene_tree_root_id = $gene_tree_root_id AND str.root_id = stn.root_id AND csg.node_id = stn.root_id";
    my $trees = $self->generic_fetch($constraint);

    if (scalar @$trees > 1) {
        throw ("Too many trees returned by fetch_by_gene_tree_root_id (only 1 expected)\n");
    }
    return $trees->[0];
}

sub fetch_all_children_for_node {
    my ($self, $node) = @_;

    my $gene_tree_root_id = $node->gene_tree_root_id();

    my $constraint = "parent_id = " . $node->node_id;
{'fraction_non_alphanumeric': 0.11526127145821544, 'fraction_numerical': 0.006413884172797585, 'mean_word_length': 2.968562874251497, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2139935', 'n_tokens_mistral': 1848, 'n_tokens_neox': 1713, 'n_words': 429}