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

View of /FigWebServices/targets.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (download) (annotate)
Tue Apr 29 08:19:31 2008 UTC (12 years, 1 month ago) by parrello
Branch: MAIN
CVS Tags: rast_rel_2008_06_18, rast_rel_2008_06_16, rast_rel_2008_07_21, mgrast_rel_2008_0806, rast_rel_2008_08_07
Changes since 1.7: +2 -2 lines
Fixed. Deprecated ScriptSetup methods are no longer exported by Tracer.

#!/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 SHDrugSearch;
use FIGRules;

my $odd = 1;
my @styles = ("even", "odd");
my $lkpdb ='http://www.rcsb.org/pdb/explore.do?structureId=';
my $fig = new FIG;
my ($cgi, $varHash) = Tracer::ScriptSetup();
#get the query paramaters
my $target = $cgi->param("target");
my $uctarget = ucfirst $target;
my %pegHash;

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;
    # Compute the peg hash if we're organism-only.
    if ($org && ! $target) {
        Trace("Computing peg hash.") if T(3);
        %pegHash = get_attribute_hash($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);
}
Tracer::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><th>Best Hit to Human</th></tr>';
    }elsif ($org) {
        $varHash->{result} .= '<table width="90%" class="targets">
         <tr class=odd><th>Organism</th><th>Functional Role</th><th>Category</th><th>PDB</th><th>Best Hit to Human</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);
    }
}

# 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 of peg $peg.") if T(4);
    # We'll put the category/attribute column value in here if this row should be
    # displayed.
    my $caColumn;
    if ($org && $target){
        if ($peg =~ m/$org/){
            $caColumn = "<td><a href=\"$lit\">$cat</a></td>\n";
        }
    }elsif($target){
        $caColumn = "<td><a href=\"$lit\">$cat</a></td>\n";
    }elsif($org){
        Trace("Peg hash is: $pegHash{$peg}.") if T(4);
        if ($pegHash{$peg}) {
            $caColumn = $pegHash{$peg};
        } else {
            $caColumn = "<td></td>\n"; # <a href=\"../content/contactus.php\">Suggest</a></td>\n";
        }
    }
    if (defined $caColumn) {
        $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} .= $caColumn;
        $varHash->{result} .= "<td color=\"$color\"><a href=\"$lkpdb$pdb\">$pdb</a></td>\n";
        # Find the best hit to a human.
        my @bbhList = FIGRules::BatchBBHs($peg, 1e-15, '9606.3');
        if (@bbhList) {
            # Here we found one, so get the best one in the list.
            my @sorted = sort { $a->[2] <=> $b->[2] } @bbhList;
            my $bestPeg = $sorted[0]->[1];
            $varHash->{result} .= "<td><a href=\"../FIG/protein.cgi?new_framework=0&SPROUT=1&prot=$bestPeg\">$sorted[0]->[2]</a></td>\n";
        } else {
            $varHash->{result} .= "<td>&nbsp;</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 the attributes of each peg related to the given genome.
sub get_attribute_hash {
    my ($genome) = @_;
    my %files = (drug => "drug.txt", toxin => "toxin.txt", vaccine => "vaccine.txt");
    my %retVal;
    my $selfURL = $cgi->url(-relative => 1);
    for my $key (keys %files) {
        Open(\*INFILE, "$FIG_Config::drug_directory/$files{$key}");
        while (! eof(INFILE)){
            my @entry = Tracer::GetLine(\*INFILE);
            if ($entry[5] =~ /$genome/){
                Trace("$entry[5] added to hash.") if T(3);
                my $title = ucfirst $key;
                $retVal{$entry[5]} = "<td><a href=$selfURL?org=$genome&target=$key>$title</a></td>\n";
            }
        }
        close(INFILE);
    }
    return %retVal;
}

#-- 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.
    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>";
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3