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

Annotation of /FigKernelPackages/AttributeTransactions.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     package AttributeTransactions;
4 :    
5 :     use TransactionProcessor;
6 :     @ISA = ('TransactionProcessor');
7 :    
8 :     use strict;
9 :     use Tracer;
10 :     use PageBuilder;
11 :     use FIG;
12 :    
13 :     =head1 Attribute Transactions
14 :    
15 :     =head2 Introduction
16 :    
17 :     This is a TransactionProcessor subclass that copies the attributes for the changed
18 :     features.
19 :    
20 :     =head2 Methods
21 :    
22 :     =head3 new
23 :    
24 :     C<< my $xprc = AttributeTransactions->new(\%options, $command, $directory, $idFile); >>
25 :    
26 :     Construct a new AttributeTransactions object.
27 :    
28 :     =over 4
29 :    
30 :     =item options
31 :    
32 :     Reference to a hash table containing the command-line options.
33 :    
34 :     =item command
35 :    
36 :     Command specified on the B<TransactFeatures> command line. This command determines
37 :     which TransactionProcessor subclass is active.
38 :    
39 :     =item directory
40 :    
41 :     Directory containing the transaction files.
42 :    
43 :     =item idFile
44 :    
45 :     Name of the ID file (if needed).
46 :    
47 :     =back
48 :    
49 :     =cut
50 :    
51 :     sub new {
52 :     # Get the parameters.
53 :     my ($class, $options, $command, $directory, $idFile) = @_;
54 : parrello 1.2 # Check to see if we're supposed to check or apply.
55 :     $options->{fix} = ($command eq 'attribute');
56 : parrello 1.1 # Construct via the subclass.
57 :     return TransactionProcessor::new($class, $options, $command, $directory, $idFile);
58 :     }
59 :    
60 :     =head3 Setup
61 :    
62 :     C<< $xprc->Setup(); >>
63 :    
64 :     Set up to attribute the transactions. This includes reading the ID file.
65 :    
66 :     =cut
67 :     #: Return Type ;
68 :     sub Setup {
69 :     # Get the parameters.
70 :     my ($self) = @_;
71 :     # Read the ID hash from the ID file.
72 :     $self->ReadIDHash();
73 :     }
74 :    
75 :     =head3 SetupGenome
76 :    
77 :     C<< $xprc->SetupGenome(); >>
78 :    
79 :     Set up for processing this genome. All we really need to do here is add
80 :     counters to the statistics object.
81 :    
82 :     =cut
83 :     #: Return Type ;
84 :     sub SetupGenome {
85 :     # Get the parameters.
86 :     my ($self) = @_;
87 :     # Create the statistic names.
88 :     $self->AddStats("attributes");
89 :     }
90 :    
91 :     =head3 Change
92 :    
93 :     C<< $xprc->Change($fid, $newID, $locations, $aliases, $translation); >>
94 :    
95 :     Replace a feature in the data store. We copy the attributes from the old feature
96 :     ID to the new one.
97 :    
98 :     =over 4
99 :    
100 :     =item fid
101 :    
102 :     ID of the feature being changed.
103 :    
104 :     =item newID
105 :    
106 :     New ID to give to the feature.
107 :    
108 :     =item locations
109 :    
110 :     New location to give to the feature, in the form of a comma-separated list of location
111 :     strings in SEED format.
112 :    
113 :     =item aliases (optional)
114 :    
115 :     A new list of alias names for the feature.
116 :    
117 :     =item translation (optional)
118 :    
119 :     New protein translation string for the feature. If this field is omitted and
120 :     the feature is a peg, the translation will be generated by normal means.
121 :    
122 :     =back
123 :    
124 :     =cut
125 :    
126 :     sub Change {
127 :     my ($self, $fid, $newID, $locations, $aliases, $translation) = @_;
128 :     my $fig = $self->{fig};
129 :     # Extract the feature type and ordinal number from the new ID.
130 :     my ($ftype, $ordinal, $key) = $self->ParseNewID($newID);
131 :     # Get the real ID.
132 :     my $realID = $self->GetRealID($ordinal, $key);
133 : parrello 1.3 # Delete any existing attributes on the target.
134 :     my @obsoleteAttributes = $fig->get_attributes($realID);
135 :     for my $attribute (@obsoleteAttributes) {
136 :     # The attribute descriptor is actually a four-tuple, but we
137 :     # only need the first three.
138 :     my ($oldID, $key, $value) = @{$attribute};
139 : parrello 1.4 # Check to see if we're really doing this.
140 :     if ($self->Option('fix')) {
141 :     # Go ahead and do it.
142 :     $fig->delete_attribute($realID, $key, $value);
143 :     } else {
144 :     # Just trace it.
145 :     Trace("Attribute $key would be cleaned from $realID.") if T(4);
146 :     }
147 : parrello 1.3 $self->IncrementStat("obsoleted");
148 :     }
149 : parrello 1.1 # Get the old attributes.
150 :     my @attributes = $fig->get_attributes($fid);
151 :     # Loop through the attributes, adding them to the replacement feature.
152 :     for my $attribute (@attributes) {
153 :     # The attribute descriptor is actually a four-tuple.
154 :     my ($oldID, $key, $value, $url) = @{$attribute};
155 : parrello 1.2 # Check to see if we're really doing this.
156 :     if ($self->Option('fix')) {
157 :     # Go ahead and do it.
158 :     $fig->add_attribute($realID, $key, $value, $url);
159 :     } else {
160 :     # Just trace it.
161 : parrello 1.4 Trace("Attribute $key would be moved to $realID.") if T(4);
162 : parrello 1.2 }
163 : parrello 1.1 # Record this operation.
164 :     $self->IncrementStat("attributes");
165 :     }
166 :     }
167 :    
168 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3