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

View of /FigWebServices/show_exp_assertions.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (download) (annotate)
Wed Mar 12 16:58:04 2008 UTC (11 years, 8 months ago) by overbeek
Branch: MAIN
CVS Tags: mgrast_dev_08112011, rast_rel_2009_05_18, mgrast_dev_08022011, rast_rel_2014_0912, rast_rel_2008_06_18, myrast_rel40, rast_rel_2008_06_16, mgrast_dev_05262011, rast_rel_2008_12_18, mgrast_dev_04082011, rast_rel_2008_07_21, rast_rel_2010_0928, rast_2008_0924, mgrast_version_3_2, mgrast_dev_12152011, rast_rel_2008_04_23, mgrast_dev_06072011, rast_rel_2008_09_30, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, rast_rel_2009_02_05, rast_rel_2011_0119, mgrast_rel_2008_0625, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, rast_rel_2008_10_09, mgrast_dev_04012011, rast_release_2008_09_29, mgrast_rel_2008_0806, mgrast_rel_2008_0923, mgrast_rel_2008_0919, rast_rel_2009_07_09, rast_rel_2010_0827, mgrast_rel_2008_1110, myrast_33, rast_rel_2011_0928, rast_rel_2008_09_29, mgrast_rel_2008_0917, rast_rel_2008_10_29, mgrast_dev_04052011, mgrast_dev_02222011, rast_rel_2009_03_26, mgrast_dev_10262011, rast_rel_2008_11_24, rast_rel_2008_08_07, HEAD
Changes since 1.8: +1 -1 lines
fix to show_exp_assertions.cgi

# -*- perl -*-
#
# Copyright (c) 2003-2006 University of Chicago and Fellowship
# for Interpretations of Genomes. All Rights Reserved.
#
# This file is part of the SEED Toolkit.
# 
# The SEED Toolkit is free software. You can redistribute
# it and/or modify it under the terms of the SEED Toolkit
# Public License. 
#
# You should have received a copy of the SEED Toolkit Public License
# along with this program; if not write to the University of Chicago
# at info@ci.uchicago.edu or the Fellowship for Interpretation of
# Genomes at veronika@thefig.info or download a copy from
# http://www.theseed.org/LICENSE.TXT.
#


use FIG;
my $fig = new FIG;

use HTML;
use strict;

use CGI;
my $cgi = new CGI;

