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

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3