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

Annotation of /Sprout/NewStuffCheck.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     =head1 New Stuff Checker
4 :    
5 :     This script compares the genomes, features, and annotations in
6 :     the old and new sprouts and lists the differences.
7 :    
8 :     The currently-supported command-line options are as follows.
9 :    
10 :     =over 4
11 :    
12 : parrello 1.2 =item summary
13 :    
14 :     Do not display details, only difference summaries.
15 :    
16 : parrello 1.8 =item nofeats
17 :    
18 :     Do not process features.
19 :    
20 : parrello 1.1 =item user
21 :    
22 :     Name suffix to be used for log files. If omitted, the PID is used.
23 :    
24 :     =item trace
25 :    
26 :     Numeric trace level. A higher trace level causes more messages to appear. The
27 :     default trace level is 2. Tracing will be directly to the standard output
28 :     as well as to a C<trace>I<User>C<.log> file in the FIG temporary directory,
29 :     where I<User> is the value of the B<user> option above.
30 :    
31 :     =item sql
32 :    
33 :     If specified, turns on tracing of SQL activity.
34 :    
35 :     =item background
36 :    
37 :     Save the standard and error output to files. The files will be created
38 :     in the FIG temporary directory and will be named C<err>I<User>C<.log> and
39 :     C<out>I<User>C<.log>, respectively, where I<User> is the value of the
40 :     B<user> option above.
41 :    
42 :     =item h
43 :    
44 :     Display this command's parameters and options.
45 :    
46 :     =item phone
47 :    
48 :     Phone number to message when the script is complete.
49 :    
50 :     =back
51 :    
52 :     =cut
53 :    
54 :     use strict;
55 :     use Tracer;
56 :     use DocUtils;
57 :     use TestUtils;
58 :     use Cwd;
59 :     use File::Copy;
60 :     use File::Path;
61 :     use FIG;
62 :     use SFXlate;
63 :     use Sprout;
64 :    
65 :     # Get the command-line options and parameters.
66 :     my ($options, @parameters) = StandardSetup([qw(Sprout) ],
67 :     {
68 : parrello 1.8 nofeats => ["", "if specified, only genome changes will be displayed; otherwise, genome features will be compared and differences shown"],
69 : parrello 1.5 trace => ["2-", "tracing level; use a minus to prevent tracing to standard output"],
70 : parrello 1.2 summary => ["", "if specified, detailed lists of the different items will not be displayed"],
71 : parrello 1.1 phone => ["", "phone number (international format) to call when load finishes"],
72 :     },
73 :     "",
74 :     @ARGV);
75 :     # Set a variable to contain return type information.
76 :     my $rtype;
77 :     # Insure we catch errors.
78 :     eval {
79 : parrello 1.2 Trace("Processing genomes.") if T(2);
80 : parrello 1.8 # Get the current SEED.
81 :     my $fig = FIG->new();
82 : parrello 1.1 # Get the old Sprout.
83 :     my $oldSprout = SFXlate->new_sprout_only($FIG_Config::oldSproutDB);
84 :     # Get its genomes in alphabetical order.
85 : parrello 1.8 my @oldGenomes = GetGenomes($oldSprout);
86 : parrello 1.1 # Get the new Sprout.
87 :     my $newSprout = SFXlate->new_sprout_only();
88 :     # Get its genomes in alphabetical order.
89 : parrello 1.8 my @newGenomes = GetGenomes($newSprout);
90 : parrello 1.7 # Compare the two genomes lists.
91 : parrello 1.1 my ($insertedGenomes, $deletedGenomes) = Tracer::CompareLists(\@newGenomes, \@oldGenomes);
92 : parrello 1.7 # Add feature counts to the new genomes.
93 :     for my $insertedGenome (@{$insertedGenomes}) {
94 :     my $genomeID = $insertedGenome->[0];
95 :     # For a new genome, display the feature count.
96 :     my $count = $newSprout->GetCount(['HasFeature'], "HasFeature(from-link) = ?",
97 :     [$genomeID]);
98 :     my $suffix = ($count == 1 ? " one feature" : "$count features");
99 :     $insertedGenome->[1] .= "($suffix)";
100 :     }
101 : parrello 1.8 # Add information about SEED status to the deleted genomes.
102 :     for my $deletedGenome (@{$deletedGenomes}) {
103 :     my $genomeID = $deletedGenome->[0];
104 :     if ($fig->is_genome($genomeID)) {
105 :     my $complete = ($fig->is_complete($genomeID) ? "complete" : "incomplete");
106 : parrello 1.9 $deletedGenome->[1] .= "(still in SEED, $complete)";
107 : parrello 1.8 }
108 :     }
109 : parrello 1.1 # Display the lists.
110 : parrello 1.2 ShowLists(! $options->{summary},
111 :     'New Genomes' => $insertedGenomes,
112 :     'Deleted Genomes' => $deletedGenomes);
113 : parrello 1.8 # Now the groups.
114 :     Trace("Comparing groups.") if T(2);
115 :     my %oldGroups = $oldSprout->GetGroups();
116 :     my %newGroups = $newSprout->GetGroups();
117 :     # Loop through the new groups.
118 :     for my $newGroup (sort keys %newGroups) {
119 :     Trace("Processing group $newGroup.") if T(3);
120 :     # Find out if this group is new to this version.
121 :     if (! exists $oldGroups{$newGroup}) {
122 :     # Construct a list of this group's genes.
123 :     my @groupGenomes = NameGenomes($newSprout, $newGroups{$newGroup});
124 :     ShowLists(! $options->{summary}, "Genomes in new group $newGroup" => \@groupGenomes);
125 :     } else {
126 :     # Here the group is in both versions. Fix the lists and compare them.
127 :     my @newGroupList = NameGenomes($newSprout, $newGroups{$newGroup});
128 :     my @oldGroupList = NameGenomes($oldSprout, $oldGroups{$newGroup});
129 :     my ($insertedGroupGenomes, $deletedGroupGenomes) = Tracer::CompareLists(\@newGroupList, \@oldGroupList);
130 :     # Delete the old group data. When we're done, this means we'll have a list of the deleted
131 :     # groups.
132 :     delete $oldGroups{$newGroup};
133 :     # Show the lists. Empty lists will not be shown.
134 :     ShowLists(! $options->{summary},
135 :     "Genomes new to $newGroup" => $insertedGroupGenomes,
136 :     "Genomes no longer in $newGroup" => $deletedGroupGenomes);
137 :     }
138 :     }
139 :     # Now list the deleted groups.
140 :     for my $oldGroup (sort keys %oldGroups) {
141 :     Trace("Processing deleted group $oldGroup.") if T(3);
142 :     my @groupGenomes = NameGenomes($oldSprout, $oldGroups{$oldGroup});
143 :     ShowLists(! $options->{summary}, "Genomes in deleted group $oldGroup" => \@groupGenomes);
144 :     }
145 : parrello 1.1 # Next, we get the subsystems.
146 : parrello 1.2 Trace("Processing subsystems.") if T(2);
147 : parrello 1.1 my @oldSubsystems = GetSubsystems($oldSprout);
148 :     my @newSubsystems = GetSubsystems($newSprout);
149 :     # Compare and display the subsystem lists.
150 :     my ($insertedSubs, $deletedSubs) = Tracer::CompareLists(\@newSubsystems, \@oldSubsystems);
151 : parrello 1.8 # Check the deleted subsystems to see if they're in SEED.
152 :     if (scalar @{$deletedSubs} > 0) {
153 :     my %subChecker = map { $_ => 1 } $fig->all_subsystems();
154 :     for my $deletedSub (@{$deletedSubs}) {
155 :     my $subID = $deletedSub->[0];
156 :     if ($subChecker{$subID}) {
157 :     my $trusted = ($fig->usable_subsystem($subID) ? "usable" : "not usable");
158 : parrello 1.9 $deletedSub->[1] .= " (still in SEED, $trusted)";
159 : parrello 1.8 }
160 :     }
161 :     }
162 : parrello 1.2 ShowLists(! $options->{summary},
163 :     'New Subsystems' => $insertedSubs,
164 :     'Deleted Subsystems' => $deletedSubs);
165 : parrello 1.8 # Now we process the features of the common genes.
166 :     if (! $options->{nofeats}) {
167 :     # First we need a hash of the inserted stuff so we know to skip it.
168 :     my %skipGenomes = map { $_->[0] => 1 } @{$insertedGenomes};
169 :     # Loop through the genomees.
170 :     for my $genome (@newGenomes) {
171 :     # Get the ID and name.
172 :     my ($genomeID, $genomeName) = @{$genome};
173 :     Trace("Processing $genomeID.") if T(3);
174 :     # Only process the common genes.
175 :     if (! $skipGenomes{$genomeID}) {
176 :     # Compare the genome group information.
177 :     # Get the new and old features. This will be very stressful to the machine,
178 :     # because there are lots of features.
179 :     my @oldFeatures = GetFeatures($oldSprout, $genomeID);
180 :     my @newFeatures = GetFeatures($newSprout, $genomeID);
181 :     Trace("Comparing features for $genomeID.") if T(3);
182 :     # Compare the lists.
183 :     my ($insertedFeatures, $deletedFeatures) = Tracer::CompareLists(\@newFeatures, \@oldFeatures);
184 :     # Display the lists. Only nonempty lists are displayed; however, we do a check
185 :     # first anyway so the trace tells us what's happening.
186 :     if (scalar @{$insertedFeatures} + scalar @{$deletedFeatures} > 0) {
187 :     Trace("Displaying feature differences.") if T(3);
188 :     ShowLists(! $options->{summary},
189 :     "New Features for $genomeID" => $insertedFeatures,
190 :     "Features Deleted from $genomeID" => $deletedFeatures);
191 :     }
192 : parrello 1.1 }
193 :     }
194 :     }
195 :     };
196 :     if ($@) {
197 :     Trace("Script failed with error: $@") if T(0);
198 :     $rtype = "error";
199 :     } else {
200 :     Trace("Script complete.") if T(2);
201 :     $rtype = "no error";
202 :     }
203 :     if ($options->{phone}) {
204 :     my $msgID = Tracer::SendSMS($options->{phone}, "Subsystem Checker terminated with $rtype.");
205 :     if ($msgID) {
206 :     Trace("Phone message sent with ID $msgID.") if T(2);
207 :     } else {
208 :     Trace("Phone message not sent.") if T(2);
209 :     }
210 :     }
211 :    
212 : parrello 1.8 =head3 GetGenomes
213 : parrello 1.1
214 : parrello 1.8 C<< my @geneList = GetGenomes($sprout); >>
215 : parrello 1.1
216 :     Return a list of the genomes in the specified Sprout instance. The genomes
217 :     are returned in alphabetical order by genome ID.
218 :    
219 :     =over 4
220 :    
221 :     =item sprout
222 :    
223 :     Sprout instance whose gene list is desired.
224 :    
225 :     =item RETURN
226 :    
227 :     Returns a list of two-tuples. The first element in each tuple is the genome ID,
228 :     and the second is the genome name (genus, species, strain).
229 :    
230 :     =back
231 :    
232 :     =cut
233 :    
234 : parrello 1.8 sub GetGenomes {
235 : parrello 1.1 # Get the parameters.
236 :     my ($sprout) = @_;
237 :     # Get the desired data.
238 :     my @genomes = $sprout->GetAll(['Genome'], "ORDER BY Genome(id)", [], ['Genome(id)',
239 :     'Genome(genus)',
240 :     'Genome(species)',
241 :     'Genome(unique-characterization)']);
242 :     # Create the genome names from the three pieces of the name.
243 :     my @retVal = map { [$_->[0], join(" ", @{$_}[1..3])] } @genomes;
244 :     # Return the result.
245 :     return @retVal;
246 :     }
247 :    
248 : parrello 1.8 =head3 NameGenomes
249 :    
250 :     C<< my $newList = NameGenomes($sprout, \@genomes); >>
251 :    
252 :     Convert a list of genome IDs to a list of genome IDs with names.
253 :    
254 :     =over 4
255 :    
256 :     =item sprout
257 :    
258 :     The relevant sprout instance.
259 :    
260 :     =item genomes
261 :    
262 :     Reference to a list of genome IDs
263 :    
264 :     =item RETURN
265 :    
266 :     Returns a list of 2-tuples, each tuple consisting of a genome ID followed by a
267 :     genome name.
268 :    
269 :     =back
270 :    
271 :     =cut
272 :    
273 :     sub NameGenomes {
274 :     # Get the parameters.
275 :     my ($sprout, $genomes) = @_;
276 :     # Attach the names.
277 :     my @retVal = map { [$_, $sprout->GenusSpecies($_) ] } @{$genomes};
278 :     # Return the result.
279 :     return @retVal;
280 :     }
281 :    
282 : parrello 1.1 =head3 GetSubsystems
283 :    
284 :     C<< my @subsystems = GetSubsystems($sprout); >>
285 :    
286 :     Get a list of the subsystems in the specified Sprout instance.
287 :    
288 :     =over 4
289 :    
290 :     =item sprout
291 :    
292 :     Sprout instance whose subsystems are desired.
293 :    
294 :     =item RETURN
295 :    
296 :     Returns a list of 2-tuples, each consisting of the subsystem name followed by
297 :     the name of the curator.
298 :    
299 :     =back
300 :    
301 :     =cut
302 :    
303 :     sub GetSubsystems {
304 :     # Get the parameters.
305 :     my ($sprout) = @_;
306 :     # Declare the return variable.
307 :     my @retVal = $sprout->GetAll(['Subsystem'], "ORDER BY Subsystem(id)",
308 :     [], ['Subsystem(id)', 'Subsystem(curator)']);
309 :     # Return the result.
310 :     return @retVal;
311 :     }
312 :    
313 :     =head3 GetFeatures
314 :    
315 :     C<< my @features = GetFeatures($sprout, $genomeID); >>
316 :    
317 :     Return the features of the specified genome in the specified Sprout instance.
318 :    
319 :     =over 4
320 :    
321 :     =item sprout
322 :    
323 :     Sprout instance to use to get the features.
324 :    
325 :     =item genomeID
326 :    
327 :     ID of the genome in question.
328 :    
329 :     =item RETURN
330 :    
331 :     Returns a list of 2-tuples, the first element being the feature ID and the second its
332 :     functional assignment (if any).
333 :    
334 :     =back
335 :    
336 :     =cut
337 :    
338 :     sub GetFeatures {
339 :     # Get the parameters.
340 :     my ($sprout, $genomeID) = @_;
341 :     # Get a list of the feature IDs and map them to their functional assignments.
342 :     my @retVal = map { [$_, $sprout->FunctionOf($_)] } $sprout->GetFlat(['HasFeature'],
343 :     "HasFeature(from-link) = ? ORDER BY HasFeature(to-link)",
344 :     [$genomeID], 'HasFeature(to-link)');
345 :     # Return the result.
346 :     return @retVal;
347 :     }
348 :    
349 :     =head3 ShowLists
350 :    
351 : parrello 1.2 C<< ShowLists($all, %lists); >>
352 : parrello 1.1
353 : parrello 1.2 Display a set of lists. Each list should consist of 2-tuples.
354 : parrello 1.1
355 :     =over 4
356 :    
357 : parrello 1.2 =item all
358 :    
359 :     TRUE if details should be displayed; FALSE if only summaries should be displayed.
360 :    
361 : parrello 1.1 =item lists
362 :    
363 :     A hash mapping list names to list references.
364 :    
365 :     =cut
366 :    
367 :     sub ShowLists {
368 :     # Get the parameters.
369 : parrello 1.2 my $all = shift @_;
370 : parrello 1.1 my %lists = @_;
371 :     # Loop through the lists in alphabetical order by list name.
372 : parrello 1.6 for my $listName (sort keys %lists) {
373 : parrello 1.1 # Get the list itself.
374 :     my $list = $lists{$listName};
375 :     # Get the number of list items.
376 :     my $listSize = scalar @{$list};
377 : parrello 1.6 # Only proceed if the list is nonempty.
378 :     if ($listSize > 0) {
379 : parrello 1.7 my $header = ShowHeader($listName, $listSize);
380 : parrello 1.6 print "$header\n";
381 :     Trace($header) if T(3);
382 :     # If we're at trace level 3, display the list.
383 :     if ($all) {
384 :     # Put a spacer under the title.
385 :     print "\n";
386 :     # Get the width of the name column.
387 :     my $width = 0;
388 :     for my $entryLen (map { length $_->[0] } @{$list}) {
389 :     $width = $entryLen if $entryLen > $width;
390 :     }
391 :     # Now display the list.
392 :     for my $entry (@{$list}) {
393 :     my ($name, $data) = @{$entry};
394 :     print " $name" . (" " x ($width - length $name)) . " $data\n";
395 :     }
396 :     print "\n\n";
397 : parrello 1.1 }
398 :     }
399 :     }
400 :     }
401 :    
402 : parrello 1.7 =head3 ShowHeader
403 :    
404 :     C<< my $header = ShowHeader($name, $count); >>
405 :    
406 :     Return a list header for a list of the specified length.
407 :    
408 :     =over 4
409 :    
410 :     =item name
411 :    
412 :     Name of the list.
413 :    
414 :     =item count
415 :    
416 :     Number of entries in the list.
417 :    
418 :     =item RETURN
419 :    
420 :     Returns a list header that shows the name of the list and the number of entries.
421 :    
422 :     =back
423 :    
424 :     =cut
425 :    
426 :     sub ShowHeader {
427 :     # Get the parameters.
428 :     my ($name, $count) = @_;
429 :     # Declare the return variable.
430 :     my $retVal;
431 :     if ($count == 0) {
432 :     $retVal = "*** $name: none";
433 :     } elsif ($count == 1) {
434 :     $retVal = "*** $name: one";
435 :     } else {
436 :     $retVal = "*** $name: $count";
437 :     }
438 :     # Return the result.
439 :     return $retVal;
440 :     }
441 :    
442 : parrello 1.1 1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3