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

Annotation of /Sprout/ShowCounts.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (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 :     =item subsummary.inc
21 :    
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 :     Target directory for the include files. The default is C<html/includes> in the
71 :     C<$FIG_Config::fig_disk> directory.
72 :    
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 :    
86 :     # Get the command-line options and parameters.
87 :     my ($options, @parameters) = StandardSetup([qw(Sprout ERDB SFXlate) ],
88 :     {
89 :     age => [14, 'maximum age of a new annotation'],
90 :     target => ["$FIG_Config::fig_disk/html/includes",
91 :     'output directory'],
92 :     },
93 :     "<version date>",
94 :     @ARGV);
95 :    
96 :     use SFXlate;
97 :    
98 :     # Get the target directory.
99 :     my $targetDir = $options->{target};
100 :     # Get the Sprout object.
101 :     my $sfx = SFXlate->new_sprout_only();
102 :     # Create the counts file.
103 :     CreateCounts($sfx, $options->{age}, $parameters[0], "$targetDir/version.inc");
104 :     # Create the subsystem summary file.
105 :     CreateSubForm($sfx, "$targetDir/subsummary.inc");
106 :     # Create the database documentation file.
107 :     CreateSproutDoc($sfx, "$targetDir/sproutdb.inc");
108 :     # Tell the user we're done.
109 :     Trace("File creation complete.") if T(2);
110 :    
111 :     =head3 CreateCounts
112 :    
113 :     C<< CreateCounts($fig, $fileName); >>
114 :    
115 :     Create the count and version display for the front page of the NMPDR.
116 :    
117 :     =over 4
118 :    
119 :     =item sfx
120 :    
121 :     A Sprout object for accessing the database.
122 :    
123 :     =item age
124 :    
125 :     The maximum age for an annotation to be considered new.
126 :    
127 :     =item versionDate
128 :    
129 :     The string to be used for the version date.
130 :    
131 :     =item fileName
132 :    
133 :     The name of the output file.
134 :    
135 :     =back
136 :    
137 :     =cut
138 :    
139 :     sub CreateCounts {
140 :     # Get the parameters.
141 :     my ($sfx, $age, $versionDate, $fileName) = @_;
142 :     # Open the output file.
143 :     my $handle = Open(undef, ">$fileName");
144 :     # Start the heading.
145 :     print $handle "<h3 class=\"home\">Version $versionDate\n";
146 :     # Get the counts.
147 :     my @counts = $sfx->GenomeCounts();
148 :     my @names = qw(archaeal bacterial eukaryal viral environmental);
149 :     # Get a list of named counts for all the categories with nonzero values.
150 :     my @namedCounts = ();
151 :     for (my $i = 0; $i <= $#names; $i++) {
152 :     if ($counts[$i]) {
153 :     push @namedCounts, "$counts[$i] $names[$i]";
154 :     }
155 :     }
156 :     # Form the named counts into English, which is a very complicated process.
157 :     my $output = "Includes $namedCounts[0]";
158 :     for (my $i = 1; $i < $#namedCounts; $i++) {
159 :     $output .= ", $namedCounts[$i]";
160 :     }
161 :     if ($#namedCounts > 0) {
162 :     $output .= ", and $namedCounts[$#namedCounts]";
163 :     }
164 :     $output .= " genomes.";
165 :     # Output the counts.
166 :     print $handle "<br />$output";
167 :     # Get the number of subsystems.
168 :     my $subsystems = $sfx->GetCount(['Subsystem'], "", []);
169 :     print $handle "<br />$subsystems subsystems";
170 :     # Get the current time and subtract the number of days indicated by the age.
171 :     my $time = time() - $age * 86400;
172 :     # Count the number of new annotations.
173 :     my $newAnnotations = $sfx->GetCount(['Annotation'], "Annotation(time) >= ?",
174 :     [$time]);
175 :     # Only display them if there's a reasonable number.
176 :     if ($newAnnotations > 5) {
177 :     print $handle ", $newAnnotations new annotations";
178 :     }
179 :     # Terminate the heading.
180 :     print $handle ".</h3>\n";
181 :     # Close the output file.
182 :     close $handle;
183 :     }
184 :    
185 :     =head3 CreateSubForm
186 :    
187 :     C<< CreateSubForm($sfx, $fileName); >>
188 :    
189 :     Output the subsystem summary form. The subsystem summary form allows the user
190 :     to select an organism and view a summary of its subsystems.
191 :    
192 :     =over 4
193 :    
194 :     =item sfx
195 :    
196 :     A Sprout object that can be used to access the NMPDR database.
197 :    
198 :     =item fileName
199 :    
200 :     The name of the file to create with the form HTML in it.
201 :    
202 :     =back
203 :    
204 :     =cut
205 :    
206 :     sub CreateSubForm {
207 :     # Get the parameters.
208 :     my ($sfx, $fileName) = @_;
209 :     # Open the output file.
210 :     my $handle = Open(undef, ">$fileName");
211 :     # TODO
212 :     # Close the file.
213 :     close $handle;
214 :    
215 :     }
216 :    
217 :     =head3 CreateSproutDoc
218 :    
219 :     C<< CreateSproutDoc($sfx, $fileName); >>
220 :    
221 :     Output the Sprout database documentation.
222 :    
223 :     =over 4
224 :    
225 :     =item sfx
226 :    
227 :     A Sprout object that can be used to access the NMPDR database.
228 :    
229 :     =item fileName
230 :    
231 :     The name of the file to create with the documentation in it.
232 :    
233 :     =back
234 :    
235 :     =cut
236 :    
237 :     sub CreateSproutDoc {
238 :     # Get the parameters.
239 :     my ($sfx, $fileName) = @_;
240 :     # Open the output file.
241 :     my $handle = Open(undef, ">$fileName");
242 :     # Write the Sprout database document into it.
243 :     print $handle $sfx->DisplayMetaData();
244 :     # Close the file.
245 :     close $handle;
246 :     }
247 :    
248 :    
249 :    
250 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3