++ed by:
Joachim Bargsten

# NAME

Bio::Grid::Run::SGE::Iterator::AllvsAll - Runs all elements of one index against each other

# SYNOPSIS

``````    use Bio::Grid::Run::SGE::Iterator::AllvsAll;
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::AllvsAll->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` jobs with N as number of elements in the index.

The difference to Bio::Grid::Run::SGE::Iterator::AllvsAllNoRep is that it does NOT assume symmetry. Thus, runing element x vs y is different from running y vs x.

## ITERATION SCHEME

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

``````    job 1 -> a a
job 2 -> a c
job 3 -> a b
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: AllvsAll
...``````

## COMPLETE EXAMPLE

### CONFIG FILE

``````    ---
input:
- format: List
elements: [ "a", "b", "c" ]
job_name: AllvsAll_test
mode: AllvsAll``````

### 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(
);

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;``````

jw bargsten, `<jwb at cpan dot org>`