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

Annotation of /FigKernelScripts/TransactFeatures.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3