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

View of /FigWebServices/targets.cgi

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.5 - (download) (annotate)
Thu Dec 7 00:36:39 2006 UTC (13 years, 5 months ago) by parrello
Branch: MAIN
Changes since 1.4: +2 -1 lines
Added tracing.

#!/usr/bin/env /vol/drugtargets/FIGdisk/env/cee/bin/perl                                                                   

    # Print the HTML header.                                                                                                               
    print "CONTENT-TYPE: text/html\n\n";
use strict;
use Tracer;
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;

eval {
    my $org = $cgi->param("org");
    # Set the descriptive variables. These change key words in the introductory
    # text and page heading.
    $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");
        &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);

# 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);
        $varHash->{result} .= ' <table width="90%" class="targets"> 
           <tr class=odd><th>Organism</th><th>Functional Role</th><th>Candidacy<th>PDB</th></tr>';
        $varHash->{result} .= '<table width="90%" class="targets">
         <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} = "";
        $varHash->{orgName} = $fig->genus_species($org);

# This Sub funtions to open up the table and keep track of the index of what row we are on
sub get_table{
    my($cgi, $varHash, $file)= @_;
    Open(\*TABLE, "<$FIG_Config::drug_directory/$file");
    Trace("Processing table $file.") if T(3);
    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";
        $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";
        $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(4);
    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/,$_);
                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";
    $varHash->{result} .= "<td><a href=\"../content/contactus.php\">Suggest</a></td>\n";

#-- 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("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
        }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
    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
    }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
    }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
                        &print_column($cgi, $varHash, $entry[14], 'green', $entry[16],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this
                }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
            }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]);
    } 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>";

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3