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

Annotation of /Sprout/ShowCounts.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3