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

Annotation of /Sprout/ShowCounts.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (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 DocUtils;
75 :     use TestUtils;
76 :     use Cwd;
77 :     use File::Copy;
78 :     use File::Path;
79 :     use FIG;
80 : parrello 1.3 use CGI qw(:standard);
81 : parrello 1.1
82 :     # Get the command-line options and parameters.
83 :     my ($options, @parameters) = StandardSetup([qw(Sprout ERDB SFXlate) ],
84 :     {
85 : parrello 1.10 trace => [2, 'tracing level'],
86 : parrello 1.2 target => ["$FIG_Config::nmpdr_pages/includes",
87 : parrello 1.1 'output directory'],
88 :     },
89 :     "<version date>",
90 :     @ARGV);
91 :    
92 :     use SFXlate;
93 :    
94 : parrello 1.14 # The return type (error/no error) will be put in here.
95 :     my $rtype;
96 :     eval {
97 :     # Get the target directory.
98 :     my $targetDir = $options->{target};
99 :     # Verify the parameters.
100 :     if (! $parameters[0]) {
101 :     Confess("Please specify a version date.");
102 :     } elsif (! -d $targetDir) {
103 :     Confess("Target directory $targetDir does not exist.");
104 :     } else {
105 :     Trace("Output going to $targetDir.") if T(2);
106 :     # Get the Sprout object.
107 :     my $sfx = SFXlate->new_sprout_only();
108 :     # Get the old Sprout.
109 :     my $oldSprout = SFXlate->old_sprout_only();
110 :     # Create the counts file.
111 :     CreateCounts($sfx, $oldSprout, $parameters[0], "$targetDir/version.inc");
112 :     # Create the subsystem summary file.
113 :     CreateSubForm($sfx, "$targetDir/forms/subsystems.inc");
114 :     # Create the organism summary file.
115 :     CreateOrgForm($sfx, "$targetDir/forms/all_genomes.inc");
116 :     # Create the database documentation file.
117 :     CreateSproutDoc($sfx, "$targetDir/sproutdb.inc");
118 :     # Tell the user we're done.
119 :     Trace("File creation complete.") if T(2);
120 :     }
121 :     };
122 :     if ($@) {
123 :     Trace("Counts failed with error: $@") if T(0);
124 :     $rtype = "error";
125 : parrello 1.4 } else {
126 : parrello 1.14 Trace("Counts complete.") if T(2);
127 :     $rtype = "no error";
128 :     }
129 :     if ($options->{phone}) {
130 :     my $msgID = Tracer::SendSMS($options->{phone}, "ShowCounts terminated with $rtype.");
131 :     if ($msgID) {
132 :     Trace("Phone message sent with ID $msgID.") if T(2);
133 :     } else {
134 :     Trace("Phone message not sent.") if T(2);
135 :     }
136 : parrello 1.4 }
137 : parrello 1.1
138 :     =head3 CreateCounts
139 :    
140 : parrello 1.14 CreateCounts($fig, $fileName);
141 : parrello 1.1
142 :     Create the count and version display for the front page of the NMPDR.
143 :    
144 :     =over 4
145 :    
146 :     =item sfx
147 :    
148 :     A Sprout object for accessing the database.
149 :    
150 : parrello 1.7 =item oldSfx
151 : parrello 1.1
152 : parrello 1.7 A Sprout object for accessing the previous database.
153 : parrello 1.1
154 :     =item versionDate
155 :    
156 :     The string to be used for the version date.
157 :    
158 :     =item fileName
159 :    
160 :     The name of the output file.
161 :    
162 :     =back
163 :    
164 :     =cut
165 :    
166 :     sub CreateCounts {
167 :     # Get the parameters.
168 : parrello 1.7 my ($sfx, $oldSfx, $versionDate, $fileName) = @_;
169 : parrello 1.1 # Open the output file.
170 :     my $handle = Open(undef, ">$fileName");
171 :     # Start the heading.
172 :     print $handle "<h3 class=\"home\">Version $versionDate\n";
173 :     # Get the counts.
174 :     my @counts = $sfx->GenomeCounts();
175 :     my @names = qw(archaeal bacterial eukaryal viral environmental);
176 :     # Get a list of named counts for all the categories with nonzero values.
177 :     my @namedCounts = ();
178 :     for (my $i = 0; $i <= $#names; $i++) {
179 :     if ($counts[$i]) {
180 :     push @namedCounts, "$counts[$i] $names[$i]";
181 :     }
182 :     }
183 :     # Form the named counts into English, which is a very complicated process.
184 :     my $output = "Includes $namedCounts[0]";
185 :     for (my $i = 1; $i < $#namedCounts; $i++) {
186 :     $output .= ", $namedCounts[$i]";
187 :     }
188 :     if ($#namedCounts > 0) {
189 :     $output .= ", and $namedCounts[$#namedCounts]";
190 :     }
191 :     $output .= " genomes.";
192 :     # Output the counts.
193 :     print $handle "<br />$output";
194 :     # Get the number of subsystems.
195 :     my $subsystems = $sfx->GetCount(['Subsystem'], "", []);
196 : parrello 1.9 print $handle "<br />$subsystems active subsystems";
197 : parrello 1.13 # Count the number of new annotations, genomes, and features.
198 : parrello 1.8 my %things = ( Annotation => 'annotations',
199 :     Feature => 'features',
200 :     Genome => 'organisms'
201 :     );
202 :     for my $thing (sort keys %things) {
203 :     my $newCount = $sfx->GetCount([$thing], "", []);
204 :     my $oldCount = $oldSfx->GetCount([$thing], "", []);
205 :     my $delta = $newCount - $oldCount;
206 :     # Only display them if there's a reasonable number.
207 :     if ($delta > 5) {
208 : parrello 1.9 print $handle ", $delta&nbsp;new&nbsp;$things{$thing}";
209 : parrello 1.8 }
210 : parrello 1.1 }
211 : parrello 1.13 # Add the docking results.
212 :     my $pdbCount = $sfx->GetCount(['PDB'], "PDB(docking-count) > ?", [0]);
213 : parrello 1.14 print $handle ", $pdbCount drug targets with in silico docking results";
214 : parrello 1.1 # Terminate the heading.
215 :     print $handle ".</h3>\n";
216 :     # Close the output file.
217 :     close $handle;
218 :     }
219 :    
220 :     =head3 CreateSubForm
221 :    
222 : parrello 1.14 CreateSubForm($sfx, $fileName);
223 : parrello 1.1
224 :     Output the subsystem summary form. The subsystem summary form allows the user
225 :     to select an organism and view a summary of its subsystems.
226 :    
227 :     =over 4
228 :    
229 :     =item sfx
230 :    
231 :     A Sprout object that can be used to access the NMPDR database.
232 :    
233 :     =item fileName
234 :    
235 :     The name of the file to create with the form HTML in it.
236 :    
237 :     =back
238 :    
239 :     =cut
240 :    
241 :     sub CreateSubForm {
242 :     # Get the parameters.
243 :     my ($sfx, $fileName) = @_;
244 : parrello 1.3 # Start the form.
245 :     my @page = ();
246 :     push @page, start_form({method => "post", action => "../FIG/genome_statistics.cgi",
247 :     enctype=> "application/x-www-form-urlencoded"});
248 :     # Make sure the script knows it's for SPROUT.
249 :     push @page, input({type => "hidden", name => "SPROUT", value => "1"});
250 :     # Surround the form parts with a table.
251 :     push @page, "<table><tr><td>";
252 : parrello 1.12 # Add the buttons.
253 :     push @page, CGI::p("For the genome selected below, show " .
254 :     input({type => "submit", name => "show_subsystems",
255 :     value => "Subsystems", class => "button"}) .
256 :     input({type => "submit", name => "show_reactions",
257 :     value => "Reactions", class => "button"}));
258 :     # End the first table cell.
259 :     push @page, "</td></tr><tr><td>";
260 : parrello 1.3 # Create the gene menu.
261 :     push @page, $sfx->GeneMenu({ name => 'genome', size => 10 }, "", []);
262 : parrello 1.12 # Close the table.
263 :     push @page, "</td></tr></table>";
264 :     # Close the form.
265 :     push @page, end_form();
266 :     # Put together all the pieces.
267 :     my $wholePage = join("\n", @page);
268 :     # Open the output file.
269 :     my $handle = Open(undef, ">$fileName");
270 :     # Write out the HTML.
271 :     print $handle $wholePage;
272 :     # Close the file.
273 :     close $handle;
274 :    
275 :     }
276 :    
277 :     =head3 CreateOrgForm
278 :    
279 : parrello 1.14 CreateOrgForm($sfx, $fileName);
280 : parrello 1.12
281 :     Output the organism summary form. The organism summary form allows the user
282 :     to select an organism and view its statistics.
283 :    
284 :     =over 4
285 :    
286 :     =item sfx
287 :    
288 :     A Sprout object that can be used to access the NMPDR database.
289 :    
290 :     =item fileName
291 :    
292 :     The name of the file to create with the form HTML in it.
293 :    
294 :     =back
295 :    
296 :     =cut
297 :    
298 :     sub CreateOrgForm {
299 :     # Get the parameters.
300 :     my ($sfx, $fileName) = @_;
301 :     # Start the form.
302 :     my @page = ();
303 :     push @page, start_form({method => "post", action => "../FIG/genome_statistics.cgi",
304 :     enctype=> "application/x-www-form-urlencoded"});
305 :     # Make sure the script knows it's for SPROUT.
306 :     push @page, input({type => "hidden", name => "SPROUT", value => "1"});
307 :     # Surround the form parts with a table.
308 :     push @page, "<table><tr><td>";
309 :     # Add the button.
310 :     push @page, CGI::p("Search or view statistics for the genome selected below " .
311 :     input({type => "submit", name => "statistics",
312 :     value => "Go", class => "button"}));
313 : parrello 1.3 # End the first table cell.
314 :     push @page, "</td></tr><tr><td>";
315 : parrello 1.12 # Create the gene menu.
316 :     push @page, $sfx->GeneMenu({ name => 'genome', size => 10 }, "", []);
317 : parrello 1.3 # Close the table.
318 :     push @page, "</td></tr></table>";
319 :     # Close the form.
320 :     push @page, end_form();
321 :     # Put together all the pieces.
322 :     my $wholePage = join("\n", @page);
323 : parrello 1.1 # Open the output file.
324 :     my $handle = Open(undef, ">$fileName");
325 : parrello 1.3 # Write out the HTML.
326 :     print $handle $wholePage;
327 : parrello 1.1 # Close the file.
328 :     close $handle;
329 :    
330 :     }
331 :    
332 :     =head3 CreateSproutDoc
333 :    
334 : parrello 1.14 CreateSproutDoc($sfx, $fileName);
335 : parrello 1.1
336 :     Output the Sprout database documentation.
337 :    
338 :     =over 4
339 :    
340 :     =item sfx
341 :    
342 :     A Sprout object that can be used to access the NMPDR database.
343 :    
344 :     =item fileName
345 :    
346 :     The name of the file to create with the documentation in it.
347 :    
348 :     =back
349 :    
350 :     =cut
351 :    
352 :     sub CreateSproutDoc {
353 :     # Get the parameters.
354 :     my ($sfx, $fileName) = @_;
355 :     # Open the output file.
356 :     my $handle = Open(undef, ">$fileName");
357 :     # Write the Sprout database document into it.
358 :     print $handle $sfx->DisplayMetaData();
359 :     # Close the file.
360 :     close $handle;
361 :     }
362 :    
363 :    
364 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3