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

Annotation of /Sprout/SHDrugSearch.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3