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

Annotation of /Sprout/ShowCounts.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (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.13 # Count the number of new annotations, genomes, and features.
179 : parrello 1.8 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 : parrello 1.13 # Add the docking results.
193 :     my $pdbCount = $sfx->GetCount(['PDB'], "PDB(docking-count) > ?", [0]);
194 :     print $handle ", $pdbCount PDBs with in silico docking results";
195 : parrello 1.1 # Terminate the heading.
196 :     print $handle ".</h3>\n";
197 :     # Close the output file.
198 :     close $handle;
199 :     }
200 :    
201 :     =head3 CreateSubForm
202 :    
203 :     C<< CreateSubForm($sfx, $fileName); >>
204 :    
205 :     Output the subsystem summary form. The subsystem summary form allows the user
206 :     to select an organism and view a summary of its subsystems.
207 :    
208 :     =over 4
209 :    
210 :     =item sfx
211 :    
212 :     A Sprout object that can be used to access the NMPDR database.
213 :    
214 :     =item fileName
215 :    
216 :     The name of the file to create with the form HTML in it.
217 :    
218 :     =back
219 :    
220 :     =cut
221 :    
222 :     sub CreateSubForm {
223 :     # Get the parameters.
224 :     my ($sfx, $fileName) = @_;
225 : parrello 1.3 # Start the form.
226 :     my @page = ();
227 :     push @page, start_form({method => "post", action => "../FIG/genome_statistics.cgi",
228 :     enctype=> "application/x-www-form-urlencoded"});
229 :     # Make sure the script knows it's for SPROUT.
230 :     push @page, input({type => "hidden", name => "SPROUT", value => "1"});
231 :     # Surround the form parts with a table.
232 :     push @page, "<table><tr><td>";
233 : parrello 1.12 # Add the buttons.
234 :     push @page, CGI::p("For the genome selected below, show " .
235 :     input({type => "submit", name => "show_subsystems",
236 :     value => "Subsystems", class => "button"}) .
237 :     input({type => "submit", name => "show_reactions",
238 :     value => "Reactions", class => "button"}));
239 :     # End the first table cell.
240 :     push @page, "</td></tr><tr><td>";
241 : parrello 1.3 # Create the gene menu.
242 :     push @page, $sfx->GeneMenu({ name => 'genome', size => 10 }, "", []);
243 : parrello 1.12 # Close the table.
244 :     push @page, "</td></tr></table>";
245 :     # Close the form.
246 :     push @page, end_form();
247 :     # Put together all the pieces.
248 :     my $wholePage = join("\n", @page);
249 :     # Open the output file.
250 :     my $handle = Open(undef, ">$fileName");
251 :     # Write out the HTML.
252 :     print $handle $wholePage;
253 :     # Close the file.
254 :     close $handle;
255 :    
256 :     }
257 :    
258 :     =head3 CreateOrgForm
259 :    
260 :     C<< CreateOrgForm($sfx, $fileName); >>
261 :    
262 :     Output the organism summary form. The organism summary form allows the user
263 :     to select an organism and view its statistics.
264 :    
265 :     =over 4
266 :    
267 :     =item sfx
268 :    
269 :     A Sprout object that can be used to access the NMPDR database.
270 :    
271 :     =item fileName
272 :    
273 :     The name of the file to create with the form HTML in it.
274 :    
275 :     =back
276 :    
277 :     =cut
278 :    
279 :     sub CreateOrgForm {
280 :     # Get the parameters.
281 :     my ($sfx, $fileName) = @_;
282 :     # Start the form.
283 :     my @page = ();
284 :     push @page, start_form({method => "post", action => "../FIG/genome_statistics.cgi",
285 :     enctype=> "application/x-www-form-urlencoded"});
286 :     # Make sure the script knows it's for SPROUT.
287 :     push @page, input({type => "hidden", name => "SPROUT", value => "1"});
288 :     # Surround the form parts with a table.
289 :     push @page, "<table><tr><td>";
290 :     # Add the button.
291 :     push @page, CGI::p("Search or view statistics for the genome selected below " .
292 :     input({type => "submit", name => "statistics",
293 :     value => "Go", class => "button"}));
294 : parrello 1.3 # End the first table cell.
295 :     push @page, "</td></tr><tr><td>";
296 : parrello 1.12 # Create the gene menu.
297 :     push @page, $sfx->GeneMenu({ name => 'genome', size => 10 }, "", []);
298 : parrello 1.3 # Close the table.
299 :     push @page, "</td></tr></table>";
300 :     # Close the form.
301 :     push @page, end_form();
302 :     # Put together all the pieces.
303 :     my $wholePage = join("\n", @page);
304 : parrello 1.1 # Open the output file.
305 :     my $handle = Open(undef, ">$fileName");
306 : parrello 1.3 # Write out the HTML.
307 :     print $handle $wholePage;
308 : parrello 1.1 # Close the file.
309 :     close $handle;
310 :    
311 :     }
312 :    
313 :     =head3 CreateSproutDoc
314 :    
315 :     C<< CreateSproutDoc($sfx, $fileName); >>
316 :    
317 :     Output the Sprout database documentation.
318 :    
319 :     =over 4
320 :    
321 :     =item sfx
322 :    
323 :     A Sprout object that can be used to access the NMPDR database.
324 :    
325 :     =item fileName
326 :    
327 :     The name of the file to create with the documentation in it.
328 :    
329 :     =back
330 :    
331 :     =cut
332 :    
333 :     sub CreateSproutDoc {
334 :     # Get the parameters.
335 :     my ($sfx, $fileName) = @_;
336 :     # Open the output file.
337 :     my $handle = Open(undef, ">$fileName");
338 :     # Write the Sprout database document into it.
339 :     print $handle $sfx->DisplayMetaData();
340 :     # Close the file.
341 :     close $handle;
342 :     }
343 :    
344 :    
345 :    
346 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3