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

View of /FigKernelScripts/generate_partitionsP.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (download) (as text) (annotate)
Thu Nov 11 17:40:43 2010 UTC (9 years, 3 months ago) by disz
Branch: MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, rast_rel_2014_0912, myrast_rel40, mgrast_dev_05262011, mgrast_dev_04082011, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2011_0119, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, mgrast_dev_04012011, myrast_33, rast_rel_2011_0928, mgrast_dev_04052011, mgrast_dev_02222011, mgrast_dev_10262011, HEAD
Changes since 1.5: +2 -2 lines
FigFam 6 digit problem

use strict;

use FIG;
my $fig = new FIG;
use FigFam;
my $procs = 8;

#my $tmpF = "tmp.fams.done.$$";
my $usage = "usage: generate_partitionsP [-log releaseX.log] families.2c OutputDir";
#my $usage = "usage: generate_partitionsP families.2c OutputDir";
my $log_file;

while ( $ARGV[0] =~ /^-/ )
{
    $_ = shift @ARGV;
    if ($_ =~ s/^-log//)     { $log_file      = ($_ || shift @ARGV) }
    else                  { print STDERR  "Bad flag: '$_'\n$usage"; exit 1 }
}

my($famsD,$fam_functions,$families,$outD);
(
 ($famsD = shift @ARGV) &&
 ($outD     = shift @ARGV)
)
    || die $usage;

$fam_functions = "$famsD/family.functions";
$families = "$famsD/families.2c";


&FIG::verify_dir($outD);

# check flag: to continue from where it left off or start a new generate_partitionsP
# if there are any files (i.e. 1) on the $outD directory, then continue from where it left off
# otherwise, start new
if (! -f "$outD/1"){
    my $dbf = $fig->db_handle;
    $dbf->drop_table( tbl => "tmp_sync_partitions" );
    $dbf->create_table( tbl  => "tmp_sync_partitions",
			flds => "fam varchar(32)"
			);
    $dbf->create_index( idx  => "fid_tmp_sync_partitions_ix",
			tbl  => "tmp_sync_partitions",
			type => "btree",
			flds => "fam" );

}

=head3

open(DONE,"| sort -u > $tmpF") || die "could not open $tmpF";
if (opendir(OUT,$outD))
{
    my @done = grep { $_ =~ /^\d/ } readdir(OUT);
    closedir(OUT);
    foreach my $file (@done)
    {
	rename("$outD/$file","$outD/$file~") || die "could not rename $outD/$file";
	open(TMPIN,"<$outD/$file~")          || die "could not open $outD/$file~";
	open(TMPOUT,">$outD/$file")          || die "could not open $outD/$file";
	while (defined($_ = <TMPIN>))
	{
	    my @set = ();
	    while (defined($_) && (substr($_,0,2) ne "//"))
	    {
		push(@set,$_);
		$_ = <TMPIN>;
	    }

	    if (defined($_))
	    {
		print TMPOUT @set,$_;
		while ($_ =~ /(FIG\d+)/g)
		{
		    print DONE "$1\n";
		}
	    }
	}
	close(TMPIN);
	close(TMPOUT);
	unlink("$outD/$file~");
    }
}
close(DONE);
=cut

open(IDS,"cut -f1 $fam_functions | sort -u |") || die "Where is family.functions?";

my @procs;
if ($log_file){
    @procs = &start_procs("generate_partitions_worker -log $log_file $families $outD",$procs);
}
else{
    @procs = &start_procs("generate_partitions_worker $families $outD",$procs);
}

my $nextP = 0;
while (defined($_ = <IDS>))
{
    if ($_ =~ /^(FIG\d+)/)
    {
	my $id = $1;
	my $fh = $procs[$nextP];
	print $fh "$id\n";
#	print STDERR $nextP+1,": assigned $id\n";
	$nextP = ($nextP == $#procs) ? 0 : $nextP+1;
    }
}

&close_procs(\@procs);
print STDERR "closed processes\n";

opendir(OUT,$outD) || die "could not open $outD";
my @files = grep { $_ =~ /^(\d+)$/ } readdir(OUT);
closedir(OUT);
foreach my $file (@files)
{
    open(TMP,"<$outD/$file") || die "could not open $outD/$file";
    while (defined($_ = <TMP>))
    {
	print $_;
    }
    close(TMP);
}

sub start_procs {
    my($cmd,$procsN) = @_;

    my @procs = ();
    open(F1,"| $cmd 1") || die 1;
    my $ofh = select F1; $| = 1; select $ofh;
    push(@procs,\*F1);
    print STDERR "starting process 1\n";

    $procsN--; if ($procsN == 0) { return @procs }
    open(F2,"| $cmd 2") || die 2;
    my $ofh = select F2; $| = 1; select $ofh;
    push(@procs,\*F2);
    print STDERR "starting process 2\n";

    $procsN--; if ($procsN == 0) { return @procs }
    open(F3,"| $cmd 3") || die 3;
    my $ofh = select F3; $| = 1; select $ofh;
    push(@procs,\*F3);
    print STDERR "starting process 3\n";

    $procsN--; if ($procsN == 0) { return @procs }
    open(F4,"| $cmd 4") || die 4;
    my $ofh = select F4; $| = 1; select $ofh;
    push(@procs,\*F4);
    print STDERR "starting process 4\n";

    $procsN--; if ($procsN == 0) { return @procs }
    open(F5,"| $cmd 5") || die 5;
    my $ofh = select F5; $| = 1; select $ofh;
    push(@procs,\*F5);
    print STDERR "starting process 5\n";

    $procsN--; if ($procsN == 0) { return @procs }
    open(F6,"| $cmd 6") || die 6;
    my $ofh = select F6; $| = 1; select $ofh;
    push(@procs,\*F6);
    print STDERR "starting process 6\n";

    $procsN--; if ($procsN == 0) { return @procs }
    open(F7,"| $cmd 7") || die 7;
    my $ofh = select F7; $| = 1; select $ofh;
    push(@procs,\*F7);
    print STDERR "starting process 7\n";

    $procsN--; if ($procsN == 0) { return @procs }
    open(F8,"| $cmd 8") || die 8;
    my $ofh = select F8; $| = 1; select $ofh;
    push(@procs,\*F8);
    print STDERR "starting process 8\n";

    $procsN--; if ($procsN == 0) { return @procs }
    open(F9,"| $cmd 9") || die 9;
    my $ofh = select F9; $| = 1; select $ofh;
    push(@procs,\*F9);
    print STDERR "starting process 9\n";

    $procsN--; if ($procsN == 0) { return @procs }
    open(F10,"| $cmd 10") || die 10;
    my $ofh = select F10; $| = 1; select $ofh;
    push(@procs,\*F10);
    print STDERR "starting process 10\n";

    $procsN--; if ($procsN == 0) { return @procs }
    open(F11,"| $cmd 11") || die 11;
    my $ofh = select F11; $| = 1; select $ofh;
    push(@procs,\*F11);
    print STDERR "starting process 11\n";

    $procsN--; if ($procsN == 0) { return @procs }
    open(F12,"| $cmd 12") || die 12;
    my $ofh = select F12; $| = 1; select $ofh;
    push(@procs,\*F12);
    print STDERR "starting process 12\n";

    $procsN--; if ($procsN == 0) { return @procs }
    open(F13,"| $cmd 13") || die 13;
    my $ofh = select F13; $| = 1; select $ofh;
    push(@procs,\*F13);
    print STDERR "starting process 13\n";

    $procsN--; if ($procsN == 0) { return @procs }
    open(F14,"| $cmd 14") || die 14;
    my $ofh = select F14; $| = 1; select $ofh;
    push(@procs,\*F14);
    print STDERR "starting process 14\n";

    return @procs;
}

sub close_procs {
    my($procs) = @_;
    my $proc;

    for (my $i=0; ($i < @$procs); $i++)
    {
	print STDERR "CLOSING ",$i+1,"\n";
	my $fh = $procs->[$i];
	print $fh "x\n";
	close($fh);
	print STDERR "CLOSED ",$i+1,"\n";
    }
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3