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

Annotation of /Sprout/NewStuffCheck.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (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.1 =item user
17 :    
18 :     Name suffix to be used for log files. If omitted, the PID is used.
19 :    
20 :     =item trace
21 :    
22 :     Numeric trace level. A higher trace level causes more messages to appear. The
23 :     default trace level is 2. Tracing will be directly to the standard output
24 :     as well as to a C<trace>I<User>C<.log> file in the FIG temporary directory,
25 :     where I<User> is the value of the B<user> option above.
26 :    
27 :     =item sql
28 :    
29 :     If specified, turns on tracing of SQL activity.
30 :    
31 :     =item background
32 :    
33 :     Save the standard and error output to files. The files will be created
34 :     in the FIG temporary directory and will be named C<err>I<User>C<.log> and
35 :     C<out>I<User>C<.log>, respectively, where I<User> is the value of the
36 :     B<user> option above.
37 :    
38 :     =item h
39 :    
40 :     Display this command's parameters and options.
41 :    
42 :     =item phone
43 :    
44 :     Phone number to message when the script is complete.
45 :    
46 :     =back
47 :    
48 :     =cut
49 :    
50 :     use strict;
51 :     use Tracer;
52 :     use DocUtils;
53 :     use TestUtils;
54 :     use Cwd;
55 :     use File::Copy;
56 :     use File::Path;
57 :     use FIG;
58 :     use SFXlate;
59 :     use Sprout;
60 :    
61 :     # Get the command-line options and parameters.
62 :     my ($options, @parameters) = StandardSetup([qw(Sprout) ],
63 :     {
64 : parrello 1.5 trace => ["2-", "tracing level; use a minus to prevent tracing to standard output"],
65 : parrello 1.2 summary => ["", "if specified, detailed lists of the different items will not be displayed"],
66 : parrello 1.1 phone => ["", "phone number (international format) to call when load finishes"],
67 :     },
68 :     "",
69 :     @ARGV);
70 :     # Set a variable to contain return type information.
71 :     my $rtype;
72 :     # Insure we catch errors.
73 :     eval {
74 : parrello 1.2 Trace("Processing genomes.") if T(2);
75 : parrello 1.1 # Get the old Sprout.
76 :     my $oldSprout = SFXlate->new_sprout_only($FIG_Config::oldSproutDB);
77 :     # Get its genomes in alphabetical order.
78 :     my @oldGenomes = GetGenes($oldSprout);
79 :     # Get the new Sprout.
80 :     my $newSprout = SFXlate->new_sprout_only();
81 :     # Get its genomes in alphabetical order.
82 :     my @newGenomes = GetGenes($newSprout);
83 :     # Compare the two gene lists.
84 :     my ($insertedGenomes, $deletedGenomes) = Tracer::CompareLists(\@newGenomes, \@oldGenomes);
85 :     # Display the lists.
86 : parrello 1.2 ShowLists(! $options->{summary},
87 :     'New Genomes' => $insertedGenomes,
88 :     'Deleted Genomes' => $deletedGenomes);
89 : parrello 1.1 # Next, we get the subsystems.
90 : parrello 1.2 Trace("Processing subsystems.") if T(2);
91 : parrello 1.1 my @oldSubsystems = GetSubsystems($oldSprout);
92 :     my @newSubsystems = GetSubsystems($newSprout);
93 :     # Compare and display the subsystem lists.
94 :     my ($insertedSubs, $deletedSubs) = Tracer::CompareLists(\@newSubsystems, \@oldSubsystems);
95 : parrello 1.2 ShowLists(! $options->{summary},
96 :     'New Subsystems' => $insertedSubs,
97 :     'Deleted Subsystems' => $deletedSubs);
98 : parrello 1.1 # Now we process the features of the common genes. First we need a hash
99 :     # of the inserted stuff so we know to skip it.
100 :     my %skipGenes = map { $_->[0] => 1 } @{$insertedGenomes};
101 :     # Loop through the genomees.
102 :     for my $genome (@newGenomes) {
103 :     # Only process this gene if it's common to both
104 :     my ($genomeID, $genomeName) = @{$genome};
105 :     if (! exists $skipGenes{$genomeID}) {
106 : parrello 1.2 Trace("Processing $genomeID.") if T(3);
107 : parrello 1.1 # Get the new and old features. This will be very stressful to the machine,
108 :     # because there are lots of features.
109 :     my @oldFeatures = GetFeatures($oldSprout, $genomeID);
110 :     my @newFeatures = GetFeatures($newSprout, $genomeID);
111 : parrello 1.2 Trace("Comparing features for $genomeID.") if T(3);
112 : parrello 1.1 # Compare the lists.
113 :     my ($insertedFeatures, $deletedFeatures) = Tracer::CompareLists(\@newFeatures, \@oldFeatures);
114 :     # If either list has data, we want to display it.
115 : parrello 1.3 if (scalar @{$insertedFeatures} + scalar @{$deletedFeatures} > 0) {
116 : parrello 1.2 Trace("Displaying feature differences.") if T(3);
117 : parrello 1.5 ShowLists(! $options->{summary},
118 : parrello 1.2 "New Features for $genomeID" => $insertedFeatures,
119 : parrello 1.1 "Features Deleted from $genomeID" => $deletedFeatures);
120 :     }
121 :     }
122 :     }
123 :     };
124 :     if ($@) {
125 :     Trace("Script failed with error: $@") if T(0);
126 :     $rtype = "error";
127 :     } else {
128 :     Trace("Script complete.") if T(2);
129 :     $rtype = "no error";
130 :     }
131 :     if ($options->{phone}) {
132 :     my $msgID = Tracer::SendSMS($options->{phone}, "Subsystem Checker terminated with $rtype.");
133 :     if ($msgID) {
134 :     Trace("Phone message sent with ID $msgID.") if T(2);
135 :     } else {
136 :     Trace("Phone message not sent.") if T(2);
137 :     }
138 :     }
139 :    
140 :     =head3 GetGenes
141 :    
142 :     C<< my @geneList = GetGenes($sprout); >>
143 :    
144 :     Return a list of the genomes in the specified Sprout instance. The genomes
145 :     are returned in alphabetical order by genome ID.
146 :    
147 :     =over 4
148 :    
149 :     =item sprout
150 :    
151 :     Sprout instance whose gene list is desired.
152 :    
153 :     =item RETURN
154 :    
155 :     Returns a list of two-tuples. The first element in each tuple is the genome ID,
156 :     and the second is the genome name (genus, species, strain).
157 :    
158 :     =back
159 :    
160 :     =cut
161 :    
162 :     sub GetGenes {
163 :     # Get the parameters.
164 :     my ($sprout) = @_;
165 :     # Get the desired data.
166 :     my @genomes = $sprout->GetAll(['Genome'], "ORDER BY Genome(id)", [], ['Genome(id)',
167 :     'Genome(genus)',
168 :     'Genome(species)',
169 :     'Genome(unique-characterization)']);
170 :     # Create the genome names from the three pieces of the name.
171 :     my @retVal = map { [$_->[0], join(" ", @{$_}[1..3])] } @genomes;
172 :     # Return the result.
173 :     return @retVal;
174 :     }
175 :    
176 :     =head3 GetSubsystems
177 :    
178 :     C<< my @subsystems = GetSubsystems($sprout); >>
179 :    
180 :     Get a list of the subsystems in the specified Sprout instance.
181 :    
182 :     =over 4
183 :    
184 :     =item sprout
185 :    
186 :     Sprout instance whose subsystems are desired.
187 :    
188 :     =item RETURN
189 :    
190 :     Returns a list of 2-tuples, each consisting of the subsystem name followed by
191 :     the name of the curator.
192 :    
193 :     =back
194 :    
195 :     =cut
196 :    
197 :     sub GetSubsystems {
198 :     # Get the parameters.
199 :     my ($sprout) = @_;
200 :     # Declare the return variable.
201 :     my @retVal = $sprout->GetAll(['Subsystem'], "ORDER BY Subsystem(id)",
202 :     [], ['Subsystem(id)', 'Subsystem(curator)']);
203 :     # Return the result.
204 :     return @retVal;
205 :     }
206 :    
207 :     =head3 GetFeatures
208 :    
209 :     C<< my @features = GetFeatures($sprout, $genomeID); >>
210 :    
211 :     Return the features of the specified genome in the specified Sprout instance.
212 :    
213 :     =over 4
214 :    
215 :     =item sprout
216 :    
217 :     Sprout instance to use to get the features.
218 :    
219 :     =item genomeID
220 :    
221 :     ID of the genome in question.
222 :    
223 :     =item RETURN
224 :    
225 :     Returns a list of 2-tuples, the first element being the feature ID and the second its
226 :     functional assignment (if any).
227 :    
228 :     =back
229 :    
230 :     =cut
231 :    
232 :     sub GetFeatures {
233 :     # Get the parameters.
234 :     my ($sprout, $genomeID) = @_;
235 :     # Get a list of the feature IDs and map them to their functional assignments.
236 :     my @retVal = map { [$_, $sprout->FunctionOf($_)] } $sprout->GetFlat(['HasFeature'],
237 :     "HasFeature(from-link) = ? ORDER BY HasFeature(to-link)",
238 :     [$genomeID], 'HasFeature(to-link)');
239 :     # Return the result.
240 :     return @retVal;
241 :     }
242 :    
243 :     =head3 ShowLists
244 :    
245 : parrello 1.2 C<< ShowLists($all, %lists); >>
246 : parrello 1.1
247 : parrello 1.2 Display a set of lists. Each list should consist of 2-tuples.
248 : parrello 1.1
249 :     =over 4
250 :    
251 : parrello 1.2 =item all
252 :    
253 :     TRUE if details should be displayed; FALSE if only summaries should be displayed.
254 :    
255 : parrello 1.1 =item lists
256 :    
257 :     A hash mapping list names to list references.
258 :    
259 :     =cut
260 :    
261 :     sub ShowLists {
262 :     # Get the parameters.
263 : parrello 1.2 my $all = shift @_;
264 : parrello 1.1 my %lists = @_;
265 :     # Loop through the lists in alphabetical order by list name.
266 :     for my $listName (keys %lists) {
267 :     # Get the list itself.
268 :     my $list = $lists{$listName};
269 :     # Get the number of list items.
270 :     my $listSize = scalar @{$list};
271 :     # Display the header.
272 : parrello 1.4 my $header;
273 : parrello 1.1 if ($listSize == 0) {
274 : parrello 1.4 $header = "*** $listName: no entries";
275 : parrello 1.1 } elsif ($listSize == 1) {
276 : parrello 1.4 $header = "*** $listName: one entry";
277 : parrello 1.1 } else {
278 : parrello 1.4 $header = "*** $listName: $listSize entries";
279 : parrello 1.1 }
280 : parrello 1.4 print "$header\n";
281 :     Trace($header) if T(3);
282 : parrello 1.1 # If we're at trace level 3, display the list.
283 : parrello 1.2 if ($all) {
284 : parrello 1.1 # Put a spacer under the title.
285 : parrello 1.2 print "\n";
286 : parrello 1.1 # Get the width of the name column.
287 :     my $width = 0;
288 :     for my $entryLen (map { length $_->[0] } @{$list}) {
289 :     $width = $entryLen if $entryLen > $width;
290 :     }
291 :     # Now display the list.
292 :     for my $entry (@{$list}) {
293 :     my ($name, $data) = @{$entry};
294 : parrello 1.2 print " $name" . (" " x ($width - length $name)) . " $data\n";
295 : parrello 1.1 }
296 : parrello 1.2 print "\n\n";
297 : parrello 1.1 }
298 :     }
299 :     }
300 :    
301 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3