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

View of /FigWebServices/get_dlits.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (download) (annotate)
Sat Jun 28 12:12:22 2008 UTC (11 years, 5 months ago) by overbeek
Branch: MAIN
Changes since 1.2: +4 -2 lines
turn off old get_dlit.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/get_dlit_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/get_dlit_parms"))
	{
	    print TMP &Dumper($cgi);
	    close(TMP);
	}
    }
    exit;
}
my($genome);

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

my $user      = $cgi->param('user'); 
my $curator   = $cgi->param('curator');
my $role      = $cgi->param('role');
my $submit1   = $cgi->param('Show Genomes');
my $submit2   = $cgi->param('Show Roles');
my $submit3   = $cgi->param('Show Genome');
my $submit4   = $cgi->param('Show Role');
my $show_just = $cgi->param('show_just');
   $show_just = ($show_just eq "all") ? '' : $show_just;

my $genomeD   = $cgi->param('genomeD');
my $submit5   = $cgi->param('Process Changes');
my $rdbH  = $fig->db_handle;

if (! $user)
{
    push(@$html,$cgi->h1('you need to set user= in the URL'));
}
elsif (! -d "$FIG_Config::data/Dlits")
{
    push(@$html,$cgi->h1("dlit data not installed"));
}
elsif ($submit5) 
{
    &process_changes($fig,$cgi,$html);
}
elsif ($submit1)
{
    my $where   = $show_just ? "AND (dlits.status = '$show_just ') " : "";
    my $genomes = $rdbH->SQL("select DISTINCT genome_hash.genome from genome_hash,dlits WHERE genome_hash.md5_hash = dlits.md5_hash $where");
    my @genomes = sort map { &compute_genome_label($fig,$_->[0]) } @$genomes;

    push(@$html, $cgi->start_form(-action => "get_dlits.cgi", -method => 'post'),
	         $cgi->hidden(-name => 'user', -value=>$user),
	         $cgi->hidden(-name => 'show_just', -value=>$show_just),
	         $cgi->hidden(-name => 'curator', -value=> $curator),
	         $cgi->scrolling_list( -name   => 'genomeD',
				       -values => [@genomes],
				       -size   => 30
				     ),
	         $cgi->br,
	         $cgi->submit( 'Show Genome' ),
	         $cgi->end_form
	 );
}
elsif ($submit2)
{
    my $where1   = $show_just ? "AND (dlits.status = '$show_just ') " : "";
    my $where2   = $curator ? "AND (curr_role.curator = '$curator' AND curr_role.role = hash_role.role) " : "";

    my @roles = map { $_->[0] } @{$rdbH->SQL("select DISTINCT hash_role.role from hash_role,dlits,curr_role WHERE hash_role.md5_hash = dlits.md5_hash $where1  $where2")};
    push(@$html, $cgi->start_form(-action => "get_dlits.cgi", -method => 'post'),
	         $cgi->hidden(-name => 'user', -value=>$user),
	         $cgi->hidden(-name => 'show_just', -value=>$show_just),
	         $cgi->hidden(-name => 'curator', -value=> $curator),
	         $cgi->scrolling_list( -name   => 'role',
				       -values => [@roles],
				       -size   => 30
				     ),
	         $cgi->br,
	         $cgi->submit( 'Show Role' ),
	         $cgi->end_form
	 );
}
elsif ($submit3 && $genomeD && ($genomeD =~ /\((\d+\.\d+)\)/))
{
    my $where = $show_just ? " AND dlits.status = '$show_just'" : '';
    my $genome = $1;
    my $tuples = $rdbH->SQL("select DISTINCT dlits.status,dlits.md5_hash,dlits.pubmed
                              FROM genome_hash,dlits
                              WHERE genome_hash.genome = '$genome' AND genome_hash.md5_hash = dlits.md5_hash $where");
    my @to_display = ();
    foreach my $x (@$tuples)
    {
	my($status,$hash,$pubmed) = @$x;
	foreach my $peg ($fig->pegs_with_md5($hash))
	{
	    if (&FIG::genome_of($peg) eq $genome)
	    {
		push(@to_display,[$status,$peg,$pubmed]);
	    }
	}
    }
    &display_set($fig,$cgi,$html,\@to_display,'Genes for $genomeD','Show Genome');
}
elsif ($submit4)
{
    my $where = $show_just ? " AND dlits.status = '$show_just'" : '';
    my $roleQ = quotemeta $role;
    my $tuples = $rdbH->SQL("select DISTINCT dlits.status,dlits.md5_hash,dlits.pubmed
                              FROM hash_role,dlits,pubmed_titles  
                              WHERE hash_role.role = '$roleQ' AND hash_role.md5_hash = dlits.md5_hash $where");
    my @to_display = ();
    foreach my $x (@$tuples)
    {
	my($status,$hash,$pubmed) = @$x;
	my @pegs = $fig->pegs_with_md5($hash);
	if (@pegs > 0)
	{
	    push(@to_display,[$status,$pegs[0],$pubmed]);
	}
    }
    &display_set($fig,$cgi,$html,\@to_display,'Genes for Role: $role','Show Role');
}
else
{
    my @cur  = map { $_->[0]} @{$rdbH->SQL( "SELECT DISTINCT curator FROM dlits" )};

    my $curN = @cur;

    my $show_just_opt =  $cgi->scrolling_list( -name   => 'show_just',
					       -values => ['all',' ','D','R','N','G'],
					       -default => 'all',
					       -override => 1,
					       -size   => 1
				     ),

    push(@$html, $cgi->start_form(-action => "get_dlits.cgi", -method => 'post'),
	         $cgi->hidden(-name => 'user', -value=>$user),
	         $cgi->scrolling_list( -name   => 'curator',
				       -values => [ @cur ],
				            -size   => $curN
					    ),
	         $cgi->scrolling_list( -name   => 'show_just',
				       -values => ['all',' ','D','R','N','G'],
				       -default => 'all',
				       -override => 1,
				       -size   => 1
				       ),
	         $cgi->br,
	         $cgi->submit( 'Show Roles' ),
	         $cgi->br,
	         $cgi->submit( 'Show Genomes' ),
	         $cgi->end_form
	 );
}

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

sub compute_genome_label
{
    my($fig, $org) = @_;

    my $gs = $fig->genus_species($org);
    return "$gs ($org)";
}

sub title_of {
    my($fig,$pubmed) = @_;

    my $rdbH  = $fig->db_handle;
    my $retval = $rdbH->SQL( "SELECT title FROM pubmed_titles WHERE (pubmed = $pubmed)");
    return (@$retval > 0) ? $retval->[0]->[0] : "";
}
	

sub display_set {
    my($fig,$cgi,$html,$to_display,$tab_title,$submit) = @_;

    my $from = $cgi->param('from_line');
    if (! $from) { $from = 0 }
    my $lines_left = 100;

    my %status_code = ( 'D' => 1, ' ' => 2, 'N' => 3, 'R' => 4, 'G' => 5);

    my $col_hdrs = [' ','G','N','R','D','PEG','Function','Genus/Species','PubMed','Title'];
    my $tab = [];
    foreach $_ (@$to_display) { $_->[0] =~ s/^\s*$/ /; }
    my @tuples = sort { ($status_code{$a->[0]} <=> $status_code{$b->[0]}) or &FIG::by_fig_id($a->[1],$b->[1]) } @$to_display;
    my $total_tuples = @tuples;

    if (@tuples > 0) { splice(@tuples,0,$from); $from = $from + $lines_left; splice(@tuples,$lines_left) }
    else
    {
	undef $from;
    }

    my $i;
    for ($i=0; ($i < @tuples); $i++)
    {
	my $tuple = $tuples[$i];
	my($status,$peg,$pubmed) = @$tuple;
	next if (! $fig->is_real_feature($peg));
	my $gs = $fig->genus_species(&FIG::genome_of($peg));
	$gs =~ s/^(\S+)\s+(\S+).*$/$1/;
	my $title = &title_of($fig,$pubmed);
	my $func = $fig->function_of($peg);
	my @codes = $cgi->radio_group(-name => "tuple:$peg:$pubmed:$status",
				      -values => [' ','G','N','R','D'],
				      -default => "$status",
				      -nolabels => 1);

	if (($i % 15) == 14) { push(@$tab,$col_hdrs) }
	push(@$tab,[@codes,&HTML::fid_link($cgi,$peg),$func,$gs,
		    "<a target=_blank href=http://www.ncbi.nlm.nih.gov/sites/entrez?db=pubmed&cmd=search&term=$pubmed>$pubmed</a>",
		    $title]);
    }
    push(@$html, $cgi->start_form(-action => "get_dlits.cgi", -method => 'post'),
	         $cgi->hidden(-name => 'user', -value=>$user),
	         $cgi->br,
	 );

    push(@$html,&HTML::make_table($col_hdrs,$tab,$tab_title));
    if (defined($from))
    {
	my $genomeD = $cgi->param('genomeD');
	$genomeD = $genomeD ? $genomeD : "none";
	push(@$html,"<br>To get the next 100 (out of $total_tuples)",
	            $cgi->hidden(-name => 'from_line', -value => $from, -override => 1),
	            $cgi->hidden(-name => 'genomeD', -value => "$genomeD"),
	            $cgi->submit($submit));
    }
    push(@$html,$cgi->br,$cgi->submit('Process Changes'));
    push(@$html,$cgi->end_form);
}

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

    my @tuples = grep { $_->[2] ne $_->[3] } 
                 map { ($_ =~ /^tuple:(fig\|\d+\.\d+\.peg\.\d+)\s*:\s*(\d+)\s*:([ RDGN])/) ? [$1,$2,$3,$cgi->param($_)] : () }
                 $cgi->param();
    my $user = $cgi->param('user');
    foreach my $tuple (@tuples)
    {
	my($peg,$pubmed,$from,$to) = @$tuple;
	$fig->add_dlit( -status   => $to,
			-peg      => $peg,
			-pubmed   => $pubmed,
			-curator  => $user,
			-override => 1
		      );
    }
    push(@$html,$cgi->h2('made the requested changes'));
}

    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3