[Bio] / FigKernelScripts / TransactFeatures.pl Repository:
ViewVC logotype

Annotation of /FigKernelScripts/TransactFeatures.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 Add / Delete / Change Features
4 :    
5 :     This method will run through a set of transaction files, adding, deleting, and changing
6 :     features in the FIG data store. The command takes three input parameters. The first is
7 :     a command. The second specifies a directory full of transaction files. The third
8 :     specifies a file that tells us which feature IDs are available for each organism.
9 :    
10 :     C<TransactFeatures> I<[options]> I<command> I<transactionDirectory> I<idFile>
11 :    
12 :     The supported commands are
13 :    
14 :     =over 4
15 :    
16 :     =item count
17 :    
18 :     Count the number of IDs needed to process the ADD and CHANGE transactions. This
19 :     will produce an listing of the number of feature IDs needed for each
20 :     organism and feature type. This command is mostly a sanity check: it provides
21 :     useful statistics without changing anything.
22 :    
23 :     =item register
24 :    
25 :     Create an ID file by requesting IDs from the clearinghouse. This performs the
26 :     same function as B<count>, but takes the additional step of creating an ID
27 :     file that can be used to process the transactions.
28 :    
29 :     =item process
30 :    
31 :     Process the transactions and update the FIG data store. This will also create
32 :     a copy of each transaction file in which the pseudo-IDs have been replaced by
33 :     real IDs.
34 :    
35 : parrello 1.4 =item annotate
36 :    
37 :     Annotate the features created by the transactions so as to indicate how they were
38 :     derived.
39 :    
40 : parrello 1.7 =item check
41 :    
42 :     Verify that the locations and translations of the new and changed features are
43 :     correct.
44 :    
45 : parrello 1.4 =item fix
46 :    
47 : parrello 1.7 Fix the locations and translations of the new and changed features.
48 : parrello 1.4
49 : parrello 1.8 =item aliasMove
50 :    
51 :     Move the aliases from the old features to the ones that replaced them.
52 :    
53 : parrello 1.9 =item attribute
54 :    
55 :     Move the attributes from the old features to the ones that replaced them.
56 :    
57 : parrello 1.1 =back
58 :    
59 :     =head2 The Transaction File
60 :    
61 :     Each transaction file is a standard tab-delimited file, one transaction per line. The
62 :     name of the file is C<tbl_diff_>I<org> where I<org> is an organism ID. All records in
63 :     the transaction file refer to transactions against the organism encoded in the file
64 :     name.
65 :    
66 :     The file must specify IDs for new features, but the real IDs cannot be known until
67 :     they are requested from the SEED clearing house. Therefore, each new ID is specified
68 :     in a special format consisting of the feature type (C<peg>, C<rna>, and so forth)
69 :     followed by a dot and the 0-based ordinal number of the new ID within that
70 :     feature type. So, for example, if the transaction file consists of a delete,
71 :     a change, and two adds, it might look like this
72 :    
73 :     delete fig|83333.1.peg.2
74 :     change fig|83333.1.peg.6 peg.0 ...
75 :     add peg.1 ...
76 :     add rna.0 ...
77 :    
78 :     Note that the old feature IDs do not participate in the numbering process, and the RNA
79 :     numbering is independent of the PEG numbering. In the discussion below of transaction
80 :     types, a field named I<newID> will always indicate one of these type/number pairs.
81 :     So, the field setup for the B<chang> command is
82 :    
83 :     change fid newID locations aliases translation
84 :    
85 :     And the I<newID> corresponds to the C<peg.6> in the example above.
86 :    
87 :     The first field of each record is the transaction type. The list of subsequent fields
88 :     depends on this type.
89 :    
90 :     =over 4
91 :    
92 :     =item DELETE fid
93 :    
94 :     Deletes a feature. The feature is marked as deleted in the FIG database, which
95 :     causes it to be skipped or ignored by most of the SEED software. The ID of the
96 :     feature to be deleted is the second field (I<fid>).
97 :    
98 :     =item ADD newID locations translation
99 :    
100 :     Adds a new feature. The I<newID> indicates the feature type and its ordinal number.
101 :     The location is a comma-separated list of location strings. The translation is the
102 :     protein translation for the location. If the translation is omitted, then it will
103 :     be generated from the location information in the normal way.
104 :    
105 :     =item CHANGE fid newID locations aliases translation
106 :    
107 :     Changes an existing feature. The current copy of the feature is marked as deleted,
108 :     and a new feature is created with a new ID. All annotations and assignments are
109 :     transferred from the deleted feature to the new one. The location is a
110 :     comma-separated list of location strings. The aliases are specified as a comma-delimited
111 :     list of alternate names for the feature. These replace any existing aliases for the
112 :     old feature. If the alias list is omitted, no aliases will be assigned to the new
113 :     feature. The translation is the protein translation for the location. If the
114 :     translation is omitted, then it will be generated from the location information in the
115 :     normal way.
116 :    
117 :     =back
118 :    
119 :     =head2 The ID File
120 :    
121 :     The ID file is a tab-delimited file containing one record for each feature type
122 :     of each organism that has a transaction file. Each record consists of three
123 :     fields.
124 :    
125 :     =over 4
126 :    
127 :     =item orgID
128 :    
129 :     The ID of the organism being updated.
130 :    
131 :     =item ftype
132 :    
133 :     The relevant feature type.
134 :    
135 :     =item firstNumber
136 :    
137 :     The first available ID number for the organism and feature type.
138 :    
139 :     =back
140 :    
141 :     This file's primary purpose is that it tells us how to create the feature IDs
142 :     for features we'll be adding to the data store, whether it be via a straight
143 :     B<add> or a B<chang> that deletes an old ID and recreates the feature with a
144 :     new ID.
145 :    
146 :     If we need new IDs for an organism not listed in this ID file, an error will be
147 :     thrown.
148 :    
149 :     =head2 Command-Line Options
150 :    
151 :     The command-line options for this script are as follows.
152 :    
153 :     =over 4
154 :    
155 :     =item trace
156 :    
157 :     Numeric trace level. A higher trace level causes more messages to appear. The
158 :     default trace level is 3.
159 :    
160 : parrello 1.2 =item safe
161 :    
162 :     Wrap each organism's processing in a database transaction. This makes the process
163 :     slightly more restartable than it would be otherwise.
164 :    
165 : parrello 1.5 =item noAlias
166 :    
167 :     Assume that the transaction files do not contain aliases. This means that in CHANGE
168 :     records the translation will immediately follow the location.
169 :    
170 : parrello 1.8 =item sql
171 :    
172 :     Trace SQL commands.
173 :    
174 :     =back
175 :    
176 : parrello 1.1 =cut
177 :    
178 :     use strict;
179 :     use Tracer;
180 :     use DocUtils;
181 :     use TestUtils;
182 :     use Cwd;
183 :     use File::Copy;
184 :     use File::Path;
185 :     use FIG;
186 :     use Stats;
187 : parrello 1.3 use TransactionProcessor;
188 :     use ApplyTransactions;
189 :     use CountTransactions;
190 :     use AnnotateTransactions;
191 : parrello 1.9 use AttributeTransactions;
192 : parrello 1.3 use FixTransactions;
193 : parrello 1.8 use MoveAliases;
194 : parrello 1.1
195 :     # Get the command-line options.
196 : parrello 1.8 my ($options, @parameters) = Tracer::ParseCommand({ trace => 3, sql => 0, safe => 0, noAlias => 0 },
197 :     @ARGV);
198 :     # Get the command.
199 :     my $mainCommand = lc shift @parameters;
200 : parrello 1.1 # Set up tracing.
201 :     my $traceLevel = $options->{trace};
202 : parrello 1.8 my $tracing = "$traceLevel Tracer DocUtils FIG";
203 :     if ($options->{sql}) {
204 :     $tracing .= " SQL";
205 :     }
206 :     TSetup($tracing, "TEXT");
207 : parrello 1.1 # Get the FIG object.
208 :     my $fig = FIG->new();
209 : parrello 1.3 # Create the transaction object.
210 :     my $controlBlock;
211 :     if ($mainCommand eq 'count' || $mainCommand eq 'register') {
212 :     $controlBlock = CountTransactions->new($options, $mainCommand, @parameters);
213 :     } elsif ($mainCommand eq 'process') {
214 :     $controlBlock = ApplyTransactions->new($options, $mainCommand, @parameters);
215 : parrello 1.6 } elsif ($mainCommand eq 'annotate') {
216 :     $controlBlock = AnnotateTransactions->new($options, $mainCommand, @parameters);
217 : parrello 1.7 } elsif ($mainCommand eq 'fix' || $mainCommand eq 'check') {
218 : parrello 1.3 $controlBlock = FixTransactions->new($options, $mainCommand, @parameters);
219 : parrello 1.8 } elsif ($mainCommand eq 'aliasmove') {
220 :     $controlBlock = MoveAliases->new($options, $mainCommand, @parameters);
221 : parrello 1.9 } elsif ($mainCommand eq 'attribute') {
222 :     $controlBlock = AttributeTransactions->new($options, $mainCommand, @parameters);
223 : parrello 1.3 } else {
224 :     Confess("Invalid command \"$mainCommand\" specified on command line.");
225 : parrello 1.1 }
226 : parrello 1.3 # Setup the process.
227 :     $controlBlock->Setup();
228 : parrello 1.1 # Verify that the organism directory exists.
229 :     if (! -d $parameters[0]) {
230 :     Confess("Directory of genome files \"$parameters[0]\" not found.");
231 :     } else {
232 :     # Here we have a valid directory, so we need the list of transaction
233 :     # files in it.
234 :     my $orgsFound = 0;
235 :     my %transFiles = ();
236 :     my @transDirectory = OpenDir($parameters[0], 1);
237 :     # The next step is to create a hash of organism IDs to file names. This
238 :     # saves us some painful parsing later.
239 :     for my $transFileName (@transDirectory) {
240 :     if ($transFileName =~ /^tbl_diff_(\d+\.\d+)$/) {
241 :     $transFiles{$1} = "$parameters[0]/$transFileName";
242 :     $orgsFound++;
243 :     }
244 :     }
245 :     Trace("$orgsFound genome transaction files found in directory $parameters[0].") if T(2);
246 :     if (! $orgsFound) {
247 :     Confess("No \"tbl_diff\" files found in directory $parameters[1].");
248 :     } else {
249 :     # Loop through the organisms.
250 :     for my $genomeID (sort keys %transFiles) {
251 : parrello 1.3 # Start this organism.
252 : parrello 1.1 Trace("Processing changes for $genomeID.") if T(3);
253 : parrello 1.3 my $orgFileName = $transFiles{$genomeID};
254 :     $controlBlock->StartGenome($genomeID, $orgFileName);
255 : parrello 1.1 # Open the organism file.
256 :     Open(\*TRANS, "<$orgFileName");
257 : parrello 1.3 # Clear the transaction counter.
258 : parrello 1.1 my $tranCount = 0;
259 :     # Loop through the organism's data.
260 :     while (my $transaction = <TRANS>) {
261 :     # Parse the record.
262 :     chomp $transaction;
263 :     my @fields = split /\t/, $transaction;
264 :     $tranCount++;
265 :     # Save the record number in the control block.
266 :     $controlBlock->{line} = $tranCount;
267 :     # Process according to the transaction type.
268 :     my $command = lc shift @fields;
269 :     if ($command eq 'add') {
270 : parrello 1.3 $controlBlock->Add(@fields);
271 : parrello 1.1 } elsif ($command eq 'delete') {
272 : parrello 1.3 $controlBlock->Delete(@fields);
273 : parrello 1.1 } elsif ($command eq 'change') {
274 : parrello 1.5 # Here we have a special case. If "noalias" is in effect, we need
275 :     # to splice an empty field in before the translation.
276 :     if ($controlBlock->Option("noAlias")) {
277 :     splice @fields, 3, 0, "";
278 :     }
279 : parrello 1.3 $controlBlock->Change(@fields);
280 : parrello 1.1 } else {
281 : parrello 1.3 $controlBlock->AddMessage("Invalid command $command in line $tranCount for genome $genomeID");
282 : parrello 1.1 }
283 : parrello 1.3 $controlBlock->IncrementStat($command);
284 : parrello 1.1 }
285 : parrello 1.3 # Terminate processing for this genome.
286 :     my $orgStats = $controlBlock->EndGenome();
287 : parrello 1.6 Trace("Statistics for $genomeID\n\n" . $orgStats->Show() . "\n") if T(3);
288 : parrello 1.2 # Close the transaction input file.
289 : parrello 1.1 close TRANS;
290 :     }
291 :     }
292 : parrello 1.3 # Terminate processing.
293 :     $controlBlock->Teardown();
294 : parrello 1.6 Trace("Statistics for this run\n\n" . $controlBlock->Show() . "\n") if T(1);
295 : parrello 1.1 Trace("Processing complete.") if T(1);
296 :     }
297 :    
298 :    
299 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3