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

View of /FigKernelScripts/make_PHOBs_for_subsystems.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Mon May 9 02:09:11 2005 UTC (14 years, 7 months ago) by overbeek
Branch: MAIN
Changes since 1.1: +22 -7 lines
Added bulletproofing. -- /gdp

# -*- perl -*-

use FIG;
my $fig = new FIG;

$usage = "usage: make_PHOBs_for_subsystems Dir < FileOf_SS-Role-PEG-Func";

(
 ($dir = shift @ARGV) && (! -d $dir)
)
    || die $usage;

mkdir($dir,0777) || die "could not make $dir";
while (defined($_ = <STDIN>))
{
    chop;
    ($ss,$role,$peg) = split(/\t/,$_);
    push(@{$subH{$ss}->{$role}},$peg);
}

$tmpF = "/tmp/pegs$$.fasta";

open(INDEXSS,">$dir/index") || die "could not open $dir/index";
$ssN = 0;
foreach $ss (sort keys(%subH))
{
    ++$ssN;
    mkdir("$dir/$ssN",0777) || die "could not make $dir/$ssN";
    print INDEXSS "$ssN\t$ss\n";

    open(INDEXR,">$dir/$ssN/index") || die "could not open $dir/$ssN/index";
    $roleN = 0;
    foreach $role (sort keys(%{$subH{$ss}}))
    {
	++$roleN;
	print INDEXR "$roleN\t$role\n";
	
	$pegs = $subH{$ss}->{$role};
	if (@$pegs < 4)
	{
	    print STDERR "Skipping $dir/$ssN/$roleN, role $role --- only ", (scalar @$pegs), " pegs\n";
	    next;
	}
	
	open(TMP,">$tmpF") || die "could not open $tmpF";
	foreach $peg (@$pegs)
	{
	    if ($pseq = $fig->get_translation($peg))
	    {
		print TMP ">$peg\n$pseq\n";
	    }
	    else
	    {
		print STDERR "failed to get translation for $peg\n";
	    }
	}
	close(TMP);
	
	mkdir("$dir/$ssN/$roleN",0777) || die "could not make $dir/$ssN/$roleN";
	&FIG::run("split_and_trim_sequences $dir/$ssN/$roleN/split_info < $tmpF");
	
	if (-s "$dir/$ssN/$roleN/split_info")
	{
	    open(SZ,"<$dir/$ssN/$roleN/split_info/set.sizes") || die " could not open $dir/$ssN/$roleN/split_info";
	    while (defined($_ = <SZ>))
	    {
		if (($_ =~ /^(\d+)\t(\d+)/) && ($2 > 3))
		{
		    $n = $1;
		    &FIG::run("make_phob_from_seqs $dir/$ssN/$roleN/$n < $dir/$ssN/$roleN/split_info/$n");
		}
	    }
	    close(SZ);
	}
	else
	{
	    system("rmdir $dir/$ssN/$roleN") && warn "Could not rmdir $dir/$ssN/$roleN";
	    print STDERR "Skipping role $role in $dir/$ssN/$roleN\n";
	}
    }
    close(INDEXR);
}
close(INDEXSS);
unlink($tmpF);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3