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

Annotation of /Sprout/ShowCounts.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (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 :     # Get the Sprout object.
108 :     my $sfx = SFXlate->new_sprout_only();
109 :     # Create the counts file.
110 :     CreateCounts($sfx, $options->{age}, $parameters[0], "$targetDir/version.inc");
111 :     # Create the subsystem summary file.
112 :     CreateSubForm($sfx, "$targetDir/forms/subsystems.inc");
113 :     # 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 :     =item age
132 :    
133 :     The maximum age for an annotation to be considered new.
134 :    
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 :     my ($sfx, $age, $versionDate, $fileName) = @_;
150 :     # 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 :     print $handle "<br />$subsystems subsystems";
178 :     # Get the current time and subtract the number of days indicated by the age.
179 :     my $time = time() - $age * 86400;
180 :     # Count the number of new annotations.
181 :     my $newAnnotations = $sfx->GetCount(['Annotation'], "Annotation(time) >= ?",
182 :     [$time]);
183 :     # Only display them if there's a reasonable number.
184 :     if ($newAnnotations > 5) {
185 :     print $handle ", $newAnnotations new annotations";
186 :     }
187 :     # Terminate the heading.
188 :     print $handle ".</h3>\n";
189 :     # Close the output file.
190 :     close $handle;
191 :     }
192 :    
193 :     =head3 CreateSubForm
194 :    
195 :     C<< CreateSubForm($sfx, $fileName); >>
196 :    
197 :     Output the subsystem summary form. The subsystem summary form allows the user
198 :     to select an organism and view a summary of its subsystems.
199 :    
200 :     =over 4
201 :    
202 :     =item sfx
203 :    
204 :     A Sprout object that can be used to access the NMPDR database.
205 :    
206 :     =item fileName
207 :    
208 :     The name of the file to create with the form HTML in it.
209 :    
210 :     =back
211 :    
212 :     =cut
213 :    
214 :     sub CreateSubForm {
215 :     # Get the parameters.
216 :     my ($sfx, $fileName) = @_;
217 : parrello 1.3 # Start the form.
218 :     my @page = ();
219 :     push @page, start_form({method => "post", action => "../FIG/genome_statistics.cgi",
220 :     enctype=> "application/x-www-form-urlencoded"});
221 :     # Make sure the script knows it's for SPROUT.
222 :     push @page, input({type => "hidden", name => "SPROUT", value => "1"});
223 :     # Surround the form parts with a table.
224 :     push @page, "<table><tr><td>";
225 :     # Create the gene menu.
226 :     push @page, $sfx->GeneMenu({ name => 'genome', size => 10 }, "", []);
227 :     # End the first table cell.
228 :     push @page, "</td></tr><tr><td>";
229 :     # Add the buttons.
230 :     push @page, input({type => "submit", name => "show_subsystems",
231 :     value => "Show Subsystems"});
232 :     push @page, input({type => "submit", name => "show_reactions",
233 :     value => "Show Reactions"});
234 :     # Close the table.
235 :     push @page, "</td></tr></table>";
236 :     # Close the form.
237 :     push @page, end_form();
238 :     # Put together all the pieces.
239 :     my $wholePage = join("\n", @page);
240 : parrello 1.1 # Open the output file.
241 :     my $handle = Open(undef, ">$fileName");
242 : parrello 1.3 # Write out the HTML.
243 :     print $handle $wholePage;
244 : parrello 1.1 # Close the file.
245 :     close $handle;
246 :    
247 :     }
248 :    
249 :     =head3 CreateSproutDoc
250 :    
251 :     C<< CreateSproutDoc($sfx, $fileName); >>
252 :    
253 :     Output the Sprout database documentation.
254 :    
255 :     =over 4
256 :    
257 :     =item sfx
258 :    
259 :     A Sprout object that can be used to access the NMPDR database.
260 :    
261 :     =item fileName
262 :    
263 :     The name of the file to create with the documentation in it.
264 :    
265 :     =back
266 :    
267 :     =cut
268 :    
269 :     sub CreateSproutDoc {
270 :     # Get the parameters.
271 :     my ($sfx, $fileName) = @_;
272 :     # Open the output file.
273 :     my $handle = Open(undef, ">$fileName");
274 :     # Write the Sprout database document into it.
275 :     print $handle $sfx->DisplayMetaData();
276 :     # Close the file.
277 :     close $handle;
278 :     }
279 :    
280 :    
281 :    
282 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3