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

Annotation of /FigWebServices/targets.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (view) (download)

1 : parrello 1.1 #!/usr/bin/env /vol/drugtargets/FIGdisk/env/cee/bin/perl
2 :    
3 :    
4 :     BEGIN {
5 :     # Print the HTML header.
6 :     print "CONTENT-TYPE: text/html\n\n";
7 :     }
8 :     use strict;
9 :     use Tracer;
10 :     use CGI;
11 :     use SHDrugSearch;
12 : parrello 1.6 use FIGRules;
13 : parrello 1.1
14 :     my $odd = 1;
15 :     my @styles = ("even", "odd");
16 :     my $lkpdb ='http://www.rcsb.org/pdb/explore.do?structureId=';
17 :     my $fig = new FIG;
18 :     my ($cgi, $varHash) = ScriptSetup();
19 :     #get the query paramaters
20 :     my $target = $cgi->param("target");
21 :     my $uctarget = ucfirst $target;
22 : parrello 1.6 my %pegHash;
23 : parrello 1.1
24 :     eval {
25 :     my $org = $cgi->param("org");
26 :     # Set the descriptive variables. These change key words in the introductory
27 :     # text and page heading.
28 :     $varHash->{target} = $target;
29 :     $varHash->{uc_first_target} = ucfirst $target;
30 :     $varHash->{org} = $org;
31 : parrello 1.6 # Compute the peg hash if we're organism-only.
32 :     if ($org && ! $target) {
33 : parrello 1.7 Trace("Computing peg hash.") if T(3);
34 : parrello 1.6 %pegHash = get_attribute_hash($org);
35 :     }
36 : parrello 1.1 #The script operates
37 :     &add_table_top($cgi, $varHash, $org);
38 :     if ($target){
39 :     &get_table($cgi, $varHash, "$target.txt");
40 :     }elsif($org){
41 :     &get_table($cgi, $varHash, $org);
42 :     }
43 :     $varHash->{result} .='</table>';
44 :     };
45 :    
46 :     # error messages
47 :     if ($@) {
48 :     my $errorMessage = $@;
49 :     Trace("Script Error: $errorMessage") if T(0);
50 :     }
51 :     ScriptFinish("targets_tmpl.php", $varHash);
52 :     #---Subs------#
53 :    
54 :     # This function adds the table header based on if we looking at a specific target category
55 :     sub add_table_top{
56 :     my ($cgi, $varHash, $org) = @_;
57 :     &add_words($cgi, $varHash, $org);
58 :     if($target){
59 :     $varHash->{result} .= ' <table width="90%" class="targets">
60 : parrello 1.6 <tr class=odd><th>Organism</th><th>Functional Role</th><th>Candidacy<th>PDB</th><th>Best Hit to Human</th></tr>';
61 :     }elsif ($org) {
62 : parrello 1.1 $varHash->{result} .= '<table width="90%" class="targets">
63 : parrello 1.6 <tr class=odd><th>Organism</th><th>Functional Role</th><th>Category</th><th>PDB</th><th>Best Hit to Human</th></tr>';
64 : parrello 1.1 }
65 :     }
66 :    
67 : parrello 1.3 # This funtion sets up the variables used by the template to display organism-related text.
68 : parrello 1.1 # and how to navigate it
69 :     sub add_words{
70 :     my ($cgi, $varHash, $org) = @_;
71 : parrello 1.3 $varHash->{orgName} = "";
72 : parrello 1.1 if($org){
73 : parrello 1.3 $varHash->{orgName} = $fig->genus_species($org);
74 : parrello 1.1 }
75 :     }
76 :    
77 :     # This Sub funtions to open up the table and keep track of the index of what row we are on
78 :     sub get_table{
79 :     my($cgi, $varHash, $file)= @_;
80 : parrello 1.4 Open(\*TABLE, "<$FIG_Config::drug_directory/$file");
81 : parrello 1.5 Trace("Processing table $file.") if T(3);
82 : parrello 1.4 while (! eof TABLE){
83 :     my @entry = Tracer::GetLine(\*TABLE);
84 :     &get_best_pdb($cgi, $varHash, @entry);
85 : parrello 1.1 }
86 :     }
87 :    
88 :    
89 :     # This Sub funtions to print the Table Row in the correct format.
90 :     sub print_column{
91 : parrello 1.4 my($cgi, $varHash, $pdb, $color, $score,$peg, $func, $lit, $cat) = @_ ;
92 : parrello 1.1 my $genome = $peg;
93 :     $genome =~ s/fig\|//;
94 :     $genome =~ s/\.peg\.\d+//;
95 :     my $which = $fig->genus_species($genome);
96 :     $pdb =~ s/pdb//;
97 :     $pdb =~ s/\.ent//;
98 : parrello 1.2 $cat = changecat($cat);
99 : parrello 1.1 my $selfURL = $cgi->url(-relative => 1);
100 :     my $link = '../FIG/protein.cgi?new_framework=0&SPROUT=1&prot=';
101 :     my $org = $cgi->param('org');
102 : parrello 1.7 Trace("Printing $color for $pdb of peg $peg.") if T(4);
103 : parrello 1.6 # We'll put the category/attribute column value in here if this row should be
104 :     # displayed.
105 :     my $caColumn;
106 : parrello 1.1 if ($org && $target){
107 :     if ($peg =~ m/$org/){
108 : parrello 1.6 $caColumn = "<td><a href=\"$lit\">$cat</a></td>\n";
109 : parrello 1.1 }
110 :     }elsif($target){
111 : parrello 1.6 $caColumn = "<td><a href=\"$lit\">$cat</a></td>\n";
112 : parrello 1.1 }elsif($org){
113 : parrello 1.7 Trace("Peg hash is: $pegHash{$peg}.") if T(4);
114 : parrello 1.6 if ($pegHash{$peg}) {
115 :     $caColumn = $pegHash{$peg};
116 :     } else {
117 : parrello 1.7 $caColumn = "<td></td>\n"; # <a href=\"../content/contactus.php\">Suggest</a></td>\n";
118 : parrello 1.6 }
119 :     }
120 :     if (defined $caColumn) {
121 : parrello 1.1 $odd = 1 - $odd;
122 :     $varHash->{result} .= "<tr class=\"$styles[$odd]\"><td><em>$which</em><br>$peg</td>\n";
123 :     $varHash->{result} .= "<td>$func (<a href=\"$link$peg\">NMPDR</a>)</td>\n";
124 : parrello 1.6 $varHash->{result} .= $caColumn;
125 :     $varHash->{result} .= "<td color=\"$color\"><a href=\"$lkpdb$pdb\">$pdb</a></td>\n";
126 :     # Find the best hit to a human.
127 :     my @bbhList = FIGRules::BatchBBHs($peg, 1e-15, '9606.3');
128 :     if (@bbhList) {
129 :     # Here we found one, so get the best one in the list.
130 :     my @sorted = sort { $a->[2] <=> $b->[2] } @bbhList;
131 :     my $bestPeg = $sorted[0]->[1];
132 :     $varHash->{result} .= "<td><a href=\"../FIG/protein.cgi?new_framework=0&SPROUT=1&prot=$bestPeg\">$sorted[0]->[2]</a></td>\n";
133 :     } else {
134 :     $varHash->{result} .= "<td>&nbsp;</td>\n";
135 :     }
136 : parrello 1.1 }
137 :     }
138 :    
139 : parrello 1.6
140 : parrello 1.1 # This sub changes the Candidacy code to something meaningful.
141 :     sub changecat{
142 :     my($dog) = @_;
143 : parrello 1.5 Trace("Selecting category for $dog.") if T(4);
144 : parrello 1.1 my $cat = SHDrugSearch::GetCategory($dog);
145 :     return $cat;
146 :     }
147 :    
148 : parrello 1.6 # This sub determines the attributes of each peg related to the given genome.
149 :     sub get_attribute_hash {
150 :     my ($genome) = @_;
151 : parrello 1.1 my %files = (drug => "drug.txt", toxin => "toxin.txt", vaccine => "vaccine.txt");
152 : parrello 1.6 my %retVal;
153 : parrello 1.1 my $selfURL = $cgi->url(-relative => 1);
154 :     for my $key (keys %files) {
155 : parrello 1.6 Open(\*INFILE, "$FIG_Config::drug_directory/$files{$key}");
156 :     while (! eof(INFILE)){
157 :     my @entry = Tracer::GetLine(\*INFILE);
158 :     if ($entry[5] =~ /$genome/){
159 : parrello 1.7 Trace("$entry[5] added to hash.") if T(3);
160 : parrello 1.6 my $title = ucfirst $key;
161 :     $retVal{$entry[5]} = "<td><a href=$selfURL?org=$genome&target=$key>$title</a></td>\n";
162 : parrello 1.1 }
163 :     }
164 : parrello 1.6 close(INFILE);
165 : parrello 1.1 }
166 : parrello 1.7 return %retVal;
167 : parrello 1.1 }
168 :    
169 :     #-- we wish to desplay only the best pdbs and those that are relavent
170 :     sub get_best_pdb{
171 : parrello 1.4 my ($cgi, $varHash, @entry)= @_;
172 : parrello 1.1 my @pdbresults =("1ah7","1dhn","1tfu"); # we define what pdb actually have been docked well.
173 : parrello 1.4 foreach (@pdbresults){ #look through the results we have
174 :     if ($entry[11] =~ m/$_/gi){ #ifwe have results for the free
175 :     &print_column($cgi, $varHash, $entry[11],'red', $entry[13],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this
176 :     return;
177 :     }elsif($entry[14] =~ m/$_/gi){ #if we have resutls for the bound
178 :     &print_column($cgi, $varHash,$entry[14], 'red', $entry[16],$entry[5], $entry[9], $entry[3], $entry[1]); #we wnat to display this
179 :     return;
180 : parrello 1.1 }
181 : parrello 1.4 }
182 :     if ($entry[13] eq "0"){ #if the free pdb is perfect
183 :     &print_column($cgi, $varHash, $entry[11], '', $entry[13],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this
184 :     return;
185 :     }elsif($entry[16] eq '0'){ #if the bound pdb is perfect
186 :     &print_column($cgi, $varHash, $entry[14], '', $entry[16],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this
187 :     return;
188 :     }elsif($entry[13] =~ /\d\.\d*E\-(\d+)/ ){ #if the eval is like 1.4E-45
189 :     if (15 < $1) { #and the exponant is less than 1.0E-15
190 :     if($entry[16] =~ /\d\.\d*E\-(\d+)/ ){ #but we should check if the bound is any better
191 :     if (15 < $1){ #and the xponant is less than 1.0-15 we need to do the comparison
192 :     my @free = split(/E\-/,$entry[13]);
193 :     my @bound = split(/E\-/,$entry[16]);
194 :     my $efree = $free[0] * 13 ** -$free[1];
195 :     my $ebound = $bound[0] * 13 ** -$bound[1];
196 :     if ($efree <= $ebound){ #if the free is less than the boutd
197 :     &print_column($cgi, $varHash, $entry[11], 'black', $entry[13],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this
198 :     return;
199 :     }else{
200 :     &print_column($cgi, $varHash, $entry[14], 'green', $entry[16],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this
201 : parrello 1.1 return;
202 :     }
203 : parrello 1.4 }else{ #the bound exponent wasn't less than 15
204 :     &print_column($cgi, $varHash, $entry[11], 'blue', $entry[13],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this
205 :     return;
206 :     }
207 :     }else{ #the bound pdb didn't even have an exponant
208 :     &print_column($cgi, $varHash, $entry[11], 'yello', $entry[13],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this
209 :     return; #this takes care the if free is good and bound is bad
210 :     }#a free pdb is no good becaus eval > 1e-15
211 :     }#free pdb was no good because eval > 1e-15
212 :     }elsif($entry[16] =~ /\d\.\d*E\-(\d+)/ ){ #we are now checking if the bound pdb is good
213 :     if (15 < $1) {
214 :     &print_column($cgi, $varHash, $entry[14], 'black', $entry[16],$entry[5], $entry[9], $entry[3], $entry[1]);
215 :     return;
216 : parrello 1.1 }
217 : parrello 1.4 } else {
218 :     Trace("Peg $entry[5] not printed.") if T(4);
219 : parrello 1.1 }
220 :     }
221 :    
222 :    
223 :     # -error interupt--these subs will probably go when bruce sees them
224 :     sub err {
225 :     my ($msg) = @_;
226 :     $msg = "Error!" unless $msg;
227 :     print (&colored($msg, "CC0033"));
228 :     die "$msg\n";
229 :     }
230 :    
231 :     sub colored {
232 :     my ($text, $color) = @_;
233 :     return "<font color=$color>$text</font>";
234 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3