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

Annotation of /Sprout/DeleteGenomes.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (view) (download) (as text)

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 : parrello 1.4 =head1 Delete Genomes from Sapling
4 : parrello 1.1
5 : parrello 1.4 This method deletes genomes from the Sapling database. Simply list the genomes
6 : parrello 1.1 as command-line parameters.
7 :    
8 :     The currently-supported command-line options are as follows.
9 :    
10 :     =over 4
11 :    
12 :     =item showOnly
13 :    
14 :     If specified, the DELETE statements will be displayed but no records will be deleted.
15 :    
16 :     =item trace
17 :    
18 :     Numeric trace level. A higher trace level causes more messages to appear. The
19 :     default trace level is 2.
20 :    
21 :     =item sql
22 :    
23 :     If specified, turns on tracing of SQL activity.
24 :    
25 :     =item h
26 :    
27 : parrello 1.6 Display this command's parameters and options.
28 :    
29 :     =item file
30 :    
31 :     The list of genomes will be taken from the first column of the specified tab-delimited file,
32 :     instead of from the command line.
33 : parrello 1.1
34 :     =back
35 :    
36 :     =cut
37 :    
38 :     use strict;
39 :     use Tracer;
40 :     use Cwd;
41 :     use FIG;
42 :     use Stats;
43 : parrello 1.4 use Sapling;
44 : parrello 1.1 use File::Copy;
45 :     use File::Path;
46 :    
47 :     # Get the command-line options.
48 : parrello 1.4 my ($options, @parameters) = StandardSetup(['ERDB'],
49 : parrello 1.1 {
50 : parrello 1.2 showOnly => [0, 'Display DELETE statements without deleting.'],
51 :     trace => [2, 'tracing level'],
52 : parrello 1.6 file => ['', 'genome ID file']
53 : parrello 1.1 },
54 :     '<genome1> <genome2> ...',
55 :     @ARGV);
56 : parrello 1.6 # Get the Sapling object.
57 : parrello 1.4 my $sprout = Sapling->new();
58 : parrello 1.1 # Save the show-only flag.
59 :     my $showOnly = $options->{showOnly};
60 :     # Create the statistics object.
61 :     my $retVal = Stats->new('genomesFound', 'genomesNotFound');
62 : parrello 1.6 # The list of genome IDs will be put in here.
63 :     my @genomes;
64 :     # Look for a genome ID file.
65 :     if ($options->{file}) {
66 : parrello 1.7 # We found one. Read the genome IDs. Note we skip blank lines.
67 : parrello 1.6 my $ih = Open(undef, "<$options->{file}");
68 :     while (! eof $ih) {
69 :     my ($genomeID) = Tracer::GetLine($ih);
70 : parrello 1.7 if ($genomeID) {
71 :     push @genomes, $genomeID;
72 :     }
73 : parrello 1.6 }
74 :     Trace(scalar(@genomes) . " genome IDs read from $options->{file}.") if T(2);
75 :     } else {
76 :     @genomes = @parameters;
77 :     Trace(scalar(@genomes) . " genome IDs found on command line.") if T(2);
78 :     }
79 : parrello 1.1 # Loop through the genome IDs.
80 : parrello 1.6 for my $genomeID (@genomes) {
81 : parrello 1.1 # Find out if the genome is real.
82 :     if (! $sprout->Exists('Genome', $genomeID)) {
83 :     # Warn the user. Nothing can get deleted if the genome is not in the Genome
84 :     # table.
85 :     Trace("Genome $genomeID not found in the genome table.") if T(1);
86 :     $retVal->Add('genomesNotFound');
87 :     } else {
88 :     # Here we can delete it.
89 : parrello 1.6 Trace("Deleting $genomeID.") if T(3);
90 : parrello 1.5 my $stats = $sprout->Delete(Genome => $genomeID, testMode => $showOnly);
91 : parrello 1.1 # Update the statistics.
92 :     $retVal->Add('genomesFound');
93 :     $retVal->Accumulate($stats);
94 :     }
95 :     }
96 :     # Display the statistcs.
97 :     Trace($retVal->Show()) if T(0);
98 :    
99 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3