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

View of /FigWebServices/get_expert_2c.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (download) (annotate)
Thu Dec 27 19:41:53 2007 UTC (11 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, 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.6: +3 -3 lines
minor check for division by 0 in get_expert_2c.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>Get Solid Assertions</TITLE>\n";

my $user   = $cgi->param('user');
my $subsys = $cgi->param('subsystem');
my $role   = $cgi->param('role');

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 && (! $role))
{
    my @roles = &roles_for_sub($cgi,$html,$fig,$subsys);;
    if (@roles > 0)
    {
	&format_roles($cgi,$html,$fig,\@roles,$subsys);
    }
    else
    {
	push(@$html,$cgi->h1('Sorry, no roles defined'));
    }
}
elsif ($subsys && $role && ($cgi->param('request') eq "show_assertions"))
{
    &format_assertions($cgi,$html,$fig,$subsys,$role);
}
elsif ($subsys && $role && ($cgi->param('request') eq "2c_assertions"))
{
    &format_2c($cgi,$html,$fig);
}
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 => "get_expert_2c.cgi",
				  -method => 'post'),
	         $cgi->hidden(-name => 'user', -value => $user, -override => 1),
	         $cgi->hidden(-name => 'request', -value => 'show_variants', -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 roles_for_sub {
    my($cgi,$html,$fig,$subsys) = @_;

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

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

    push(@$html, $cgi->start_form(-action => "get_expert_2c.cgi",
				  -method => 'post'),
	         $cgi->hidden(-name => 'user', -value => $user, -override => 1),
	         $cgi->hidden(-name => 'subsystem', -value => $subsys, -override => 1),
	         $cgi->hidden(-name => 'request', -value => 'show_assertions', -override => 1),
	         $cgi->scrolling_list( -name   => 'role',
				       -values => $roles,
				       -size   => 10
				       ),
	         $cgi->br,
	         $cgi->br,
	         $cgi->br,
	         'Require Clustering with ',
	         $cgi->textfield(-name => "clusters_with", -size => 3, -value => 0),
	         $cgi->br,
	         $cgi->submit( 'Show Assertions to Pick From' ),
	         $cgi->end_form
	 );
}

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

    my $clusters_with = $cgi->param('clusters_with');
    my $subsysQ = quotemeta $subsys;
    push(@$html, $cgi->start_form(-action => "get_expert_2c.cgi",
				  -method => 'post'),
	         $cgi->hidden(-name => 'user', -value => $user, -override => 1),
	         $cgi->hidden(-name => 'subsystem', -value => $subsys, -override => 1),
	         $cgi->hidden(-name => 'role', -value => $role, -override => 1),
	         $cgi->hidden(-name => 'request', -value => '2c_assertions', -override => 1)
	 );

    my $sub           = $fig->get_subsystem($subsys);
    my @genomes       = $sub->get_genomes;
    my %variant_codes;
    foreach my $genome (@genomes)
    {
	my $var = $sub->get_variant_code_for_genome($genome);
	$variant_codes{$genome} = $var;
    }
    
    my $col_hdrs = ['Solid','Possibly Truncated','Duplicates','Length','variant code','PEG','Clusters with','Genome','Function'];
    my $tab1 = [];
    my $tab2 = [];

    my @all_pegs = ();

    my($peg,$ln);
    foreach my $genome (@genomes)
    {
	my @pegs = $sub->get_pegs_from_cell($genome,$role);
	if (@pegs > 0)
	{
	    push(@all_pegs,[map { $peg = $_; $ln = length($fig->get_translation($peg)); [$peg,$ln] } @pegs ]);
	}
    }

    my $tot = 0;
    my $n = 0;
    foreach my $gset (@all_pegs)
    {
	foreach my $tuple (@$gset)
	{
	    ($peg,$ln) = @$tuple;
	    $tot += $ln;
	    $n++;
	}
    }
    my $avg = ($n > 0) ? int($tot/$n) : 1000000;

    foreach my $gset (@all_pegs)
    {
	foreach my $tuple (@$gset)
	{
	    ($peg,$ln) = @$tuple;

	    my $trunc = $fig->possibly_truncated($peg) ? "yes" : '&nbsp;';
	    my $dup   = (@$gset > 1) ? scalar @$gset : '&nbsp;';
	    my $genome = &FIG::genome_of($peg);
	    my $gs = $fig->genus_species($genome);
	    my $func = $fig->function_of($peg);
	    my $bad_ln = (abs($ln - $avg) > (0.2 * $avg));
	    my @tmp = map { ($_->[2] =~ /^icw\((\d+)\);$subsysQ/) ? $1 : () } $fig->get_attributes($peg,'evidence_code');
	    my $icw = (@tmp > 0) ? $tmp[0] : 0;

	    my $solid = (($variant_codes{$genome} =~ /^(0|-1)$/) ||
			 (($trunc eq "yes") || (@$gset > 1) || $bad_ln)) ? "no" : "yes";
		
	    my $checked = (($solid eq "yes") && ((! $clusters_with) || ($icw >= $clusters_with))) ? 1 : 0;

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

	    my $link = &HTML::fid_link($cgi,$peg);

	    if (($solid eq "yes") && ((! $clusters_with) || ($icw >= $clusters_with)))
	    {
		push(@$tab1,[$check,$trunc,$dup,$ln,$variant_codes{$genome},$link,$icw,$gs,$func]);
	    }
	    else
	    {
		push(@$tab2,[$check,
			     ($trunc eq "yes") ? [$trunc,'td bgcolor=yellow'] : $trunc,
			     ($dup =~ /^[0-9]/) ? [$dup,'td bgcolor=yellow'] : $dup,
			     $bad_ln ? [$ln,'td bgcolor=yellow'] : $ln,
			     ($variant_codes{$genome} =~ /^(0|-1)$/) ? 
			           [$variant_codes{$genome},'td bgcolor=yellow'] : 
			           $variant_codes{$genome},
			     $link,$icw,$gs,$func
			    ]);
	    }
	}
    }

    $tab1 = [sort { $a->[6] cmp $b->[6] } @$tab1];
    $tab2 = [sort { $a->[6] cmp $b->[6] } @$tab2];

    push(@$html,&HTML::make_table($col_hdrs,$tab1,"Solid: Avg Length = $avg"));

    push(@$html,&HTML::make_table($col_hdrs,$tab2,"Maybe Not So Solid: Avg Length = $avg"));

    push(@$html, $cgi->br,
	         $cgi->submit( 'Show 3-column Assertion Table [Id, Function, genus/specie]' ),
	         $cgi->end_form
	 );

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

    my @checked = $cgi->param('checked');
    push(@$html,"<pre>");
    foreach my $peg (@checked)
    {
	my $func = $fig->function_of($peg);
	my $org  = $fig->genus_species(&FIG::genome_of($peg));
	push(@$html,"$peg\t$func\t$org\n");
    }
    push(@$html,"</pre>");
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3