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

Annotation of /Sprout/NewStuffCheck.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3