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

View of /Sprout/GeneFile.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Wed Aug 30 15:01:59 2006 UTC (13 years, 2 months ago) by parrello
Branch: MAIN
Changes since 1.1: +13 -9 lines
Changed to specify genomes to include rather than genomes to exclude.

#!/usr/bin/perl -w

=head1 GenomeFile

This script generates a genome file. The file will include all complete genomes
plus the ones listed as parameters.

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 phone

Phone number to message when the script is complete.

=item geneFile

Name of the gene file to produce. The default is C<genes.tbl> in the SproutData
directory.

=item code

Access code to assign to the genomes.

=back

=cut

use strict;
use Tracer;
use DocUtils;
use TestUtils;
use Cwd;
use File::Copy;
use File::Path;
use FIG;

# Get the command-line options and parameters.
my ($options, @parameters) = StandardSetup([qw() ],
                                           {
                                              phone => ["", "phone number (international format) to call when load finishes"],
                                              code => ["1", "genome access code"],
                                              geneFile => ["$FIG_Config::sproutData/genes.tbl", "output file"],
                                           },
                                           "<include1> <include2> ...",
                                           @ARGV);
# Set a variable to contain return type information.
my $rtype;
# Insure we catch errors.
eval {
    my $fig = FIG->new();
    # Get the access code.
    my $code = $options->{code};
    # Get a list of the complete genomes.
    my @genes = $fig->genomes(1);
    # Add the genomes in the parameter list, taking care to avoid
    # duplicates.
    for my $parm (@parameters) {
        if (grep { $_ eq $parm } @genes) {
            Trace("Genome $parm is now in the standard list.") if T(2);
        } else {
            push @genes, $parm;
        }
    }
    # Start a counter.
    my $counter = 0;
    # Open the output file.
    my $outFile = $options->{geneFile};
    Open(\*GENEFILE, ">$outFile");
    # Loop through the genes, creating output.
    for my $gene (@genes) {
        print GENEFILE "$gene\t$code\n";
        $counter++;
    }
    # Close the output file.
    close GENEFILE;
    Trace("$counter genomes written to $outFile.") if T(2);
};
if ($@) {
    Trace("Script failed with error: $@") if T(0);
    $rtype = "error";
} else {
    Trace("Script complete.") if T(2);
    $rtype = "no error";
}
if ($options->{phone}) {
    my $msgID = Tracer::SendSMS($options->{phone}, "GenomeFile terminated with $rtype.");
    if ($msgID) {
        Trace("Phone message sent with ID $msgID.") if T(2);
    } else {
        Trace("Phone message not sent.") if T(2);
    }
}

1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3