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

View of /FigWebServices/cleanup.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (download) (annotate)
Fri Jan 9 19:39:02 2009 UTC (10 years, 10 months ago) by overbeek
Branch: MAIN
CVS Tags: mgrast_dev_08112011, rast_rel_2009_05_18, mgrast_dev_08022011, rast_rel_2014_0912, myrast_rel40, mgrast_dev_05262011, mgrast_dev_04082011, rast_rel_2010_0928, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, 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, rast_rel_2009_02_05, rast_rel_2011_0119, 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, mgrast_dev_04012011, rast_rel_2009_07_09, rast_rel_2010_0827, myrast_33, rast_rel_2011_0928, mgrast_dev_04052011, mgrast_dev_02222011, rast_rel_2009_03_26, mgrast_dev_10262011, HEAD
Changes since 1.3: +2 -2 lines
add sizes to tables

# -*- 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 URI::Escape;

use CGI;
my $cgi = new CGI;

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

my $html = [];
unshift @$html, "<TITLE>Cleanup Annotations</TITLE>\n";

my $user       = $cgi->param('user');
my $request          = $cgi->param('request');

if (! -d "$FIG_Config::data/BadPegs")
{
    push(@$html,$cgi->h1("Missing BadPegs Directory: Contact Ross"));
}
elsif ((! $user) || (! $request))
{
    &get_user_request($fig,$cgi,$html);
}
else
{
    if ($request eq 'no_ss')
    {
	&process_no_ss($fig,$cgi,$html,$user);
    }
    elsif ($request eq 'ss_clash')
    {
	&process_ss_clash($fig,$cgi,$html,$user);
    }
    elsif ($request eq 'most_in_ss')
    {
	&process_most_in_ss($fig,$cgi,$html,$user);
    }
    elsif ($request eq 'a_few_ss')
    {
	&process_a_few_ss($fig,$cgi,$html,$user);
    }
}
&HTML::show_page($cgi,$html, 1, undef, undef, undef, undef, { no_fig_search => 1 });

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

    push(@$html, $cgi->start_form(-action => "cleanup.cgi",
				  -method => 'get'),
	         '<br><br>User: ',
	         $cgi->textfield(-name => "user", -size => 10, -value => ''),
	         $cgi->br,
	         $cgi->br,
	         $cgi->radio_group( -name       => 'request',
				    -default    => 'no_ss',
				    -override   => 1,
				    -values     => ['ss_clash','most_in_ss','a_few_ss','no_ss']
				    ),
	         $cgi->br,
	         $cgi->br,
	         $cgi->submit( 'Do it' ),
	         $cgi->end_form
	 );

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

    my @no_ss   = map { chop; [split(/\t/,$_)] } `cat $FIG_Config::data/BadPegs/bad.nosubs.fc`;
    my @tuples = &get_good_tuples($fig,\@no_ss);

    my $col_hdrs = ['PEG','Size','Coupled to','Max Coupling','Function'];
    my $tab = [];
    foreach my $tuple (@tuples)
    {
	if ($tuple =~ /^(fig\|\d+\.\d+\.peg\.\d+),(\d+),(\d+)$/)
	{
	    my $peg = $1;
	    my $n_fc = $2;
	    my $max_fc = $3;
	    
	    my $func = $fig->function_of($peg);
	    my $link = &link($cgi,$peg);
	    push(@$tab,[$link,&size($fig,$peg),$n_fc,$max_fc,$func]);
	}
    }
    push(@$html,&HTML::make_table($col_hdrs,$tab,'PEGs Same, Different Function'));
}

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

    &process_ss($fig,$cgi,$html,$user,'bad.sub.multifunc','PEGs Same, Conflict in Subsystems');
}

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

    &process_ss($fig,$cgi,$html,$user,'bad.mostsubs','Most PEGs in Subsystems');
}

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

    &process_ss($fig,$cgi,$html,$user,'bad.fewsubs','Few PEGs in Subsystems');
}

sub process_ss {
    my($fig,$cgi,$html,$user,$file,$title) = @_;

    my @bad   = map { chop; [split(/\t/,$_)] } `grep $user $FIG_Config::data/BadPegs/$file`;
    my @tuples = &get_good_tuples($fig,\@bad);

    my $col_hdrs = ['PEG','Size','Curators','Function'];
    my $tab = [];
    foreach my $tuple (@tuples)
    {
	if ($tuple =~ /^(fig\|\d+\.\d+\.peg\.\d+)(; (\S+))?$/)
	{
	    my $peg = $1;
	    my $others = $3 ? $3 : "&nbsp;";
	    my $func = $fig->function_of($peg);
	    if (! $func) { $func = "&nbsp;"; }
	    my $link = &link($cgi,$peg);
	    push(@$tab,[$link,&size($fig,$peg),$others,$func]);
	}
    }
    push(@$html,&HTML::make_table($col_hdrs,$tab,$title));
}

sub link {
    my($cgi,$peg) = @_;

    my $user = $cgi->param('user');
    return "<a target=other.$$ href=http://anno-3.nmpdr.org/anno/FIG/seedviewer.cgi?page=Annotation&feature=$peg&user=$user>$peg</a>";
#   return "<a target=other.$$ href=\"http://anno-3.nmpdr.org/anno/FIG/protein.cgi?user=$user&prot=$peg&compare_region=1#compared_regions\">$peg</a>";
}


sub get_good_tuples {
    my($fig,$from_file) = @_;

    my @tuples = ();
    while ((@tuples == 0) || &all_ok($fig,\@tuples))
    {
        my $n = int(rand() * (@$from_file - 1));
 	@tuples = @{$from_file->[$n]};
    }
    return @tuples;
}

sub func_of_tuple {
    my($fig,$tuple) = @_;

    $tuple =~ /^(fig\|\d+\.\d+\.peg\.\d+)/;
    return $fig->function_of($1);
}

sub all_ok {
    my($fig,$tuples) = @_;

    my $func = &func_of_tuple($fig,$tuples->[0]);
    my $i;
    for ($i=1; ($i < @$tuples) && ($func eq &func_of_tuple($fig,$tuples->[$i])); $i++) {}
    return ($i == @$tuples);
}

sub size {
    my($fig,$peg) = @_;
    
    my $seq = $fig->get_translation($peg);
    return $seq ? length($seq) : 0;
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3