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

View of /FigWebServices/ligands.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (annotate)
Tue Apr 29 08:11:34 2008 UTC (11 years, 6 months ago) by parrello
Branch: MAIN
CVS Tags: mgrast_dev_08112011, rast_rel_2009_05_18, mgrast_dev_08022011, rast_rel_2014_0912, rast_rel_2008_06_18, myrast_rel40, rast_rel_2008_06_16, mgrast_dev_05262011, rast_rel_2008_12_18, mgrast_dev_04082011, rast_rel_2008_07_21, rast_rel_2010_0928, rast_2008_0924, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, rast_rel_2008_09_30, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, rast_rel_2009_02_05, rast_rel_2011_0119, mgrast_rel_2008_0625, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, rast_rel_2008_10_09, mgrast_dev_04012011, rast_release_2008_09_29, mgrast_rel_2008_0806, mgrast_rel_2008_0923, mgrast_rel_2008_0919, rast_rel_2009_07_09, rast_rel_2010_0827, mgrast_rel_2008_1110, myrast_33, rast_rel_2011_0928, rast_rel_2008_09_29, mgrast_rel_2008_0917, rast_rel_2008_10_29, mgrast_dev_04052011, mgrast_dev_02222011, rast_rel_2009_03_26, mgrast_dev_10262011, rast_rel_2008_11_24, rast_rel_2008_08_07, HEAD
Changes since 1.1: +2 -2 lines
Fixed. Deprecated ScriptSetup methods are no longer exported by Tracer.

#!/usr/bin/perl -w

BEGIN {
    # 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>.

=back

=cut

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

my ($cgi, $varHash) = Tracer::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");
}
Tracer::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;
        }
        $lineCount++;
    }
    # 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" .
                           "<td>$score</td></tr>\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();
}

1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3