[Bio] / FortyEight / rp_compute_sims.pl Repository:
ViewVC logotype

View of /FortyEight/rp_compute_sims.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (download) (as text) (annotate)
Tue Jan 12 20:43:05 2010 UTC (10 years, 1 month ago) by olson
Branch: MAIN
CVS Tags: mgrast_dev_05262011, mgrast_dev_04082011, rast_rel_2010_0928, mgrast_dev_06072011, rast_rel_2010_0526, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, 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_0, mgrast_dev_04132011, mgrast_dev_04012011, rast_rel_2010_0827, myrast_33, mgrast_dev_04052011, mgrast_dev_02222011
Changes since 1.3: +62 -52 lines
Support computing multiple sims batches, if the number of tasks is less than the number
of entries in the chunked work.

#
# Compute one piece of sims work.
#
# Usage: rp_compute_sims sims_job_dir
#
# SGE_TASK_ID is set to the taskid to be computed.
#

use GenomeMeta;
use FIG_Config;
use strict;

@ARGV == 1 or die "Usage: $0 job-dir\n";

my $jobdir = shift;
my $sims_jobdir = "$jobdir/sims.job";

-d $jobdir or die "$0: job dir $jobdir does not exist\n";
-d $sims_jobdir or die "$0: job dir $jobdir does not exist\n";

my $task_num = $ENV{SGE_TASK_ID};
my $num_tasks = $ENV{SGE_TASK_LAST} - $ENV{SGE_TASK_FIRST} + 1;

$task_num =~ /^\d+$/ or die "$0: SGE_TASK_ID not numeric\n";

my $meta = new GenomeMeta(undef, "$jobdir/meta.xml");

if ($task_num == 1 and $meta->get_metadata("status.sims") eq 'queued')
{
    $meta->set_metadata("status.sims", "in_progress");
}

open(TL, "<$sims_jobdir/task.list") or die "$0: cannot open tasklist $sims_jobdir/task.list: $!\n";

my ($in, $nr, $flags, $out, $err);

my @my_work;

while (<TL>)
{
    chomp;
    my @a = split(/\t/);
    my $work_id = $a[0];
    if ((($work_id - $task_num) % $num_tasks) == 0)
    {
	#($in, $nr, $flags, $out, $err) = @a[1 .. 5];
	push(@my_work, [@a[1..5]]);
    }
}
close(TL);

for my $work_ent (@my_work)
{
    my($in, $nr, $flags, $out, $err) = @$work_ent;

    $in or die "Could not find task $task_num";

    #$meta->add_log_entry($0, ['running ', $task_num, $in, $nr, $flags, $out, $err]);
    print "Computing on $in\n";
    my $t1 = time;
    
    my $blast_args = "$flags -i $in -d $nr -o $out";
    
    if ($ENV{NSLOTS} =~ /^(\d+)$/)
    {
	my $n = $1;
	print "Running $n processor blast due to parallel environment '$ENV{PE}'\n";
	$blast_args .= " -a $n";
    }
    
    open(E, ">$err") or die "Cannot open $err: $!";
    open(P, "$FIG_Config::ext_bin/blastall $blast_args 2>&1 |") or die "Cannot run blastall: $!";
    
    while (<P>)
    {
	print;
	print E $_;
    }
    
    my $rc = close(P);
    
    my $t2 = time;
    my $elap = $t2 - $t1;
    
    my $min = int($elap / 60);
    my $sec = $elap % 60;
    
    printf E "%d:%02d $t1 $t2 $elap\n", $min, $sec;
    printf "%d:%02d $t1 $t2 $elap\n", $min, $sec;
    
    if (!$rc)
    {
	if ($!)
	{
	    #	$meta->add_log_entry($0, ['blastall close error', $!]);
	    print "Error closing blastall: $!\n";
	    print E "Error closing blastall: $!\n";
	}
	else
	{
	    my $err = $?;
	    #	$meta->add_log_entry($0, ['blastall nonzero exit', $err]);
	    print "Nonzero exit status $err from blastall\n";
	    print E "Nonzero exit status $err from blastall\n";
	}
	last;
    }
    else
    {
	#    $meta->add_log_entry($0, ['blastall success', $elap]);
	print E "SUCCESS\n";
    }
    
    close(E);
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3