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

View of /FigWebServices/split_role_in_ss.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (download) (annotate)
Fri Sep 11 21:11:12 2009 UTC (10 years, 2 months ago) by overbeek
Branch: MAIN
CVS Tags: mgrast_dev_08112011, 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_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_2010_0827, myrast_33, rast_rel_2011_0928, mgrast_dev_04052011, mgrast_dev_02222011, mgrast_dev_10262011, HEAD
Changes since 1.3: +11 -3 lines
minor fixes

my $fig = new FIG;

use HTML;
use strict;

use CGI;
my $cgi = new CGI;

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

my $dir     = $cgi->param('dir');
my $roleI   = $cgi->param('roleI');
my $request = $cgi->param('request');
my $set     = $cgi->param('set');
my $comment = $cgi->param('comment');

if ((! $dir) && (! $request))
{
    &initial_page($fig,$cgi,$html);
}
elsif ((! $dir) && ($request eq "pick_role"))
{
    &pick_role($fig,$cgi,$html);
}
elsif ((! $dir) && ($request eq "initialize_dir"))
{
    &initialize_dir($fig,$cgi,$html);
}
elsif ($dir && ($request eq "mark_comments") && defined($set))
{
    my @pegs = map { ($_ =~ /^>(fig\|\d+\.\d+\.peg\.\d+)/) ? $1 : () } `cat $dir/$set`;
    foreach my $peg (@pegs)
    {
	my $func = $fig->function_of($peg);
	if ($func !~ /$comment/)
	{
            if ($func =~ /\#/)
            {
                $func = $func . ", $comment";
            }
            else
            {
                $func .= " # $comment";
            }

	    my $user = ($cgi->param('user') || 'master');
	    $fig->assign_function($peg,$user,$func);
	}
    }
    &show_dir($fig,$dir,$html);
}
else
{
    &show_dir($fig,$dir,$html);
}
&HTML::show_page($cgi,$html);

sub link_to_peg {
    my($peg) = @_;

    return "<a href=http://anno-3.nmpdr.org/anno/FIG/seedviewer.cgi?page=Annotation&feature=$peg>$peg</a>";
}

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

    my @sub = sort grep { $fig->usable_subsystem($_) } $fig->all_subsystems;
    push(@$html,$cgi->start_form(-action => "./split_role_in_ss.cgi"),
	        "Pick a subsystem: <br><br>",
	        $cgi->scrolling_list( -name => 'subsys',
				      -values => \@sub,
				      -size => 30),
	        "<br><br>",
	        $cgi->hidden( -name => "request", -value => 'pick_role', -override => 1),
	        $cgi->submit('Pick Subsystem'),
	        $cgi->end_form);

    &FIG::verify_dir("$FIG_Config::global/JensenAnalysis");
}

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

    my $subsys = $cgi->param('subsys');
    $subsys || die "Failed to get subsys";
    my @roles = $fig->subsystem_to_roles($subsys);

    push(@$html,$cgi->start_form(-action => "./split_role_in_ss.cgi"),
	        "Pick one or more roles: <br><br>",
	        $cgi->scrolling_list( -name => 'role_to_process',
				      -values => \@roles,
				      -size => 30),
	        "<br><br>",
	        $cgi->hidden( -name => "request", -value => 'initialize_dir', -override => 1),
	        $cgi->hidden( -name => "subsys", -value => $subsys, -override => 1),
	        $cgi->submit('Pick Role'),
	        $cgi->end_form);
}

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

    my $subsys = $cgi->param('subsys');
    my $role  = $cgi->param('role_to_process');
    my $dir = "$FIG_Config::temp/tmp.role.$$";

    open(SPLIT,"| $FIG_Config::bin/split_sequences_into_sets $dir")
	|| die "could not open SPLIT";
    my @genomes = map { $_->[0] } @{$fig->subsystem_genomes($subsys)};

    foreach my $genome (@genomes)
    {
	foreach my $peg ($fig->pegs_in_subsystem_cell($subsys,$genome,$role))
	{
	    my $seq = $fig->get_translation($peg);
	    if ($seq)
	    {
		print SPLIT ">$peg\n$seq\n";
	    }
	}
    }
    close(SPLIT);
    &show_dir($fig,$dir,$html);
}

sub show_dir {
    my($fig,$dir,$html) = @_;

    my @sets = map { $_ =~ /^(\d+)\s+(\d+)/; [$1,$2] } `cat $dir/set.sizes`;
    if (@sets == 0)
    {
	push(@$html,$cgi->h2('something is very wrong'));
    }
    elsif (@sets == 1)
    {
	push(@$html,$cgi->h2('no outliers'));
    }
    else
    {
	my $col_hdrs = ['set','size','representative','Len of Rep','Mark as Frameshifts','Mark as Truncated'];
	my $tab = [];
	foreach my $tuple (@sets)
	{
	    my($set,$sz) = @$tuple;
	    open(TMP,"<$dir/$set") || die "could not open $dir/$set";
	    $_ = <TMP>;
	    close(TMP);
	    $_ =~ />(\S+)/;
	    my $peg = $1;
	    push(@$tab,[$set,$sz,&link_to_peg($peg),length($fig->get_translation($peg)),
	                &link_to_action($dir,$set,'frameshift'),
                        &link_to_action($dir,$set,'truncated')]);
	}
	push(@$html,&HTML::make_table($col_hdrs,$tab,'Sets of Sinmilar PEGs'));
    }
}

sub link_to_action {
    my($dir,$set,$comment) = @_;

    return "<a href=http:split_role_in_ss.cgi?dir=$dir&set=$set&comment=$comment&request=mark_comments>mark all</a>";
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3