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

View of /FigWebServices/figfam_proto.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (download) (annotate)
Tue Feb 27 21:06:16 2007 UTC (12 years, 10 months ago) by mkubal
Branch: MAIN
Changes since 1.2: +68 -22 lines
latest

# -*- perl -*-

use FIG;
use FigFam;
use FIG_Config;
use HTML;
use CGI;
my $cgi=new CGI;
use LWP::Simple qw(!head); # see the caveat in perldoc LWP about importing two head methods.

$fig = new FIG;
my $html = [];

unshift(@$html, "<TITLE>Domain Analysis of Protein Sets</TITLE>\n");

my $inputs;
if ($cgi->param('request') ) 
{
  my $input =$cgi->param('proteins');
  my @inputs = split("\n",$input);

  if ($cgi->upload('fileupload'))
  {
     my $fh=$cgi->upload('fileupload');
     @inputs = <$fh> ;
  }

  $given = [@inputs];
  &analyze_domains($cgi,$fig,$given); 
 
}
else
{
  &show_initial($fig,$cgi,$html);
  &HTML::show_page($cgi,$html,1);
  exit;
}

sub show_initial {
    my ($fig,$cgi,$html)=@_;
    push @$html, 
    $cgi->start_multipart_form(),
    "<h3>Enter FigFam ID</h3>",
    $cgi->textarea(-name=>"figfam_id", -rows=>1, -columns=>20),
    $cgi->br,
    "<h3>Enter set of pegs</h3>\n",
    $cgi->textarea(-name=>"set_of_pegs", -rows=>10, -columns=>40), 
    $cgi->br,  
    "<h3>Upload File</h3>",
    $cgi->filefield(-name=>"fileupload", -size=>50),
    $cgi->br,
    $cgi->hr,
    $cgi->submit(-name=>'request', -value=>'Submit for Domain Analysis'),
    $cgi->reset, $cgi->end_form;
    return $html;
}

sub analyze_domains 
{
    my ($cgi,$fig,$given) =@_;

    my $sops = $cgi->param('set_of_pegs');
    my $figfam_id = $cgi->param('figfam_id');
    my $figfam = FigFam->new($fig,$figfam_id);
    my $function = $figfam->family_function();
    my %peg_to_domain;
    my %peg_to_score; 
    my %domain;
    my %domain_location;
    my %domain_length;
        
    my $set = $figfam->pegs_of();
    my	$count = scalar(@$set);
    
    if($figfam_id){
	my @returns = $fig->get_attributes($set,'CDD');
	foreach $return (@returns){
	    my $peg = @$return[0];
	    my $seq = $fig->get_translation($peg);
	    my $length = length($seq);
		
	    if(@$return[2] =~/^(\d+\.\d+);(\d+)-(\d+)/){
		my $score = $1;
		my $begin = $2;
		my $end = $3;
		my $begin_percent = $begin/$length;
		my $end_percent = $end/$length;
	
		if($peg_to_score{$peg}){
		    if($peg_to_score{$peg} > $score){
			$peg_to_score{$peg} = $score;
			if(@$return[1] =~/(\d+)/){
			    my $id = $1;
			    $peg_to_domain{$peg} = "$id\t$begin_percent\t$end_percent\t$length";
			}
		    }
		}
		else{
		    $peg_to_score{$peg} = $score;
		    if(@$return[1] =~/(\d+)/){
			my $id = $1;
			$peg_to_domain{$peg} = "$id\t$begin_percent\t$end_percent\t$length";
		    }
		}
	    }
	    
	}

	foreach $peg (keys(%peg_to_domain)){
	    my($id,$begin,$end,$length) = split("\t",$peg_to_domain{$peg});
            my $number;
	    if($domain{$id}){
		$number = $domain{$id};
		$domain_begin{$id} = (($domain_begin{$id} * $number) + $begin)/($number + 1);
		$domain_end{$id} = (($domain_end{$id} * $number) + $end)/($number + 1);    
		$domain_length{$id} = (($domain_length{$id} * $number) + $length)/($number + 1);    
		$domain{$id} = $number + 1;
	    }
	    else{
		$domain{$id} = 1;
		$domain_begin{$id} = $begin;
		$domain_end{$id} = $end;
		$domain_length{$id} = $length;
	    }
	}	
	
	push @$html,
	"<h3>Domain Analysis Results for $count pegs in $figfam_id</h3>",
	"<h3>Family Function: $function</h3>",
	"<br>",
	"<table border>";
	push @$html,"<tr><td>CDD Domain</td><td>Occurences</td><td>AVG Protein Length</td><td>AVG Begin</td><td>AVG End</td></tr>";
	
	foreach $dom (keys(%domain)){
	    my ($length,$begin,$end);
	    my $instances = $domain{$dom};
	    if($domain_length{$dom} =~/^(\d+)/){$length = $1};
	    $begin = $domain_begin{$dom};
	    $end = $domain_end{$dom};
	    
	    push @$html,"<tr><td>$dom</td><td>$instances</td><td>$length</td><td>$begin</td><td>$end</td></tr>";
	}
	push @$html,"</table>";
	
	&HTML::show_page($cgi,$html,1);
	exit;
    }   
    
    else{
	push @$html, 
	"<h3>Must enter either FigFam ID or set of pegs</h3>";
	&HTML::show_page($cgi,$html,1);
	exit;
    }
    
}


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3