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

View of /FigWebServices/targets.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (annotate)
Tue Nov 28 21:52:10 2006 UTC (13 years, 6 months ago) by parrello
Branch: MAIN
New script for drug targets.

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


BEGIN {
    # 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");
    }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>';
    }else{
        $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 adds the paragraphs needed to explain what we are looking at 
# and how to navigate it
sub add_words{
    my ($cgi, $varHash, $org) = @_;
    if($org){
        my $name= $fig->genus_species($org);
        $varHash->{result} .= "<h1>$name targets</h1>";
        if($target){
            $varHash->{result} .= "<p>Cross section of<em> $name </em> and $uctarget Targets.</p>
<p>Candidacy column connects to literature source.</p>";
        }else{
            $varHash->{result} .= "<p>To narrow the table scope to a specific target category 
click on a category within the larger table under the category column.</p>"; 
        }
        return;
    }elsif($target){
        $varHash->{result} .= "<h1> $uctarget Targets</h1>
<p>The proteins in these sets come from diverse sources
 and the criteria for inclusion is intentionally broad.
 Further curation, filtering and additions to these sets are planned. 
Feedback to the NMPDR on these proteins is welcome.</p>
<p>To narrow the table scope to a specific organism
click on an organism in the larger table under the organism column</p>
<p>Candidacy column connects to literature source.</p>";
        return;
    }
}

# 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");
    while (<TABLE>){
        my @lines = split (/\r/,$_);
        for my $i (0..scalar@lines-1) {
            my @entry = split (/\t/,$lines[$i]);
#           &print_row($entry[5], $entry[9], $entry[3], $entry[1], $i);
            &get_best_pdb($cgi, $varHash, $i,$file);
        }
    }
}


# 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, $i) = @_ ;
    my $genome = $peg;
    $genome =~ s/fig\|//;
    $genome =~ s/\.peg\.\d+//;
    my $which  = $fig->genus_species($genome);
    $pdb =~ s/pdb//;
    $pdb =~ s/\.ent//;
    my $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, $i, $file)= @_;
    my @pdbresults =("1ah7","1dhn","1tfu"); # we define what pdb actually have been docked well.
    Open(\*TABLE, "$FIG_Config::drug_directory/$file");
    while (<TABLE>){
        my @lines = split (/\r/,$_);
        my @entry = split(/\t/,$lines[$i]);
        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], $i); #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], $i); #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], $i); #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], $i); #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], $i); #we want to display this
                            return;
                        }else{
                            &print_column($cgi, $varHash, $entry[14], 'green', $entry[16],$entry[5], $entry[9], $entry[3], $entry[1], $i); #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], $i); #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], $i); #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], $i);
                return;
            }
        }
    }
    Trace("No result printed for line $i in file $file.") 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