[Bio] / FigKernelPackages / FudgeTransactions.pm Repository:
ViewVC logotype

Annotation of /FigKernelPackages/FudgeTransactions.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (view) (download) (as text)

1 : parrello 1.1 #!/usr/bin/perl -w
2 : olson 1.2 #
3 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
4 :     # for Interpretations of Genomes. All Rights Reserved.
5 :     #
6 :     # This file is part of the SEED Toolkit.
7 :     #
8 :     # The SEED Toolkit is free software. You can redistribute
9 :     # it and/or modify it under the terms of the SEED Toolkit
10 :     # Public License.
11 :     #
12 :     # You should have received a copy of the SEED Toolkit Public License
13 :     # along with this program; if not write to the University of Chicago
14 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
15 :     # Genomes at veronika@thefig.info or download a copy from
16 :     # http://www.theseed.org/LICENSE.TXT.
17 :     #
18 :    
19 : parrello 1.1
20 :     package FudgeTransactions;
21 :    
22 :     use TransactionProcessor;
23 :     @ISA = ('TransactionProcessor');
24 :    
25 :     use strict;
26 :     use Tracer;
27 :     use PageBuilder;
28 :     use FIG;
29 :    
30 :     =head1 Fudge Transactions
31 :    
32 :     =head2 Introduction
33 :    
34 :     This is a TransactionProcessor subclass that creates test data from transactions
35 :     that have already been applied. Each ADD is converted into an ADD and a DELETE,
36 :     and each CHANGE is updated to use the new ID. Note that the ID file will need to
37 :     be modified before the transactions can be applied.
38 :    
39 :     =head2 Methods
40 :    
41 :     =head3 new
42 :    
43 :     C<< my $xprc = FudgeTransactions->new(\%options, $command, $directory, $idFile); >>
44 :    
45 :     Construct a new FudgeTransactions object.
46 :    
47 :     =over 4
48 :    
49 :     =item options
50 :    
51 :     Reference to a hash table containing the command-line options.
52 :    
53 :     =item command
54 :    
55 :     Command specified on the B<TransactFeatures> command line. This command determines
56 :     which TransactionProcessor subclass is active.
57 :    
58 :     =item directory
59 :    
60 :     Directory containing the transaction files.
61 :    
62 :     =item idFile
63 :    
64 :     Name of the ID file (if needed).
65 :    
66 :     =back
67 :    
68 :     =cut
69 :    
70 :     sub new {
71 :     # Get the parameters.
72 :     my ($class, $options, $command, $directory, $idFile) = @_;
73 :     # Construct via the subclass.
74 :     return TransactionProcessor::new($class, $options, $command, $directory, $idFile);
75 :     }
76 :    
77 :     =head3 Setup
78 :    
79 :     C<< $xprc->Setup(); >>
80 :    
81 :     Set up to apply the transactions. This includes reading the ID file.
82 :    
83 :     =cut
84 :     #: Return Type ;
85 :     sub Setup {
86 :     # Get the parameters.
87 :     my ($self) = @_;
88 :     # Read the ID hash from the ID file.
89 :     $self->ReadIDHash();
90 :     }
91 :    
92 :    
93 :     =head3 Teardown
94 :    
95 :     C<< $xprc->Teardown(); >>
96 :    
97 :     Update the ID table with high numbers to avoid duplication.
98 :    
99 :     =cut
100 :     #: Return Type ;
101 :     sub Teardown {
102 :     # Get the parameters.
103 :     my ($self) = @_;
104 :     # Get the ID hash.
105 :     my $idHash = $self->IDHash;
106 :     # Loop through the ID hash, creating a new ID file.
107 :     my $countFile = $self->IDFileName;
108 :     Open(\*COUNTFILE, ">$countFile");
109 :     print "\nTable of Counts\n";
110 :     for my $idKey (keys %{$idHash}) {
111 :     $idKey =~ /^(\d+\.\d+)\.([a-z]+)$/;
112 :     my ($org, $ftype) = ($1, $2);
113 :     print COUNTFILE "$org\t$ftype\t9000\n";
114 :     }
115 :     close COUNTFILE;
116 :     Trace("ID file $countFile updated.") if T(2);
117 :     }
118 :    
119 :     =head3 SetupGenome
120 :    
121 :     C<< $xprc->SetupGenome(); >>
122 :    
123 :     Set up for processing this genome. This opens the output file.
124 :    
125 :     =cut
126 :     #: Return Type ;
127 :     sub SetupGenome {
128 :     # Get the parameters.
129 :     my ($self) = @_;
130 :     my $fig = $self->FIG();
131 :     # Create the output file for this genome.
132 :     my $fileBase = $self->CurrentFileName;
133 :     Open(\*TRANSOUT, ">$fileBase.tbl");
134 :     }
135 :    
136 :     =head3 TeardownGenome
137 :    
138 :     C<< $xprc->TeardownGenome(); >>
139 :    
140 :     Clean up after processing this genome. This involves closing the output file and
141 :     doing a rename.
142 :    
143 :     =cut
144 :     #: Return Type ;
145 :     sub TeardownGenome {
146 :     # Get the parameters.
147 :     my ($self) = @_;
148 :     my $fig = $self->FIG();
149 :     # Close the transaction output file.
150 :     close TRANSOUT;
151 :     # Rename the files.
152 :     my $fileBase = $self->CurrentFileName;
153 :     my $nameBase = $fileBase;
154 :     if ($fileBase =~ m!/(.*)$!) {
155 :     $nameBase = $1;
156 :     }
157 :     my $okFlag = rename($fileBase, "$nameBase.bak");
158 :     $okFlag = rename("$fileBase.tbl", $nameBase);
159 :     }
160 :    
161 :     =head3 Add
162 :    
163 :     C<< $xprc->Add($newID, $locations, $translation); >>
164 :    
165 :     Add a new feature to the data store. The Add is transmitted unmodified to the
166 :     output file and then a delete is created for the ID added the last time.
167 :    
168 :     =over 4
169 :    
170 :     =item newID
171 :    
172 :     ID to give to the new feature.
173 :    
174 :     =item locations
175 :    
176 :     Location of the new feature, in the form of a comma-separated list of location
177 :     strings in SEED format.
178 :    
179 :     =item translation (optional)
180 :    
181 :     Protein translation string for the new feature. If this field is omitted and
182 :     the feature is a peg, the translation will be generated by normal means.
183 :    
184 :     =back
185 :    
186 :     =cut
187 :    
188 :     sub Add {
189 :     my ($self, $newID, $locations, $translation) = @_;
190 :     my $fig = $self->{fig};
191 :     # Echo the add to the output file.
192 :     print TRANSOUT "ADD\t$newID\t$locations\t$translation\n";
193 :     # Extract the feature type and ordinal number from the new ID.
194 :     my ($ftype, $ordinal, $key) = $self->ParseNewID($newID);
195 :     # Get the real version of the new ID.
196 :     my $realID = $self->GetRealID($ordinal, $key);
197 :     # Create the delete command.
198 :     print TRANSOUT "DELETE\t$realID\n";
199 :     }
200 :    
201 :     =head3 Change
202 :    
203 :     C<< $xprc->Change($fid, $newID, $locations, $aliases, $translation); >>
204 :    
205 :     Replace a feature to the data store. The feature will be marked for deletion and
206 :     a new feature will be put in its place.
207 :    
208 :     We change this so that it replaces the original real ID.
209 :    
210 :     =over 4
211 :    
212 :     =item fid
213 :    
214 :     ID of the feature being changed.
215 :    
216 :     =item newID
217 :    
218 :     New ID to give to the feature.
219 :    
220 :     =item locations
221 :    
222 :     New location to give to the feature, in the form of a comma-separated list of location
223 :     strings in SEED format.
224 :    
225 :     =item aliases (optional)
226 :    
227 :     A new list of alias names for the feature.
228 :    
229 :     =item translation (optional)
230 :    
231 :     New protein translation string for the feature. If this field is omitted and
232 :     the feature is a peg, the translation will be generated by normal means.
233 :    
234 :     =back
235 :    
236 :     =cut
237 :    
238 :     sub Change {
239 :     my ($self, $fid, $newID, $locations, $aliases, $translation) = @_;
240 :     my $fig = $self->{fig};
241 :     # Extract the feature type and ordinal number from the new ID.
242 :     my ($ftype, $ordinal, $key) = $self->ParseNewID($newID);
243 :     # Get the real version of the new ID.
244 :     my $realID = $self->GetRealID($ordinal, $key);
245 :     # Create the change command.
246 :     print TRANSOUT "CHANGE\t$realID\t$newID\t$locations\t$aliases\t$translation\n";
247 :     }
248 :    
249 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3