[Bio] / Sprout / AttrDBRefresh.pl Repository:
ViewVC logotype

Diff of /Sprout/AttrDBRefresh.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5, Wed Nov 29 20:28:52 2006 UTC revision 1.6, Fri Dec 15 03:24:41 2006 UTC
# Line 38  Line 38 
38    
39  =item migrate  =item migrate
40    
41  If specified, then in addition to refreshing the objects, the actual attributes  If specified, the attributes will be migrated from the old FIG system to the
42  will be migrated. If this option is specified on a system that is using the new  new attribute system.
43  attribute system, it will have no effect, but it will take a very long time  
44  doing it.  =item preserve
45    
46    If specified, a comma-delimited list of attributes that should not be migrated.
47    The values of these attributes in the new system will be preserved.
48    
49  =item initializeAndClear  =item initializeAndClear
50    
# Line 62  Line 65 
65  object IDs, the second attribute key names, and the remaining columns the  object IDs, the second attribute key names, and the remaining columns the
66  attribute values.  attribute values.
67    
68    =item hh_copy
69    
70    If specified, the attributes used by the collections system will be converted from the
71    old system to the new one. In the old system, these attributes are assigned either to
72    a genome or to the word "Subsystem". If they are attached to the word "Subsystem", then
73    the value is the subsystem name; otherwise, the value is ignored. In the new attribute
74    system, the attribute key is always "collection" and the value is the collection name.
75    Rather than attaching attributes to the word "Subsystem", we attach them to the
76    subsystem itself.
77    
78  =back  =back
79    
80  =cut  =cut
# Line 83  Line 96 
96                                                trace => [3, "trace level"],                                                trace => [3, "trace level"],
97                                                initializeAndClear => ["", "if specified, the tables of the attribute database will be re-created"],                                                initializeAndClear => ["", "if specified, the tables of the attribute database will be re-created"],
98                                                migrate => ["", "if specified, attribute data will be migrated along with the object IDs"],                                                migrate => ["", "if specified, attribute data will be migrated along with the object IDs"],
99                                                  preserve => ["", "comma-delimited list of attributes to be preserved during migration"],
100                                                phone => ["", "phone number (international format) to call when load finishes"],                                                phone => ["", "phone number (international format) to call when load finishes"],
101                                                load => ["", "file from which to load attribute data"],                                                load => ["", "file from which to load attribute data"],
102                                                backup => ["", "file to which attribute data should be dumped"]                                                backup => ["", "file to which attribute data should be dumped"],
103                                                  hh_copy => ["", "if specified, the attributes used by the collections system will be converted"]
104                                             },                                             },
105                                             "",                                             "",
106                                             @ARGV);                                             @ARGV);
# Line 114  Line 129 
129      if ($options->{migrate}) {      if ($options->{migrate}) {
130          # Migrate the data.          # Migrate the data.
131          Trace("Migrating attribute data.") if T(2);          Trace("Migrating attribute data.") if T(2);
132          my $stats = MigrateAttributes($ca, $fig);          my $stats = MigrateAttributes($ca, $fig, $options->{preserve});
133          Trace("Migration statistics:\n" . $stats->Show()) if T(2);          Trace("Migration statistics:\n" . $stats->Show()) if T(2);
134      }      }
135        if ($options->{hh_copy}) {
136            # Migrate the collections keys to the new system.
137            Trace("Migrating collections data.") if T(2);
138            my $stats = MigrateCollections($ca, $fig);
139            Trace("Collection statistics:\n" . $stats->Show()) if T(2);
140        }
141      if ($options->{load}) {      if ($options->{load}) {
142          # We want to load the attribute data from the specified file, but          # We want to load the attribute data from the specified file, but
143          # first we need to verify that the file exists.          # first we need to verify that the file exists.
# Line 156  Line 177 
177    
178  =head3 MigrateAttributes  =head3 MigrateAttributes
179    
180  C<< my $stats = MigrateAttributes($ca, $fig); >>  C<< my $stats = MigrateAttributes($ca, $fig, $preserve); >>
181    
182  Migrate all the attributes data from the specified FIG instance. This is a long, slow  Migrate all the attributes data from the specified FIG instance. This is a long, slow
183  method used to convert the old attribute data to the new system. Only attribute  method used to convert the old attribute data to the new system. Only attribute
# Line 174  Line 195 
195    
196  A FIG object that can be used to retrieve attributes for migration purposes.  A FIG object that can be used to retrieve attributes for migration purposes.
197    
198    =item preserve (optional)
199    
200    A comma-delimited list of attributes that are not to be migrated.
201    
202  =item RETURN  =item RETURN
203    
204  Returns a statistical object for the load process.  Returns a statistical object for the load process.
# Line 184  Line 209 
209    
210  sub MigrateAttributes {  sub MigrateAttributes {
211      # Get the parameters.      # Get the parameters.
212      my ($ca, $fig) = @_;      my ($ca, $fig, $preserve) = @_;
213      # Create the return value.      # Create the return value.
214      my $retVal = Stats->new('keysIn');      my $retVal = Stats->new('keysIn');
215      # Create a loader for the value table.      # Create a loader for the value table.
216      my $hasValueFor = ERDBLoad->new($ca, 'HasValueFor', $FIG_Config::temp);      my $hasValueFor = ERDBLoad->new($ca, 'HasValueFor', $FIG_Config::temp);
217      # Create a hash for the target objects.      # Create a hash for the target objects.
218      my %targetObjectHash = ();      my %targetObjectHash = ();
219        # Get a list of the attributes we're to preserve.
220        my %preserve = ();
221        if (defined $preserve) {
222            %preserve = map { $_ => 1 } split /\s*,\s*/, $preserve;
223        }
224        # Put the preserved keys into the load file.
225        for my $key (keys %preserve) {
226            Trace("Preserving key $key.") if T(3);
227            my @newValues = $ca->GetAttributes(undef, $key);
228            Trace(scalar(@newValues) . " values of $key will be preserved.");
229            # Put the values into the load file.
230            PutValue($hasValueFor, $ca, @newValues);
231        }
232      # Get a list of all our attribute keys.      # Get a list of all our attribute keys.
233      my @keys = $ca->GetFlat(['AttributeKey'], "", [], 'AttributeKey(id)');      my @allKeys = $ca->GetFlat(['AttributeKey'], "", [], 'AttributeKey(id)');
234      # Loop through them, building the load files. Note that this process will      # Delete the preserved keys.
235      # erase and rebuild the data tables involved.      my @keys = grep { ! $preserve{$_} } @allKeys;
236        # Loop through the reset, building the load files.
237      for my $key (@keys) {      for my $key (@keys) {
238          Trace("Migrating key $key.") if T(3);          Trace("Migrating key $key.") if T(3);
239          $retVal->Add(keysIn => 1);          $retVal->Add(keysIn => 1);
# Line 202  Line 241 
241          my @oldValues = $fig->get_attributes(undef, $key);          my @oldValues = $fig->get_attributes(undef, $key);
242          my $count = scalar(@oldValues);          my $count = scalar(@oldValues);
243          Trace("$count values found for $key in source system.") if T(3);          Trace("$count values found for $key in source system.") if T(3);
244          # Loop through the rows.          # Put the values into the load file.
245          for my $row (@oldValues) {          PutValue($hasValueFor, $ca, @oldValues);
             # Get this row's data.  
             my ($id, undef, @values) = @{$row};  
             # Format the values.  
             my $valueString = join($ca->{splitter}, @values);  
             # Add the value.  
             $hasValueFor->Put($key, $id, $valueString);  
         }  
246      }      }
247      # Close and finish the loads to upload the data.      # Close and finish the loads to upload the data.
248      Trace("Closing value table.") if T(2);      Trace("Closing value table.") if T(2);
# Line 222  Line 254 
254      return $retVal;      return $retVal;
255  }  }
256    
257    =head3 PutValue
258    
259    C<< PutValue($hasValueFor, $ca, @values); >>
260    
261    Put the values from an attribute value list into a HasValueFor load file.
262    
263    =over 4
264    
265    =item hasValueFor
266    
267    Load object for the HasValueFor table.
268    
269    =item ca
270    
271    A CustomAttribute object. We get the splitter value from it.
272    
273    =item value
274    
275    A list of tuples, each consisting of an object ID, a key name, and one or more values.
276    
277    =back
278    
279    =cut
280    
281    sub PutValue {
282        # Get the parameters.
283        my ($hasValueFor, $ca, @values) = @_;
284        # Loop through the value rows.
285        for my $row (@values) {
286            # Get this row's data.
287            my ($id, $key, @values) = @{$row};
288            # Format the values.
289            my $valueString = join($ca->{splitter}, @values);
290            # Add the value.
291            $hasValueFor->Put($key, $id, $valueString);
292        }
293    }
294    
295    =head3 MigrateCollections
296    
297    C<< my $stats = MigrateCollections($ca, $fig); >>
298    
299    This method copies the collection data from the specified FIG object and stores it as values
300    of the C<collection> attribute in the specified custom attribute database.
301    
302    =over 4
303    
304    =item ca
305    
306    Custom attribute database into which the collections are to be stored.
307    
308    =item fig
309    
310    FIG object from which the collection attributes are to be harvested.
311    
312    =item RETURN
313    
314    Returns a statistics object with informatino about the migration.
315    
316    =back
317    
318    =cut
319    
320    sub MigrateCollections {
321        # Get the parameters.
322        my ($ca, $fig) = @_;
323        # Declare the return variable.
324        my $retVal = Stats->new();
325        # Get the collection names.
326        my @collections = qw(higher_plants eukaryotic_ps nonoxygenic_ps hundred_hundred functional_coupling_paper ecoli_essentiality_paper);
327        # Erase the current collection date.
328        $ca->EraseAttribute('collection');
329        # Loop through the collection attributes.
330        for my $cname (@collections) {
331            $retVal->Add(collection => 1);
332            # Get this attribute from the old system.
333            my @rows = $fig->get_attributes(undef, $cname);
334            # Loop through its values.
335            for my $row (@rows) {
336                $retVal->Add($cname => 1);
337                # Determine the object key.
338                my $objectID = ($row->[0] eq 'Subsystem' ? $row->[2] : $row->[0]);
339                $ca->AddAttribute($objectID, 'collection', $cname);
340            }
341        }
342        # Return the statistics.
343        return $retVal;
344    }
345    
346  1;  1;

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3