NAME

Bio::Grid::Run::SGE::Iterator::Consecutive - iterate consecutively through an index

SYNOPSIS

use Bio::Grid::Run::SGE::Iterator::Consecutive;
use Bio::Grid::Run::SGE::Index;

# the dummy index contains the letters a..c as elements
my $index = Bio::Grid::Run::SGE::Index->new( format => 'Dummy', idx_file => undef, idx => [ 'a'..'c'] )->create;

my $it = Bio::Grid::Run::SGE::Iterator::Consecutive->new( indices => [$index] );

# run through all combinations
my ($from, $to) = (0, $it->num_comb - 1);
$it->range( [ $from, $to]  );

my @result;
my $i = $from;
while ( my $comb = $it->next_comb ) {
  print "job " . $i++ . " -> " . $comb->[0] . "\n";
}

DESCRIPTION

This is the simplest iterator, it runs through a range of elements in an index. It takes exactly one index. Results in N opeations with N as number of elements in the index.

ITERATION SCHEME

An index with elements (a..c) combines to 3 jobs:

job 1 -> a
job 2 -> b
job 3 -> c

CONFIGURATION

---
...
mode: Consecutive
...

COMPLETE EXAMPLE

CONFIG FILE

---
input:
  - format: List
    elements: [ "a", "b", "c" ]
job_name: Consecutive_test
mode: Consecutive

CLUSTER SCRIPT

#!/usr/bin/env perl

use warnings;
use strict;
use 5.010;

use Bio::Grid::Run::SGE;
use File::Spec::Functions qw(catfile);
use Bio::Grid::Run::SGE::Util qw(result_files);

run_job(
  task => \&do_worker_stuff
);

sub do_worker_stuff {
  my ( $c, $result_prefix, $elems_a ) = @_;

  # write results to result prefix (== result file)
  open my $fh, '>', $result_prefix or die "Can't open filehandle: $!";

  # because we have a list index, $elems_a is an array reference
  # other indices might give file names instead, so check the documentation

  my $num_elems = @$elems_a;
  for ( my $i = 0; $i < @$elems_a; $i++ ) {
    say $fh $elems_a->[$i];
  }
  $fh->close;

  # return 1 on success
  return 1;
}

1;

SEE ALSO

Bio::Grid::Run::SGE::Role::Iterable, Bio::Grid::Run::SGE::Iterator

AUTHOR

jw bargsten, <jwb at cpan dot org>