[Bio] / Sprout / ShowCounts.pl Repository:
ViewVC logotype

Annotation of /Sprout/ShowCounts.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     =head1 Generate NMPDR Web Page Includes
4 :    
5 :     This script generates the include files for the NMPDR cover pages. The include
6 :     files go in the C<html/includes> directory for the current NMPDR, and are
7 :     based on data in the Sprout database. They need to be generated after the
8 :     Sprout database is loaded, but before the cover pages are put online.
9 :    
10 :     The include files generated are:
11 :    
12 :     =over 4
13 :    
14 :     =item version.inc
15 :    
16 :     Displays the version date, the genome counts, the number of subsystems,
17 :     and the number of new annotations. This file is included in the
18 :     C<index.php> document.
19 :    
20 : parrello 1.11 =item forms/all_genomes.inc
21 : parrello 1.1
22 :     Displays a form allowing the user to select an organism and see a summary of
23 :     its subsystems and reactions. This file is included in the
24 :     C<content/subsystems.php> document.
25 :    
26 :     =item sproutdb.inc
27 :    
28 :     Displays the documentation for the Sprout database. This file is included in
29 :     the C<content/docs.php> document.
30 :    
31 :     =back
32 :    
33 :     The currently-supported command-line options are as follows.
34 :    
35 :     =over 4
36 :    
37 :     =item user
38 :    
39 :     Name suffix to be used for log files. If omitted, the PID is used.
40 :    
41 :     =item trace
42 :    
43 :     Numeric trace level. A higher trace level causes more messages to appear. The
44 :     default trace level is 2. Tracing will be directly to the standard output
45 :     as well as to a C<trace>I<User>C<.log> file in the FIG temporary directory,
46 :     where I<User> is the value of the B<user> option above.
47 :    
48 :     =item sql
49 :    
50 :     If specified, turns on tracing of SQL activity.
51 :    
52 :     =item background
53 :    
54 :     Save the standard and error output to files. The files will be created
55 :     in the FIG temporary directory and will be named C<err>I<User>C<.log> and
56 :     C<out>I<User>C<.log>, respectively, where I<User> is the value of the
57 :     B<user> option above.
58 :    
59 :     =item h
60 :    
61 :     Display this command's parameters and options.
62 :    
63 :     =item target
64 :    
65 : parrello 1.2 Target directory for the include files. The default is C<includes> in the
66 :     C<$FIG_Config::nmpdr_pages> directory.
67 : parrello 1.1
68 :     =back
69 :    
70 :     =cut
71 :    
72 :     use strict;
73 :     use Tracer;
74 :     use Cwd;
75 :     use File::Copy;
76 :     use File::Path;
77 :     use FIG;
78 : parrello 1.3 use CGI qw(:standard);
79 : parrello 1.1
80 :     # Get the command-line options and parameters.
81 :     my ($options, @parameters) = StandardSetup([qw(Sprout ERDB SFXlate) ],
82 :     {
83 : parrello 1.10 trace => [2, 'tracing level'],
84 : parrello 1.2 target => ["$FIG_Config::nmpdr_pages/includes",
85 : parrello 1.1 'output directory'],
86 :     },
87 :     "<version date>",
88 :     @ARGV);
89 :    
90 :     use SFXlate;
91 :    
92 : parrello 1.14 # The return type (error/no error) will be put in here.
93 :     my $rtype;
94 :     eval {
95 :     # Get the target directory.
96 :     my $targetDir = $options->{target};
97 :     # Verify the parameters.
98 :     if (! $parameters[0]) {
99 :     Confess("Please specify a version date.");
100 :     } elsif (! -d $targetDir) {
101 :     Confess("Target directory $targetDir does not exist.");
102 :     } else {
103 :     Trace("Output going to $targetDir.") if T(2);
104 :     # Get the Sprout object.
105 :     my $sfx = SFXlate->new_sprout_only();
106 :     # Get the old Sprout.
107 :     my $oldSprout = SFXlate->old_sprout_only();
108 :     # Create the counts file.
109 :     CreateCounts($sfx, $oldSprout, $parameters[0], "$targetDir/version.inc");
110 :     # Create the subsystem summary file.
111 :     CreateSubForm($sfx, "$targetDir/forms/subsystems.inc");
112 :     # Create the organism summary file.
113 :     CreateOrgForm($sfx, "$targetDir/forms/all_genomes.inc");
114 :     # Create the database documentation file.
115 :     CreateSproutDoc($sfx, "$targetDir/sproutdb.inc");
116 :     # Tell the user we're done.
117 :     Trace("File creation complete.") if T(2);
118 :     }
119 :     };
120 :     if ($@) {
121 :     Trace("Counts failed with error: $@") if T(0);
122 :     $rtype = "error";
123 : parrello 1.4 } else {
124 : parrello 1.14 Trace("Counts complete.") if T(2);
125 :     $rtype = "no error";
126 :     }
127 :     if ($options->{phone}) {
128 :     my $msgID = Tracer::SendSMS($options->{phone}, "ShowCounts terminated with $rtype.");
129 :     if ($msgID) {
130 :     Trace("Phone message sent with ID $msgID.") if T(2);
131 :     } else {
132 :     Trace("Phone message not sent.") if T(2);
133 :     }
134 : parrello 1.4 }
135 : parrello 1.1
136 :     =head3 CreateCounts
137 :    
138 : parrello 1.14 CreateCounts($fig, $fileName);
139 : parrello 1.1
140 :     Create the count and version display for the front page of the NMPDR.
141 :    
142 :     =over 4
143 :    
144 :     =item sfx
145 :    
146 :     A Sprout object for accessing the database.
147 :    
148 : parrello 1.7 =item oldSfx
149 : parrello 1.1
150 : parrello 1.7 A Sprout object for accessing the previous database.
151 : parrello 1.1
152 :     =item versionDate
153 :    
154 :     The string to be used for the version date.
155 :    
156 :     =item fileName
157 :    
158 :     The name of the output file.
159 :    
160 :     =back
161 :    
162 :     =cut
163 :    
164 :     sub CreateCounts {
165 :     # Get the parameters.
166 : parrello 1.7 my ($sfx, $oldSfx, $versionDate, $fileName) = @_;
167 : parrello 1.1 # Open the output file.
168 :     my $handle = Open(undef, ">$fileName");
169 :     # Start the heading.
170 :     print $handle "<h3 class=\"home\">Version $versionDate\n";
171 :     # Get the counts.
172 :     my @counts = $sfx->GenomeCounts();
173 :     my @names = qw(archaeal bacterial eukaryal viral environmental);
174 :     # Get a list of named counts for all the categories with nonzero values.
175 :     my @namedCounts = ();
176 :     for (my $i = 0; $i <= $#names; $i++) {
177 :     if ($counts[$i]) {
178 :     push @namedCounts, "$counts[$i] $names[$i]";
179 :     }
180 :     }
181 :     # Form the named counts into English, which is a very complicated process.
182 :     my $output = "Includes $namedCounts[0]";
183 :     for (my $i = 1; $i < $#namedCounts; $i++) {
184 :     $output .= ", $namedCounts[$i]";
185 :     }
186 :     if ($#namedCounts > 0) {
187 :     $output .= ", and $namedCounts[$#namedCounts]";
188 :     }
189 :     $output .= " genomes.";
190 :     # Output the counts.
191 :     print $handle "<br />$output";
192 :     # Get the number of subsystems.
193 :     my $subsystems = $sfx->GetCount(['Subsystem'], "", []);
194 : parrello 1.9 print $handle "<br />$subsystems active subsystems";
195 : parrello 1.13 # Count the number of new annotations, genomes, and features.
196 : parrello 1.8 my %things = ( Annotation => 'annotations',
197 :     Feature => 'features',
198 :     Genome => 'organisms'
199 :     );
200 :     for my $thing (sort keys %things) {
201 :     my $newCount = $sfx->GetCount([$thing], "", []);
202 :     my $oldCount = $oldSfx->GetCount([$thing], "", []);
203 :     my $delta = $newCount - $oldCount;
204 :     # Only display them if there's a reasonable number.
205 :     if ($delta > 5) {
206 : parrello 1.9 print $handle ", $delta&nbsp;new&nbsp;$things{$thing}";
207 : parrello 1.8 }
208 : parrello 1.1 }
209 : parrello 1.13 # Add the docking results.
210 :     my $pdbCount = $sfx->GetCount(['PDB'], "PDB(docking-count) > ?", [0]);
211 : parrello 1.14 print $handle ", $pdbCount drug targets with in silico docking results";
212 : parrello 1.1 # Terminate the heading.
213 :     print $handle ".</h3>\n";
214 :     # Close the output file.
215 :     close $handle;
216 :     }
217 :    
218 :     =head3 CreateSubForm
219 :    
220 : parrello 1.14 CreateSubForm($sfx, $fileName);
221 : parrello 1.1
222 :     Output the subsystem summary form. The subsystem summary form allows the user
223 :     to select an organism and view a summary of its subsystems.
224 :    
225 :     =over 4
226 :    
227 :     =item sfx
228 :    
229 :     A Sprout object that can be used to access the NMPDR database.
230 :    
231 :     =item fileName
232 :    
233 :     The name of the file to create with the form HTML in it.
234 :    
235 :     =back
236 :    
237 :     =cut
238 :    
239 :     sub CreateSubForm {
240 :     # Get the parameters.
241 :     my ($sfx, $fileName) = @_;
242 : parrello 1.3 # Start the form.
243 :     my @page = ();
244 :     push @page, start_form({method => "post", action => "../FIG/genome_statistics.cgi",
245 :     enctype=> "application/x-www-form-urlencoded"});
246 :     # Make sure the script knows it's for SPROUT.
247 :     push @page, input({type => "hidden", name => "SPROUT", value => "1"});
248 :     # Surround the form parts with a table.
249 :     push @page, "<table><tr><td>";
250 : parrello 1.12 # Add the buttons.
251 :     push @page, CGI::p("For the genome selected below, show " .
252 :     input({type => "submit", name => "show_subsystems",
253 :     value => "Subsystems", class => "button"}) .
254 :     input({type => "submit", name => "show_reactions",
255 :     value => "Reactions", class => "button"}));
256 :     # End the first table cell.
257 :     push @page, "</td></tr><tr><td>";
258 : parrello 1.3 # Create the gene menu.
259 : parrello 1.16 push @page, $sfx->GenomeMenu(id => 'genome', size => 10);
260 : parrello 1.12 # Close the table.
261 :     push @page, "</td></tr></table>";
262 :     # Close the form.
263 :     push @page, end_form();
264 :     # Put together all the pieces.
265 :     my $wholePage = join("\n", @page);
266 :     # Open the output file.
267 :     my $handle = Open(undef, ">$fileName");
268 :     # Write out the HTML.
269 :     print $handle $wholePage;
270 :     # Close the file.
271 :     close $handle;
272 :    
273 :     }
274 :    
275 :     =head3 CreateOrgForm
276 :    
277 : parrello 1.14 CreateOrgForm($sfx, $fileName);
278 : parrello 1.12
279 :     Output the organism summary form. The organism summary form allows the user
280 :     to select an organism and view its statistics.
281 :    
282 :     =over 4
283 :    
284 :     =item sfx
285 :    
286 :     A Sprout object that can be used to access the NMPDR database.
287 :    
288 :     =item fileName
289 :    
290 :     The name of the file to create with the form HTML in it.
291 :    
292 :     =back
293 :    
294 :     =cut
295 :    
296 :     sub CreateOrgForm {
297 :     # Get the parameters.
298 :     my ($sfx, $fileName) = @_;
299 :     # Start the form.
300 :     my @page = ();
301 :     push @page, start_form({method => "post", action => "../FIG/genome_statistics.cgi",
302 :     enctype=> "application/x-www-form-urlencoded"});
303 :     # Make sure the script knows it's for SPROUT.
304 :     push @page, input({type => "hidden", name => "SPROUT", value => "1"});
305 :     # Surround the form parts with a table.
306 :     push @page, "<table><tr><td>";
307 :     # Add the button.
308 :     push @page, CGI::p("Search or view statistics for the genome selected below " .
309 :     input({type => "submit", name => "statistics",
310 :     value => "Go", class => "button"}));
311 : parrello 1.3 # End the first table cell.
312 :     push @page, "</td></tr><tr><td>";
313 : parrello 1.12 # Create the gene menu.
314 : parrello 1.16 push @page, $sfx->GenomeMenu(id => 'genome', size => 10);
315 : parrello 1.3 # Close the table.
316 :     push @page, "</td></tr></table>";
317 :     # Close the form.
318 :     push @page, end_form();
319 :     # Put together all the pieces.
320 :     my $wholePage = join("\n", @page);
321 : parrello 1.1 # Open the output file.
322 :     my $handle = Open(undef, ">$fileName");
323 : parrello 1.3 # Write out the HTML.
324 :     print $handle $wholePage;
325 : parrello 1.1 # Close the file.
326 :     close $handle;
327 :    
328 :     }
329 :    
330 :     =head3 CreateSproutDoc
331 :    
332 : parrello 1.14 CreateSproutDoc($sfx, $fileName);
333 : parrello 1.1
334 :     Output the Sprout database documentation.
335 :    
336 :     =over 4
337 :    
338 :     =item sfx
339 :    
340 :     A Sprout object that can be used to access the NMPDR database.
341 :    
342 :     =item fileName
343 :    
344 :     The name of the file to create with the documentation in it.
345 :    
346 :     =back
347 :    
348 :     =cut
349 :    
350 :     sub CreateSproutDoc {
351 :     # Get the parameters.
352 :     my ($sfx, $fileName) = @_;
353 :     # Open the output file.
354 :     my $handle = Open(undef, ">$fileName");
355 :     # Write the Sprout database document into it.
356 :     print $handle $sfx->DisplayMetaData();
357 :     # Close the file.
358 :     close $handle;
359 :     }
360 :    
361 :    
362 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3