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

Annotation of /Sprout/ShowCounts.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3