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

View of /FigWebServices/edit_feature.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (annotate)
Mon Feb 5 03:12:11 2007 UTC (13 years, 4 months ago) by overbeek
Branch: MAIN
CVS Tags: rast_rel_2008_06_18, rast_rel_2008_06_16, rast_rel_2008_07_21, rast_rel_2008_04_23, mgrast_rel_2008_0806, rast_rel_2008_08_07
initial, undebugged version of edit_feature.cgi

# 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 GenoGraphics;
use CGI;
my $cgi = new CGI;
use FIG_CGI;

my ($fig, $cgi, $user) = FIG_CGI::init(debug_save   => 0,
				       debug_load   => 0,
				       print_params => 0
				      );

my $html = [];

if (! $user)
{
    unshift @$html, "<TITLE>The SEED: Edit Feature Page</TITLE>\n";
    push(@$html,"<h1>Sorry, you need to specify a user</h1>\n");
    &HTML::show_page($cgi,$html);
    exit;
}

unshift @$html, "<TITLE>The SEED Edit Feature Page</TITLE>\n";

my $feature = $cgi->param('feature');
if ((! $feature) || (! $fig->is_real_feature($feature)))
{
    unshift @$html, "<TITLE>The SEED: Edit Feature Page</TITLE>\n";
    push(@$html,"<h1>Sorry, you need to specify a feature</h1>\n");
    &HTML::show_page($cgi,$html);
    exit;
}

my $request = $cgi->param("request") ||
              $cgi->param('Delete Feature') ||
              $cgi->param('Replace Feature') ||
              $cgi->param('Update Data') ||
	      "";


if ($request eq 'Update Data')
{
    &update($fig,$cgi,$html,$user,$feature);
}
elsif ($request eq 'Delete Feature')
{
    &delete($fig,$cgi,$html,$user,$feature);
}
elsif ($request eq 'Replace Feature')
{
    &replace($fig,$cgi,$html,$user,$feature);
}
else
{
    &format_feature_data($fig,$cgi,$html,$user,$feature);
}
&HTML::show_page($cgi,$html);
exit;

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

    my $loc = $fig->feature_location($fid);
    my $aliases = $fig->feature_aliases($fid);
    my $function = $fig->function_of($fid);
    my($translation,$new_translation);
    if (&FIG::ftype($fid) eq 'peg')
    {
	$new_translation = $cgi->param('translation');
    }

    my $new_func = $cgi->param('function');
    my $new_loc  = $cgi->param('location');
    my $new_aliases = $cgi->param('aliases');


    if ($loc ne $new_loc)
    {
	$fig->change_location_of_feature($fid,$new_loc,$new_translation);
	push(@$html,$cgi->h2("changed location of $fid to $new_loc"));
    }

    if ($aliases ne $new_aliases)
    {
	&FIG::add_tbl_entry($fid,$new_loc,$aliases);
	push(@$html,$cgi->h2("changed aliases of $fid to $new_aliases"));
    }

    if ($function ne $new_func)
    {
	$fig->assign_function($fid,$user,$new_func);
	$fig->add_annotation($fid,$user,"Set master function to\n$new_func\n");
	push(@$html,$cgi->h2("changed function of $fid to $new_func"));
    }
    &format_feature_data($fig,$cgi,$html,$user,$fid);
}

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

    my $new_func = $cgi->param('function');
    my $new_loc  = $cgi->param('location');
    my $aliases = $fig->feature_aliases($fid);
    my $new_aliases = $cgi->param('aliases');
    my $new_translation = $cgi->param('translation');

    my $new_fid = $fig->replace_features_with( old_fids => $fid,
					       user     => $user,
					       genome   => &FIG::genome_of($fid),
					       type     => &FIG::ftype($fid),
					       location => $new_loc,
					       translation => $new_translation,
					       function => $new_func
					       );
    if ($aliases ne $new_aliases)
    {
	&FIG::add_tbl_entry($fid,$new_loc,$aliases);
    }
    my $fid_link = &HTML::fid_link($cgi,$fid);
    push(@$html,$cgi->h1("Replaced $fid_link with $new_fid"));
}

sub delete {
    my($fig,$cgi,$html,$user,$feature) = @_;
    $fig->delete_feature($feature);
    push(@$html,$cgi->h1("$feature deleted"));
}

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

    my $loc = $fig->feature_location($fid);
    my $aliases = $fig->feature_aliases($fid);
    my $function = $fig->function_of($fid);

    push(@$html,$cgi->start_form(-action => "edit_feature.cgi"),
	        $cgi->hidden(-name => 'user', -value => $user, -override => 1),
	        $cgi->hidden(-name => 'feature', -value => $fid, -override => 1),
	        $cgi->h1("Edit Data Relating to $fid"),
	        "Location: ",$cgi->textfield(-name => "location", -size => 100, -value => $loc),$cgi->br,
                "Aliases: &nbsp;&nbsp;",$cgi->textfield(-name => "aliases", -size => 100, -value => $aliases),$cgi->br,
                "Function: ",$cgi->textfield(-name => "function", -size => 100, -value => $function),$cgi->br,
	        $cgi->br,
	 );
    if (&FIG::ftype($fid) eq "peg")
    {
	my $translation = $fig->get_translation($fid);
	my $text = <<'END_TEXT';
<br><br>
Since you are editing a PEG, you need to understand the implications of editing the location. <br>
If you edit the location and just update the feature, the result will be a PEG for which the similarity data <br>
does not precisely match the actual characters in the translation (assuming that altering the location <br>
resulted in an alteration of the translation, as well).  We will periodically search for such mismatches <br>
and rerun similarities for the effected PEGs.
<p>
You have the option of replacing the PEG, which assigns a new ID (inheriting annotations from the old). <br>
In this case, you will have no similarities for a period (hopefully, short) and then they should appear. <br>
<br><br>
END_TEXT
        push(@$html,"Translation: ",$cgi->textfield(-name => "translation", -size => 100, -value => $translation),$cgi->br,
	            $text,
	            $cgi->submit('Replace Feature')
	     );
    }
    push(@$html,$cgi->submit('Update Data'),$cgi->submit('Delete Feature'),
                $cgi->end_form
	 );
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3