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

View of /Sprout/DeleteGenomes.pl

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.7 - (download) (as text) (annotate)
Fri Nov 8 18:43:35 2013 UTC (5 years, 3 months ago) by parrello
Branch: MAIN
CVS Tags: rast_rel_2014_0912, rast_rel_2014_0729, HEAD
Changes since 1.6: +4 -2 lines
Minor fix to allow blank lines in genome ID file.

#!/usr/bin/perl -w

=head1 Delete Genomes from Sapling

This method deletes genomes from the Sapling database. Simply list the genomes
as command-line parameters.

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

=over 4

=item showOnly

If specified, the DELETE statements will be displayed but no records will be deleted.

=item trace

Numeric trace level. A higher trace level causes more messages to appear. The
default trace level is 2.

=item sql

If specified, turns on tracing of SQL activity.

=item h

Display this command's parameters and options.

=item file

The list of genomes will be taken from the first column of the specified tab-delimited file,
instead of from the command line.



use strict;
use Tracer;
use Cwd;
use FIG;
use Stats;
use Sapling;
use File::Copy;
use File::Path;

# Get the command-line options.
my ($options, @parameters) = StandardSetup(['ERDB'],
                                            showOnly => [0, 'Display DELETE statements without deleting.'],
                                            trace => [2, 'tracing level'],
                                            file => ['', 'genome ID file']
                                            '<genome1> <genome2> ...',
# Get the Sapling object.
my $sprout = Sapling->new();
# Save the show-only flag.
my $showOnly = $options->{showOnly};
# Create the statistics object.
my $retVal = Stats->new('genomesFound', 'genomesNotFound');
# The list of genome IDs will be put in here.
my @genomes;
# Look for a genome ID file.
if ($options->{file}) {
    # We found one. Read the genome IDs. Note we skip blank lines.
    my $ih = Open(undef, "<$options->{file}");
    while (! eof $ih) {
        my ($genomeID) = Tracer::GetLine($ih);
        if ($genomeID) {
            push @genomes, $genomeID;
    Trace(scalar(@genomes) . " genome IDs read from $options->{file}.") if T(2);
} else {
    @genomes = @parameters;
    Trace(scalar(@genomes) . " genome IDs found on command line.") if T(2);
# Loop through the genome IDs.
for my $genomeID (@genomes) {
    # Find out if the genome is real.
    if (! $sprout->Exists('Genome', $genomeID)) {
        # Warn the user. Nothing can get deleted if the genome is not in the Genome
        # table.
        Trace("Genome $genomeID not found in the genome table.") if T(1);
    } else {
        # Here we can delete it.
        Trace("Deleting $genomeID.") if T(3);
        my $stats = $sprout->Delete(Genome => $genomeID, testMode => $showOnly);
        # Update the statistics.
# Display the statistcs.
Trace($retVal->Show()) if T(0);


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3