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

View of /FigKernelScripts/make_annotations_for_sprout.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (download) (as text) (annotate)
Wed Dec 8 21:28:10 2004 UTC (15 years, 3 months ago) by overbeek
Branch: MAIN
Changes since 1.5: +1 -1 lines
raw time for annotations

# -*- perl -*-

use FIG;
($fig = new FIG) || die "FIG constructor failed";

$usage = "make_FIG_annotations_for_sprout GenomeFile AnnotationsFile IsTargetOfFile MadeAnnotationFile";

(@ARGV
&& ($genomes_file     = shift) && (-s $genomes_file)
&& ($annotations_file = shift)
&& ($istarget_file    = shift)
&& ($makeannot_file   = shift)
) || die "\n   usage: $usage\n\n";

@genomes = grep { m/^(\S+)/; $_ = $1 } `cut -f1 $genomes_file`;

open(ANNOT,  "| sort -u > $annotations_file") || die "could not write-open $annotations_file";
open(TARGET, "| sort -u > $istarget_file")    || die "could not write-open $istarget_file";
open(MAKEAN, "| sort -u > $makeannot_file")   || die "could not write-open $makeannot_file";

$time = time();
%user_time = (KEGG => $time + 1,
	      NCBI => $time + 2,
	      SwissProt => $time + 3,
	      UniProt => $time + 4);
$tick = 0;
foreach $org (@genomes)
{
    print STDERR "Processing $org " if $ENV{FIG_VERBOSE};
    
    @pegs = $fig->pegs_of($org);
    warn "No pegs for $org" unless @pegs;
    
    foreach $peg (@pegs)
    {
	if ($ENV{FIG_VERBOSE} && ($tick >= 1000)) { print STDERR '.'; $tick = 0; } else {++$tick; }
	
	if ($func = $fig->function_of($peg))
	{
	    if (!$fig->hypo($func))
	    {
		print ANNOT  "$peg:$time\t$time\tFIG\\nSet FIG function to\\n$func\n";
		print TARGET "$peg\t$peg:$time\n";
		print MAKEAN "FIG\t$peg:$time\n";
	    }
	    
	    foreach $x ($fig->feature_annotations($peg,"raw"))
	    {
		(undef, $timestamp, $user, $annot) = @$x;
		$annot =~ s/\cM//gs;
		$annot =~ s/\n/\\n/gs;
		if ($annot !~ m/^Set .*function to/)
		{
		    if ($timestamp =~ /^\d+$/)
		    {
			print ANNOT  "$peg:$timestamp\t$timestamp\t$user\\n$annot\n";
			print TARGET "$peg\t$peg:$timestamp\n";
			print MAKEAN "$user\t$peg:$timestamp\n";
		    }
		    else
		    {
			print STDERR "$peg has nonnumeric timestamp in annotations\n";
		    }
		}
	    }
	    
	    if (@aliases = $fig->mapped_prot_ids($peg))
	    {
		foreach $alias_record (@aliases)
		{
		    $alias = $alias_record->[0];
		    $func  = $fig->function_of($alias);
		    
		    $user  = $setname = "";
		    if ($alias =~ m/^fig\|/)
		    {
			next;
		    }
		    elsif ($alias =~ m/^kegg\|/)
		    {
			$user = $setname = 'KEGG';
		    }
		    elsif ($alias =~ m/^gi\|/)
		    {
			$user = $setname = 'NCBI';
		    }
		    elsif ($alias =~ m/^(sp|tr|tn)\|/)
		    {
			$user = $setname = 'SwissProt';
		    }
		    elsif ($alias =~ m/^uni\|/)
		    {
			$user = $setname = 'UniProt';
		    }
		    else
		    {
			warn "could not handle alias $alias";
			next;
		    }
		    
		    if ($user && $setname && $func)
		    {
			my $thistime = $user_time{$user};
			die "No time found for user $user" unless defined($thistime);
			print ANNOT  "$alias:$thistime\t$thistime\t$user\\nSet $setname function to\\n$func\n";
			print TARGET "$alias\t$alias:$thistime\n";
			print MAKEAN "$user\t$alias:$thistime\n";
		    }
		}
	    }
	}
    }
    
    print STDERR "\n" if $ENV{FIG_VERBOSE};
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3