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

Diff of /FigWebServices/targets.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4, Wed Dec 6 23:50:46 2006 UTC revision 1.9, Wed Sep 3 20:36:36 2008 UTC
# Line 1  Line 1 
1  #!/usr/bin/env /vol/drugtargets/FIGdisk/env/cee/bin/perl  #!/usr/bin/env /vol/drugtargets/FIGdisk/env/cee/bin/perl
2    
3    #!/usr/bin/perl -w
4    
 BEGIN {  
     # Print the HTML header.  
     print "CONTENT-TYPE: text/html\n\n";  
 }  
5  use strict;  use strict;
6  use Tracer;  use Tracer;
7  use CGI;  use CGI;
 use Sprout;  
 use SHDrugSearch;  
   
 my $odd = 1;  
 my @styles = ("even", "odd");  
 my $lkpdb ='http://www.rcsb.org/pdb/explore.do?structureId=';  
 my $fig = new FIG;  
   
 my ($cgi, $varHash) = ScriptSetup();  
 #get the query paramaters  
 my $target = $cgi->param("target");  
 my $uctarget = ucfirst $target;  
8    
9  eval {  my $cgi = CGI->new();
10      my $org = $cgi->param("org");  my $parms = $cgi->query_string();
11      # Set the descriptive variables. These change key words in the introductory  if ($parms) {
12      # text and page heading.      $parms = "?$parms";
     $varHash->{target} = $target;  
     $varHash->{uc_first_target} = ucfirst $target;  
     $varHash->{org} = $org;  
     #The script operates  
     &add_table_top($cgi, $varHash, $org);  
     if ($target){  
         &get_table($cgi, $varHash, "$target.txt");  
     }elsif($org){  
         &get_table($cgi, $varHash, $org);  
     }  
     $varHash->{result} .='</table>';  
 };  
   
 # error messages  
 if ($@) {  
     my $errorMessage = $@;  
     Trace("Script Error: $errorMessage") if T(0);  
 }  
 ScriptFinish("targets_tmpl.php", $varHash);  
 #---Subs------#  
   
 # This function adds the table header based on if we looking at a specific target category  
 sub add_table_top{  
     my ($cgi, $varHash, $org) = @_;  
     &add_words($cgi, $varHash, $org);  
     if($target){  
         $varHash->{result} .= ' <table width="90%" class="targets">  
            <tr class=odd><th>Organism</th><th>Functional Role</th><th>Candidacy<th>PDB</th></tr>';  
13      }else{      }else{
14          $varHash->{result} .= '<table width="90%" class="targets">      $parms = "";
          <tr class=odd><th>Organism</th><th>Functional Role</th><th>Category</th><th>PDB</th></tr>';  
     }  
 }  
   
 # This funtion sets up the variables used by the template to display organism-related text.  
 # and how to navigate it  
 sub add_words{  
     my ($cgi, $varHash, $org) = @_;  
     $varHash->{orgName} = "";  
     if($org){  
         $varHash->{orgName} = $fig->genus_species($org);  
     }  
15  }  }
16    print CGI::redirect("$FIG_Config::cgi_url/wiki/rest.cgi/NmpdrPlugin/drugs$parms");
17    
18  # This Sub funtions to open up the table and keep track of the index of what row we are on  1;
 sub get_table{  
     my($cgi, $varHash, $file)= @_;  
     Open(\*TABLE, "<$FIG_Config::drug_directory/$file");  
     while (! eof TABLE){  
         my @entry = Tracer::GetLine(\*TABLE);  
         &get_best_pdb($cgi, $varHash, @entry);  
     }  
 }  
   
   
 # This Sub funtions to print the Table Row in the correct format.  
 sub print_column{  
     my($cgi, $varHash, $pdb, $color, $score,$peg, $func, $lit, $cat) = @_ ;  
     my $genome = $peg;  
     $genome =~ s/fig\|//;  
     $genome =~ s/\.peg\.\d+//;  
     my $which  = $fig->genus_species($genome);  
     $pdb =~ s/pdb//;  
     $pdb =~ s/\.ent//;  
     $cat = changecat($cat);  
     my $selfURL = $cgi->url(-relative => 1);  
     my $link = '../FIG/protein.cgi?new_framework=0&SPROUT=1&prot=';  
     my $org = $cgi->param('org');  
     Trace("Printing $color for $pdb.") if T(4);  
     if ($org && $target){  
         if ($peg =~ m/$org/){  
             $odd = 1 - $odd;  
             $varHash->{result} .= "<tr class=\"$styles[$odd]\"><td><em>$which</em><br>$peg</td>\n";  
             $varHash->{result} .= "<td>$func (<a href=\"$link$peg\">NMPDR</a>)</td>\n";  
             $varHash->{result} .= "<td><a href=\"$lit\">$cat</a></td>\n";  
             $varHash->{result} .= "<td color=\"$color\"><a href=\"$lkpdb$pdb\">$pdb</a></td>\n";  
         }  
     }elsif($target){  
         $odd = 1 - $odd;  
         $varHash->{result} .= "<tr class=\"$styles[$odd]\"><td><a href=\"$selfURL?org=$genome&target=$target\"><em>$which</em></a><br>$peg</td>\n";  
         $varHash->{result} .= "<td>$func (<a href=\"$link$peg\">NMPDR</a>)</td>\n";  
         $varHash->{result} .= "<td><a href=\"$lit\">$cat</a></td>\n";  
         $varHash->{result} .= "<td color=\"$color\"><a href=\"$lkpdb$pdb\">$pdb</a></td>\n";  
     }elsif($org){  
         $odd = 1 - $odd;  
         $varHash->{result} .= "<tr class=\"$styles[$odd]\"><td><em>$which</em><br>$peg</td>\n";  
         $varHash->{result} .= "<td>$func (<a href=\"$link$peg\">NMPDR</a>)</td>\n";  
         &get_attribute($cgi, $varHash, $peg, $genome);  
         $varHash->{result} .= "<td color=$color><a href=\"$lkpdb$pdb\">$pdb</a></td>\n";  
     }  
 }  
   
 # This sub changes the Candidacy code to something meaningful.  
 sub changecat{  
     my($dog) = @_;  
     Trace("Selecting category for $dog.") if T(3);  
     my $cat = SHDrugSearch::GetCategory($dog);  
     return $cat;  
 }  
   
 # This sub determines if a peg has an atribute  
 sub get_attribute{  
     my ($cgi, $varHash, $peg, $genome) = @_;  
     my %files = (drug => "drug.txt", toxin => "toxin.txt", vaccine => "vaccine.txt");  
     my $selfURL = $cgi->url(-relative => 1);  
     for my $key (keys %files) {  
         Open(\*DATA, "$FIG_Config::drug_directory/$files{$key}");  
         while (<DATA>){  
             my @lines = split (/\r/,$_);  
             foreach(@lines){  
                 my @entry = split(/\t/,$_);  
                 if ("$entry[5]" eq "$peg"){  
                     my $title = ucfirst $key;  
                     $varHash->{result} .= "<td><a href=$selfURL?org=$genome&target=$key>$title</a></td>\n";  
                     return;  
                 }  
             }  
         }  
         close(DATA);  
     }  
     $varHash->{result} .= "<td><a href=\"../content/contactus.php\">Suggest</a></td>\n";  
     return;  
 }  
   
 #-- we wish to desplay only the best pdbs and those that are relavent  
 sub get_best_pdb{  
     my ($cgi, $varHash, @entry)= @_;  
     my @pdbresults =("1ah7","1dhn","1tfu"); # we define what pdb actually have been docked well.  
     if (T(4)) {  
         my $line = "Processing line\n";  
         for (my $i = 0; $i <= $#entry; $i++) {  
             $line .= "$i. $entry[$i]\n";  
         }  
         Trace($line);  
     }  
     Trace("Analyzing PDB $entry[11].") if T(4);  
     foreach (@pdbresults){ #look through the results we have  
         if ($entry[11] =~ m/$_/gi){ #ifwe have results for the free  
             &print_column($cgi, $varHash, $entry[11],'red', $entry[13],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this  
             return;  
         }elsif($entry[14] =~ m/$_/gi){ #if we have resutls for the bound  
             &print_column($cgi, $varHash,$entry[14], 'red', $entry[16],$entry[5], $entry[9], $entry[3], $entry[1]); #we wnat to display this  
             return;  
         }  
     }  
     if ($entry[13] eq "0"){ #if the free pdb is perfect  
         &print_column($cgi, $varHash, $entry[11], '', $entry[13],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this  
         return;  
     }elsif($entry[16] eq '0'){ #if the bound  pdb is perfect  
         &print_column($cgi, $varHash, $entry[14], '', $entry[16],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this  
         return;  
     }elsif($entry[13] =~ /\d\.\d*E\-(\d+)/ ){ #if the eval is like 1.4E-45  
         if (15 < $1) { #and the exponant is less than 1.0E-15  
             if($entry[16] =~ /\d\.\d*E\-(\d+)/ ){ #but we should check if the bound is any better  
                 if (15 < $1){ #and the xponant is less than 1.0-15 we need to do the comparison  
                     my @free = split(/E\-/,$entry[13]);  
                     my @bound = split(/E\-/,$entry[16]);  
                     my $efree = $free[0] * 13 ** -$free[1];  
                     my $ebound = $bound[0] * 13 ** -$bound[1];  
                     if ($efree <= $ebound){ #if the free is less than the boutd  
                         &print_column($cgi, $varHash, $entry[11], 'black', $entry[13],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this  
                         return;  
                     }else{  
                         &print_column($cgi, $varHash, $entry[14], 'green', $entry[16],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this  
                         return;  
                     }  
                 }else{ #the bound exponent wasn't less than 15  
                     &print_column($cgi, $varHash, $entry[11], 'blue', $entry[13],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this  
                     return;  
                 }  
             }else{ #the bound pdb didn't even have an exponant  
                 &print_column($cgi, $varHash, $entry[11], 'yello', $entry[13],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this  
                 return; #this takes care the if free is good and bound is bad  
             }#a free pdb is no good becaus eval > 1e-15  
         }#free pdb was no good because eval > 1e-15  
     }elsif($entry[16] =~ /\d\.\d*E\-(\d+)/ ){ #we are now checking if the bound pdb is good  
         if (15 < $1) {  
             &print_column($cgi, $varHash, $entry[14], 'black', $entry[16],$entry[5], $entry[9], $entry[3], $entry[1]);  
             return;  
         }  
     } else {  
         Trace("Peg $entry[5] not printed.") if T(4);  
     }  
 }  
   
   
 # -error interupt--these subs will probably go when bruce sees them  
 sub err {  
     my ($msg) = @_;  
     $msg = "Error!" unless $msg;  
     print (&colored($msg, "CC0033"));  
     die "$msg\n";  
 }  
   
 sub colored {  
     my ($text, $color) = @_;  
     return "<font color=$color>$text</font>";  
 }  

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.9

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3