[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.16, Wed May 2 06:05:30 2007 UTC revision 1.17, Wed May 23 02:29:59 2007 UTC
# Line 114  Line 114 
114    
115      -mapSubkey=docking_results/^ZINC//      -mapSubkey=docking_results/^ZINC//
116    
117    =item mapObjectID
118    
119    Object ID mapping rule. Consists of a key name, followed by a substitution command enclosed in
120    slashes. For example, to add the prefix C<fig|> to all the object IDs for the C<PRODOM> key,
121    you would code
122    
123        -mapObjectID=PRODOM/^/fig\|/
124    
125  =item dockClean  =item dockClean
126    
127  If specified, Predicted docking results will be removed from the attribute database.  If specified, Predicted docking results will be removed from the attribute database.
# Line 152  Line 160 
160                                                appendLoad => ["", "if specified, no data will be erased before loading from the load file"],                                                appendLoad => ["", "if specified, no data will be erased before loading from the load file"],
161                                                showKeyDef => ["", "if specified, the name of a key whose descriptive data is to be displayed"],                                                showKeyDef => ["", "if specified, the name of a key whose descriptive data is to be displayed"],
162                                                mapSubkey => ["", "instructions for fixing subkey values"],                                                mapSubkey => ["", "instructions for fixing subkey values"],
163                                                  mapObjectID => ["", "instructions for fixing object ID values"],
164                                                dockClean => ["", "if specified, Predicted docking results will be removed from the database"],                                                dockClean => ["", "if specified, Predicted docking results will be removed from the database"],
165                                             },                                             },
166                                             "",                                             "",
# Line 388  Line 397 
397              WritePage($options->{compare}, 'Attribute System Comparison', \@lines);              WritePage($options->{compare}, 'Attribute System Comparison', \@lines);
398          }          }
399      }      }
400      if ($options->{mapSubkey}) {      if ($options->{mapSubkey} || $options->{mapObjectID}) {
401          # Parse out the main key.          # Parse out the main key.
402          my $mapSubkey = $options->{mapSubkey};          my $type = ($options->{mapSubkey} ? 'mapSubkey' : 'mapObjectID');
403          if ($mapSubkey =~ m#([^/]+)(/.+)#) {          my $mapThing = $options->{$type};
404            my $field = ($options->{mapSubkey} ? 'subkey' : 'to-link');
405            if ($mapThing =~ m#([^/]+)(/.+)#) {
406              my ($keyName, $pattern) = ($1, $2);              my ($keyName, $pattern) = ($1, $2);
407              Trace("Processing subkey mapping for $keyName with pattern s$pattern.") if T(2);              Trace("Processing $type mapping for $keyName with pattern s$pattern.") if T(2);
408              # Create a statistics object.              # Create a statistics object.
409              my $results = Stats->new();              my $results = Stats->new();
410              # Get all the subkey values.              # Get all the field values.
411              my %subkeys = map { $_ => 1 } $ca->GetFlat(['HasValueFor'], "HasValueFor(from-link) = ?", [$keyName],              my %things = map { $_ => 1 } $ca->GetFlat(['HasValueFor'], "HasValueFor(from-link) = ?", [$keyName],
412                                                         'HasValueFor(subkey)');                                                         "HasValueFor($field)");
413              my $totalSubkeys = scalar keys %subkeys;              my $totalThings = scalar keys %things;
414              Trace("$totalSubkeys subkeys found.") if T(2);              Trace("$totalThings ${field}s found.") if T(2);
415              # Loop through them, doing updates where necessary.              # Loop through the values, doing updates where necessary.
416              for my $subKey (keys %subkeys) {              for my $thing (keys %things) {
417                  # Count this subkey.                  # Count this subkey.
418                  my $subkeyCount = $results->Add(subkeys => 1);                  my $thingCount = $results->Add("${field}s" => 1);
419                  # Apply the substitution.                  # Apply the substitution.
420                  my $newSubKey = $subKey;                  my $newThing = $thing;
421                  eval("\$newSubKey =~ s$pattern");                  eval("\$newThing =~ s$pattern");
422                  # If the evaluation resulted in an error, stop immediately.                  # If the evaluation resulted in an error, stop immediately.
423                  if ($@) {                  if ($@) {
424                      Confess("Error in substitution pattern: $@");                      Confess("Error in substitution pattern: $@");
425                  } elsif ($newSubKey ne $subKey) {                  } elsif ($newThing ne $thing) {
426                      # Here the substitution worked and it changed the key value.                      # Here the substitution worked and it changed the key value.
427                      # We need to update the database.                      # We need to update the database.
428                      $results->Add(updates => 1);                      $results->Add(updates => 1);
429                      my $count = $ca->UpdateField('HasValueFor(subkey)', $subKey, $newSubKey,                      my $count = $ca->UpdateField("HasValueFor($field)", $thing, $newThing,
430                                                   "HasValueFor(from-link) = ?", [$keyName]);                                                   "HasValueFor(from-link) = ?", [$keyName]);
431                      $results->Add(rowsChanged => $count);                      $results->Add(rowsChanged => $count);
432                  }                  }
433                  # Trace our progress.                  # Trace our progress.
434                  if ($subkeyCount % 100 == 0) {                  if ($thingCount % 100 == 0) {
435                      Trace("$subkeyCount of $totalSubkeys processed.") if T(3);                      Trace("$thingCount of $things processed.") if T(3);
436                  }                  }
437              }              }
438              # Display the statistics.              # Display the statistics.
439              Trace("Statistics from mapSubkey update:\n" . $results->Show()) if T(2);              Trace("Statistics from $field update:\n" . $results->Show()) if T(2);
440          } else {          } else {
441              # Here the incoming parameter was in the wrong format. Mostly this means there              # Here the incoming parameter was in the wrong format. Mostly this means there
442              # was nothing before the slash or no slash was found.              # was nothing before the slash or no slash was found.
443              Confess("Invalid substitution syntax in mapSubkey option.");              Confess("Invalid substitution syntax in map option.");
444          }          }
445      }      }
446      if ($options->{dockClean}) {      if ($options->{dockClean}) {

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3