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

Annotation of /Sprout/ShowCounts.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (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 :     # Get the Sprout object.
102 :     my $sfx = SFXlate->new_sprout_only();
103 :     # Create the counts file.
104 :     CreateCounts($sfx, $options->{age}, $parameters[0], "$targetDir/version.inc");
105 :     # Create the subsystem summary file.
106 : parrello 1.3 CreateSubForm($sfx, "$targetDir/forms/subsystems.inc");
107 : parrello 1.1 # Create the database documentation file.
108 :     CreateSproutDoc($sfx, "$targetDir/sproutdb.inc");
109 :     # Tell the user we're done.
110 :     Trace("File creation complete.") if T(2);
111 :    
112 :     =head3 CreateCounts
113 :    
114 :     C<< CreateCounts($fig, $fileName); >>
115 :    
116 :     Create the count and version display for the front page of the NMPDR.
117 :    
118 :     =over 4
119 :    
120 :     =item sfx
121 :    
122 :     A Sprout object for accessing the database.
123 :    
124 :     =item age
125 :    
126 :     The maximum age for an annotation to be considered new.
127 :    
128 :     =item versionDate
129 :    
130 :     The string to be used for the version date.
131 :    
132 :     =item fileName
133 :    
134 :     The name of the output file.
135 :    
136 :     =back
137 :    
138 :     =cut
139 :    
140 :     sub CreateCounts {
141 :     # Get the parameters.
142 :     my ($sfx, $age, $versionDate, $fileName) = @_;
143 :     # Open the output file.
144 :     my $handle = Open(undef, ">$fileName");
145 :     # Start the heading.
146 :     print $handle "<h3 class=\"home\">Version $versionDate\n";
147 :     # Get the counts.
148 :     my @counts = $sfx->GenomeCounts();
149 :     my @names = qw(archaeal bacterial eukaryal viral environmental);
150 :     # Get a list of named counts for all the categories with nonzero values.
151 :     my @namedCounts = ();
152 :     for (my $i = 0; $i <= $#names; $i++) {
153 :     if ($counts[$i]) {
154 :     push @namedCounts, "$counts[$i] $names[$i]";
155 :     }
156 :     }
157 :     # Form the named counts into English, which is a very complicated process.
158 :     my $output = "Includes $namedCounts[0]";
159 :     for (my $i = 1; $i < $#namedCounts; $i++) {
160 :     $output .= ", $namedCounts[$i]";
161 :     }
162 :     if ($#namedCounts > 0) {
163 :     $output .= ", and $namedCounts[$#namedCounts]";
164 :     }
165 :     $output .= " genomes.";
166 :     # Output the counts.
167 :     print $handle "<br />$output";
168 :     # Get the number of subsystems.
169 :     my $subsystems = $sfx->GetCount(['Subsystem'], "", []);
170 :     print $handle "<br />$subsystems subsystems";
171 :     # Get the current time and subtract the number of days indicated by the age.
172 :     my $time = time() - $age * 86400;
173 :     # Count the number of new annotations.
174 :     my $newAnnotations = $sfx->GetCount(['Annotation'], "Annotation(time) >= ?",
175 :     [$time]);
176 :     # Only display them if there's a reasonable number.
177 :     if ($newAnnotations > 5) {
178 :     print $handle ", $newAnnotations new annotations";
179 :     }
180 :     # Terminate the heading.
181 :     print $handle ".</h3>\n";
182 :     # Close the output file.
183 :     close $handle;
184 :     }
185 :    
186 :     =head3 CreateSubForm
187 :    
188 :     C<< CreateSubForm($sfx, $fileName); >>
189 :    
190 :     Output the subsystem summary form. The subsystem summary form allows the user
191 :     to select an organism and view a summary of its subsystems.
192 :    
193 :     =over 4
194 :    
195 :     =item sfx
196 :    
197 :     A Sprout object that can be used to access the NMPDR database.
198 :    
199 :     =item fileName
200 :    
201 :     The name of the file to create with the form HTML in it.
202 :    
203 :     =back
204 :    
205 :     =cut
206 :    
207 :     sub CreateSubForm {
208 :     # Get the parameters.
209 :     my ($sfx, $fileName) = @_;
210 : parrello 1.3 # Start the form.
211 :     my @page = ();
212 :     push @page, start_form({method => "post", action => "../FIG/genome_statistics.cgi",
213 :     enctype=> "application/x-www-form-urlencoded"});
214 :     # Make sure the script knows it's for SPROUT.
215 :     push @page, input({type => "hidden", name => "SPROUT", value => "1"});
216 :     # Surround the form parts with a table.
217 :     push @page, "<table><tr><td>";
218 :     # Create the gene menu.
219 :     push @page, $sfx->GeneMenu({ name => 'genome', size => 10 }, "", []);
220 :     # End the first table cell.
221 :     push @page, "</td></tr><tr><td>";
222 :     # Add the buttons.
223 :     push @page, input({type => "submit", name => "show_subsystems",
224 :     value => "Show Subsystems"});
225 :     push @page, input({type => "submit", name => "show_reactions",
226 :     value => "Show Reactions"});
227 :     # Close the table.
228 :     push @page, "</td></tr></table>";
229 :     # Close the form.
230 :     push @page, end_form();
231 :     # Put together all the pieces.
232 :     my $wholePage = join("\n", @page);
233 : parrello 1.1 # Open the output file.
234 :     my $handle = Open(undef, ">$fileName");
235 : parrello 1.3 # Write out the HTML.
236 :     print $handle $wholePage;
237 : parrello 1.1 # Close the file.
238 :     close $handle;
239 :    
240 :     }
241 :    
242 :     =head3 CreateSproutDoc
243 :    
244 :     C<< CreateSproutDoc($sfx, $fileName); >>
245 :    
246 :     Output the Sprout database documentation.
247 :    
248 :     =over 4
249 :    
250 :     =item sfx
251 :    
252 :     A Sprout object that can be used to access the NMPDR database.
253 :    
254 :     =item fileName
255 :    
256 :     The name of the file to create with the documentation in it.
257 :    
258 :     =back
259 :    
260 :     =cut
261 :    
262 :     sub CreateSproutDoc {
263 :     # Get the parameters.
264 :     my ($sfx, $fileName) = @_;
265 :     # Open the output file.
266 :     my $handle = Open(undef, ">$fileName");
267 :     # Write the Sprout database document into it.
268 :     print $handle $sfx->DisplayMetaData();
269 :     # Close the file.
270 :     close $handle;
271 :     }
272 :    
273 :    
274 :    
275 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3