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

View of /Sprout/ShowCounts.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (download) (as text) (annotate)
Wed Feb 21 13:19:54 2007 UTC (12 years, 8 months ago) by parrello
Branch: MAIN
Changes since 1.10: +2 -2 lines
Fixed the output file name for the genome control.

#!/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.

=back

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.

=item target

Target directory for the include files. The default is C<includes> in the
C<$FIG_Config::nmpdr_pages> directory.

=back

=cut

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

# Get the command-line options and parameters.
my ($options, @parameters) = StandardSetup([qw(Sprout ERDB SFXlate) ],
                                           {
                                            trace => [2, 'tracing level'],
                                            target => ["$FIG_Config::nmpdr_pages/includes",
                                                          'output directory'],
                                           },
                                           "<version date>",
                                           @ARGV);

use SFXlate;

# Get the target directory.
my $targetDir = $options->{target};
# Verify the parameters.
if (! $parameters[0]) {
    Confess("Please specify a version date.");
} elsif (! -d $targetDir) {
    Confess("Target directory $targetDir does not exist.");
} else {
    Trace("Output going to $targetDir.") if T(2);
    # Get the Sprout object.
    my $sfx = SFXlate->new_sprout_only();
    # Get the old Sprout.
    my $oldSprout = SFXlate->new_sprout_only($FIG_Config::oldSproutDB);
    # Create the counts file.
    CreateCounts($sfx, $oldSprout, $parameters[0], "$targetDir/version.inc");
    # Create the subsystem summary file.
    CreateSubForm($sfx, "$targetDir/forms/all_genomes.inc");
    # Create the database documentation file.
    CreateSproutDoc($sfx, "$targetDir/sproutdb.inc");
    # Tell the user we're done.
    Trace("File creation complete.") if T(2);
}

=head3 CreateCounts

C<< CreateCounts($fig, $fileName); >>

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

=over 4

=item sfx

A Sprout object for accessing the database.

=item oldSfx

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.

=back

=cut

sub CreateCounts {
    # Get the parameters.
    my ($sfx, $oldSfx, $versionDate, $fileName) = @_;
    # Open the output file.
    my $handle = Open(undef, ">$fileName");
    # Start the heading.
    print $handle "<h3 class=\"home\">Version $versionDate\n";
    # Get the counts.
    my @counts = $sfx->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.
    print $handle "<br />$output";
    # Get the number of subsystems.
    my $subsystems = $sfx->GetCount(['Subsystem'], "", []);
    print $handle "<br />$subsystems active subsystems";
    # Count the number of new annotations and features.
    my %things = ( Annotation => 'annotations',
                   Feature => 'features',
                   Genome => 'organisms'
                 );
    for my $thing (sort keys %things) {
        my $newCount = $sfx->GetCount([$thing], "", []);
        my $oldCount = $oldSfx->GetCount([$thing], "", []);
        my $delta = $newCount - $oldCount;
        # Only display them if there's a reasonable number.
        if ($delta > 5) {
            print $handle ", $delta&nbsp;new&nbsp;$things{$thing}";
        }
    }
    # Terminate the heading.
    print $handle ".</h3>\n";
    # Close the output file.
    close $handle;
}

=head3 CreateSubForm

C<< CreateSubForm($sfx, $fileName); >>

Output the subsystem summary form. The subsystem summary form allows the user
to select an organism and view a summary of its subsystems.

=over 4

=item sfx

A Sprout object that can be used to access the NMPDR database.

=item fileName

The name of the file to create with the form HTML in it.

=back

=cut

sub CreateSubForm {
    # Get the parameters.
    my ($sfx, $fileName) = @_;
    # Start the form.
    my @page = ();
    push @page, start_form({method => "post", action => "../FIG/genome_statistics.cgi",
                            enctype=> "application/x-www-form-urlencoded"});
    # Make sure the script knows it's for SPROUT.
    push @page, input({type => "hidden", name => "SPROUT", value => "1"});
    # Surround the form parts with a table.
    push @page, "<table><tr><td>";
    # Create the gene menu.
    push @page, $sfx->GeneMenu({ name => 'genome', size => 10 }, "", []);
    # End the first table cell.
    push @page, "</td></tr><tr><td>";
    # Add the buttons.
    push @page, input({type => "submit", name => "show_subsystems",
                       value => "Show Subsystems"});
    push @page, input({type => "submit", name => "show_reactions",
                       value => "Show Reactions"});
    # Close the table.
    push @page, "</td></tr></table>";
    # Close the form.
    push @page, end_form();
    # Put together all the pieces.
    my $wholePage = join("\n", @page);
    # Open the output file.
    my $handle = Open(undef, ">$fileName");
    # Write out the HTML.
    print $handle $wholePage;
    # Close the file.
    close $handle;

}

=head3 CreateSproutDoc

C<< CreateSproutDoc($sfx, $fileName); >>

Output the Sprout database documentation.

=over 4

=item sfx

A Sprout object that can be used to access the NMPDR database.

=item fileName

The name of the file to create with the documentation in it.

=back

=cut

sub CreateSproutDoc {
    # Get the parameters.
    my ($sfx, $fileName) = @_;
    # Open the output file.
    my $handle = Open(undef, ">$fileName");
    # Write the Sprout database document into it.
    print $handle $sfx->DisplayMetaData();
    # Close the file.
    close $handle;
}



1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3