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

Annotation of /Sprout/NmpdrCheck.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     #
4 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
5 :     # for Interpretations of Genomes. All Rights Reserved.
6 :     #
7 :     # This file is part of the SEED Toolkit.
8 :     #
9 :     # The SEED Toolkit is free software. You can redistribute
10 :     # it and/or modify it under the terms of the SEED Toolkit
11 :     # Public License.
12 :     #
13 :     # You should have received a copy of the SEED Toolkit Public License
14 :     # along with this program; if not write to the University of Chicago
15 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
16 :     # Genomes at veronika@thefig.info or download a copy from
17 :     # http://www.theseed.org/LICENSE.TXT.
18 :     #
19 :    
20 :     use strict;
21 :     use Tracer;
22 :     use FIG;
23 :     use SFXlate;
24 :     use Sprout;
25 :     use Stats;
26 :    
27 :     =head1 NmpdrCheck Script
28 :    
29 :     =head2 Introduction
30 :    
31 :     This script performs useful NMPDR validation functions. The various command-line
32 :     options direct it to perform basic tests of the NMPDR data.
33 :    
34 :     =head2 Command-Line Options
35 :    
36 :     =over 4
37 :    
38 :     =item trace
39 :    
40 :     Specifies the tracing level. The higher the tracing level, the more messages
41 :     will appear in the trace log. Use E to specify emergency tracing.
42 :    
43 :     =item diagrams
44 :    
45 :     This option lists all the subsystem diagrams, along with an indication of which
46 :     are new and which are old.
47 :    
48 :     =item subsystems
49 :    
50 :     This option lists all the SEED subsystems, indicating which are in the Sprout
51 :     and which are marked for NMPDR but not yet in the Sprout, and what the status is
52 :     of each diagram.
53 :    
54 :     =item user
55 :    
56 :     Name suffix to be used for log files. If omitted, the PID is used.
57 :    
58 :     =item sql
59 :    
60 :     If specified, turns on tracing of SQL activity.
61 :    
62 :     =item background
63 :    
64 :     Save the standard and error output to files. The files will be created
65 :     in the FIG temporary directory and will be named C<err>I<User>C<.log> and
66 :     C<out>I<User>C<.log>, respectively, where I<User> is the value of the
67 :     B<user> option above.
68 :    
69 :     =item help
70 :    
71 :     Display this command's parameters and options.
72 :    
73 :     =item warn
74 :    
75 :     Create an event in the RSS feed when an error occurs.
76 :    
77 :     =item phone
78 :    
79 :     Phone number to message when the script is complete.
80 :    
81 :     =back
82 :    
83 :     =cut
84 :    
85 :     # This hash maps option names to subroutine names. To add an option, you must
86 :     # create a subroutine to process it, add POD documentation above, add a summary
87 :     # to the StandardSetup call below, and map its name to the subroutine name in
88 :     # this constant.
89 :     my %OptionMap = (
90 :     subsystems => 'CheckSubsystems',
91 :     );
92 :     # Get the command-line options and parameters.
93 :     my ($options, @parameters) = StandardSetup([qw(SproutSubsys Sprout) ],
94 :     {
95 :     trace => ["2", "tracing level"],
96 :     subsystems => ["", "if specified, will verify the subsystem list"],
97 :     phone => ["", "phone number (international format) to call when load finishes"]
98 :     },
99 :     "",
100 :     @ARGV);
101 :     # Set a variable to contain return type information.
102 :     my $rtype;
103 :     # Insure we catch errors.
104 :     eval {
105 :     # Create the FIG object.
106 :     my $fig = FIG->new();
107 :     # Create the SFXlate object.
108 :     my $sfx = SFXlate->new();
109 :     # Create the statistics object.
110 :     my $stats = Stats->new();
111 :     # Display version information.
112 :     Trace("NMPDR version $FIG_Config::version type $FIG_Config::nmpdr_site_type.") if T(2);
113 :     # Process according to the options specified.
114 :     for my $option (sort keys %OptionMap) {
115 :     # Is this option specified?
116 :     if ($options->{$option}) {
117 :     $stats->Add(checks => 1);
118 :     # Call the method.
119 :     my $newStats = eval("$OptionMap{$option}(\$fig, \$sfx)");
120 :     if ($@) {
121 :     Trace("Error in $option check: $@") if T(0);
122 :     $stats->Add(crashes => 1);
123 :     } else {
124 :     # Display the statistics.
125 :     Trace("Statistics for $option check:\n" . $newStats->Show()) if T(2);
126 :     # Roll up the statistics.
127 :     $stats->Accumulate($newStats);
128 :     }
129 :     }
130 :     }
131 :     # If there was an error, or more than one test, display the rolled statistics.
132 :     if ($stats->Ask('checks') > 1 || $stats->Ask('crashes')) {
133 :     Trace("Summary statistics for all checks:\n" . $stats->Show()) if T(2);
134 :     }
135 :     };
136 :     if ($@) {
137 :     Trace("Script failed with error: $@") if T(0);
138 :     $rtype = "error";
139 :     } else {
140 :     Trace("Script complete.") if T(2);
141 :     $rtype = "no error";
142 :     }
143 :     if ($options->{phone}) {
144 :     my $msgID = Tracer::SendSMS($options->{phone}, "NmpdrCheck terminated with $rtype.");
145 :     if ($msgID) {
146 :     Trace("Phone message sent with ID $msgID.") if T(2);
147 :     } else {
148 :     Trace("Phone message not sent.") if T(2);
149 :     }
150 :     }
151 :    
152 :     =head3 CheckSubsystems
153 :    
154 :     my $stats = CheckSubsystems($fig, $sfx);
155 :    
156 :     Loop through all of the SEED subsystems, listing their NMPDR status and
157 :     enumerating the diagrams.
158 :    
159 :     =over 4
160 :    
161 :     =item fig
162 :    
163 :     [[FigPm]] object for accessing the SEED data store.
164 :    
165 :     =item sfx
166 :    
167 :     [[SFXlatePm]] object for accessing the NMPDE database.
168 :    
169 :     =item RETURN
170 :    
171 :     Returns a statistics object with a summary of what happened.
172 :    
173 :     =back
174 :    
175 :     =cut
176 :    
177 :     sub CheckSubsystems {
178 :     # Get the parameters.
179 :     my ($fig, $sfx) = @_;
180 :     # Create the statistics object.
181 :     my $retVal = Stats->new(qw(nmpdrPure nmpdrInserting nmpdrDeleting nmpdrExcluded));
182 :     # Get all of the SEED subsystems.
183 :     my %inSeed = map { $_ => 1 } $fig->all_subsystems();
184 :     # Get all of the NMPDR subsystems.
185 :     my %inNmpdr = map { $_ => 1 } $sfx->all_subsystems();
186 :     # Loop through the SEED subsystems.
187 :     for my $subName (sort keys %inSeed) {
188 :     Trace("Processing SEED subsystem $subName.") if T(3);
189 :     my $markedNmpdr = $fig->nmpdr_subsystem($subName);
190 :     # We'll accumulate data lines for the subsystem in here.
191 :     my @lines;
192 :     # Determine the NMPDR status.
193 :     my $status;
194 :     if ($inNmpdr{$subName} && $markedNmpdr) {
195 :     push @lines, "Subsystem is marked NMPDR and is found in the NMPDR database.";
196 :     $status = 'nmpdrPure';
197 :     } elsif ($inNmpdr{$subName}) {
198 :     push @lines, "Subsystem is not marked NMPDR and is found in the NMPDR database.";
199 :     $status = 'nmpdrDeleting';
200 :     } elsif ($markedNmpdr) {
201 :     push @lines, "Subsystem is marked NMPDR and is not found in the NMPDR database.";
202 :     $status = 'nmpdrInserting';
203 :     } else {
204 :     push @lines, "Subsystem is not marked NMPDR and is not found in the NMPDR database.";
205 :     $status = 'nmpdrExcluded';
206 :     }
207 :     $retVal->Add($status => 1);
208 :     # Get the SEED subsystem object.
209 :     Trace("Retrieving subsystem object for $subName.") if T(3);
210 :     my $subData = $fig->get_subsystem($subName);
211 :     if (! $subData) {
212 :     push @lines, "ERROR: Subsystem object cannot be created.";
213 :     $retVal->Add(seedSubError => 1);
214 :     } else {
215 :     $retVal->Add(seedSubFound => 1);
216 :     # Check the diagrams.
217 :     my @diagrams = $subData->get_diagrams();
218 :     for my $diagramData (@diagrams) {
219 :     $retVal->Add(subDiagram => 1);
220 :     my ($diagramID) = @{$diagramData};
221 :     my $diagramFlag = ($subData->is_new_diagram($diagramID) ? "new" : "old");
222 :     $retVal->Add("subDiagram" . ucfirst($diagramFlag) => 1);
223 :     push @lines, "Diagram $diagramID is $diagramFlag format.";
224 :     }
225 :     }
226 :     my $thing = join("\n ", "Results for $subName", @lines);
227 :     Trace($thing) if T(2);
228 :     }
229 :     # Now check for deleted subsystems.
230 :     for my $subName (sort keys %inNmpdr) {
231 :     if (! $inSeed{$subName}) {
232 :     Trace("Subsystem $subName is in NMPDR but deleted from SEED.") if T(2);
233 :     $retVal->Add(nmpdrDeleted => 1);
234 :     }
235 :     }
236 :     # Return the statistics object.
237 :     return $retVal;
238 :     }
239 :    
240 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3