if (0)
{
    my $VAR1;
    eval(join("",`cat /tmp/exp_2c_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/exp_2c_parms"))
	{
	    print TMP &Dumper($cgi);
	    close(TMP);
	}
    }
    exit;
}
my($genome);

my $html = [];
unshift @$html, "<TITLE>Show Solid Assertions</TITLE>\n";

my $subsys  = $cgi->param('subsystem');
my @options = $cgi->param('options');
my @rules   = $cgi->param('rule');

if (! $subsys)
{
    my @ssa = &existing_subsystem_annotations;

    if (@ssa > 0)
    {
	&format_ssa_table($cgi,$html,\@ssa);
    }
    else
    {
	push(@$html,$cgi->h1('Sorry, no subsystems defined'));
    }
}
elsif ($subsys && (@options == 0))
{
    &format_experts_and_options($cgi,$html,$fig,$subsys);
}
elsif ($subsys && (@options > 0) && (@rules == 0))
{
    my @roles = &roles_for_sub($fig,$subsys);
    if (@roles > 0)
    {
	&format_roles($cgi,$html,$fig,\@roles,$subsys,\@options);
    }
    else
    {
	push(@$html,$cgi->h1('Sorry, no roles defined'));
    }
}
elsif (@rules > 0)
{
    &add_rules($fig,$cgi,$html,\@rules);
    my @roles = &roles_for_sub($fig,$subsys);
    if (@roles > 0)
    {
	&format_roles($cgi,$html,$fig,\@roles,$subsys,\@options);
    }
    else
    {
	push(@$html,$cgi->h1('Sorry, no roles defined'));
    }
}
else
{
    push(@$html,$cgi->h1('invalid parameters'));
}

&HTML::show_page($cgi,$html);

sub format_ssa_table {
    my($cgi,$html,$ssaP) = @_;

    push(@$html, $cgi->start_form(-action => "show_exp_assertions.cgi",
				  -method => 'post'),
	         $cgi->scrolling_list( -name   => 'subsystem',
				       -values => [ map { $_->[0] } @$ssaP ],
				       -size   => 10
				       ),
	         $cgi->br,
	         $cgi->submit( 'Pick One' ),
	         $cgi->end_form
	 );
}

sub existing_subsystem_annotations {
    my($ssa,$name);
    my @ssa = ();
    if (opendir(SSA,"$FIG_Config::data/Subsystems"))
    {
	@ssa = map { $ssa = $_; $name = $ssa; $ssa =~ s/[ \/]/_/g; [$name,&curator($ssa)] } grep { $_ !~ /^\./ } readdir(SSA);
	closedir(SSA);
    }
    return sort { $a->[0] cmp $b->[0] } @ssa;
}

sub curator {
    my($ssa) = @_;
    my($who) = "";

    if (open(DATA,"<$FIG_Config::data/Subsystems/$ssa/curation.log"))
    {
	$_  = <DATA>;
	if ($_ =~ /^\d+\t(\S+)\s+started/)
	{
	    $who = $1;
	}
	close(DATA);
    }
    return $who;
}

sub roles_for_sub {
    my($fig,$subsys) = @_;

    my $sub           = $fig->get_subsystem($subsys);
    my @roles         = $sub->get_roles;
    return @roles;
}

sub format_roles {
    my($cgi,$html,$fig,$roles,$subsys,$options) = @_;

    my %experts_to_show = map { $_ => 1 } @$options;
    my $role;
    my $subO = $fig->get_subsystem($subsys);
    my @genomes = $subO->get_genomes;
    
    if ($experts_to_show{'just_different'})
    {
	push(@$html, $cgi->start_form(-action => "show_exp_assertions.cgi",
				      -method => 'post'),
	             $cgi->hidden(-name => 'subsystem', -value => $subsys, -override => 1)

	    );
	foreach my $opt (@$options)
	{
	    push(@$html,$cgi->hidden(-name => 'options', -value => $opt, -override => 1));
	}
    }
    
    my $roles_shown = 0;
    foreach $role (@$roles)
    {
	my $col_hdrs = ['Id','Organism','FIG Function','Expert','Expert Assertion'];
	if ($experts_to_show{'just_different'})
	{
	    push(@$col_hdrs,'To Add Rule');
	}
	my $tab      = [];
	
	my @pegs = ();
	foreach my $genome (@genomes)
	{
	    push(@pegs,grep { $fig->is_real_feature($_) } $subO->get_pegs_from_cell($genome,$role));
	}

	my @assertions = sort { &FIG::by_fig_id($a->[0],$b->[0]) } 
	                 grep { $experts_to_show{'all'} || $experts_to_show{$_->[1]} }
	                 &FIG::get_expert_assertions(\@pegs);
	foreach my $tuple (@assertions)
	{
	    my($peg,$expert,$exp_assertion) = @$tuple;
	    my $func = $fig->function_of($peg);
	    my $translated = $fig->translate_function($exp_assertion);
	    if (! ($experts_to_show{'just_different'} && ($func eq $translated)))
	    {
		my $org = $fig->genus_species(&FIG::genome_of($peg));
		my $row = [&HTML::fid_link($cgi,$peg),$org,$func,$expert];
		if ($experts_to_show{'just_different'})
		{
		    my $check = $cgi->checkbox(-name => 'rule',
					       -value => "$exp_assertion\t$func", 
					       -checked => 0, 
					       -override => 1,
					       -label => '');
		    push(@$row,($exp_assertion,$func ? $check : '' ));
		}
		else
		{
		    push(@$row,$translated);
		}
		push(@$tab,$row);
	    }
	}

	if (@$tab > 0)
        {
	    $roles_shown++;
	    push(@$html,&HTML::make_table($col_hdrs,$tab,"PEGs with Expert Assertions for $role"),
	                $cgi->br,$cgi->br);
        }
    }
    
    if ($roles_shown == 0)
    {
	push(@$html,$cgi->h2('no roles have expert assertions meeting the criteria to display'));
    }

    elsif ($experts_to_show{'just_different'})
    {
	push(@$html,$cgi->br,
	            $cgi->submit( 'Add Translation Rules' ),
	            $cgi->end_form
	 );

    }
}

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

    push(@$html, $cgi->start_form(-action => "show_exp_assertions.cgi",
				  -method => 'post'),
	         $cgi->hidden(-name => 'subsystem', -value => $subsys, -override => 1)
	 );

    my $subO = $fig->get_subsystem($subsys);
    my @pegs = $subO->get_all_pegs;
    my @assertions = &FIG::get_expert_assertions(\@pegs);
    my %by_whom = map { $_->[1] => 1 }  @assertions;
    my @experts = sort keys(%by_whom);
     
    my $col_hdrs = ['','Expert'];
    my $tab = [];

    my $check = $cgi->checkbox(-name => 'options',
			       -value => 'all', 
			       -checked => 0, 
			       -override => 1,
			       -label => '');

    push(@$tab,[$check,'all']);
    foreach my $expert (@experts)
    {
	my $check = $cgi->checkbox(-name => 'options',
				   -value => $expert, 
				   -checked => 0, 
				   -override => 1,
				   -label => '');
	push(@$tab,[$check,$expert]);
    }
    push(@$html,&HTML::make_table($col_hdrs,$tab,"SHOW"),$cgi->br,$cgi->br);
	 
    push(@$html,$cgi->checkbox(-name => 'options',
			       -value => 'just_different', 
			       -checked => 0, 
			       -override => 1,
			       -label => 'Show Only Differing Opinions'),
	         $cgi->br,
	         $cgi->submit( 'Show Expert Opinions' ),
	         $cgi->end_form
	 );
}

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

    my($from,$to,$line);
    my %tran = map { my($f1,$f2) = split(/\t/,$_); $f1 => $f2 } @$rules;
    if (open(TMP,"<$FIG_Config::global/function.synonyms")) 
    {
	while (defined($line = <TMP>))
	{
	    chomp $line;
	    ($from,$to) = split(/\t/,$line);
	    if (($from ne $to) && (! $tran{$to}))
	    {
		$tran{$from} = $to;
	    }
	}
	close(TMP);

	foreach $from (keys(%tran))
	{
	    $to = $tran{$from};
	    while ($tran{$to})
	    {
		$to = $tran{$to};
	    }
	    $tran{$from} = $to;
	}
    }

    if (open(TMP,">$FIG_Config::global/function.synonyms"))
    {
	foreach $from (sort keys(%tran))
	{
	    print TMP "$from\t$tran{$from}\n";
	}
	close(TMP);
    }
    $_ = @$rules;
    push(@$html,$cgi->h2("added $_ rules"));
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3