Bio-Grid-Run-SGE
view release on metacpan or search on metacpan
lib/Bio/Grid/Run/SGE/Worker.pm view on Meta::CPAN
package Bio::Grid::Run::SGE::Worker;
use warnings;
use strict;
use Mouse;
use 5.010;
use Storable;
use Data::Dumper;
use Carp;
use File::Spec::Functions;
use File::Spec;
use Bio::Grid::Run::SGE::Index;
use Net::Domain qw(hostfqdn);
use IO::Handle;
use Try::Tiny;
use Cwd qw/fastcwd/;
our $VERSION = '0.066'; # VERSION
has [qw/config env/] => ( is => 'rw', required => 1 );
has [qw/task/] => ( is => 'rw', required => 1 );
has log => ( is => 'rw', required => 1 );
has status_log_fh => ( is => 'rw' );
has [qw/iterator/] => ( is => 'rw', lazy_build => 1 );
sub BUILD {
my ( $self, $args ) = @_;
my $conf = $self->config;
my $env = $self->env;
$env->{nslots} = $ENV{NSLOTS} // 1;
confess "task is no code reference" unless ( $self->task && ref $self->task eq 'CODE' );
confess "given range is not in the correct format"
if ( $env->{range} && @{ $env->{range} } < 2 );
$self->_determine_range;
my $log_file = catfile( $conf->{log_dir},
sprintf( "%s.l%d.%d", $env->{job_name_save}, $env->{job_id}, $env->{task_id} ) );
$self->log->info( "log: " . $log_file );
open my $status_log_fh, '>', $log_file or confess "Can't open filehandle: $!";
$self->status_log_fh($status_log_fh);
$self->_log_current_settings;
}
sub _build_iterator {
my ($self) = @_;
my $c = $self->config;
my @indices;
for my $in ( @{ $c->{input} } ) {
push @indices, Bio::Grid::Run::SGE::Index->new( %{$in} );
$self->log_status( "index_file: " . $in->{idx_file} );
}
# create iterator
my $iter = Bio::Grid::Run::SGE::Iterator->new( mode => $c->{mode}, indices => \@indices );
return $iter;
}
sub _determine_range {
my ($self) = @_;
my $conf = $self->config;
my $env = $self->env;
my $task_id = $env->{task_id};
my ( $num_comb, $num_parts ) = ( $env->{num_comb}, $conf->{num_parts} );
( run in 0.829 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )