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

View of /FigKernelScripts/FFB2_build_updated_FF.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (download) (as text) (annotate)
Mon Jul 12 21:06:53 2010 UTC (9 years, 4 months ago) by olson
Branch: MAIN
Changes since 1.10: +3 -1 lines
Sort get_oligos output in 10M oligo chunks with an explicit merge when done, so we
can better overlap the actual get_oligos computation with the sorts.

########################################################################

use strict;
use FIG;
use IPC::Run qw(start finish);
use Cache::Memcached::Fast;

my $usage = "usage: FFB2_build_updated_FF OldReleaseDir NewReleaseDir memcache-host memcache-port [ssfam]";

my($oldD,$newD,$mchost, $mcport);

(
 ($oldD = shift @ARGV) && (-d $oldD) &&
 ($newD = shift @ARGV) &&
 ($mchost = shift @ARGV) &&
 ($mcport = shift @ARGV)
)
    || die $usage;

my $in_ssfam = shift;

$ENV{TMPDIR} = $FIG_Config::temp;

my $sort_args = "-T $FIG_Config::temp -S 4G";

mkdir($newD,0777) || die "You have an existing $newD; remove it and try again";

my $mc = new Cache::Memcached::Fast({ servers => ["$mchost:$mcport"] } );
$mc or die "Could not connect to memcached at $mchost:$mcport\n";

$mc->flush_all();

#
# Do some work up front to ensure we can load the memcache with all the data we need.
#

my $ssfam;
if (-f $in_ssfam)
{
    $ssfam = $in_ssfam;
}
else
{
    $ssfam = "$FIG_Config::temp/subsys.based.families.$$";
    &FIG::run("FFB2_make_subsys_based_families > $ssfam");
}

print "Loading memcache\n";
&FIG::run("FFB2_load_memcache $ssfam $oldD/families.2c $mchost $mcport");
print "Done\n";

my $parallel = 1;
my $child_pid;
if ($parallel)
{
    #
    # Run the FF update in a child process while we manage getting the phylo oligos here.
    #

    $child_pid = fork;

    if ($child_pid == 0)
    {
	figfam_processing();
	exit;
    }
}
else
{
    figfam_processing();
}

#
# Run the new parallel get-prots
#
my $n_get_prots = 3;

my @handles;
for my $i (0..$n_get_prots - 1)
{
    my $outfile = "$FIG_Config::temp/ffb2_xx.$$.$i";
    
    my $h = start(['FFB2_xx', 12,  "$newD/setI", $n_get_prots, $i, $mchost, $mcport],
		  "<", "/dev/null", ">", $outfile);
    push(@handles, [$i, $h, $outfile]);
}
for my $e (@handles)
{
    my($i, $h, $file) = @$e;
    print "Wait for finish $i $file\n";
    $h->finish();
}

my @files = map { $_->[2] } @handles;
print STDERR "Merging phylo @files\n";
&FIG::run("sort -m @files | FFB2_usable_motifs $newD/PhyloSigs");
    
#&FIG::run("FFB2_get_prots $newD/ProtsByGenomeSet $newD/setI");
#&FIG::run("FFB2_get_prot_gs_oligos $newD/ProtsByGenomeSet 12 | sort $sort_args | FFB2_usable_motifs $newD/PhyloSigs");

if ($parallel)
{
    my $rc = waitpid($child_pid, 0);
    if ($? != 0)
    {
	die "Error running parallel child: $?\n";
    }
}


mkdir("$newD/Merged",0777) || die "could not make $newD/Merged: $!";

my @merge_handles;

foreach my $i (7..12)
{
    mkdir("$newD/Merged/$i",0777) || die "could not make $newD/Merged/$i: $!";
    my $h = start(["FFB2_merge_oligos", "$newD/Kmers/$i/good.oligos", "$newD/PhyloSigs/$i/good.oligos"], "|",
		  ["FFB2_create_binary_kmers", "-l", $i, "-s", "4,2", "-", "$newD/Merged/$i/table.binary"]);

    push(@merge_handles, [$h, $i]);

#    &FIG::run("FFB2_merge_oligos $newD/Kmers/$i/good.oligos $newD/PhyloSigs/$i/good.oligos > $newD/Merged/$i/merged.oligos");
}

for my $ent (@merge_handles)
{
    my($h, $k) = @$ent;
    print "Wait for finish for k=$k\n";
    my $r = $h->finish();
    print "done r=$r\n";
}

my $load1 = start(["FFB2_load_oligo_index", "$newD/function.index",  "$newD/FRI.db"]);
my $load2 = start(["FFB2_load_oligo_index", "$newD/setI", "$newD/setI.db"]);
my $build = start(["build_prok_nonff_fasta", "$newD"],  ">", "$newD/extra_prok_seqs.fasta");


#foreach my $i (7..12)
#{
#    &FIG::run("FFB2_create_binary_kmers -s 4,2 $newD/Merged/$i/merged.oligos $newD/Merged/$i/table.binary");
#}

system("FFB2_run_tests $newD");
system("FFB2_compare_tests $oldD $newD");
$build->finish();
&FIG::run("formatdb -p T -i $newD/extra_prok_seqs.fasta");

$load1->finish();
$load2->finish();

&FIG::run("FFB2_make_FF_index $newD $newD/fam.func.index $newD/FamFuncBlastD");
&FIG::run("FFB2_build_ff_indexes $newD");

sub figfam_processing
{
    &FIG::run("FFB2_update_FIGfams -f $ssfam $newD/families.2c $newD/family.functions $oldD");
    &FIG::run("FFB2_get_oligos $newD/families.2c $newD/family.functions 2> $newD/function.index |" .
	      "FFB2_usable_motifs $newD/Kmers");
}    



MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3