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

Annotation of /Sprout/SHDrugSearch.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (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 :     =back
37 :    
38 : parrello 1.2 =cut
39 :    
40 :     # Table of drug topic category codes.
41 :     my %CodeTable = (
42 :     'ES' => 'essential',
43 :     'ES-X' => 'essential, determined by experiment',
44 :     'ES-L' => 'essential, from the literature',
45 :     'KA-T' => 'known Antibiotic target',
46 :     'KA-I' => 'known Antibiotic Inhibitor',
47 :     'VA' => 'virulence associated',
48 :     'VA-K' => 'known virulence associated',
49 :     'VA-P' => 'putative virulence assocated'
50 :     );
51 :    
52 : parrello 1.1 =head2 Virtual Methods
53 :    
54 :     =head3 Form
55 :    
56 :     C<< my $html = $shelp->Include(); >>
57 :    
58 :     Generate the HTML for a form to request a new search.
59 :    
60 :     =cut
61 :    
62 :     sub Form {
63 :     # Get the parameters.
64 :     my ($self) = @_;
65 :     # Get the CGI and sprout objects.
66 :     my $cgi = $self->Q();
67 :     my $sprout = $self->DB();
68 :     # Start the form.
69 :     my $retVal = $self->FormStart("Select Drug Target Project");
70 :     # Get a list of all the projects.
71 :     my @projectNames = $sprout->GetFlat(['DrugProject'], "", [], 'DrugProject(id)');
72 :     # See if there's already a project selected.
73 :     my $defaultProject = $cgi->param('project');
74 :     # Convert the project list into a drop-down menu.
75 :     my $menu = $cgi->popup_menu(-name => 'project', -values => \@projectNames,
76 :     -default => $defaultProject);
77 :     # Build a table from the drop-down menu, the special options, and the submit row.
78 :     my @rows = ($cgi->Tr($cgi->th('Project'), $cgi->td($menu)),
79 :     FeatureQuery::SpecialOptions($self),
80 :     $self->SubmitRow());
81 :     $retVal .= $self->MakeTable(\@rows);
82 :     # Close the form.
83 :     $retVal .= $self->FormEnd();
84 :     # Return the result.
85 :     return $retVal;
86 :     }
87 :    
88 :     =head3 Find
89 :    
90 :     C<< my $resultCount = $shelp->Find(); >>
91 :    
92 :     Conduct a search based on the current CGI query parameters. The search results will
93 :     be written to the session cache file and the number of results will be
94 :     returned. If the search parameters are invalid, a result count of C<undef> will be
95 :     returned and a result message will be stored in this object describing the problem.
96 :    
97 :     =cut
98 :    
99 :     sub Find {
100 :     my ($self) = @_;
101 :     # Get the CGI and Sprout objects.
102 :     my $cgi = $self->Q();
103 :     my $sprout = $self->DB();
104 :     # Declare the return variable. If it remains undefined, the caller will
105 :     # know that an error occurred.
106 :     my $retVal;
107 :     # Insure a project is selected.
108 :     my $project = $cgi->param('project');
109 :     if (! $project) {
110 :     $self->SetMessage("No project specified.");
111 :     } else {
112 :     # Initialize the session file.
113 :     $self->OpenSession();
114 :     # Initialize the result counter.
115 :     $retVal = 0;
116 :     # Get a query that will return the features for the project.
117 : parrello 1.2 my $query= $sprout->Get(['ContainsTopic', 'DrugTopic', 'ContainsAnalysisOf', 'PDB',
118 : parrello 1.1 'DescribesProteinForFeature', 'Feature'],
119 :     "ContainsTopic(from-link) = ?", [$project]);
120 :     # Create a feature data object to manage our results.
121 :     my $fd = FeatureData->new($self);
122 :     # Loop through the results.
123 :     while (my $record = $query->Fetch()) {
124 :     # Validate the PDB ID.
125 :     my ($pdb) = $record->Value('DescribesProteinForFeature(from-link)');
126 :     if ($pdb =~ /^pdb([^.]+)\./i) {
127 :     # Here we're okay, so we yank out the real PDB ID from the file title and
128 :     # apply a link.
129 :     my $pdbID = $1;
130 :     my $pdbInfo = $cgi->a({href => "http://www.rcsb.org/pdb/explore.do?structureId=$pdbID",
131 :     title => "display this protein's page in the Protein Data Bank",
132 :     alt => "display this protein's page in the Protein Data Bank",
133 :     target => "_blank"}, $pdbID);
134 : parrello 1.2 # Get the topic category. This explains why the PDB is interesting.
135 :     my ($categoryCode) = $record->Value('DrugTopic(category)');
136 :     my $category = $CodeTable{$categoryCode};
137 : parrello 1.1 # Store this feature in the data object.
138 :     $fd->Store($record);
139 :     # Add the PDB columns.
140 : parrello 1.2 $fd->AddExtraColumns('Free PDB' => $pdbInfo, 'Reason' => $category);
141 : parrello 1.1 # Put it in the results list.
142 :     $self->PutFeature($fd);
143 :     $retVal++;
144 :     } else {
145 :     # Here the PDB didn't have the format we expected.
146 :     Confess("Invalid PDB ID \"$pdb\" found in database.")
147 :     }
148 :     }
149 :     # Close the session file.
150 :     $self->CloseSession();
151 :     }
152 :     # Return the result count.
153 :     return $retVal;
154 :     }
155 :    
156 :     =head3 DefaultFeatureColumns
157 :    
158 :     C<< my @cols = $shelp->DefaultFeatureColumns(); >>
159 :    
160 :     This method returns a list of the descriptors for the columns to be
161 :     displayed by this search, overriding the standard column set.
162 :    
163 :     =cut
164 :    
165 :     sub DefaultFeatureColumns {
166 :     # Get the parameters.
167 :     my ($self) = @_;
168 :     # Return the result.
169 :     return qw(orgName function protlink);
170 :     }
171 :    
172 :     =head3 Description
173 :    
174 :     C<< my $htmlText = $shelp->Description(); >>
175 :    
176 :     Return a description of this search. The description is used for the table of contents
177 :     on the main search tools page. It may contain HTML, but it should be character-level,
178 :     not block-level, since the description is going to appear in a list.
179 :    
180 :     =cut
181 :    
182 :     sub Description {
183 :     # Get the parameters.
184 :     my ($self) = @_;
185 :     # Return the result.
186 :     return "Show the PDB and feature relationships for a specified drug target analysis project.";
187 :     }
188 :    
189 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3