The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Bio::Grid::Run::SGE::Iterator::AvsB - iterate over two different indices

SYNOPSIS

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

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

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

    my $it = Bio::Grid::Run::SGE::Iterator::AvsB->new( indices => [$indexA, $indexB] );

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

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

DESCRIPTION

Runs all elements of the first index against all elements of the second index. Takes exactly two indices. Results in N * M jobs with N as number of elements in the first index and M as number of elements in the second index.

ITERATION SCHEME

Index A with 3 elements (a..c) and index B with 3 elements (A..C) combine to:

    job 1 -> a A
    job 2 -> a B
    job 3 -> a C
    job 4 -> b A
    job 5 -> b B
    job 6 -> b C
    job 7 -> c A
    job 8 -> c B
    job 9 -> c C

CONFIGURATION

  ---
  ...
  mode: AvsB
  ...

COMPLETE EXAMPLE

CONFIG FILE

    ---
    input:
      - format: List
        elements: [ "a", "b", "c" ]
      - format: List
        elements: [ "A", "B", "C" ]
    job_name: AvsB_test
    mode: AvsB

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, $elems_b ) = @_;

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

      # because we have list indices, $elems_a and $elems_b are (paired) array references
      # 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 join( " ", $elems_a->[$i], $elems_b->[$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>