NAME

Bio::Grid::Run::SGE::Iterator::AllvsAllNoRep - Runs all elements of one index against each other, without repetitions

SYNOPSIS

    use Bio::Grid::Run::SGE::Iterator::AllvsAllNoRep;
    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::AllvsAllNoRep->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++ . " -> " . join(" ",  $comb->[0], $comb->[1] ) . "\n";
    }

DESCRIPTION

Runs all elements of the index against each other. Takes exactly one index. Results in (N * N)/2 jobs with N as number of elements in the index.

The difference to Bio::Grid::Run::SGE::Iterator::AllvsAll is that it assumes symmetry. Runing element x vs. y is the same as running y vs. x and therefore a repetition.

ITERATION SCHEME

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

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

CONFIGURATION

  ---
  ...
  mode: AllvsAllNoRep
  ...

COMPLETE EXAMPLE

CONFIG FILE

    ---
    input:
      - format: List
        elements: [ "a", "b", "c" ]
    job_name: AllvsAllNoRep_test
    mode: AllvsAllNoRep

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>