<commit_before>=head1 LICENSE

  Copyright (c) 1999-2010 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::ncRNAtrees::SecStructModelTree

=head1 SYNOPSIS

=head1 DESCRIPTION

=head1 INHERITANCE TREE

  Bio::EnsEMBL::Compara::RunnableDB::BaseRunnable
  +- Bio::EnsEMBL::Hive::Process

=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::RunnableDB::ncRNAtrees::SecStructModelTree;

use strict;
use Time::HiRes qw(time);                          # Needed *
use Bio::EnsEMBL::Compara::Graph::NewickParser;    # Needed *

use base ('Bio::EnsEMBL::Compara::RunnableDB::BaseRunnable');


=head2 fetch_input

   Title   :   fetch_input
   Usage   :   $self->fetch_input
   Function:   Fetches input data from the database
   Returns :   none
   Args    :   none

=cut

sub fetch_input {
    my $self = shift @_;

    $self->input_job->transient_error(0);
    my $nc_tree_id = $self->param('nc_tree_id') or $self->throw("An 'nc_tree_id' is mandatory");  # Better to have a nc_tree instead?
    $self->input_job->transient_error(1);

    my $nc_tree = $self->compara_dba->get_NCTreeAdaptor->fetch_node_by_node_id($nc_tree_id) or die "Could not fetch nc_tree with id=$nc_tree_id\n";
    $self->param('nc_tree',$nc_tree);

    if(my $input_aln = $self->_dumpMultipleAlignmentStructToWorkdir($nc_tree) ) {
        $self->param('input_aln', $input_aln);
    } else {
        die "An input_aln is mandatory";
    }
}

sub run {

    my ($self) = @_;

    my $model = $self->param('model') or die "A model is mandatory";
    my $nc_tree = $self->param('nc_tree');
    my $aln_file = $self->param('input_aln');
    my $struct_file = $self->param('struct_aln') or die "An struct_aln is mandatory";
    my $bootstrap_num = $self->param('bootstrap_num') or die "A boostrap_num is mandatory";
    my $root_id = $nc_tree->node_id;

    my $raxml_tag = $root_id . "." . $self->worker->process_id . ".raxml";
    my $raxml_executable = '/software/ensembl/compara/raxml/RAxML-7.2.2/raxmlHPC-SSE3';
    $self->throw("can't find a raxml executable to run\n") unless(-e $raxml_executable);

    my $tag = 'ss_IT_' . $model;
    my $sql1 = "select value from nc_tree_tag where node_id=$root_id and tag='$tag'";
    my $sth1 = $self->dbc->prepare($sql1);
    $sth1->execute;
    my $raxml_tree_string = $sth1->fetchrow_hashref;
    $sth1->finish;
    if ($raxml_tree_string->{value}) {
        my $eval_tree;
        # Checks the tree string can be parsed successfully
        eval {
            $eval_tree = Bio::EnsEMBL::Compara::Graph::NewickParser::parse_newick_into_tree($raxml_tree_string->{value});
        };
        if (defined($eval_tree) and !$@) {
            # The secondary structure RAxML tree for this model has been obtained already and the tree can be parsed successfully.
            return;  # We have ended with this model
        }
    }

    # /software/ensembl/compara/raxml/RAxML-7.2.2/raxmlHPC-SSE3
    # -m GTRGAMMA -s nctree_20327.aln -S nctree_20327.struct -A S7D -n nctree_20327.raxml
    my $cmd = $raxml_executable;
    $cmd .= " -T 2";
    $cmd .= " -m GTRGAMMA";
    $cmd .= " -s $aln_file";
    $cmd .= " -S $struct_file";<commit_msg>Updated RAxML version: 7.2.8-ALPHA<commit_after>=head1 LICENSE

  Copyright (c) 1999-2010 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::ncRNAtrees::SecStructModelTree

=head1 SYNOPSIS

=head1 DESCRIPTION

=head1 INHERITANCE TREE

  Bio::EnsEMBL::Compara::RunnableDB::BaseRunnable
  +- Bio::EnsEMBL::Hive::Process

=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::RunnableDB::ncRNAtrees::SecStructModelTree;

use strict;
use Time::HiRes qw(time);                          # Needed *
use Bio::EnsEMBL::Compara::Graph::NewickParser;    # Needed *

use base ('Bio::EnsEMBL::Compara::RunnableDB::BaseRunnable');


=head2 fetch_input

   Title   :   fetch_input
   Usage   :   $self->fetch_input
   Function:   Fetches input data from the database
   Returns :   none
   Args    :   none

=cut

sub fetch_input {
    my $self = shift @_;

    $self->input_job->transient_error(0);
    my $nc_tree_id = $self->param('nc_tree_id') or $self->throw("An 'nc_tree_id' is mandatory");  # Better to have a nc_tree instead?
    $self->input_job->transient_error(1);

    my $nc_tree = $self->compara_dba->get_NCTreeAdaptor->fetch_node_by_node_id($nc_tree_id) or die "Could not fetch nc_tree with id=$nc_tree_id\n";
    $self->param('nc_tree',$nc_tree);

    if(my $input_aln = $self->_dumpMultipleAlignmentStructToWorkdir($nc_tree) ) {
        $self->param('input_aln', $input_aln);
    } else {
        die "An input_aln is mandatory";
    }
}

sub run {

    my ($self) = @_;

    my $model = $self->param('model') or die "A model is mandatory";
    my $nc_tree = $self->param('nc_tree');
    my $aln_file = $self->param('input_aln');
    my $struct_file = $self->param('struct_aln') or die "An struct_aln is mandatory";
    my $bootstrap_num = $self->param('bootstrap_num') or die "A boostrap_num is mandatory";
    my $root_id = $nc_tree->node_id;

    my $raxml_tag = $root_id . "." . $self->worker->process_id . ".raxml";
    my $raxml_executable = '/software/ensembl/compara/raxml/RAxML-7.2.8-ALPHA/raxmlHPC-SSE3';
    $self->throw("can't find a raxml executable to run\n") unless(-e $raxml_executable);

    my $tag = 'ss_IT_' . $model;
    my $sql1 = "select value from nc_tree_tag where node_id=$root_id and tag='$tag'";
    my $sth1 = $self->dbc->prepare($sql1);
    $sth1->execute;
    my $raxml_tree_string = $sth1->fetchrow_hashref;
    $sth1->finish;
    if ($raxml_tree_string->{value}) {
        my $eval_tree;
        # Checks the tree string can be parsed successfully
        eval {
            $eval_tree = Bio::EnsEMBL::Compara::Graph::NewickParser::parse_newick_into_tree($raxml_tree_string->{value});
        };
        if (defined($eval_tree) and !$@) {
            # The secondary structure RAxML tree for this model has been obtained already and the tree can be parsed successfully.
            return;  # We have ended with this model
        }
    }

    # /software/ensembl/compara/raxml/RAxML-7.2.2/raxmlHPC-SSE3
    # -m GTRGAMMA -s nctree_20327.aln -S nctree_20327.struct -A S7D -n nctree_20327.raxml
    my $cmd = $raxml_executable;
    $cmd .= " -T 2";
    $cmd .= " -m GTRGAMMA";
    $cmd .= " -s $aln_file";
    $cmd .= " -S $struct_file";
{'fraction_non_alphanumeric': 0.12974213581746996, 'fraction_numerical': 0.013635749966248143, 'mean_word_length': 3.4412470023980815, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 28}, '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': '4231704', 'n_tokens_mistral': 2757, 'n_tokens_neox': 2614, 'n_words': 636}