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