<commit_before>=head1 LICENSE

  Copyright (c) 1999-2012 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>>.

=cut

=head1 NAME

Bio::EnsEMBL::Compara::RunnableDB::GeneTrees::GeneGainLossCommon

=head1 SYNOPSIS

=head1 DESCRIPTION

This RunnableDB calculates the dynamics of a GeneTree family (based on the tree obtained and the CAFE software) in terms of gains losses per branch tree. It needs a CAFE-compliant species tree.

=head1 INHERITANCE TREE

Bio::EnsEMBL::Compara::RunnableDB::BaseRunnable

=head1 APPENDIX

The rest of the documentation details each of the object methods.
Internal methods are usually preceded with an underscore (_)

=cut

package Bio::EnsEMBL::Compara::RunnableDB::GeneTrees::GeneGainLossCommon;

use strict;
use warnings;
use Data::Dumper;
use Bio::EnsEMBL::Compara::Graph::NewickParser;
use base ('Bio::EnsEMBL::Compara::RunnableDB::BaseRunnable');

sub get_tree_string_from_mlss_tag {
    my ($self) = @_;
    my $mlss_id = $self->param('mlss_id');

    my $sql = "SELECT value FROM method_link_species_set_tag WHERE tag = 'cafe_tree_string' AND method_link_species_set_id = ?";
    my $sth = $self->compara_dba->dbc->prepare($sql);
    $sth->execute($mlss_id);

    my ($cafe_tree_string) = $sth->fetchrow_array();
    $sth->finish;
    print STDERR "CAFE_TREE_STRING: $cafe_tree_string\n" if ($self->debug());
    return $cafe_tree_string;
}

sub get_cafe_tree_from_string {
    my ($self) = @_;
    my $cafe_tree_string = $self->param('cafe_tree_string');
    print STDERR "$cafe_tree_string\n" if ($self->debug());
    my $cafe_tree = Bio::EnsEMBL::Compara::Graph::NewickParser::parse_newick_into_tree($cafe_tree_string);
    $self->param('cafe_tree', $cafe_tree);
    return;
}

sub load_split_genes {
    my ($self) = @_;
    my $member_id_to_gene_split_id;
    my $gene_split_id_to_member_ids;
    my $sql = "SELECT member_id, gene_split_id FROM split_genes";
    my $sth = $self->compara_dba->dbc->prepare($sql);
    $sth->execute();
    my $n_split_genes = 0;
    while (my ($member_id, $gene_split_id) = $sth->fetchrow_array()) {
        $n_split_genes++;
        $member_id_to_gene_split_id->{$member_id} = $gene_split_id;
        push @{$gene_split_id_to_member_ids->{$gene_split_id}}, $member_id;
    }
    if ($n_split_genes == 0) {
        $self->param('no_split_genes', 1);
    }
    $self->param('member_id_to_gene_split_id', $member_id_to_gene_split_id);
    $self->param('gene_split_id_to_member_ids', $gene_split_id_to_member_ids);

    return;
}

sub filter_split_genes {
    my ($self, $all_members) = @_;
    my $member_id_to_gene_split_id = $self->param('member_id_to_gene_split_id');<commit_msg>Fixes to work with the new species tree adaptors<commit_after>=head1 LICENSE

  Copyright (c) 1999-2012 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>>.

=cut

=head1 NAME

Bio::EnsEMBL::Compara::RunnableDB::GeneTrees::GeneGainLossCommon

=head1 SYNOPSIS

=head1 DESCRIPTION

This RunnableDB calculates the dynamics of a GeneTree family (based on the tree obtained and the CAFE software) in terms of gains losses per branch tree. It needs a CAFE-compliant species tree.

=head1 INHERITANCE TREE

Bio::EnsEMBL::Compara::RunnableDB::BaseRunnable

=head1 APPENDIX

The rest of the documentation details each of the object methods.
Internal methods are usually preceded with an underscore (_)

=cut

package Bio::EnsEMBL::Compara::RunnableDB::GeneTrees::GeneGainLossCommon;

use strict;
use warnings;
use Data::Dumper;
use Bio::EnsEMBL::Compara::Graph::NewickParser;
use base ('Bio::EnsEMBL::Compara::RunnableDB::BaseRunnable');

sub get_tree_string_from_mlss_tag {
    my ($self) = @_;
    my $mlss_id = $self->param('mlss_id');

    my $sql = "SELECT value FROM method_link_species_set_tag WHERE tag = 'cafe_tree_string' AND method_link_species_set_id = ?";
    my $sth = $self->compara_dba->dbc->prepare($sql);
    $sth->execute($mlss_id);

    my ($cafe_tree_string) = $sth->fetchrow_array();
    $sth->finish;
    print STDERR "CAFE_TREE_STRING: $cafe_tree_string\n" if ($self->debug());
    return $cafe_tree_string;
}

sub get_cafe_tree_from_string {
    my ($self) = @_;
    my $cafe_tree_string = $self->param('species_tree_string');
    print STDERR "$cafe_tree_string\n" if ($self->debug());
    my $cafe_tree = Bio::EnsEMBL::Compara::Graph::NewickParser::parse_newick_into_tree($cafe_tree_string, 'Bio::EnsEMBL::Compara::SpeciesTreeNode');
    $self->param('cafe_tree', $cafe_tree);
    return;
}

sub load_split_genes {
    my ($self) = @_;
    my $member_id_to_gene_split_id;
    my $gene_split_id_to_member_ids;
    my $sql = "SELECT member_id, gene_split_id FROM split_genes";
    my $sth = $self->compara_dba->dbc->prepare($sql);
    $sth->execute();
    my $n_split_genes = 0;
    while (my ($member_id, $gene_split_id) = $sth->fetchrow_array()) {
        $n_split_genes++;
        $member_id_to_gene_split_id->{$member_id} = $gene_split_id;
        push @{$gene_split_id_to_member_ids->{$gene_split_id}}, $member_id;
    }
    if ($n_split_genes == 0) {
        $self->param('no_split_genes', 1);
    }
    $self->param('member_id_to_gene_split_id', $member_id_to_gene_split_id);
    $self->param('gene_split_id_to_member_ids', $gene_split_id_to_member_ids);

    return;
}

sub filter_split_genes {
    my ($self, $all_members) = @_;
    my $member_id_to_gene_split_id = $self->param('member_id_to_gene_split_id');
{'fraction_non_alphanumeric': 0.12275839582654059, 'fraction_numerical': 0.0058689272905119005, 'mean_word_length': 4.8428571428571425, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6988675', 'n_tokens_mistral': 2323, 'n_tokens_neox': 2177, 'n_words': 488}