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

View of /FigWebServices/lock_subsys.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (annotate)
Sat Dec 23 04:32:47 2006 UTC (12 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.1: +48 -8 lines
allow selection of all roles/genomes for locking

# -*- 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 Subsystem;

use HTML;
use strict;

use CGI;
my $cgi = new CGI;

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

my $user = $cgi->param('user'); 
$user    =~ s/^master://;
$fig->set_user($user);

my $html = [];
unshift @$html, "<TITLE>Set Locks for a Subsystem</TITLE>\n";

if (! $user)
{
    push(@$html,$cgi->h1('you need to set a user'));
    &HTML::show_page($cgi,$html);
    exit;
}

my $subsys = $cgi->param('subsystem');
if (! $subsys)
{
    my @ssa = &existing_subsystem_annotations($user);

    if (@ssa > 0)
    {
	&format_ssa_table($cgi,$html,\@ssa);
    }
    else
    {
	push(@$html,$cgi->h1('Sorry, no subsystems defined'));
    }
}
elsif ($cgi->param('lock annotations'))
{
    my @orgs;
    if ($cgi->param('select_all_genomes'))
    {
	@orgs = map { $_->[0] } @{$fig->subsystem_genomes($subsys)};
    }
    else
    {
	@orgs  = $cgi->param('genome_to_lock');
	@orgs = map { $_ =~ /^(\d+\.\d+)/; $1 } @orgs;
    }

    my @roles ;
    if ($cgi->param('select_all_roles'))
    {
	@roles = $fig->subsystem_to_roles($subsys);
    }
    else
    {
	@roles = $cgi->param('roles_to_lock');
    }
    push(@$html,"<br>");

    foreach my $genome (@orgs)
    {
	foreach my $role (@roles)
	{
	    foreach my $peg ($fig->pegs_in_subsystem_cell($subsys,$genome,$role))
	    {
		$user =~ s/master://;
		$fig->lock_fid($user,$peg);
		push(@$html,"locked $peg<br>\n");
	    }
	}
    }
    &show_subsystem($fig,$cgi,$html,$subsys,$user);
}
elsif ($cgi->param('unlock annotations'))
{
    my @orgs;
    if ($cgi->param('select_all_genomes'))
    {
	@orgs = map { $_->[0] } @{$fig->subsystem_genomes($subsys)};
    }
    else
    {
	@orgs  = $cgi->param('genome_to_lock');
	@orgs = map { $_ =~ /^(\d+\.\d+)/; $1 } @orgs;
    }

    my @roles ;
    if ($cgi->param('select_all_roles'))
    {
	@roles = $fig->subsystem_to_roles($subsys);
    }
    else
    {
	@roles = $cgi->param('roles_to_lock');
    }
    push(@$html,"<br>");

    foreach my $genome (@orgs)
    {
	foreach my $role (@roles)
	{
	    foreach my $peg ($fig->pegs_in_subsystem_cell($subsys,$genome,$role))
	    {
		$user =~ s/master://;
		$fig->unlock_fid($user,$peg);
		push(@$html,"unlocked $peg<br>\n");
	    }
	}
    }
    &show_subsystem($fig,$cgi,$html,$subsys,$user);
}
else
{
    &show_subsystem($fig,$cgi,$html,$subsys,$user);
}

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

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

    push(@$html, $cgi->start_form(-action => "lock_subsys.cgi",
				  -method => 'post'),
                 $cgi->hidden(-name => 'user', -value=>$user),
	         $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($user) = @_;

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

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

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

    my $format = $cgi->param('format');
    if (! $format)  { $format = 'concise' }

    my $subO           = $fig->get_subsystem($subsys);

    push(@$html,$cgi->hr);
    push(@$html,$cgi->h3('Reset Subsets'));
    my @subset_names = sort $subO->get_subset_namesC;
    my($active_subsetC,$active_subsetR);
    $active_subsetC = ($cgi->param('active_subsetC') or $subO->get_active_subsetC );
    if (@subset_names > 1)
    {
	push(@$html,$cgi->scrolling_list(-name => 'active_subsetC',
					 -values => [@subset_names],
					 -default => $active_subsetC
					 )
	     );
    }
    $active_subsetR = ($cgi->param('active_subsetR') or $subO->get_active_subsetR);
    my @tmp = grep { $_ ne "All" } sort $subO->get_subset_namesR;
    push(@$html,$cgi->scrolling_list(-name => 'active_subsetR',
                                     -values => ["All",@tmp],
                                     -default => $active_subsetR,
                                     -size => 5
                                     )
	 );
    push(@$html,$cgi->hr);
    my @colmem     = $subO->get_subsetC($active_subsetC);
#    print &Dumper($subO->get_role($colmem[0]),$subO->get_role_abbr($colmem[0]));
    my @rowmem     = $subO->get_subsetR($active_subsetR);
    my @genomes = grep { $subO->get_variant_code_for_genome($_) !~ /^(0|-1)$/ } @rowmem;
#    print &Dumper(\@genomes,$active_subsetR); die "aborted";

    my $col_hdrs = ['','Abbrev','Role'];
    my $tab = [];
    my $i;
    for ($i=1; ($i <= @colmem); $i++)
    {
	push(@$tab,[$i,$subO->get_role_abbr($colmem[$i-1]),$subO->get_role($colmem[$i-1])]);
    }
    push(@$html,&HTML::make_table($col_hdrs,$tab,"Roles"));
    push(@$html,$cgi->hr,"Reset format<br>");

    push(@$html,$cgi->radio_group(-name => 'format',
				  -values => ['concise','show pegs'],
				  -default => $format,
				  -override => 1
				  ));
    $col_hdrs = ['Genome','genus species','variant'];
    $tab      = [];
    for ($i=1; ($i <= @colmem); $i++)
    {
	push(@$col_hdrs,($format eq "concise") ? $i : $subO->get_role_abbr($colmem[$i]));
    }

    foreach my $genome (@genomes)
    {
	my $genome_idx = $subO->get_genome_index($genome);
	my $row = [$genome,$fig->genus_species($genome),$subO->get_variant_code($genome_idx)];
	foreach my $role_idx (@colmem)
	{
	    my $cell = $subO->get_cell($genome_idx,$role_idx);
	    my @tuples = map { [$_,$fig->is_locked_fid($_)] } @$cell;
	    my @locks = ();
	    for ($i=0;($i < @tuples); $i++)
	    {
		my $url = &HTML::fid_link($cgi,$tuples[$i]->[0],0,1);
		my($val,$link);
		if ($format eq "concise")
		{
		    $val = ($tuples[$i]->[1]) ? "+" : "-";
		    $link = $val;
		}
		else
		{
		    $tuples[$i]->[0] =~ /(\d+)$/;
		    $val = ($tuples[$i]->[1]) ? "+$1" : "-$1";
		    $link = "<a href=$url>$val</a>";
		}
		push(@locks,$link);
	    }
	    push(@$row,join("<br>",@locks));
	}
	push(@$tab,$row);
    }

    my $sort = $cgi->param('sort') || 'by_phylo';
    if ($sort eq "by_pattern")
    {
	my @tmp = ();
	my $row;
	foreach $row (@$tab)
	{
	    my @var = ();
	    my $i;
	    for ($i=3; ($i < @$row); $i++)
	    {
		push(@var, $row->[$i] ? 1 : 0);
	    }
	    push(@tmp,[join("",@var),$row]);
	}
	$tab = [map { $_->[1] } sort { $a->[0] cmp $b->[0] } @tmp];
    }
    elsif ($sort eq "by_phylo")
    {
	$tab = [map      { $_->[0] }
		sort     { ($a->[1] cmp $b->[1]) or ($a->[0]->[1] cmp $b->[0]->[1]) }
		map      { [$_, $fig->taxonomy_of($_->[0])] }
		@$tab];
    }
    elsif ($sort eq "alphabetic")
    {
	$tab = [sort     { ($a->[1] cmp $b->[1]) or ($a->[0] <=> $b->[0]) } @$tab];
    }
    elsif ($sort eq "by_variant")
    {
	$tab = [sort     { ($a->[2] cmp $b->[2]) or ($a->[1] <=> $b->[1]) } @$tab];
    }

    push(@$html,&HTML::make_table($col_hdrs,$tab,'Spreadsheet'));
        my %sortmenu = (
            alphabetic => "Alphabetical",
            by_pattern => "Patterns",
            by_phylo   => "Phylogeny",
            by_variant => "Variant Code",
        );

    push @$html, $cgi->hr,
                 "Sort spreadsheet genomes by ",
                 $cgi->popup_menu( -name     => 'sort', 
				   -values   => [sort keys %sortmenu],
				   -labels   => \%sortmenu,
				   -default  => $sort,
				   -override => 1
				   );

    push(@$html,$cgi->hr,
	        $cgi->submit('show again, after setting/uynsetting locks and parameters')
	 );

    my @orgs = map { "$_->[0]: " . $_->[1] } 
               map { [$_,$fig->genus_species($_)] }
               grep { $subO->get_variant_code($subO->get_genome_index($_)) ne "-1" }
               map { $_->[0] } @$tab;

    my @roles = map { $subO->get_role($_) } @colmem;

    push(@$html,$cgi->hr,$cgi->h1('Lock PEGs in Cells'));
    push(@$html, $cgi->scrolling_list( -name     => 'genome_to_lock',
                                       -values   => [ @orgs ],
                                        -size     => 10,
                                        -multiple => 1
				       ),
	         $cgi->checkbox(-name => 'select_all_genomes', -value => 1, -checked => 0, -override => 1,
				-label => 'select all genomes'),
	         "<br>",
	         $cgi->scrolling_list(  -name     => 'roles_to_lock',
                                        -values   => [ @roles ],
                                        -size     => 10,
                                        -multiple => 1
					),
	         $cgi->checkbox(-name => 'select_all_roles', -value => 1, -checked => 0, -override => 1,
				-label => 'select all roles'),
	        "<br>");

    push(@$html,$cgi->submit('lock annotations')," OR ");
    push(@$html,$cgi->submit('unlock annotations'),$cgi->br);
    push(@$html,$cgi->end_form);
}


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3