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

Annotation of /Sprout/SHDrugSearch.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     package SHDrugSearch;
4 :    
5 :     use strict;
6 :     use Tracer;
7 :     use SearchHelper;
8 :     use CGI;
9 :     use HTML;
10 :     use Sprout;
11 :     use FeatureData;
12 :     use FeatureQuery;
13 :    
14 :     our @ISA = qw(SearchHelper);
15 :    
16 :     =head1 Drug Target Project Summary Feature Search Helper
17 :    
18 :     =head2 Introduction
19 :    
20 :     This search helper will display all the features that participated in a particular
21 :     drug target project. Each project represents a single study, generally related
22 :     to a specified organism. The study finds PDBs that are good drug target
23 :     candidates, and these are connected to the relevant B<DrugTargetProject> entity
24 :     instance in the database. From the PDB, we can get a list of the related
25 :     features, and these features are the ones we return in the search.
26 :    
27 :     This search has the following extra parameters in addition to the ones
28 :     produced by the B<SpecialOptions> method of the B<FeatureQuery> object.
29 :    
30 :     =over 4
31 :    
32 :     =item project
33 :    
34 :     ID of the drug target project to display.
35 :    
36 : parrello 1.3 =item score
37 :    
38 :     Maximum allowable score for a PDB/PEG match to be considered good
39 :     enough to display. The default is 1e-15.
40 :    
41 : parrello 1.1 =back
42 :    
43 : parrello 1.2 =cut
44 :    
45 :     # Table of drug topic category codes.
46 :     my %CodeTable = (
47 :     'ES' => 'essential',
48 :     'ES-X' => 'essential, determined by experiment',
49 :     'ES-L' => 'essential, from the literature',
50 :     'KA-T' => 'known Antibiotic target',
51 :     'KA-I' => 'known Antibiotic Inhibitor',
52 :     'VA' => 'virulence associated',
53 :     'VA-K' => 'known virulence associated',
54 :     'VA-P' => 'putative virulence assocated'
55 :     );
56 :    
57 : parrello 1.1 =head2 Virtual Methods
58 :    
59 :     =head3 Form
60 :    
61 : parrello 1.3 C<< my $html = $shelp->Form(); >>
62 : parrello 1.1
63 :     Generate the HTML for a form to request a new search.
64 :    
65 :     =cut
66 :    
67 :     sub Form {
68 :     # Get the parameters.
69 :     my ($self) = @_;
70 :     # Get the CGI and sprout objects.
71 :     my $cgi = $self->Q();
72 :     my $sprout = $self->DB();
73 :     # Start the form.
74 :     my $retVal = $self->FormStart("Select Drug Target Project");
75 :     # Get a list of all the projects.
76 :     my @projectNames = $sprout->GetFlat(['DrugProject'], "", [], 'DrugProject(id)');
77 :     # See if there's already a project selected.
78 :     my $defaultProject = $cgi->param('project');
79 :     # Convert the project list into a drop-down menu.
80 :     my $menu = $cgi->popup_menu(-name => 'project', -values => \@projectNames,
81 :     -default => $defaultProject);
82 : parrello 1.3 # Create the drop-down menu for scoring.
83 :     my $defaultScore = $cgi->param('score') || '1e-15';
84 :     my $scoreMenu = $cgi->popup_menu(-name => 'score',
85 :     -values => ['1e-30', '1e-15', '1e-10', '1e-5', '1', '10'],
86 :     -default => $defaultScore);
87 : parrello 1.1 # Build a table from the drop-down menu, the special options, and the submit row.
88 :     my @rows = ($cgi->Tr($cgi->th('Project'), $cgi->td($menu)),
89 : parrello 1.3 $cgi->Tr($cgi->th('Max Score'), $cgi->td($scoreMenu)),
90 :     FeatureQuery::SpecialOptions($self),
91 :     $self->SubmitRow()
92 :     );
93 : parrello 1.1 $retVal .= $self->MakeTable(\@rows);
94 :     # Close the form.
95 :     $retVal .= $self->FormEnd();
96 :     # Return the result.
97 :     return $retVal;
98 :     }
99 :    
100 :     =head3 Find
101 :    
102 :     C<< my $resultCount = $shelp->Find(); >>
103 :    
104 :     Conduct a search based on the current CGI query parameters. The search results will
105 :     be written to the session cache file and the number of results will be
106 :     returned. If the search parameters are invalid, a result count of C<undef> will be
107 :     returned and a result message will be stored in this object describing the problem.
108 :    
109 :     =cut
110 :    
111 :     sub Find {
112 :     my ($self) = @_;
113 :     # Get the CGI and Sprout objects.
114 :     my $cgi = $self->Q();
115 :     my $sprout = $self->DB();
116 :     # Declare the return variable. If it remains undefined, the caller will
117 :     # know that an error occurred.
118 :     my $retVal;
119 : parrello 1.3 # Insure a project and score are selected.
120 : parrello 1.1 my $project = $cgi->param('project');
121 : parrello 1.3 my $score = $cgi->param('score');
122 : parrello 1.1 if (! $project) {
123 :     $self->SetMessage("No project specified.");
124 : parrello 1.3 } elsif (! $score) {
125 :     $self->SetMessage("No score specified.");
126 : parrello 1.1 } else {
127 :     # Initialize the session file.
128 :     $self->OpenSession();
129 :     # Initialize the result counter.
130 :     $retVal = 0;
131 :     # Get a query that will return the features for the project.
132 : parrello 1.2 my $query= $sprout->Get(['ContainsTopic', 'DrugTopic', 'ContainsAnalysisOf', 'PDB',
133 : parrello 1.1 'DescribesProteinForFeature', 'Feature'],
134 : parrello 1.3 "ContainsTopic(from-link) = ? AND DescribesProteinForFeature(score) <= ?",
135 :     [$project, $score]);
136 : parrello 1.1 # Create a feature data object to manage our results.
137 :     my $fd = FeatureData->new($self);
138 :     # Loop through the results.
139 :     while (my $record = $query->Fetch()) {
140 :     # Validate the PDB ID.
141 :     my ($pdb) = $record->Value('DescribesProteinForFeature(from-link)');
142 :     if ($pdb =~ /^pdb([^.]+)\./i) {
143 :     # Here we're okay, so we yank out the real PDB ID from the file title and
144 :     # apply a link.
145 :     my $pdbID = $1;
146 :     my $pdbInfo = $cgi->a({href => "http://www.rcsb.org/pdb/explore.do?structureId=$pdbID",
147 :     title => "display this protein's page in the Protein Data Bank",
148 :     alt => "display this protein's page in the Protein Data Bank",
149 :     target => "_blank"}, $pdbID);
150 : parrello 1.2 # Get the topic category. This explains why the PDB is interesting.
151 :     my ($categoryCode) = $record->Value('DrugTopic(category)');
152 :     my $category = $CodeTable{$categoryCode};
153 : parrello 1.3 # Extract the score.
154 :     my ($score) = $record->Value('DescribesProteinForFeature(score)');
155 : parrello 1.1 # Store this feature in the data object.
156 :     $fd->Store($record);
157 :     # Add the PDB columns.
158 : parrello 1.3 $fd->AddExtraColumns('Free PDB' => $pdbInfo, 'Reason' => $category, 'Score' => $score);
159 : parrello 1.1 # Put it in the results list.
160 :     $self->PutFeature($fd);
161 :     $retVal++;
162 :     } else {
163 :     # Here the PDB didn't have the format we expected.
164 :     Confess("Invalid PDB ID \"$pdb\" found in database.")
165 :     }
166 :     }
167 :     # Close the session file.
168 :     $self->CloseSession();
169 :     }
170 :     # Return the result count.
171 :     return $retVal;
172 :     }
173 :    
174 :     =head3 DefaultFeatureColumns
175 :    
176 :     C<< my @cols = $shelp->DefaultFeatureColumns(); >>
177 :    
178 :     This method returns a list of the descriptors for the columns to be
179 :     displayed by this search, overriding the standard column set.
180 :    
181 :     =cut
182 :    
183 :     sub DefaultFeatureColumns {
184 :     # Get the parameters.
185 :     my ($self) = @_;
186 :     # Return the result.
187 :     return qw(orgName function protlink);
188 :     }
189 :    
190 :     =head3 Description
191 :    
192 :     C<< my $htmlText = $shelp->Description(); >>
193 :    
194 :     Return a description of this search. The description is used for the table of contents
195 :     on the main search tools page. It may contain HTML, but it should be character-level,
196 :     not block-level, since the description is going to appear in a list.
197 :    
198 :     =cut
199 :    
200 :     sub Description {
201 :     # Get the parameters.
202 :     my ($self) = @_;
203 :     # Return the result.
204 : parrello 1.4 return "Show the PDB and gene relationships for a specified drug target analysis project.";
205 : parrello 1.1 }
206 :    
207 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3