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

Annotation of /FigWebServices/ligands.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download)

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     BEGIN {
4 :     # Print the HTML header.
5 :     print "CONTENT-TYPE: text/html\n\n";
6 :     }
7 :    
8 :     =head1 Ligand Display Script
9 :    
10 :     This script reads data from a file in the drug targets data directory
11 :     (C<$FIG_Config::drug_directory>) and uses the data therein to display the
12 :     ZINC codes, diagrams, and binding energy for various ligands against
13 :     the specified PDB protein.
14 :    
15 :     This script supports the following CGI query parameters.
16 :    
17 :     =over 4
18 :    
19 :     =item pdb
20 :    
21 :     Name of the PDB (short form, e.g. C<1hdn>).
22 :    
23 :     =item type
24 :    
25 :     Type of analysis: C<rich> or C<random>. The random analysis is used to
26 :     train the neural net that does the quick checking of ligands vs. the
27 :     protein. The rich analysis is applied to the ligands determined to be
28 :     the best by the quick check, and it is from this set that the best
29 :     ligands are culled.
30 :    
31 :     =item start
32 :    
33 :     Number of lines from the ligand file to skip before displaying. The default
34 :     is C<0>.
35 :    
36 :     =item pageSize
37 :    
38 :     Number of lines to display per page. The default is C<50>.
39 :    
40 :     =back
41 :    
42 :     =cut
43 :    
44 :     use strict;
45 :     use Tracer;
46 :     use CGI;
47 :     use Sprout;
48 :    
49 :     my ($cgi, $varHash) = ScriptSetup();
50 :     eval {
51 :     # Get the query parameters.
52 :     my $pdb = $cgi->param("pdb");
53 :     my $type= $cgi->param("type");
54 :     my $start = $cgi->param("start") || 0;
55 :     my $pageSize = $cgi->param("pageSize") || 50;
56 :     # Set the descriptive variables. These change key words in the introductory
57 :     # text and page heading.
58 :     $varHash->{type} = $type;
59 :     $varHash->{uc_first_type} = ucfirst $type;
60 :     $varHash->{pdb} = $pdb;
61 :     # Compute the NEXT/PREV links. There is always a NEXT, even though it might be empty.
62 :     my $status_url = Tracer::GenerateURL($cgi->url(-relative => 1), pdb => $pdb, type => $type, pageSize => $pageSize);
63 :     my $nextPage = $start + $pageSize;
64 :     my $navigator = $cgi->a({ href => "$status_url;start=$nextPage" }, [">> Next Page"]);
65 :     # There will be a previous page if we're not at 0.
66 :     if ($start > 0) {
67 :     my $prevPage = $start - $pageSize;
68 :     if ($prevPage < 0) { $prevPage = 0; }
69 :     $navigator = $cgi->a({ href => "$status_url;start=$prevPage" }, ["<< Prev Page"]) .
70 :     " | " . $navigator;
71 :     }
72 :     # Now format it as a centered paragraph object and start our page with it.
73 :     $navigator = $cgi->p($cgi->center($navigator));
74 :     $varHash->{results} = $navigator;
75 :     # Now build the table of stuff.
76 :     &add_table_top($cgi, $varHash);
77 :     &get_table($cgi, $varHash, $pdb, $type, $start, $pageSize);
78 :     &add_table_bottom($cgi, $varHash);
79 :     # Close off with another navigator.
80 :     $varHash->{results} .= $navigator;
81 :     };
82 :     if ($@) {
83 :     my $errorMessage = $@;
84 :     Trace("Script Error: $errorMessage") if T(0);
85 :     $varHash->{results} = $cgi->h3("Script Error: $errorMessage");
86 :     }
87 :     ScriptFinish("Ligands_tmpl.php", $varHash);
88 :    
89 :     sub get_table {
90 :     # Get the parameters.
91 :     my ($cgi, $varHash, $pdb, $type, $start, $pageSize) = @_;
92 :     # Initialize the row style to "even". The table header was odd, and it's
93 :     # already happened.
94 :     my $odd = 0;
95 :     my @styles = ("even", "odd");
96 :     # Compute the file name.
97 :     my $fileName = "$FIG_Config::drug_directory/${pdb}_$type.txt";
98 :     Open(\*TABLE, "<$fileName");
99 :     # Compute the last line to display.
100 :     my $end = $start + $pageSize;
101 :     # Loop through the data, producing the table rows. Note we use a counter to
102 :     # start and stop the actual displaying.
103 :     my $lineCount = 0;
104 :     while (defined(my $line = <TABLE>) && $lineCount < $end){
105 :     if ($lineCount >= $start) {
106 :     my @entry = split (/\t/,$line);
107 :     &print_row($entry[0], $entry[1], $varHash, $styles[$odd]);
108 :     $odd = 1 - $odd;
109 :     }
110 :     $lineCount++;
111 :     }
112 :     # Close the input file.
113 :     close TABLE;
114 :     }
115 :    
116 :     sub print_row{
117 :     my ($zinc, $score, $varHash, $style) = @_;
118 :     # The table contains the ZINC IDs as ZINCxxxx, but we only want the "x"s part.
119 :     $zinc =~ s/ZINC//gi;
120 :     # Accumulate the row in the desired style.
121 :     $varHash->{results} .= "<tr class=$style><td><a href=\"http://blaster.docking.org/zinc/srchdb.pl?zinc=$zinc\">$zinc</a></td>\n" .
122 :     "<td><img src=http://marilyn2.compbio.ucsf.edu/cgi-bin/depict3.pl?sub_id=$zinc></td>\n" .
123 :     "<td>$score</td></tr>\n";
124 :     }
125 :    
126 :     sub add_table_top {
127 :     my ($cgi, $varHash) = @_;
128 :     $varHash->{results} .= $cgi->start_table({class => "targets"}) .
129 :     $cgi->Tr({class => "odd"}, $cgi->th(['ZINC', 'image', 'Energy KJ/mol']));
130 :     }
131 :    
132 :    
133 :     sub add_table_bottom {
134 :     my ($cgi, $varHash) = @_;
135 :     $varHash->{results} .= $cgi->end_table();
136 :     }
137 :    
138 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3