[Bio] / FigWebServices / status_of_model.cgi Repository:
ViewVC logotype

View of /FigWebServices/status_of_model.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (annotate)
Thu Aug 4 14:56:05 2005 UTC (14 years, 6 months ago) by overbeek
Branch: MAIN
add cgi script to spot needed connections to reactions

# -*- perl -*-

# This is in a highly-unfinished state.  I will work on it more
# once people become available to make their desires known.

use FIG;
my $fig = new FIG;
my $cgi = new CGI;
use HTML;

if (1) {
    my $VAR1;
    eval(join("",`cat /tmp/som_parms`));
    $cgi = $VAR1;
#   print STDERR &Dumper($cgi);
}

if (0) {
    print $cgi->header;
    my @params = $cgi->param;
    print "<pre>\n";
    foreach $_ (@params) {
		print "$_\t:",join(",",$cgi->param($_)),":\n";
    }

    if (0) {
        if (open(TMP,">/tmp/som_parms")) {
	    	print TMP &Dumper($cgi);
	    	close(TMP);
		}
    }
    exit;
}

my $html = [];

my $model = $cgi->param('model');
if ($model && ($model =~ /\((\d+\.\d+)\)/) && ($model = $1) && (-s "$FIG_Config::global/Models/$model"))
{
    &som($fig,$cgi,$html,$model);
}
else
{
    &poss_models($fig,$cgi,$html);
}
&HTML::show_page($cgi,$html);

sub poss_models {
    my($fig,$cgi,$html) = @_;

    my $user = $cgi->param('user');
    if (opendir(MODELS,"$FIG_Config::global/Models") &&
	(@models = grep { ($_ !~ /^\./) && (-s "$FIG_Config::global/Models/$_") } readdir(MODELS)) &&
	(@models > 0))
    {
	my @orgs = sort map { $_ =~ /^(\d+\.\d+)/; 
			      my $org = $1; 
			      my $gs = $fig->genus_species($org); 
			      "$gs ($org)" 
			    } @models;
	push(@$html,$cgi->hr,
	            $cgi->start_form(-action => "status_of_model.cgi"),
	            $cgi->hidden(-name => 'user', -value => $user),
	            $cgi->scrolling_list( -name   => 'model',
					  -values => [ @orgs ],
					  -size   => 10,
					  ), $cgi->br,
	            $cgi->submit('Status of Model'),
	            $cgi->end_form
	     );
    }
    else
    {
	push(@$html,$cgi->h1('Sorry, no PEGs for Models in this SEED'));
    }
}


# I accumulate all the connections and then do nothing
# with them.  I will end up using them, I think

sub som {
    my($fig,$cgi,$html,$model) = @_;
    my(@pegs,$genome,$peg,@in,$tuple,$subsys,$role,@poss,$subsystem,$variant);
    my($reactions,$reaction,%peg2react,%react2peg);

    @pegs = map { ($_ =~ /(fig\|\d+\.\d+\.peg\.\d+)/) ? $1 : () } `cat $FIG_Config::global/Models/$model`;
    if (@pegs < 1) 
    {
	push(@$html,$cgi->h1("Too few PEGs in model for $model"));
    }
    else
    {
	$genome = &FIG::genome_of($pegs[0]);

	foreach $peg (@pegs)
	{
	    @in = $fig->peg_to_roles_in_subsystems($peg);
	    foreach $tuple (@in)
	    {
		($subsys,$role) = @$tuple;
		push(@poss,[$peg,$subsys,$role]);
		$to_check{$subsys}->{$role} = 1;
	    }
	}
    
	foreach $subsys (keys(%to_check))
	{
	    if (($subsystem = new Subsystem($subsys,$fig,0)) &&
		($variant = $subsystem->get_variant_code_for_genome($genome)) &&
		($variant && ($variant ne "-1")))
	    {
		if ($reactions = $subsystem->get_reactions)
		{
		    foreach $role (keys(%{$to_check{$subsys}}))
		    {
			if (($reactions->{$role}))
			{
			    my @pegs = $subsystem->get_pegs_from_cell($genome,$role);
			    foreach $reaction (@{$reactions->{$role}})
			    {
				foreach $peg (@pegs)
				{
				    $peg2react{$peg}->{$reaction} = 1;
				    push(@{$react2peg{$reaction}->{$peg}},[$subsys,$role]);
				}
			    }
			}
		    }
		}
	    }
	}
	&display_connections($fig,$cgi,$html,\@pegs,\%peg2react,\%react2peg);
    }
}

sub display_connections {
    my($fig,$cgi,$html,$pegs,$peg2react,$react2peg) = @_;
    my($peg,$func);

    my $col_hdrs = ["PEG","function"];
    my $tab = [];
    foreach $peg (sort { &FIG::by_fig_id($a,$b) } @$pegs)
    {
	if (! $peg2react->{$peg})
	{
	    $func = $fig->function_of($peg);
	    push(@$tab,[&HTML::fid_link($cgi,$peg),$func]);
	}
    }
    push(@$html,&HTML::make_table($col_hdrs,$tab,"PEGs that do not yet connect"));
}
    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3