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

View of /FigWebServices/ligands.cgi

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.1 - (download) (annotate)
Tue Nov 7 22:28:49 2006 UTC (13 years, 8 months ago) by parrello
Branch: MAIN
CVS Tags: rast_rel_2008_04_23
Added to display docking information for drug target pages.

#!/usr/bin/perl -w

    # Print the HTML header.
    print "CONTENT-TYPE: text/html\n\n";

=head1 Ligand Display Script

This script reads data from a file in the drug targets data directory
(C<$FIG_Config::drug_directory>) and uses the data therein to display the
ZINC codes, diagrams, and binding energy for various ligands against
the specified PDB protein.

This script supports the following CGI query parameters.

=over 4

=item pdb

Name of the PDB (short form, e.g. C<1hdn>).

=item type

Type of analysis: C<rich> or C<random>. The random analysis is used to
train the neural net that does the quick checking of ligands vs. the
protein. The rich analysis is applied to the ligands determined to be
the best by the quick check, and it is from this set that the best
ligands are culled.

=item start

Number of lines from the ligand file to skip before displaying. The default
is C<0>.

=item pageSize

Number of lines to display per page. The default is C<50>.



use strict;
use Tracer;
use CGI;
use Sprout;

my ($cgi, $varHash) = ScriptSetup();
eval {
    # Get the query parameters.
    my $pdb = $cgi->param("pdb");
    my $type= $cgi->param("type");
    my $start = $cgi->param("start") || 0;
    my $pageSize = $cgi->param("pageSize") || 50;
    # Set the descriptive variables. These change key words in the introductory
    # text and page heading.
    $varHash->{type} = $type;
    $varHash->{uc_first_type} = ucfirst $type;
    $varHash->{pdb} = $pdb;
    # Compute the NEXT/PREV links. There is always a NEXT, even though it might be empty.
    my $status_url = Tracer::GenerateURL($cgi->url(-relative => 1), pdb => $pdb, type => $type, pageSize => $pageSize);
    my $nextPage = $start + $pageSize;
    my $navigator = $cgi->a({ href => "$status_url;start=$nextPage" }, [">> Next Page"]);
    # There will be a previous page if we're not at 0.
    if ($start > 0) {
        my $prevPage = $start - $pageSize;
        if ($prevPage < 0) { $prevPage = 0; }
        $navigator = $cgi->a({ href => "$status_url;start=$prevPage" }, ["<< Prev Page"]) .
                    " | " . $navigator;
    # Now format it as a centered paragraph object and start our page with it.
    $navigator = $cgi->p($cgi->center($navigator));
    $varHash->{results} = $navigator;
    # Now build the table of stuff.
    &add_table_top($cgi, $varHash);
    &get_table($cgi, $varHash, $pdb, $type, $start, $pageSize);
    &add_table_bottom($cgi, $varHash);
    # Close off with another navigator.
    $varHash->{results} .= $navigator;
if ($@) {
    my $errorMessage = $@;
    Trace("Script Error: $errorMessage") if T(0);
    $varHash->{results} = $cgi->h3("Script Error: $errorMessage");
ScriptFinish("Ligands_tmpl.php", $varHash);

sub get_table {
    # Get the parameters.
    my ($cgi, $varHash, $pdb, $type, $start, $pageSize) = @_;
    # Initialize the row style to "even". The table header was odd, and it's
    # already happened.
    my $odd = 0;
    my @styles = ("even", "odd");
    # Compute the file name.
    my $fileName = "$FIG_Config::drug_directory/${pdb}_$type.txt";
    Open(\*TABLE, "<$fileName");
    # Compute the last line to display.
    my $end = $start + $pageSize;
    # Loop through the data, producing the table rows. Note we use a counter to
    # start and stop the actual displaying.
    my $lineCount = 0;
    while (defined(my $line = <TABLE>) && $lineCount < $end){
        if ($lineCount >= $start) {
            my @entry = split (/\t/,$line);
            &print_row($entry[0], $entry[1], $varHash, $styles[$odd]);
            $odd = 1 - $odd;
    # Close the input file.
    close TABLE;

sub print_row{
    my ($zinc, $score, $varHash, $style) = @_;
    # The table contains the ZINC IDs as ZINCxxxx, but we only want the "x"s part.
    $zinc =~ s/ZINC//gi;
    # Accumulate the row in the desired style.
    $varHash->{results} .= "<tr class=$style><td><a href=\"http://blaster.docking.org/zinc/srchdb.pl?zinc=$zinc\">$zinc</a></td>\n" .
                           "<td><img src=http://marilyn2.compbio.ucsf.edu/cgi-bin/depict3.pl?sub_id=$zinc></td>\n" .

sub add_table_top {
    my ($cgi, $varHash) = @_;
    $varHash->{results} .= $cgi->start_table({class => "targets"}) .
                           $cgi->Tr({class => "odd"}, $cgi->th(['ZINC', 'image', 'Energy KJ/mol']));

sub add_table_bottom {
    my ($cgi, $varHash) = @_;
    $varHash->{results} .= $cgi->end_table();


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3