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

View of /FigKernelScripts/salvage_subsystem_rows.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Thu Nov 3 21:29:49 2005 UTC (14 years, 8 months ago) by overbeek
Branch: MAIN
undebugged code for replacement of genomes

use FIG;
my $fig = new FIG;

my $usage = "usage: salvage_subsystem_rows From To Mapping";  

# Foreach Subsystem in To (a directory of subsystems), if Subsystem is in From,
# then each row representing an organism in Mapping will be "salvaged" and added
# to Subsystem in To
#

(
 ($from    = shift @ARGV) &&
 ($to      = shift @ARGV) &&
 ($mapping = shift @ARGV)
)
    || die $usage;

foreach $_ (`cat $mapping`)
{
    if ($_ =~ /^(fig\|(\d+\.\d+)\.peg\.\d+)\t(fig\|(\d+\.\d+)\.peg\.(\d+))$/)
    {
	$old{$2} = $4;
	$map{$1} = $5;
    }
}

opendir(SUBS,$to) || die "could not open $to";
@subs = grep { $_ !~ /^\./ } readdir(SUBS);
closedir(SUBS);

foreach $sub (@subs)
{
    next if (! -d "$from/$sub/spreadsheet");

    undef %salvaged;
    open(IN,"<$from/$sub/spreadsheet") || die "$from/$sub/spreadsheet";
    while (defined($_ = <IN>))
    {
	if (($_ =~ /^(\d+\.\d+)\t(\S+)\t(.*)$/) && ($new = $old{$1}))
	{
	    $var = $2;
	    @old_pegs = split(/\t/,$3);
	    @new_pegs = ();
	    foreach $peg (@old_pegs)
	    {
		if ($peg && ($pegN = $map{$peg}))
		{
		    push(@new_pegs,"fig|$new\.peg\.$pegN");
		}
		else
		{
		    push(@new_pegs,"");
		}
	    }
	    salvaged{$new} = join("\t",($new,$var,@new_pegs));
	}
    }
    close(IN);

    open(IN,"<$to/$sub/spreadsheet") || die "$to/$sub/spreadsheet";
    $/ = "\n//\n";
    @spreadsheet = <IN>;
    close(IN);

    open(OUT,">$to/$sub/spreadsheet") || die "$to/$sub/spreadsheet";
    for ($i=0; ($i < @spreadsheet); $i++)
    {
	if ($i != 2)
	{
	    print OUT $spreadsheet[$i];
	}
	else
	{
	    $_ = spreadsheet[$i];
	    chomp;
	    @lines = split(/\n/,$_);
	    %in_already = map { $_ =~ /^(\d+\.\d+)/; $1 => 1 } @lines;
	    foreach $new (keys(%salvaged))
	    {
		if (($new =~ /^(\d+\.\d+)/) && (! $in_already{$1}))
		{
		    push(@lines,$salvaged{$new});
		}
	    }
	    print OUT join("\n",@lines),$/;
	}
    }
    close(OUT);
    $/ = "\n";
}


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3