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

Annotation of /Sprout/ShowCounts.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (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 :     =back
64 :    
65 :     =cut
66 :    
67 :     use strict;
68 :     use Tracer;
69 :     use Cwd;
70 :     use File::Copy;
71 :     use File::Path;
72 :     use FIG;
73 : parrello 1.3 use CGI qw(:standard);
74 : parrello 1.17 use WikiTools;
75 : parrello 1.1
76 :     # Get the command-line options and parameters.
77 : parrello 1.17 my ($options, @parameters) = StandardSetup([qw(Sprout ERDB SFXlate WikiTools) ],
78 : parrello 1.1 {
79 : parrello 1.10 trace => [2, 'tracing level'],
80 : parrello 1.1 },
81 :     "<version date>",
82 :     @ARGV);
83 :    
84 :     use SFXlate;
85 :    
86 : parrello 1.14 # The return type (error/no error) will be put in here.
87 :     my $rtype;
88 :     eval {
89 :     # Get the target directory.
90 :     my $targetDir = $options->{target};
91 :     # Verify the parameters.
92 :     if (! $parameters[0]) {
93 :     Confess("Please specify a version date.");
94 :     } else {
95 : parrello 1.17 Trace("Connecting to Sprout.") if T(2);
96 : parrello 1.14 # Get the Sprout object.
97 :     my $sfx = SFXlate->new_sprout_only();
98 :     # Get the old Sprout.
99 :     my $oldSprout = SFXlate->old_sprout_only();
100 : parrello 1.17 # Create the counts page.
101 :     my $page = CreateCounts($sfx, $oldSprout, $parameters[0]);
102 : parrello 1.18 Trace("Page = \n$page") if T(4);
103 : parrello 1.17 # Put it in the wiki.
104 :     my $wiki = WikiTools->new();
105 :     my $rc = $wiki->Save('NmpdrVersion', 'Main', 'WebHome', $page);
106 :     if ($rc) {
107 :     Trace("Page creation complete.") if T(2);
108 :     } else {
109 :     Confess("Page creation failed: " . $wiki->{error});
110 :     }
111 : parrello 1.14 }
112 :     };
113 :     if ($@) {
114 :     Trace("Counts failed with error: $@") if T(0);
115 :     $rtype = "error";
116 : parrello 1.4 } else {
117 : parrello 1.14 Trace("Counts complete.") if T(2);
118 :     $rtype = "no error";
119 :     }
120 :     if ($options->{phone}) {
121 :     my $msgID = Tracer::SendSMS($options->{phone}, "ShowCounts terminated with $rtype.");
122 :     if ($msgID) {
123 :     Trace("Phone message sent with ID $msgID.") if T(2);
124 :     } else {
125 :     Trace("Phone message not sent.") if T(2);
126 :     }
127 : parrello 1.4 }
128 : parrello 1.1
129 :     =head3 CreateCounts
130 :    
131 : parrello 1.17 my $content = CreateCounts($sprout, $oldSprout, $versionDate);
132 : parrello 1.1
133 :     Create the count and version display for the front page of the NMPDR.
134 :    
135 :     =over 4
136 :    
137 : parrello 1.17 =item sprout
138 : parrello 1.1
139 :     A Sprout object for accessing the database.
140 :    
141 : parrello 1.17 =item oldSprout
142 : parrello 1.1
143 : parrello 1.7 A Sprout object for accessing the previous database.
144 : parrello 1.1
145 :     =item versionDate
146 :    
147 :     The string to be used for the version date.
148 :    
149 :     =item fileName
150 :    
151 :     The name of the output file.
152 :    
153 : parrello 1.17 =item RETURN
154 :    
155 :     Returns a string that can be published for inclusion in the front page of the wiki.
156 :    
157 : parrello 1.1 =back
158 :    
159 :     =cut
160 :    
161 :     sub CreateCounts {
162 :     # Get the parameters.
163 : parrello 1.17 my ($sprout, $oldSprout, $versionDate) = @_;
164 : parrello 1.1 # Start the heading.
165 : parrello 1.17 my $retVal = "<h3 class=\"home\">Version of $versionDate\n";
166 : parrello 1.1 # Get the counts.
167 : parrello 1.17 my @counts = $sprout->GenomeCounts();
168 : parrello 1.1 my @names = qw(archaeal bacterial eukaryal viral environmental);
169 :     # Get a list of named counts for all the categories with nonzero values.
170 :     my @namedCounts = ();
171 :     for (my $i = 0; $i <= $#names; $i++) {
172 :     if ($counts[$i]) {
173 :     push @namedCounts, "$counts[$i] $names[$i]";
174 :     }
175 :     }
176 :     # Form the named counts into English, which is a very complicated process.
177 :     my $output = "Includes $namedCounts[0]";
178 :     for (my $i = 1; $i < $#namedCounts; $i++) {
179 :     $output .= ", $namedCounts[$i]";
180 :     }
181 :     if ($#namedCounts > 0) {
182 :     $output .= ", and $namedCounts[$#namedCounts]";
183 :     }
184 :     $output .= " genomes.";
185 :     # Output the counts.
186 : parrello 1.17 $retVal .= "<br />$output";
187 : parrello 1.1 # Get the number of subsystems.
188 : parrello 1.17 my $subsystems = $sprout->GetCount(['Subsystem'], "", []);
189 :     $retVal .= "<br />$subsystems active subsystems";
190 : parrello 1.13 # Count the number of new annotations, genomes, and features.
191 : parrello 1.8 my %things = ( Annotation => 'annotations',
192 :     Feature => 'features',
193 :     Genome => 'organisms'
194 :     );
195 :     for my $thing (sort keys %things) {
196 : parrello 1.17 my $newCount = $sprout->GetCount([$thing], "", []);
197 :     my $oldCount = $oldSprout->GetCount([$thing], "", []);
198 : parrello 1.8 my $delta = $newCount - $oldCount;
199 :     # Only display them if there's a reasonable number.
200 :     if ($delta > 5) {
201 : parrello 1.17 $retVal .= ", $delta&nbsp;new&nbsp;$things{$thing}";
202 : parrello 1.8 }
203 : parrello 1.1 }
204 :     # Terminate the heading.
205 : parrello 1.17 $retVal .= ".</h3>\n";
206 :     # Return it.
207 :     return $retVal;
208 : parrello 1.1 }
209 :    
210 :    
211 :    
212 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3