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

View of /FigWebServices/comp_MR.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (download) (annotate)
Mon Mar 12 21:58:58 2007 UTC (13 years ago) by paarmann
Branch: MAIN
Changes since 1.2: +79 -11 lines
added links to seed viewer
added find similar pegs function

# -*- 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 HTML;
use strict;

use CGI;
my $cgi = new CGI;

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

my $genome1 = $cgi->param('genome1');
my $genome2 = $cgi->param('genome2');
my $request = $cgi->param('request');

use CompareMR;
use FIG;
use FIGV;

my($fig,$use_figV);
if ($genome1 =~ /^\d+\.\d+/)
{
    $fig = new FIG;
    $use_figV = 0;
}
elsif (($genome1 =~ /\d+\.\d+$/) && (-d $genome1))
{
    my $tmp = new FIG;
    $fig    = new FIGV($genome1,$tmp);
    $use_figV = 1;
}

my($common,$in1_not2,$in2_not1) = &CompareMR::compare_genomes_MR($genome1,$genome2);

my $html = [];

if ($request eq "common")
{
    push @$html, "<h2>Showing common pegs between $genome1 and $genome2</h2>";
    &process_data($fig,$cgi,$html,$common,$use_figV);
}
elsif ($request eq "in1_not2")
{
    push @$html, "<h2>Showing pegs in $genome1, but not in $genome2</h2>";
    &process_data($fig,$cgi,$html,$in1_not2,$use_figV);
}
elsif ($request eq "in2_not1")
{
    push @$html, "<h2>Showing pegs in $genome2, but not in $genome1</h2>";
    &process_data($fig,$cgi,$html,$in2_not1,0);
}
elsif ($request eq "find_similar_pegs") {
    &find_similar_pegs($fig, $cgi, $html,$use_figV);
}	
unshift @$html, "<TITLE>Compare Metabolic Reconstructions</TITLE>\n";

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

sub process_data {
    my($fig,$cgi,$html,$data,$use_figV) = @_;
    my($tuple,$sub,$role,$pegs1,$pegs2,$classification,$class1,$class2);
    my($key,%subH,$subH1,$subH2,$subH3,@roles,$subL,$pegL,$peg);

    foreach $tuple (@$data)
    {
	($sub,$role,$pegs1) = @$tuple;
	$classification = $fig->subsystem_classification($sub);
	$class1 = $classification->[0] || "Unclassified";
	$class2 = $classification->[1] || "Unclassified";
	$subH{$class1}->{$class2}->{$sub}->{$role} = [$pegs1,$pegs2];
    }

    foreach $class1 (sort keys(%subH))
    {
	$subH1 = $subH{$class1};
	push(@$html,"<h1>$class1</h1>\n");
	foreach $class2 (sort keys(%$subH1))
	{
	    $subH2 = $subH1->{$class2};
	    push(@$html,"<h2>$class2</h2>\n");
	    foreach $sub (sort keys(%$subH2))
	    {
		if ($use_figV)
		{
		    $subL = &sub_P1K_link($cgi,$sub);
		}
		else
		{
		    $subL  = &HTML::sub_link($cgi,$sub);
		}
		$subH3 = $subH2->{$sub};
		push(@$html,"<h3>$subL</h3>\n");
		push(@$html,"<ul>\n");
		foreach $role (sort keys(%$subH3))
		{
		    push(@$html,"<li>$role\n");
		    ($pegs1,$pegs2) = @{$subH3->{$role}};
		    push(@$html,"<ul>\n");

		    foreach $peg (sort { &FIG::by_fig_id($a,$b) } @$pegs1)
		    {
			$pegL = &peg_P1K_link($cgi,$fig,$peg, $use_figV);
			
			push(@$html,"<li>$pegL\n");
			
			if ($cgi->param('request') eq 'in1_not2' or
			    $cgi->param('request') eq 'in2_not1') {
			    push(@$html, &peg_find_similar_link($cgi,$fig, $peg));
			}

		    }
		    push(@$html,"</ul>\n");
		}
		push(@$html,"</ul>\n");
	    }
	}
    }
}

sub peg_link {
    my ($cgi, $fig, $use_figV, $peg) = @_;
    if ($use_figV) {
	return &peg_P1K_link($cgi,$fig,$peg);
    }
    else {
	return &HTML::fid_link($cgi,$peg);
    }
}

sub peg_find_similar_link {
    my($cgi,$fig,$peg) = @_;
    return '&nbsp; <a target="find_similar_pegs" href="?genome1='.$cgi->param('genome1').
	'&genome2='.$cgi->param('genome2').'&request=find_similar_pegs&peg='.
	$peg.'">find similar pegs</a>';
}

sub peg_P1K_link {
    my($cgi,$fig,$peg) = @_;

    $fig->organism_directory =~ /(\d+)\/rp\/\d+\.\d+$/;
    return "<a target='seedviewer' href='".$FIG_Config::seedviewer_url.
	"?action=ShowAnnotation&prot=$peg&job=$1'>$peg</a>";

}

sub sub_P1K_link {
    my($cgi,$sub) = @_;

    $fig->organism_directory =~ /(\d+)\/rp\/\d+\.\d+$/;
    return "<a target='seedviewer' href='".$FIG_Config::seedviewer_url.
	"?action=ShowSubsystem&subsystem_name=$sub&job=$1'>$sub</a>";    

    return $sub;
}


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

    my $peg = $cgi->param('peg');
    my @sims = $fig->sims($peg, 50, 1.0e-20, 'fig');

    $cgi->param('genome1') =~ /(\d+\.\d+)/;
    my $genome1 = $1;
    $cgi->param('genome2') =~ /(\d+\.\d+)/;
    my $genome2 = $1;

    $peg =~ /fig\|(\d+\.\d+)\./;
    my $source = $1;
    my $target = ($genome1 eq $source) ? $genome2 : $genome1;

    push(@$html, "<h2>Showing similar pegs from $target for $peg</h2>");
    my @table;
    foreach (@sims) {
	$_->[1] =~ /fig\|(\d+\.\d+)\./;
	if ($1 eq $target) {
	    
	    unless (@table) {
		push @table, [ &peg_link($cgi, $fig, $use_figV, $peg), 
			       $fig->function_of($peg), '100.00', 'n/a', 'n/a' ];
	    }
	    push @table, [ &peg_link($cgi, $fig, $use_figV, $_->[1]), 
			   $fig->function_of($_->[1]), $_->[2], $_->[10], $_->[11] ];
	    last if (scalar(@table) == 3);
	}
    }
    if (scalar(@table)) {
	push @$html, &HTML::make_table( ['Id', 'Function', '% Identity', 'E-value', 'Bitscore' ], \@table );
    }
    else {
	push @$html, '<p>No similar pegs found.</p>';
    }
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3