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

Annotation of /Sprout/NewStuffCheck.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3