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

View of /Sprout/ShowCounts.pl

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.17 - (download) (as text) (annotate)
Tue Sep 16 18:59:01 2008 UTC (11 years, 6 months ago) by parrello
Branch: MAIN
CVS Tags: rast_2008_0924, rast_rel_2008_09_30, mgrast_rel_2008_0924, mgrast_rel_2008_0625, rast_release_2008_09_29, mgrast_rel_2008_0923, mgrast_rel_2008_0919, rast_rel_2008_09_29, mgrast_rel_2008_0917
Changes since 1.16: +32 -183 lines
Fixed to work with the wiki.

#!/usr/bin/perl -w

=head1 Generate NMPDR Web Page Includes

This script generates the include files for the NMPDR cover pages. The include
files go in the C<html/includes> directory for the current NMPDR, and are
based on data in the Sprout database. They need to be generated after the
Sprout database is loaded, but before the cover pages are put online.

The include files generated are:

=over 4

=item version.inc

Displays the version date, the genome counts, the number of subsystems,
and the number of new annotations. This file is included in the
C<index.php> document.

=item forms/all_genomes.inc

Displays a form allowing the user to select an organism and see a summary of
its subsystems and reactions. This file is included in the
C<content/subsystems.php> document.

=item sproutdb.inc

Displays the documentation for the Sprout database. This file is included in
the C<content/docs.php> document.


The currently-supported command-line options are as follows.

=over 4

=item user

Name suffix to be used for log files. If omitted, the PID is used.

=item trace

Numeric trace level. A higher trace level causes more messages to appear. The
default trace level is 2. Tracing will be directly to the standard output
as well as to a C<trace>I<User>C<.log> file in the FIG temporary directory,
where I<User> is the value of the B<user> option above.

=item sql

If specified, turns on tracing of SQL activity.

=item background

Save the standard and error output to files. The files will be created
in the FIG temporary directory and will be named C<err>I<User>C<.log> and
C<out>I<User>C<.log>, respectively, where I<User> is the value of the
B<user> option above.

=item h

Display this command's parameters and options.



use strict;
use Tracer;
use Cwd;
use File::Copy;
use File::Path;
use FIG;
use CGI qw(:standard);
use WikiTools;

# Get the command-line options and parameters.
my ($options, @parameters) = StandardSetup([qw(Sprout ERDB SFXlate WikiTools) ],
                                            trace => [2, 'tracing level'],
                                           "<version date>",

use SFXlate;

# The return type (error/no error) will be put in here.
my $rtype;
eval {
    # Get the target directory.
    my $targetDir = $options->{target};
    # Verify the parameters.
    if (! $parameters[0]) {
        Confess("Please specify a version date.");
    } else {
        Trace("Connecting to Sprout.") if T(2);
        # Get the Sprout object.
        my $sfx = SFXlate->new_sprout_only();
        # Get the old Sprout.
        my $oldSprout = SFXlate->old_sprout_only();
        # Create the counts page.
        my $page = CreateCounts($sfx, $oldSprout, $parameters[0]);
        # Put it in the wiki.
        my $wiki = WikiTools->new();
        my $rc = $wiki->Save('NmpdrVersion', 'Main', 'WebHome', $page);
        if ($rc) {
            Trace("Page creation complete.") if T(2);
        } else {
            Confess("Page creation failed: " . $wiki->{error});
if ($@) {
    Trace("Counts failed with error: $@") if T(0);
    $rtype = "error";
} else {
    Trace("Counts complete.") if T(2);
    $rtype = "no error";
if ($options->{phone}) {
    my $msgID = Tracer::SendSMS($options->{phone}, "ShowCounts terminated with $rtype.");
    if ($msgID) {
        Trace("Phone message sent with ID $msgID.") if T(2);
    } else {
        Trace("Phone message not sent.") if T(2);

=head3 CreateCounts

    my $content = CreateCounts($sprout, $oldSprout, $versionDate);

Create the count and version display for the front page of the NMPDR.

=over 4

=item sprout

A Sprout object for accessing the database.

=item oldSprout

A Sprout object for accessing the previous database.

=item versionDate

The string to be used for the version date.

=item fileName

The name of the output file.

=item RETURN

Returns a string that can be published for inclusion in the front page of the wiki.



sub CreateCounts {
    # Get the parameters.
    my ($sprout, $oldSprout, $versionDate) = @_;
    # Start the heading.
    my $retVal = "<h3 class=\"home\">Version of $versionDate\n";
    # Get the counts.
    my @counts = $sprout->GenomeCounts();
    my @names = qw(archaeal bacterial eukaryal viral environmental);
    # Get a list of named counts for all the categories with nonzero values.
    my @namedCounts = ();
    for (my $i = 0; $i <= $#names; $i++) {
        if ($counts[$i]) {
            push @namedCounts, "$counts[$i] $names[$i]";
    # Form the named counts into English, which is a very complicated process.
    my $output = "Includes $namedCounts[0]";
    for (my $i = 1; $i < $#namedCounts; $i++) {
        $output .= ", $namedCounts[$i]";
    if ($#namedCounts > 0) {
        $output .= ", and $namedCounts[$#namedCounts]";
    $output .= " genomes.";
    # Output the counts.
    $retVal .= "<br />$output";
    # Get the number of subsystems.
    my $subsystems = $sprout->GetCount(['Subsystem'], "", []);
    $retVal .= "<br />$subsystems active subsystems";
    # Count the number of new annotations, genomes, and features.
    my %things = ( Annotation => 'annotations',
                   Feature => 'features',
                   Genome => 'organisms'
    for my $thing (sort keys %things) {
        my $newCount = $sprout->GetCount([$thing], "", []);
        my $oldCount = $oldSprout->GetCount([$thing], "", []);
        my $delta = $newCount - $oldCount;
        # Only display them if there's a reasonable number.
        if ($delta > 5) {
            $retVal .= ", $delta&nbsp;new&nbsp;$things{$thing}";
    # Terminate the heading.
    $retVal .= ".</h3>\n";
    # Return it.
    return $retVal;


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3