<commit_before>=head1 LICENSE

Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Copyright [2016-2020] EMBL-European Bioinformatics Institute

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=cut

=pod

=head1 NAME

Bio::EnsEMBL::Compara::RunnableDB::Flatfiles::FindHomologyIDRange

=head1 DESCRIPTION



=cut

package Bio::EnsEMBL::Compara::RunnableDB::Flatfiles::FindHomologyIDRange;

use warnings;
use strict;

use Bio::EnsEMBL::Compara::Utils::FlatFile qw(get_line_count);

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

sub param_defaults {
    my ($self) = @_;
    return {
        %{$self->SUPER::param_defaults},
        'range_index'   => 1,
        'offset'        => '#range_index#00000001',
    }
}

sub fetch_input {
    my $self = shift;

    # grab range start from pipeline_wide_parameters
    my $range_start = $self->param('homology_id_range_start');
    return if defined $range_start;

    # initialise the range if it doesn't exist yet (i.e. first job)
    $range_start = $self->param_required('offset');
}

sub run {
    my $self = shift;

    my $this_range_start = $self->param('homology_id_range_start') || $self->param_required('offset');
    $self->param('this_range_start', $this_range_start);

    my $homology_count = get_line_count($self->param('homology_flatfile')) - 1; # remove header line
    $self->param('next_range_start', $this_range_start + $homology_count);
}

sub write_output {
    my $self = shift;

    $self->db->hive_pipeline->add_new_or_update('PipelineWideParameters',
        'param_name' => 'homology_id_range_start',
        'param_value' => $self->param('next_range_start'),
    );

    $self->dataflow_output_id( {
        homology_id_start => $self->param('this_range_start'),
        homology_flatfile => $self->param('homology_flatfile'),
    }, 1 );
}

1;<commit_msg>Add description and remove fetch_input<commit_after>=head1 LICENSE

Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Copyright [2016-2020] EMBL-European Bioinformatics Institute

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=cut

=pod

=head1 NAME

Bio::EnsEMBL::Compara::RunnableDB::Flatfiles::FindHomologyIDRange

=head1 DESCRIPTION

Detects and assigns a range of homology_ids for the given file. Range starts at
pipeline_wide_parameter `homology_id_range_start`, or param `offset` if it is not
yet defined. Stores updated `homology_id_range_start` into pipeline_wide_parameters
for the next job to use.

IMPORTANT!! This runnable should ONLY use a capacity of 1.

=cut

package Bio::EnsEMBL::Compara::RunnableDB::Flatfiles::FindHomologyIDRange;

use warnings;
use strict;

use Bio::EnsEMBL::Compara::Utils::FlatFile qw(get_line_count);

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

sub param_defaults {
    my ($self) = @_;
    return {
        %{$self->SUPER::param_defaults},
        'range_index'   => 1,
        'offset'        => '#range_index#00000001',
    }
}

sub run {
    my $self = shift;

    my $this_range_start = $self->param('homology_id_range_start') || $self->param_required('offset');
    $self->param('this_range_start', $this_range_start);

    my $homology_count = get_line_count($self->param('homology_flatfile')) - 1; # remove header line
    $self->param('next_range_start', $this_range_start + $homology_count);
}

sub write_output {
    my $self = shift;

    $self->db->hive_pipeline->add_new_or_update('PipelineWideParameters',
        'param_name' => 'homology_id_range_start',
        'param_value' => $self->param('next_range_start'),
    );

    $self->dataflow_output_id( {
        homology_id_start => $self->param('this_range_start'),
        homology_flatfile => $self->param('homology_flatfile'),
    }, 1 );
}

1;
{'fraction_non_alphanumeric': 0.11364587693595647, 'fraction_numerical': 0.014859773964001675, 'mean_word_length': 4.576429404900817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '5013632', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1475, 'n_words': 407}