[Bio] / Sprout / DrugTargets.pm Repository:
ViewVC logotype

Annotation of /Sprout/DrugTargets.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (view) (download) (as text)

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     #
4 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
5 :     # for Interpretations of Genomes. All Rights Reserved.
6 :     #
7 :     # This file is part of the SEED Toolkit.
8 :     #
9 :     # The SEED Toolkit is free software. You can redistribute
10 :     # it and/or modify it under the terms of the SEED Toolkit
11 :     # Public License.
12 :     #
13 :     # You should have received a copy of the SEED Toolkit Public License
14 :     # along with this program; if not write to the University of Chicago
15 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
16 :     # Genomes at veronika@thefig.info or download a copy from
17 :     # http://www.theseed.org/LICENSE.TXT.
18 :     #
19 :     package DrugTargets;
20 :    
21 :     use strict;
22 :     use Tracer;
23 : parrello 1.2 use CGI qw(-nosticky);
24 : parrello 1.1 use SHDrugSearch;
25 :     use FIGRules;
26 :     use TWiki::Func;
27 :     use HTML::Template;
28 :     use SFXlate;
29 :    
30 :     my @styles = ("even", "odd");
31 :     my $odd;
32 :     my $lkpdb ='http://www.rcsb.org/pdb/explore.do?structureId=';
33 :    
34 :     sub main {
35 :     my ($cgi, $session, $varHash) = @_;
36 :     ETracing($cgi);
37 :     $odd = 1;
38 :     my $fig = SFXlate->new();
39 :     #get the query paramaters
40 :     my $target = $cgi->param("target");
41 :     my %pegHash;
42 :     my $org = $cgi->param("org");
43 :     # Set the descriptive variables. These change key words in the introductory
44 :     # text and page heading.
45 :     $varHash->{target} = $target;
46 :     $varHash->{org} = $org;
47 :     # Compute the peg hash if we're organism-only.
48 :     if ($org && ! $target) {
49 :     Trace("Computing peg hash.") if T(3);
50 :     %pegHash = get_attribute_hash($org);
51 :     }
52 :     #The script operates
53 :     &add_table_top($fig, $cgi, $varHash, $org, $target);
54 :     if ($target){
55 :     &get_table($fig, $cgi, $varHash, "$target.txt", \%pegHash);
56 :     }elsif($org){
57 :     &get_table($fig, $cgi, $varHash, $org, \%pegHash);
58 :     }
59 :     $varHash->{result} .= '</table>';
60 :     print $cgi->header();
61 :     my $page = MyPage($varHash);
62 :     print $page;
63 :     };
64 :    
65 :     =head3 MyPage
66 :    
67 :     my $html = MyPage($varHash);
68 :    
69 :     Output a drug target page. The incoming hash contains parameters that are plugged
70 :     into a template.
71 :    
72 :     =over 4
73 :    
74 :     =item varHash
75 :    
76 :     Hash containing the variable data to be placed on the page.
77 :    
78 :     =item RETURN
79 :    
80 :     Returns the page HTML to display.
81 :    
82 :     =back
83 :    
84 :     The variables in the hash should be as follows.
85 :    
86 :     =over 4
87 :    
88 :     =item org
89 :    
90 :     Organism name.
91 :    
92 :     =item results
93 :    
94 :     Table displaying the result data.
95 :    
96 :     =item target
97 :    
98 :     Type of target desired.
99 :    
100 :     =item uc_first_target
101 :    
102 :     Target type as a WikiWord.
103 :    
104 :     =back
105 :    
106 :     =cut
107 :    
108 :     sub MyPage {
109 :     # Get the parameters.
110 :     my ($varHash) = @_;
111 :     # Get the text template. This is an HTML template, not a TWiki template.
112 :     my $htmlTemplate = TWiki::Func::readAttachment('Main', 'CandidateTargetsPipeline', 'DrugTargets.tmpl');
113 :     my $templateObject = HTML::Template->new(scalarref => \$htmlTemplate,
114 :     die_on_bad_params => 0);
115 :     # Next, we pass in the variable values.
116 :     for my $varKey (keys %{$varHash}) {
117 :     # Get the variable value.
118 :     my $varValue = $varHash->{$varKey};
119 :     # Check for an undefined value.
120 :     if (! defined($varValue)) {
121 :     # Treat it as a null string.
122 :     $templateObject->param($varKey => "");
123 :     } else {
124 :     # Check for an array of scalars. We convert this into a string
125 :     # for compatibility with earlier stuff. An array of hashes is
126 :     # okay, because it's used for loops.
127 :     if (ref $varValue eq 'ARRAY') {
128 :     if (scalar @{$varValue} > 0 && ! ref $varValue->[0]) {
129 :     $varValue = join("\n", @{$varValue});
130 :     }
131 :     }
132 :     # Record the parameter.
133 :     Trace("Variable $varKey has value \"$varValue\".") if T(4);
134 :     $templateObject->param($varKey => $varValue);
135 :     }
136 :     }
137 :     # Finally, we produce the text.
138 :     my $text = $templateObject->output();
139 :     # Get the view template. This IS a TWiki template.
140 :     my $template = TWiki::Func::loadTemplate('view');
141 :     # Set the meta-variable values.
142 :     $template =~ s/%TEXT%/$text/g;
143 :     $template =~ s/%REVTITLE%//g;
144 :     # Expand it.
145 :     my $raw = TWiki::Func::expandCommonVariables($template, 'CandidateTargetsReport', 'Main');
146 :     # Render it into HTML.
147 :     my $retVal = TWiki::Func::renderText($raw, 'Main');
148 :     # Clean the nops.
149 :     $retVal =~ s/<nop>//g;
150 :     # Return the result.
151 :     return $retVal;
152 :     }
153 :    
154 :    
155 :     # This function adds the table header based on if we are looking at a specific target category
156 :     sub add_table_top{
157 :     my ($fig, $cgi, $varHash, $org, $target) = @_;
158 :     &add_words($fig, $cgi, $varHash, $org);
159 :     if($target){
160 :     $varHash->{result} .= ' <table width="90%" class="targets">
161 :     <tr class=odd><th>Organism</th><th>Functional Role</th><th>Candidacy<th>PDB</th><th>Best Hit to Human</th></tr>';
162 :     }elsif ($org) {
163 :     $varHash->{result} .= '<table width="90%" class="targets">
164 :     <tr class=odd><th>Organism</th><th>Functional Role</th><th>Category</th><th>PDB</th><th>Best Hit to Human</th></tr>';
165 :     }
166 :     }
167 :    
168 :     # This funtion sets up the variables used by the template to display organism-related text.
169 :     # and how to navigate it
170 :     sub add_words{
171 :     my ($fig, $cgi, $varHash, $org) = @_;
172 :     $varHash->{orgName} = "";
173 :     if($org){
174 :     $varHash->{orgName} = $fig->genus_species($org);
175 :     }
176 :     }
177 :    
178 :     # This Sub funtions to open up the table and keep track of the index of what row we are on
179 :     sub get_table{
180 :     my($fig, $cgi, $varHash, $file, $pegHash)= @_;
181 :     Open(\*TABLE, "<$FIG_Config::drug_directory/$file");
182 :     Trace("Processing table $file.") if T(3);
183 :     my $count = 0;
184 :     while (! eof TABLE){
185 :     my @entry = Tracer::GetLine(\*TABLE);
186 :     &get_best_pdb($fig, $pegHash, $cgi, $varHash, @entry);
187 :     $count++;
188 :     }
189 :     Trace("$count entries found in $file.") if T(3);
190 :     }
191 :    
192 :    
193 :     # This Sub funtions to print the Table Row in the correct format.
194 :     sub print_column{
195 :     my($fig, $pegHash, $cgi, $varHash, $pdb, $color, $score,$peg, $func, $lit, $cat) = @_ ;
196 :     my $genome = $peg;
197 :     $genome =~ s/fig\|//;
198 :     $genome =~ s/\.peg\.\d+//;
199 :     my $which = $fig->genus_species($genome);
200 :     $pdb =~ s/pdb//;
201 :     $pdb =~ s/\.ent//;
202 :     $cat = changecat($cat);
203 :     my $selfURL = $cgi->url(-relative => 1);
204 :     my $org = $cgi->param('org') || "";
205 :     my $target = $cgi->param('target') || "";
206 :     Trace("Printing $color for $pdb of peg $peg. Org,target = \"$org,%target\".") if T(4);
207 :     # We'll put the category/attribute column value in here if this row should be
208 :     # displayed.
209 :     my $caColumn;
210 :     if ($org && $target){
211 :     if ($peg =~ m/$org/){
212 :     $caColumn = "<td><a href=\"$lit\">$cat</a></td>\n";
213 :     }
214 :     }elsif($target){
215 :     $caColumn = "<td><a href=\"$lit\">$cat</a></td>\n";
216 :     }elsif($org){
217 :     Trace("Peg hash is: $pegHash->{$peg}.") if T(4);
218 :     if ($pegHash->{$peg}) {
219 :     $caColumn = $pegHash->{$peg};
220 :     } else {
221 :     $caColumn = "<td></td>\n"; # <a href=\"../content/contactus.php\">Suggest</a></td>\n";
222 :     }
223 :     }
224 :     if (defined $caColumn) {
225 :     $odd = 1 - $odd;
226 :     $varHash->{result} .= "<tr class=\"$styles[$odd]\"><td><em>$which</em><br>$peg</td>\n";
227 :     $varHash->{result} .= "<td>$func (%SV{\"NMPDR\" id=\"$peg\"})</td>\n";
228 :     $varHash->{result} .= $caColumn;
229 :     $varHash->{result} .= "<td color=\"$color\"><a href=\"$lkpdb$pdb\">$pdb</a></td>\n";
230 :     # Find the best hit to a human.
231 :     my @bbhList = FIGRules::BatchBBHs($peg, 1e-15, '9606.3');
232 :     if (@bbhList) {
233 :     # Here we found one, so get the best one in the list.
234 :     my @sorted = sort { $a->[2] <=> $b->[2] } @bbhList;
235 :     my $bestPeg = $sorted[0]->[1];
236 :     $varHash->{result} .= "<td>%SV{\"$sorted[0]->[2]\" id=\"$bestPeg\"}%</td>\n";
237 :     } else {
238 :     $varHash->{result} .= "<td>&nbsp;</td>\n";
239 :     }
240 :     }
241 :     }
242 :    
243 :    
244 :     # This sub changes the Candidacy code to something meaningful.
245 :     sub changecat{
246 :     my($dog) = @_;
247 :     Trace("Selecting category for $dog.") if T(4);
248 :     my $cat = SHDrugSearch::GetCategory($dog);
249 :     return $cat;
250 :     }
251 :    
252 :     # This sub determines the attributes of each peg related to the given genome.
253 :     sub get_attribute_hash {
254 :     my ($genome) = @_;
255 :     my %files = (drug => "drug.txt", toxin => "toxin.txt", vaccine => "vaccine.txt");
256 :     my %retVal;
257 :     my $selfURL = "$FIG_Config::cgi_url/wiki/rest.cgi/NmpdrPlugin/drugs";
258 :     for my $key (keys %files) {
259 :     Open(\*INFILE, "$FIG_Config::drug_directory/$files{$key}");
260 :     while (! eof(INFILE)){
261 :     my @entry = Tracer::GetLine(\*INFILE);
262 :     if ($entry[5] =~ /$genome/){
263 :     Trace("$entry[5] added to hash.") if T(3);
264 :     my $title = ucfirst $key;
265 :     $retVal{$entry[5]} = "<td><a href=$selfURL?org=$genome&target=$key>$title</a></td>\n";
266 :     }
267 :     }
268 :     close(INFILE);
269 :     }
270 :     return %retVal;
271 :     }
272 :    
273 :     #-- we wish to desplay only the best pdbs and those that are relavent
274 :     sub get_best_pdb{
275 :     my ($fig, $pegHash, $cgi, $varHash, @entry)= @_;
276 :     Trace("Processing best PDB for $entry[5].") if T(4);
277 :     my @pdbresults =("1ah7","1dhn","1tfu"); # we define what pdb actually have been docked well.
278 :     foreach (@pdbresults){ #look through the results we have
279 :     if ($entry[11] =~ m/$_/gi){ #ifwe have results for the free
280 :     &print_column($fig, $pegHash, $cgi, $varHash, $entry[11],'red', $entry[13],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this
281 :     return;
282 :     }elsif($entry[14] =~ m/$_/gi){ #if we have resutls for the bound
283 :     &print_column($fig, $pegHash, $cgi, $varHash,$entry[14], 'red', $entry[16],$entry[5], $entry[9], $entry[3], $entry[1]); #we wnat to display this
284 :     return;
285 :     }
286 :     }
287 :     if ($entry[13] eq "0"){ #if the free pdb is perfect
288 :     &print_column($fig, $pegHash, $cgi, $varHash, $entry[11], '', $entry[13],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this
289 :     return;
290 :     }elsif($entry[16] eq '0'){ #if the bound pdb is perfect
291 :     &print_column($fig, $pegHash, $cgi, $varHash, $entry[14], '', $entry[16],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this
292 :     return;
293 :     }elsif($entry[13] =~ /\d\.\d*E\-(\d+)/ ){ #if the eval is like 1.4E-45
294 :     if (15 < $1) { #and the exponant is less than 1.0E-15
295 :     if($entry[16] =~ /\d\.\d*E\-(\d+)/ ){ #but we should check if the bound is any better
296 :     if (15 < $1){ #and the xponant is less than 1.0-15 we need to do the comparison
297 :     my @free = split(/E\-/,$entry[13]);
298 :     my @bound = split(/E\-/,$entry[16]);
299 :     my $efree = $free[0] * 13 ** -$free[1];
300 :     my $ebound = $bound[0] * 13 ** -$bound[1];
301 :     if ($efree <= $ebound){ #if the free is less than the boutd
302 :     &print_column($fig, $pegHash, $cgi, $varHash, $entry[11], 'black', $entry[13],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this
303 :     return;
304 :     }else{
305 :     &print_column($fig, $pegHash, $cgi, $varHash, $entry[14], 'green', $entry[16],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this
306 :     return;
307 :     }
308 :     }else{ #the bound exponent wasn't less than 15
309 :     &print_column($fig, $pegHash, $cgi, $varHash, $entry[11], 'blue', $entry[13],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this
310 :     return;
311 :     }
312 :     }else{ #the bound pdb didn't even have an exponant
313 :     &print_column($fig, $pegHash, $cgi, $varHash, $entry[11], 'yello', $entry[13],$entry[5], $entry[9], $entry[3], $entry[1]); #we want to display this
314 :     return; #this takes care the if free is good and bound is bad
315 :     }#a free pdb is no good becaus eval > 1e-15
316 :     }#free pdb was no good because eval > 1e-15
317 :     }elsif($entry[16] =~ /\d\.\d*E\-(\d+)/ ){ #we are now checking if the bound pdb is good
318 :     if (15 < $1) {
319 :     &print_column($fig, $pegHash, $cgi, $varHash, $entry[14], 'black', $entry[16],$entry[5], $entry[9], $entry[3], $entry[1]);
320 :     return;
321 :     }
322 :     } else {
323 :     Trace("Peg $entry[5] not printed.") if T(4);
324 :     }
325 :     }
326 :    
327 :    
328 :     # -error interupt--these subs will probably go when bruce sees them
329 :     sub err {
330 :     my ($msg) = @_;
331 :     $msg = "Error!" unless $msg;
332 :     print (&colored($msg, "CC0033"));
333 :     die "$msg\n";
334 :     }
335 :    
336 :     sub colored {
337 :     my ($text, $color) = @_;
338 :     return "<font color=$color>$text</font>";
339 :     }
340 :    
341 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3