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

Annotation of /Sprout/ShowCounts.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (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.3 =item forms/subsystems.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 age
64 :    
65 :     Maximum age in days of an annotation for it to be considered new. The default is
66 :     C<14>.
67 :    
68 :     =item target
69 :    
70 : parrello 1.2 Target directory for the include files. The default is C<includes> in the
71 :     C<$FIG_Config::nmpdr_pages> directory.
72 : parrello 1.1
73 :     =back
74 :    
75 :     =cut
76 :    
77 :     use strict;
78 :     use Tracer;
79 :     use DocUtils;
80 :     use TestUtils;
81 :     use Cwd;
82 :     use File::Copy;
83 :     use File::Path;
84 :     use FIG;
85 : parrello 1.3 use CGI qw(:standard);
86 : parrello 1.1
87 :     # Get the command-line options and parameters.
88 :     my ($options, @parameters) = StandardSetup([qw(Sprout ERDB SFXlate) ],
89 :     {
90 :     age => [14, 'maximum age of a new annotation'],
91 : parrello 1.2 target => ["$FIG_Config::nmpdr_pages/includes",
92 : parrello 1.1 'output directory'],
93 :     },
94 :     "<version date>",
95 :     @ARGV);
96 :    
97 :     use SFXlate;
98 :    
99 :     # Get the target directory.
100 :     my $targetDir = $options->{target};
101 : parrello 1.4 # Verify the parameters.
102 :     if (! $parameters[0]) {
103 :     Confess("Please specify a version date.");
104 :     } elsif (! -d $targetDir) {
105 :     Confess("Target directory $targetDir does not exist.");
106 :     } else {
107 : parrello 1.5 Trace("Output going to $targetDir.") if T(2);
108 : parrello 1.4 # Get the Sprout object.
109 :     my $sfx = SFXlate->new_sprout_only();
110 :     # Create the counts file.
111 :     CreateCounts($sfx, $options->{age}, $parameters[0], "$targetDir/version.inc");
112 :     # Create the subsystem summary file.
113 :     CreateSubForm($sfx, "$targetDir/forms/subsystems.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 : parrello 1.1
120 :     =head3 CreateCounts
121 :    
122 :     C<< CreateCounts($fig, $fileName); >>
123 :    
124 :     Create the count and version display for the front page of the NMPDR.
125 :    
126 :     =over 4
127 :    
128 :     =item sfx
129 :    
130 :     A Sprout object for accessing the database.
131 :    
132 :     =item age
133 :    
134 :     The maximum age for an annotation to be considered new.
135 :    
136 :     =item versionDate
137 :    
138 :     The string to be used for the version date.
139 :    
140 :     =item fileName
141 :    
142 :     The name of the output file.
143 :    
144 :     =back
145 :    
146 :     =cut
147 :    
148 :     sub CreateCounts {
149 :     # Get the parameters.
150 :     my ($sfx, $age, $versionDate, $fileName) = @_;
151 :     # Open the output file.
152 :     my $handle = Open(undef, ">$fileName");
153 :     # Start the heading.
154 :     print $handle "<h3 class=\"home\">Version $versionDate\n";
155 :     # Get the counts.
156 :     my @counts = $sfx->GenomeCounts();
157 :     my @names = qw(archaeal bacterial eukaryal viral environmental);
158 :     # Get a list of named counts for all the categories with nonzero values.
159 :     my @namedCounts = ();
160 :     for (my $i = 0; $i <= $#names; $i++) {
161 :     if ($counts[$i]) {
162 :     push @namedCounts, "$counts[$i] $names[$i]";
163 :     }
164 :     }
165 :     # Form the named counts into English, which is a very complicated process.
166 :     my $output = "Includes $namedCounts[0]";
167 :     for (my $i = 1; $i < $#namedCounts; $i++) {
168 :     $output .= ", $namedCounts[$i]";
169 :     }
170 :     if ($#namedCounts > 0) {
171 :     $output .= ", and $namedCounts[$#namedCounts]";
172 :     }
173 :     $output .= " genomes.";
174 :     # Output the counts.
175 :     print $handle "<br />$output";
176 :     # Get the number of subsystems.
177 :     my $subsystems = $sfx->GetCount(['Subsystem'], "", []);
178 :     print $handle "<br />$subsystems subsystems";
179 :     # Get the current time and subtract the number of days indicated by the age.
180 :     my $time = time() - $age * 86400;
181 :     # Count the number of new annotations.
182 :     my $newAnnotations = $sfx->GetCount(['Annotation'], "Annotation(time) >= ?",
183 :     [$time]);
184 :     # Only display them if there's a reasonable number.
185 :     if ($newAnnotations > 5) {
186 : parrello 1.6 print $handle ", $newAnnotations updated annotations";
187 : parrello 1.1 }
188 :     # Terminate the heading.
189 :     print $handle ".</h3>\n";
190 :     # Close the output file.
191 :     close $handle;
192 :     }
193 :    
194 :     =head3 CreateSubForm
195 :    
196 :     C<< CreateSubForm($sfx, $fileName); >>
197 :    
198 :     Output the subsystem summary form. The subsystem summary form allows the user
199 :     to select an organism and view a summary of its subsystems.
200 :    
201 :     =over 4
202 :    
203 :     =item sfx
204 :    
205 :     A Sprout object that can be used to access the NMPDR database.
206 :    
207 :     =item fileName
208 :    
209 :     The name of the file to create with the form HTML in it.
210 :    
211 :     =back
212 :    
213 :     =cut
214 :    
215 :     sub CreateSubForm {
216 :     # Get the parameters.
217 :     my ($sfx, $fileName) = @_;
218 : parrello 1.3 # Start the form.
219 :     my @page = ();
220 :     push @page, start_form({method => "post", action => "../FIG/genome_statistics.cgi",
221 :     enctype=> "application/x-www-form-urlencoded"});
222 :     # Make sure the script knows it's for SPROUT.
223 :     push @page, input({type => "hidden", name => "SPROUT", value => "1"});
224 :     # Surround the form parts with a table.
225 :     push @page, "<table><tr><td>";
226 :     # Create the gene menu.
227 :     push @page, $sfx->GeneMenu({ name => 'genome', size => 10 }, "", []);
228 :     # End the first table cell.
229 :     push @page, "</td></tr><tr><td>";
230 :     # Add the buttons.
231 :     push @page, input({type => "submit", name => "show_subsystems",
232 :     value => "Show Subsystems"});
233 :     push @page, input({type => "submit", name => "show_reactions",
234 :     value => "Show Reactions"});
235 :     # Close the table.
236 :     push @page, "</td></tr></table>";
237 :     # Close the form.
238 :     push @page, end_form();
239 :     # Put together all the pieces.
240 :     my $wholePage = join("\n", @page);
241 : parrello 1.1 # Open the output file.
242 :     my $handle = Open(undef, ">$fileName");
243 : parrello 1.3 # Write out the HTML.
244 :     print $handle $wholePage;
245 : parrello 1.1 # Close the file.
246 :     close $handle;
247 :    
248 :     }
249 :    
250 :     =head3 CreateSproutDoc
251 :    
252 :     C<< CreateSproutDoc($sfx, $fileName); >>
253 :    
254 :     Output the Sprout database documentation.
255 :    
256 :     =over 4
257 :    
258 :     =item sfx
259 :    
260 :     A Sprout object that can be used to access the NMPDR database.
261 :    
262 :     =item fileName
263 :    
264 :     The name of the file to create with the documentation in it.
265 :    
266 :     =back
267 :    
268 :     =cut
269 :    
270 :     sub CreateSproutDoc {
271 :     # Get the parameters.
272 :     my ($sfx, $fileName) = @_;
273 :     # Open the output file.
274 :     my $handle = Open(undef, ">$fileName");
275 :     # Write the Sprout database document into it.
276 :     print $handle $sfx->DisplayMetaData();
277 :     # Close the file.
278 :     close $handle;
279 :     }
280 :    
281 :    
282 :    
283 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3