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

Annotation of /FigWebServices/targets.cgi

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3