<commit_before>#
# Interface for running programs
#
# You may distribute this module under the same terms as perl itself
#
# POD documentation - main docs before the code

=pod 

=head1 NAME

Bio::EnsEMBL::Pipeline::RunnableI

=head1 SYNOPSIS

=head1 DESCRIPTION

Interface for running external programs

=head1 CONTACT

Describe contact details here

=head1 APPENDIX

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

=cut

# Let the code begin...

package Bio::EnsEMBL::Pipeline::RunnableI;

use vars qw(@ISA);
use strict;

use Bio::EnsEMBL::Analysis::Programs;
use Bio::EnsEMBL::Root;
use Bio::SeqIO;
use Bio::EnsEMBL::Pipeline::Config::General;

@ISA = qw(Bio::EnsEMBL::Root);


=head1 ABSTRACT METHODS

These methods need to be implemented in any
module which implements
C<Bio::EnsEMBL::Pipeline::RunnableI>.

=head2 run

    $self->run();

Actually runs the analysis programs.  If the
analysis has fails, it should throw an
exception.  It should also remove any temporary
files created (before throwing the exception!).

=head2 output

    @output = $self->output();

Return a list of objects created by the analysis
run (eg: C<Bio::EnsEMBL::FeaturePair> objects).

=cut

sub run {
    my ($self) = @_;

    $self->throw("run not implemented");
}

sub output {
    my ($self) = @_;

		if (!defined($self->{_output})) {
			$self->{_output} = [];
		}

		return @{$self->{_output}};
}

sub locate_executable {
    my ($self, $binary) = @_;

    if ($binary) {
        Bio::EnsEMBL::Analysis::Programs->import($binary);
        return $Bio::EnsEMBL::Analysis::Programs::Program_Paths { $binary };
    }
}

sub filename {
    my ($self, $filename) = @_;
    #my ($p, $f, $l) = caller;
    #print STDERR "Setting filename to ".$filename." $f:$l\n" if($filename);
    $self->{_filename} = $filename if ($filename);
    return $self->{_filename};
}

sub results {
    my ($self, $results) = @_;
    $self->{_results} = $results if ($results);
    return $self->{_results};
}

sub queryname {
    my ($self, $queryname) = @_;
    $self->{_queryname} = $queryname if ($queryname);
    return $self->{_queryname};
}


=head2 protect

    Title   :   protect
    Usage   :   $obj->protect('.masked', '.p');
    Function:   Protects files with suffix from deletion when execution ends
    Args    :   File suffixes

=cut

sub protect {
    my ($self, @filename) =@_;
    
    if (!defined($self->{_protected})) {
      $self->{_protected} = [];
    }

    push (@{$self->{_protected}}, @filename) if (@filename);

    return @{$self->{_protected}};
}

=head2 threshold

    Title   :   threshold
    Usage   :   $obj->threshold($value);
    Function:   Get/set method for threshold score required for outputting
                Feature/FeaturePair
    Args    :   Optional value (depends on type of Analysis)

=cut

sub threshold {
  my ($self, $value) = @_;
 
  
  if (defined ($value)) {
    $self->{_threshold} = $value;
  }
    
  return  $self->{'_threshold'};
}


sub threshold_type {
    my($self, $value) = @_;

    if (defined($value)) {
			$self->{'_threshold_type'} = $value;
    }

    return $self->{'_threshold_type'};
}


=head2 workdir

    Title   :   workdir
    Usage   :   $obj->workdir('~humpub/temp');
    Function:   Get/set method for the location of a directory to contain temp files
    Args    :   File path (optional)

=cut

sub workdir {
    my ($self, $directory) = @_;
		
    if (!defined($self->{_workdir})) {
        if ($directory) {
            mkdir ($directory, '777') unless (-d $directory);
            $self->throw ("$directory doesn't exist\n") unless (-d $directory);
            $self->{_workdir} = $directory;
}	elsif ($PIPELINE_WORK_DIR)	{
            $self->{_workdir}= $PIPELINE_WORK_DIR;
        } else {
            $self->{_workdir} = '/tmp';
        }
    }
    return $self->{_workdir};
}


