#!/usr/bin/perl -w
# run GeneNeighborsConserved.pl for every genome

use strict;
use lib "../Perl/modules";
use Genome;
use GenomicsUtils;
use Getopt::Long;

my $minScaffoldK = 300;
my $maxSep = 5000;
my $out = "";
my $debug = 0;
my $host=undef;

(GetOptions('minScaffoldK=i' => \$minScaffoldK,
	    'maxSep=i' => \$maxSep,
	    'out=s' => \$out,
	    'host=s' => \$host,
	    'debug=i' => \$debug)
 && @ARGV == 0 && $out)
    || die "Usage: GeneNeighborsConservedAll -out=dir/prefix [-host=s -minScaffoldK=i -maxSep=i -debug=i]\n";

GenomicsUtils::setDebug($debug) if $debug > 0;
connect();
my @genomes = Genome::getGenomeList();
foreach my $genome (@genomes) {
    my $taxon = $genome->taxonomyId();
    my $cmd = join(" ", "./GeneNeighborsConserved.pl",
		   "-taxon=$taxon",
		   "-out=$out$taxon",
		   (defined $host ? "-host=$host" : ""),
		   "-minScaffoldK=$minScaffoldK",
		   "-maxSep=$maxSep",
		   "-debug=$debug");
    print STDERR "Running: $cmd\n";
    system($cmd) == 0 || die "Failed executing $cmd";
}
