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

View of /FortyEight/rp_auto_assign.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Wed Nov 22 21:01:42 2006 UTC (13 years ago) by olson
Branch: MAIN
48hr mods

#
# Perform auto-assignment on unassigned pegs.
#

use strict;
use FIG;
use FIG_Config;
use File::Basename;
use GenomeMeta;

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

my $jobdir = shift;

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

my $genome = &FIG::file_head("$jobdir/GENOME_ID");
chomp $genome;
$genome =~ /^\d+\.\d+/ or die "$0: Cannnot find genome ID for jobdir $jobdir\n";

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

my $tbl = "$jobdir/rp/$genome/Features/peg/tbl";
-f $tbl or die "$0: Cannot find tbl file $tbl\n";

my $proposed = "$jobdir/rp/$genome/proposed_functions";

my %done;

if (!open(PROP, "<$proposed"))
{
    warn "could not  open proposed functions $proposed: $!";
    $meta->add_log_entry($0, "could not open proposed fucntions $proposed");
}
else
{
    while (<PROP>)
    {
	chomp;
	my($peg, $assign) = split;
	$done{$peg} = $assign;
    }
    close(PROP);
}

my @sims = <$jobdir/sims.job/sims.proc/*>;
my $simtmp;
my $simfile;
if (@sims == 0)
{
    &fatal("No sims found in $jobdir/sims.job/sims.proc\n");
}
elsif (@sims == 1)
{
    $simfile = shift @sims;
}
elsif (@sims > 1)
{
    my $d = "/scratch";
    if (! -d $d)
    {
	$d = "/tmp";
    }
    $simtmp = "$d/simtmp.$$";
    system("cat @sims > $simtmp");
    $simfile = $simtmp;
}

open(TBL, "<$tbl") or &fatal("Cannot open tbl file $tbl: $!");

my $cmd = "$FIG_Config::bin/auto_assign sims=$simfile > $jobdir/rp/$genome/auto_assign.functions";
print "running $cmd\n";
open(AA, "| $cmd")
	or &fatal("aa failed: $!");

my $peg_count = 0;
while (<TBL>)
{
    chomp;
    my($peg, @rest) = split(/\t/);
    if (!$done{$peg})
    {
	$peg_count++;
	print AA "$peg\n";
    }
}
close(TBL);

$meta->add_log_entry($0, "computing auto_assign on $peg_count pegs");

if (!close(AA))
{
    &fatal("error on close \$?=$? \$!=$!");
}

$meta->add_log_entry($0, "auto_assign completed\n");
$meta->set_metadata("status.auto_assign", "complete");

sub fatal
{
    my($msg) = @_;

    $meta->add_log_entry($0, ['fatal error', $msg]);
    $meta->set_metadata("status.auto_assign", "error");

    croak "$0: $msg";
}
    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3