[Bio] / FigKernelScripts / build_PGs_for_OTUs.pl Repository:
ViewVC logotype

View of /FigKernelScripts/build_PGs_for_OTUs.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Fri Jun 15 19:01:33 2012 UTC (7 years, 5 months ago) by overbeek
Branch: MAIN
CVS Tags: rast_rel_2014_0912, rast_rel_2014_0729, HEAD
Changes since 1.1: +2 -2 lines
fix path

use strict;
use Data::Dumper;
use SeedEnv;
my $sapO = SAPserver->new;
use Proc::ParallelLoop;

my $dir  = $ARGV[0] ? $ARGV[0] : 'Output';
(-d $dir) || mkdir($dir,0777) || die "could not make $dir";

my $otuH = $sapO->representative_genomes;
my($genome2set,$set2genomes) = @$otuH;

my @otus = sort { $a <=> $b } keys(%$set2genomes);

my @todo;
foreach my $otu (@otus)
{
    my @genomes = &shuffle(@{$set2genomes->{$otu}});
    my $i;
    for ($i=0; ($i < @genomes); $i += 6)
    {
	if (($i + 6) > @genomes)
	{
	    $i = &SeedUtils::max(@genomes - 6,0);
	}
	my $first = $i;
	my $last  = &SeedUtils::min($#genomes,$i+5);
	if ($last > $first)
	{
	    my @genome_set = @genomes[$first..$last];
	    my $name = "$otu.$first.$last";
	    if (! -d "$dir/$name")
	    {
		push(@todo,[$name,\@genome_set]);
	    }
	}
    }
}

my @random_order = &randomize(\@todo);
&pareach(\@random_order,\&process,{ Max_Workers => 4 });

sub process {
    my($tuple) = @_;

    my($name,$genome_set) = @$tuple;
    if (! -d "$dir/$name")
    {
	mkdir("$dir/$name",0777) || die "could not make $dir/$name";
	open(GENOMES,"| make_PG /vol/public-pseed/FIGdisk $dir/$name/PG 2> $dir/$name/stderr")
	    || die "could not make $dir/$name/PG";
	foreach my $genome (@$genome_set)
	{
	    my $gdir = "/vol/public-pseed/FIGdisk/FIG/Data/Organisms/$genome";
	    if (-d $gdir)
	    {
		print GENOMES "$gdir\n";
	    }
	}
	close(GENOMES);
	&run("svr_inconsistent_sets -s -f $dir/$name/assignments.repeat.clusters -k < $dir/$name/PG/repeat.clusters > $dir/$name/consistent.repeat.clusters 2> $dir/$name/inconsistent.repeat.clusters");
	&run("svr_inconsistent_sets -s -f $dir/$name/assignments.pg.sets -k < $dir/$name/PG/pg.sets > $dir/$name/consistent.pg.sets 2> $dir/$name/inconsistent.pg.sets");
    }
}

use List::Util qw(shuffle);
sub randomize {
    my($list) = @_;
    my @random = &shuffle(@$list);
    return @random;
}

sub run {
    my($cmd) = @_;

#    print STDERR "running: $cmd\n";
    my $rc = system($cmd);
    if ($rc)
    {
	die "$rc: $cmd failed";
    }
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3