sub get_tmp_file {
    my ($self,$dir,$stub,$ext) = @_;

   
    if ($dir !~ /\/$/) {
        $dir = $dir . "/";
    }

		# This is not good

    my $num = int(rand(100000));
    my $file = $dir . $stub . "." . $num . "." . $ext;
    #print STDERR "have filename ".$file."\n";
    while (-e $file) {
        $num = int(rand(100000));
        $file = $dir.$stub . "." . $num . "." . $ext;
    }
    #my($p, $f, $l) = caller;<commit_msg>in method RunnableI::workdir fixed call to mkdir function to set mask correctly with 0777 rather than '777'<commit_after>#
# Interface for running programs
#
# You may distribute this module under the same terms as perl itself
#
# POD documentation - main docs before the code

=pod 

=head1 NAME

Bio::EnsEMBL::Pipeline::RunnableI

=head1 SYNOPSIS

=head1 DESCRIPTION

Interface for running external programs

=head1 CONTACT

Describe contact details here

=head1 APPENDIX

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

=cut

# Let the code begin...

package Bio::EnsEMBL::Pipeline::RunnableI;

use vars qw(@ISA);
use strict;

use Bio::EnsEMBL::Analysis::Programs;
use Bio::EnsEMBL::Root;
use Bio::SeqIO;
use Bio::EnsEMBL::Pipeline::Config::General;

@ISA = qw(Bio::EnsEMBL::Root);


=head1 ABSTRACT METHODS

These methods need to be implemented in any
module which implements
C<Bio::EnsEMBL::Pipeline::RunnableI>.

=head2 run

    $self->run();

Actually runs the analysis programs.  If the
analysis has fails, it should throw an
exception.  It should also remove any temporary
files created (before throwing the exception!).

=head2 output

    @output = $self->output();

Return a list of objects created by the analysis
run (eg: C<Bio::EnsEMBL::FeaturePair> objects).

=cut

sub run {
    my ($self) = @_;

    $self->throw("run not implemented");
}

sub output {
    my ($self) = @_;

		if (!defined($self->{_output})) {
			$self->{_output} = [];
		}

		return @{$self->{_output}};
}

sub locate_executable {
    my ($self, $binary) = @_;

    if ($binary) {
        Bio::EnsEMBL::Analysis::Programs->import($binary);
        return $Bio::EnsEMBL::Analysis::Programs::Program_Paths { $binary };
    }
}

sub filename {
    my ($self, $filename) = @_;
    #my ($p, $f, $l) = caller;
    #print STDERR "Setting filename to ".$filename." $f:$l\n" if($filename);
    $self->{_filename} = $filename if ($filename);
    return $self->{_filename};
}

sub results {
    my ($self, $results) = @_;
    $self->{_results} = $results if ($results);
    return $self->{_results};
}

sub queryname {
    my ($self, $queryname) = @_;
    $self->{_queryname} = $queryname if ($queryname);
    return $self->{_queryname};
}


=head2 protect

    Title   :   protect
    Usage   :   $obj->protect('.masked', '.p');
    Function:   Protects files with suffix from deletion when execution ends
    Args    :   File suffixes

=cut

sub protect {
    my ($self, @filename) =@_;
    
    if (!defined($self->{_protected})) {
      $self->{_protected} = [];
    }

    push (@{$self->{_protected}}, @filename) if (@filename);

    return @{$self->{_protected}};
}

=head2 threshold

    Title   :   threshold
    Usage   :   $obj->threshold($value);
    Function:   Get/set method for threshold score required for outputting
                Feature/FeaturePair
    Args    :   Optional value (depends on type of Analysis)

=cut

sub threshold {
  my ($self, $value) = @_;
 
  
  if (defined ($value)) {
    $self->{_threshold} = $value;
  }
    
  return  $self->{'_threshold'};
}


sub threshold_type {
    my($self, $value) = @_;

    if (defined($value)) {
			$self->{'_threshold_type'} = $value;
    }

    return $self->{'_threshold_type'};
}


=head2 workdir

    Title   :   workdir
    Usage   :   $obj->workdir('~humpub/temp');
    Function:   Get/set method for the location of a directory to contain temp files
    Args    :   File path (optional)

=cut

sub workdir {
    my ($self, $directory) = @_;
		
    if (!defined($self->{_workdir})) {
        if ($directory) {
            mkdir ($directory, 0777) unless (-d $directory);
            $self->throw ("$directory doesn't exist\n") unless (-d $directory);
            $self->{_workdir} = $directory;
}	elsif ($PIPELINE_WORK_DIR)	{
            $self->{_workdir}= $PIPELINE_WORK_DIR;
        } else {
            $self->{_workdir} = '/tmp';
        }
    }
    return $self->{_workdir};
}


sub get_tmp_file {
    my ($self,$dir,$stub,$ext) = @_;

   
    if ($dir !~ /\/$/) {
        $dir = $dir . "/";
    }

		# This is not good

    my $num = int(rand(100000));
    my $file = $dir . $stub . "." . $num . "." . $ext;
    #print STDERR "have filename ".$file."\n";
    while (-e $file) {
        $num = int(rand(100000));
        $file = $dir.$stub . "." . $num . "." . $ext;
    }
    #my($p, $f, $l) = caller;
{'fraction_non_alphanumeric': 0.15976263836585644, 'fraction_numerical': 0.006846970215679562, 'mean_word_length': 2.9072670530539457, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 67, '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': '1677736', 'n_tokens_mistral': 3115, 'n_tokens_neox': 2946, 'n_words': 815}