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

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

my $minScaffoldK = 300;
my $out = "";
my $debug = 0;
my $cluster="";
my $gnc="";
my $host=undef;

(GetOptions('out=s' => \$out,
	    'cluster=s' => \$cluster,
	    'gnc=s' => \$gnc,
	    'minScaffoldK=i' => \$minScaffoldK,
	    'host=s' => \$host,
	    'debug=i' => \$debug)
 && @ARGV == 0 && $out ne "" && $gnc ne "" && $cluster ne "")
    || die ("Usage: GenePhyloScoresAll.pl -gnc=genomeSim -cluster=similarGenomes -host=host"
            . " -out=s [-debug=i]\n");
die "Bad cluster" if !(-f $cluster);

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