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

Annotation of /FigKernelScripts/TransactFeatures.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3