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

View of /FigWebServices/check_subsys.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.26 - (download) (annotate)
Thu Aug 9 12:07:18 2007 UTC (12 years, 3 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.25: +2 -2 lines
attempt to fix some of the mistakes introduced into check_subsys.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 URI::Escape;
use Subsystem;

use HTML;
use strict;

use CGI;
my $cgi = new CGI;

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

my $html = [];
my $subsys = $cgi->param('subsystem');
my $user = $cgi->param('user');
$user =~ s/master://;

if (! $subsys)
{
    if ($cgi->param('request') eq "check_summary")
    {
	&check_summary($fig,$cgi,$html,$user);
    }
    else
    {
	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 && ($cgi->param('request') eq "check_ssa"))
{
    &check_subsystem($cgi,$fig,$html,$subsys);
}
&HTML::show_page($cgi,$html);

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

    my $user = $cgi->param('user');
    $user = $user ? $user : "";
    push(@$html, $cgi->start_form(-action => "check_subsys.cgi",
				  -method => 'post'),
	         $cgi->hidden(-name => 'request', -value => 'check_ssa', -override => 1),
	         $cgi->hidden(-name => 'user', -value => "$user", -override => 1),
	         $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 check_subsystem {
    my($cgi,$fig,$html,$subsys) = @_;
    my($col_hdrs1,$col_hdrs2,$tab1,$tab2,$x);

    my $user=$cgi->param('user');
    my @raw_output = &get_check_data($cgi,$subsys,$fig);

#   my @raw_output = &FIG::run_gathering_output("$FIG_Config::bin/check_subsystems", $subsys);
#   warn "Got raw output @raw_output\n";
    my @checked = map { chop; [split(/\t/,$_)] } @raw_output;

    # RAE: it only makes sense to have Assign Role in column 1, so I duplicate this instead of leaving the column empty. Blah.
    $col_hdrs1 = ["PEG","Function","Role","Assign Role","Other Subsystems","Genome"];
    $col_hdrs2 = ["PEG","Function","Role","Other Subsystems","Genome"];
    $tab1 = [];
    $tab2 = [];

    foreach $x (@checked)
    {
	if ($x->[0] =~ /^(mismatch|left-out)/)
	{
	    my($code,$peg,$func,$role,$gs) = @$x;
	    $role =~ s/\s+$//;
	    next if (! $fig->is_real_feature($peg));
	    next if ($func ne scalar &stripped_function_of($fig,$peg));
	    next if (($code eq "mismatch") && (&still_left_out($fig,$peg,$subsys)));
	    next if (($code eq "mismatch") && ($func eq $role));
	    next if (($code eq "left-out") && (! &still_left_out($fig,$peg,$subsys)));

	    #RAE added the other subsystems column to the table
	    my $othersubsys='';
	    if (my @otherss = $fig->subsystems_for_peg($peg))
	    {
		foreach my $ssr (@otherss) 
		{
		    next if ($$ssr[0] eq $subsys);
		    $othersubsys .= $cgi->a({href => "subsys.cgi?user=$user&ssa_name=" . uri_escape($$ssr[0]) . "&request=show_ssa"}, $$ssr[0])  . "<br\n";
		}
	    }
	    my $link = &HTML::fid_link($cgi,$peg);
	    my $checkbox=$cgi->checkbox(-name=>"checked", -label=>'', -value=>"to=$peg,from=$role");
	    if ($code eq "mismatch")
	    {
		push(@$tab1,[$link,$func,$role,$checkbox,$othersubsys,$gs]);
	    }
	    elsif ($code eq 'left-out')
	    {
		push(@$tab2,[$link,$func,$role,$othersubsys,$gs]);
	    }
	}
    }

    # RAE addd the form controls
    push(@$html, $cgi->start_form( -method => 'post', -action => 'fid_checked.cgi', -name => 'fid_checked'), $cgi->hidden(-name => 'user', -value => $user));
    push(@$html,&HTML::make_table($col_hdrs1,$tab1,"PEGs IN Subsystem with MISMATCHING Functions"));
    
    push(@$html, $cgi->br, &HTML::java_buttons("fid_checked", "checked"), $cgi->br);
    push(@$html, $cgi->submit(-name=>'batch_assign', -label=>"Assign Roles to Selected PEGs"));
    push(@$html,$cgi->hr,$cgi->br,$cgi->br);

    push(@$html,&HTML::make_table($col_hdrs2,$tab2,"PEGs NOT in Subsystem with MATCHING Functions"));
    push(@$html,$cgi->end_form);

    my $col_hdrs3 = ['Genome','Genus and Species','Possible Variant Codes','Detected Roles'];
    my $tab3      = [];
    
    my $sobj = $fig->get_subsystem($subsys);
    my %genomes_in_sub = map { $_ => 1 } $sobj->get_genomes;
    my @to_add = grep { ($_->[1] eq 'maybe-add') && (! $genomes_in_sub{$_->[4]}) } @checked;

    my($entry,$vcodes,$genome,$gs,@roles);
    foreach $entry (sort { $a->[5] cmp $b->[5] } @to_add)
    {
	(undef,undef,undef,$vcodes,$genome,$gs,@roles) = @$entry;
	push(@$tab3,[$genome,$gs,$vcodes,join("<br>",@roles)]);
    }
    push(@$html,&HTML::make_table($col_hdrs3,$tab3,"Genomes that Should Be Considered For Addition"));
}

sub get_check_data {
    my($cgi,$subsys,$fig) = @_;
    my @raw_output;

    if ($cgi->param('fast') && (-e "$FIG_Config::data/Subsystems/$subsys/warnings"))
    {
	@raw_output = $fig->file_read("$FIG_Config::data/Subsystems/$subsys/warnings");
    }
    else
    {
	@raw_output = &FIG::run_gathering_output("$FIG_Config::bin/check_subsystems", $subsys);
#       warn "Got raw output @raw_output\n";
    }
    return @raw_output;
}
 
sub still_left_out {
    my($fig,$peg,$sub) = @_;

    my @subs = $fig->peg_to_subsystems($peg);
    my $i;
    for ($i=0; ($i < @subs) && ($sub ne $subs[$i]); $i++) {}
    return ($i == @subs);
}

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

    my $col_hdrs = ["Subsystem","Last Check Computed","Mismatching Entries","Missing Entries","Genomes to Add"];
    my $tab = [];
    my @subs = ();
    foreach my $sub ($fig->all_subsystems)
    {
	my $curr = $fig->subsystem_curator($sub); 
	$curr =~ s/^master://; 
	if (($curr eq $user) && 
	    (-e "$FIG_Config::data/Subsystems/$sub/warnings"))
	{
	    push(@subs,$sub);
	}
    }
    foreach my $sub (@subs)
    {
	my $ts = localtime($^T - ((-M "$FIG_Config::data/Subsystems/$sub/warnings") * 24 * 60 * 60));
	my @tmp = $fig->file_read("$FIG_Config::data/Subsystems/$sub/warnings");
	my @mismatches   = grep { ($_ =~ /mismatch\t(\S+)\t([^\t]+)/) } @tmp;
	my $mismatchesN  = (@mismatches > 0) ? @mismatches : 0;
	my @left_out     = grep { ($_ =~ /left-out\t(\S+)\t([^\t]+)/) } @tmp;
	my $left_outN    = (@left_out > 0) ? @left_out : 0;
	my @maybe_add    = grep { ($_ =~ /maybe-add\t[^\t]+\t[^\t]+\t(\d+\.\d+)/) } @tmp;
	my $maybe_addN   = (@maybe_add > 0) ? @maybe_add : 0;
	push(@$tab,[&sub_link($cgi,$sub,$user),$ts,$mismatchesN,$left_outN,$maybe_addN]);
    }
    push(@$html,$cgi->h3("Note that the following statistics do not take into account actions since last check"),
	 &HTML::make_table($col_hdrs,$tab,"Summary of Possible Things to Check"));
}

sub sub_link {
    my($cgi,$sub,$user) = @_;
    my $esc_sub = uri_escape($sub);
    my $url = &FIG::cgi_url . "/subsys.cgi?request=show_ssa&user=master:$user&ssa_name=$esc_sub&can_alter=1&check=1";
    my $target = "window$$";
    return "<a href=$url target=$target>$sub</a>";
}

sub stripped_function_of {
    my($fig,$peg) = @_;

    my $func = $fig->function_of($peg);
    $func =~ s/\s*\#.*$//;
    return $func;
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3