[Bio] / Sprout / SproutLoad.pm Repository:
ViewVC logotype

Diff of /Sprout/SproutLoad.pm

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

revision 1.40, Thu Jun 8 15:37:32 2006 UTC revision 1.70, Wed Sep 27 12:58:18 2006 UTC
# Line 120  Line 120 
120                      # an omitted access code can be defaulted to 1.                      # an omitted access code can be defaulted to 1.
121                      for my $genomeLine (@genomeList) {                      for my $genomeLine (@genomeList) {
122                          my ($genomeID, $accessCode) = split("\t", $genomeLine);                          my ($genomeID, $accessCode) = split("\t", $genomeLine);
123                          if (undef $accessCode) {                          if (! defined($accessCode)) {
124                              $accessCode = 1;                              $accessCode = 1;
125                          }                          }
126                          $genomes{$genomeID} = $accessCode;                          $genomes{$genomeID} = $accessCode;
# Line 136  Line 136 
136      # We only need it if load-only is NOT specified.      # We only need it if load-only is NOT specified.
137      if (! $options->{loadOnly}) {      if (! $options->{loadOnly}) {
138          if (! defined $subsysFile || $subsysFile eq '') {          if (! defined $subsysFile || $subsysFile eq '') {
139              # Here we want all the NMPDR subsystems. First we get the whole list.              # Here we want all the usable subsystems. First we get the whole list.
140              my @subs = $fig->all_subsystems();              my @subs = $fig->all_subsystems();
141              # Loop through, checking for the NMPDR file.              # Loop through, checking for usability.
142              for my $sub (@subs) {              for my $sub (@subs) {
143                  if (-e "$FIG_Config::data/Subsystems/$sub/NMPDR") {                  if ($fig->usable_subsystem($sub)) {
144                      $subsystems{$sub} = 1;                      $subsystems{$sub} = 1;
145                  }                  }
146              }              }
# Line 266  Line 266 
266              my $extra = join " ", @extraData;              my $extra = join " ", @extraData;
267              # Get the full taxonomy.              # Get the full taxonomy.
268              my $taxonomy = $fig->taxonomy_of($genomeID);              my $taxonomy = $fig->taxonomy_of($genomeID);
269                # Open the NMPDR group file for this genome.
270                my $group;
271                if (open(TMP, "<$FIG_Config::organisms/$genomeID/NMPDR") &&
272                    defined($group = <TMP>)) {
273                    # Clean the line ending.
274                    chomp $group;
275                } else {
276                    # No group, so use the default.
277                    $group = $FIG_Config::otherGroup;
278                }
279                close TMP;
280              # Output the genome record.              # Output the genome record.
281              $loadGenome->Put($genomeID, $accessCode, $fig->is_complete($genomeID), $genus,              $loadGenome->Put($genomeID, $accessCode, $fig->is_complete($genomeID), $genus,
282                               $species, $extra, $taxonomy);                               $group, $species, $extra, $taxonomy);
283              # Now we loop through each of the genome's contigs.              # Now we loop through each of the genome's contigs.
284              my @contigs = $fig->all_contigs($genomeID);              my @contigs = $fig->all_contigs($genomeID);
285              for my $contigID (@contigs) {              for my $contigID (@contigs) {
# Line 340  Line 351 
351      my $fig = $self->{fig};      my $fig = $self->{fig};
352      # Get the genome hash.      # Get the genome hash.
353      my $genomeFilter = $self->{genomes};      my $genomeFilter = $self->{genomes};
354      my $genomeCount = (keys %{$genomeFilter});      # Set up an ID counter for the PCHs.
355      my $featureCount = $genomeCount * 4000;      my $pchID = 0;
356      # Start the loads.      # Start the loads.
357      my $loadCoupling = $self->_TableLoader('Coupling');      my $loadCoupling = $self->_TableLoader('Coupling');
358      my $loadIsEvidencedBy = $self->_TableLoader('IsEvidencedBy', $self->PrimaryOnly);      my $loadIsEvidencedBy = $self->_TableLoader('IsEvidencedBy', $self->PrimaryOnly);
# Line 375  Line 386 
386                  for my $coupleData (@couplings) {                  for my $coupleData (@couplings) {
387                      my ($peg2, $score) = @{$coupleData};                      my ($peg2, $score) = @{$coupleData};
388                      # Compute the coupling ID.                      # Compute the coupling ID.
389                      my $coupleID = Sprout::CouplingID($peg1, $peg2);                      my $coupleID = $self->{erdb}->CouplingID($peg1, $peg2);
390                      if (! exists $dupHash{$coupleID}) {                      if (! exists $dupHash{$coupleID}) {
391                          $loadCoupling->Add("couplingIn");                          $loadCoupling->Add("couplingIn");
392                          # Here we have a new coupling to store in the load files.                          # Here we have a new coupling to store in the load files.
# Line 411  Line 422 
422                              }                              }
423                          }                          }
424                          for my $evidenceID (keys %evidenceMap) {                          for my $evidenceID (keys %evidenceMap) {
425                                # Get the ID for this evidence.
426                                $pchID++;
427                              # Create the evidence record.                              # Create the evidence record.
428                              my ($peg3, $peg4, $usage) = @{$evidenceMap{$evidenceID}};                              my ($peg3, $peg4, $usage) = @{$evidenceMap{$evidenceID}};
429                              $loadPCH->Put($evidenceID, $usage);                              $loadPCH->Put($pchID, $usage);
430                              # Connect it to the coupling.                              # Connect it to the coupling.
431                              $loadIsEvidencedBy->Put($coupleID, $evidenceID);                              $loadIsEvidencedBy->Put($coupleID, $pchID);
432                              # Connect it to the features.                              # Connect it to the features.
433                              $loadUsesAsEvidence->Put($evidenceID, $peg3, 1);                              $loadUsesAsEvidence->Put($pchID, $peg3, 1);
434                              $loadUsesAsEvidence->Put($evidenceID, $peg4, 2);                              $loadUsesAsEvidence->Put($pchID, $peg4, 2);
435                          }                          }
436                      }                      }
437                  }                  }
# Line 447  Line 460 
460      FeatureUpstream      FeatureUpstream
461      IsLocatedIn      IsLocatedIn
462      HasFeature      HasFeature
463        HasRoleInSubsystem
464    
465  =over 4  =over 4
466    
# Line 472  Line 486 
486      my $loadFeatureLink = $self->_TableLoader('FeatureLink');      my $loadFeatureLink = $self->_TableLoader('FeatureLink');
487      my $loadFeatureTranslation = $self->_TableLoader('FeatureTranslation');      my $loadFeatureTranslation = $self->_TableLoader('FeatureTranslation');
488      my $loadFeatureUpstream = $self->_TableLoader('FeatureUpstream');      my $loadFeatureUpstream = $self->_TableLoader('FeatureUpstream');
489      my $loadHasFeature = $self->_TableLoader('HasFeature');      my $loadHasFeature = $self->_TableLoader('HasFeature', $self->PrimaryOnly);
490        my $loadHasRoleInSubsystem = $self->_TableLoader('HasRoleInSubsystem', $self->PrimaryOnly);
491      # Get the maximum sequence size. We need this later for splitting up the      # Get the maximum sequence size. We need this later for splitting up the
492      # locations.      # locations.
493      my $chunkSize = $self->{sprout}->MaxSegment();      my $chunkSize = $self->{sprout}->MaxSegment();
# Line 486  Line 501 
501              $loadFeature->Add("genomeIn");              $loadFeature->Add("genomeIn");
502              # Get the feature list for this genome.              # Get the feature list for this genome.
503              my $features = $fig->all_features_detailed($genomeID);              my $features = $fig->all_features_detailed($genomeID);
504                # Sort and count the list.
505                my @featureTuples = sort { $a->[0] cmp $b->[0] } @{$features};
506                my $count = scalar @featureTuples;
507                Trace("$count features found for genome $genomeID.") if T(3);
508                # Set up for our duplicate-feature check.
509                my $oldFeatureID = "";
510              # Loop through the features.              # Loop through the features.
511              for my $featureData (@{$features}) {              for my $featureTuple (@featureTuples) {
                 $loadFeature->Add("featureIn");  
512                  # Split the tuple.                  # Split the tuple.
513                  my ($featureID, $locations, undef, $type) = @{$featureData};                  my ($featureID, $locations, undef, $type) = @{$featureTuple};
514                    # Check for duplicates.
515                    if ($featureID eq $oldFeatureID) {
516                        Trace("Duplicate feature $featureID found.") if T(1);
517                    } else {
518                        $oldFeatureID = $featureID;
519                        # Count this feature.
520                        $loadFeature->Add("featureIn");
521                        # Get the functional assignment.
522                        my $assignment = $fig->function_of($featureID);
523                  # Create the feature record.                  # Create the feature record.
524                  $loadFeature->Put($featureID, 1, $type);                      $loadFeature->Put($featureID, 1, $type, $assignment);
525                  # Link it to the parent genome.                  # Link it to the parent genome.
526                  $loadHasFeature->Put($genomeID, $featureID, $type);                  $loadHasFeature->Put($genomeID, $featureID, $type);
527                  # Create the aliases.                  # Create the aliases.
# Line 517  Line 546 
546                          $loadFeatureUpstream->Put($featureID, $upstream);                          $loadFeatureUpstream->Put($featureID, $upstream);
547                      }                      }
548                  }                  }
549                        # Now we need to find the subsystems this feature participates in.
550                        my @subsystems = $fig->peg_to_subsystems($featureID);
551                        for my $subsystem (@subsystems) {
552                            $loadHasRoleInSubsystem->Put($featureID, $genomeID, $type, $subsystem);
553                        }
554                  # This part is the roughest. We need to relate the features to contig                  # This part is the roughest. We need to relate the features to contig
555                  # locations, and the locations must be split so that none of them exceed                  # locations, and the locations must be split so that none of them exceed
556                  # the maximum segment size. This simplifies the genes_in_region processing                  # the maximum segment size. This simplifies the genes_in_region processing
# Line 546  Line 580 
580              }              }
581          }          }
582      }      }
583        }
584      # Finish the loads.      # Finish the loads.
585      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
586      return $retVal;      return $retVal;
# Line 594  Line 629 
629              Trace("Processing features for genome $genomeID.") if T(3);              Trace("Processing features for genome $genomeID.") if T(3);
630              # Get the feature list for this genome.              # Get the feature list for this genome.
631              my $features = $fig->all_features_detailed($genomeID);              my $features = $fig->all_features_detailed($genomeID);
632                # Count the BBHs we find.
633                my $bbhCount = 0;
634              # Loop through the features.              # Loop through the features.
635              for my $featureData (@{$features}) {              for my $featureData (@{$features}) {
636                  # Split the tuple.                  # Split the tuple.
# Line 609  Line 646 
646                      if ($genomeHash->{$targetGenomeID}) {                      if ($genomeHash->{$targetGenomeID}) {
647                          $loadIsBidirectionalBestHitOf->Put($featureID, $targetID, $targetGenomeID,                          $loadIsBidirectionalBestHitOf->Put($featureID, $targetID, $targetGenomeID,
648                                                             $score);                                                             $score);
649                            $bbhCount++;
650                      }                      }
651                  }                  }
652              }              }
653                Trace("$bbhCount BBHs found for $genomeID.") if T(3);
654          }          }
655      }      }
656      # Finish the loads.      # Finish the loads.
# Line 634  Line 673 
673  The following relations are loaded by this method.  The following relations are loaded by this method.
674    
675      Subsystem      Subsystem
676        SubsystemClass
677      Role      Role
678      RoleEC      RoleEC
679      SSCell      SSCell
# Line 696  Line 736 
736      my $loadConsistsOfGenomes = $self->_TableLoader('ConsistsOfGenomes', $self->PrimaryOnly);      my $loadConsistsOfGenomes = $self->_TableLoader('ConsistsOfGenomes', $self->PrimaryOnly);
737      my $loadHasRoleSubset = $self->_TableLoader('HasRoleSubset', $self->PrimaryOnly);      my $loadHasRoleSubset = $self->_TableLoader('HasRoleSubset', $self->PrimaryOnly);
738      my $loadHasGenomeSubset = $self->_TableLoader('HasGenomeSubset', $self->PrimaryOnly);      my $loadHasGenomeSubset = $self->_TableLoader('HasGenomeSubset', $self->PrimaryOnly);
739        my $loadSubsystemClass = $self->_TableLoader('SubsystemClass', $self->PrimaryOnly);
740      if ($self->{options}->{loadOnly}) {      if ($self->{options}->{loadOnly}) {
741          Trace("Loading from existing files.") if T(2);          Trace("Loading from existing files.") if T(2);
742      } else {      } else {
# Line 721  Line 762 
762                  my $curator = $sub->get_curator();                  my $curator = $sub->get_curator();
763                  my $notes = $sub->get_notes();                  my $notes = $sub->get_notes();
764                  $loadSubsystem->Put($subsysID, $curator, $notes);                  $loadSubsystem->Put($subsysID, $curator, $notes);
765                    my $classList = $fig->subsystem_classification($subsysID);
766                    my @classes = @$classList;
767                    if (@classes) {
768                        for my $class (@classes) {
769                            $loadSubsystemClass->Put($subsysID, $class);
770                        }
771                    }
772                  # Connect it to its roles. Each role is a column in the subsystem spreadsheet.                  # Connect it to its roles. Each role is a column in the subsystem spreadsheet.
773                  for (my $col = 0; defined($roleID = $sub->get_role($col)); $col++) {                  for (my $col = 0; defined($roleID = $sub->get_role($col)); $col++) {
774                      # Connect to this role.                      # Connect to this role.
# Line 785  Line 833 
833                          if ($pegCount > 0) {                          if ($pegCount > 0) {
834                              Trace("$pegCount PEGs in $cellCount cells for $genomeID.") if T(3);                              Trace("$pegCount PEGs in $cellCount cells for $genomeID.") if T(3);
835                              $loadParticipatesIn->Put($genomeID, $subsysID, $variantCode);                              $loadParticipatesIn->Put($genomeID, $subsysID, $variantCode);
                             # Partition the PEGs found into clusters.  
                             my @clusters = $fig->compute_clusters(\@pegsFound, $sub);  
836                              # Create a hash mapping PEG IDs to cluster numbers.                              # Create a hash mapping PEG IDs to cluster numbers.
837                              # We default to -1 for all of them.                              # We default to -1 for all of them.
838                              my %clusterOf = map { $_ => -1 } @pegsFound;                              my %clusterOf = map { $_ => -1 } @pegsFound;
839                                # Partition the PEGs found into clusters.
840                                my @clusters = $fig->compute_clusters([keys %clusterOf], $sub);
841                              for (my $i = 0; $i <= $#clusters; $i++) {                              for (my $i = 0; $i <= $#clusters; $i++) {
842                                  my $subList = $clusters[$i];                                  my $subList = $clusters[$i];
843                                  for my $peg (@{$subList}) {                                  for my $peg (@{$subList}) {
# Line 837  Line 885 
885                      }                      }
886                  }                  }
887              }              }
888            }
889              # Now we loop through the diagrams. We need to create the diagram records              # Now we loop through the diagrams. We need to create the diagram records
890              # and link each diagram to its roles. Note that only roles which occur              # and link each diagram to its roles. Note that only roles which occur
891              # in subsystems (and therefore appear in the %ecToRoles hash) are              # in subsystems (and therefore appear in the %ecToRoles hash) are
# Line 870  Line 919 
919                  }                  }
920              }              }
921          }          }
     }  
922      # Finish the load.      # Finish the load.
923      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
924      return $retVal;      return $retVal;
# Line 923  Line 971 
971          my %propertyKeys = ();          my %propertyKeys = ();
972          my $nextID = 1;          my $nextID = 1;
973          # Loop through the genomes.          # Loop through the genomes.
974          for my $genomeID (keys %{$genomeHash}) {          for my $genomeID (sort keys %{$genomeHash}) {
975              $loadProperty->Add("genomeIn");              $loadProperty->Add("genomeIn");
976              Trace("Generating properties for $genomeID.") if T(3);              Trace("Generating properties for $genomeID.") if T(3);
977              # Get the genome's features. The feature ID is the first field in the              # Get the genome's features. The feature ID is the first field in the
# Line 1042  Line 1090 
1090                  # Get the annotation tuple.                  # Get the annotation tuple.
1091                  my ($peg, $timestamp, $user, $text) = @{$tuple};                  my ($peg, $timestamp, $user, $text) = @{$tuple};
1092                  # Here we fix up the annotation text. "\r" is removed,                  # Here we fix up the annotation text. "\r" is removed,
1093                  # and "\t" and "\n" are escaped. Note we use the "s"                  # and "\t" and "\n" are escaped. Note we use the "gs"
1094                  # modifier so that new-lines inside the text do not                  # modifier so that new-lines inside the text do not
1095                  # stop the substitution search.                  # stop the substitution search.
1096                  $text =~ s/\r//gs;                  $text =~ s/\r//gs;
# Line 1205  Line 1253 
1253      } else {      } else {
1254          Trace("Generating external data.") if T(2);          Trace("Generating external data.") if T(2);
1255          # We loop through the files one at a time. First, the organism file.          # We loop through the files one at a time. First, the organism file.
1256          Open(\*ORGS, "<$FIG_Config::global/ext_org.table");          Open(\*ORGS, "sort +0 -1 -u -t\"\t\" $FIG_Config::global/ext_org.table |");
1257          my $orgLine;          my $orgLine;
1258          while (defined($orgLine = <ORGS>)) {          while (defined($orgLine = <ORGS>)) {
1259              # Clean the input line.              # Clean the input line.
# Line 1217  Line 1265 
1265          close ORGS;          close ORGS;
1266          # Now the function file.          # Now the function file.
1267          my $funcLine;          my $funcLine;
1268          Open(\*FUNCS, "<$FIG_Config::global/ext_func.table");          Open(\*FUNCS, "sort +0 -1 -u -t\"\t\" $FIG_Config::global/ext_func.table |");
1269          while (defined($funcLine = <FUNCS>)) {          while (defined($funcLine = <FUNCS>)) {
1270              # Clean the line ending.              # Clean the line ending.
1271              chomp $funcLine;              chomp $funcLine;
# Line 1349  Line 1397 
1397    
1398      GenomeGroups      GenomeGroups
1399    
1400  There is no direct support for genome groups in FIG, so we access the SEED  Currently, we do not use groups. We used to use them for NMPDR groups,
1401    butThere is no direct support for genome groups in FIG, so we access the SEED
1402  files directly.  files directly.
1403    
1404  =over 4  =over 4
# Line 1375  Line 1424 
1424          Trace("Loading from existing files.") if T(2);          Trace("Loading from existing files.") if T(2);
1425      } else {      } else {
1426          Trace("Generating group data.") if T(2);          Trace("Generating group data.") if T(2);
1427            # Currently there are no groups.
1428        }
1429        # Finish the load.
1430        my $retVal = $self->_FinishAll();
1431        return $retVal;
1432    }
1433    
1434    =head3 LoadSynonymData
1435    
1436    C<< my $stats = $spl->LoadSynonymData(); >>
1437    
1438    Load the synonym groups into Sprout.
1439    
1440    The following relations are loaded by this method.
1441    
1442        SynonymGroup
1443        IsSynonymGroupFor
1444    
1445    The source information for these relations is taken from the C<maps_to_id> method
1446    of the B<FIG> object. Unfortunately, to make this work, we need to use direct
1447    SQL against the FIG database.
1448    
1449    =over 4
1450    
1451    =item RETURNS
1452    
1453    Returns a statistics object for the loads.
1454    
1455    =back
1456    
1457    =cut
1458    #: Return Type $%;
1459    sub LoadSynonymData {
1460        # Get this object instance.
1461        my ($self) = @_;
1462        # Get the FIG object.
1463        my $fig = $self->{fig};
1464        # Get the genome hash.
1465        my $genomeHash = $self->{genomes};
1466        # Create a load object for the table we're loading.
1467        my $loadSynonymGroup = $self->_TableLoader('SynonymGroup');
1468        my $loadIsSynonymGroupFor = $self->_TableLoader('IsSynonymGroupFor');
1469        if ($self->{options}->{loadOnly}) {
1470            Trace("Loading from existing files.") if T(2);
1471        } else {
1472            Trace("Generating synonym group data.") if T(2);
1473            # Get the database handle.
1474            my $dbh = $fig->db_handle();
1475            # Ask for the synonyms.
1476            my $sth = $dbh->prepare_command("SELECT maps_to, syn_id FROM peg_synonyms ORDER BY maps_to");
1477            my $result = $sth->execute();
1478            if (! defined($result)) {
1479                Confess("Database error in Synonym load: " . $sth->errstr());
1480            } else {
1481                # Remember the current synonym.
1482                my $current_syn = "";
1483                # Count the features.
1484                my $featureCount = 0;
1485                # Loop through the synonym/peg pairs.
1486                while (my @row = $sth->fetchrow()) {
1487                    # Get the synonym ID and feature ID.
1488                    my ($syn_id, $peg) = @row;
1489                    # Insure it's for one of our genomes.
1490                    my $genomeID = FIG::genome_of($peg);
1491                    if (exists $genomeHash->{$genomeID}) {
1492                        # Verify the synonym.
1493                        if ($syn_id ne $current_syn) {
1494                            # It's new, so put it in the group table.
1495                            $loadSynonymGroup->Put($syn_id);
1496                            $current_syn = $syn_id;
1497                        }
1498                        # Connect the synonym to the peg.
1499                        $loadIsSynonymGroupFor->Put($syn_id, $peg);
1500                        # Count this feature.
1501                        $featureCount++;
1502                        if ($featureCount % 1000 == 0) {
1503                            Trace("$featureCount features processed.") if T(3);
1504                        }
1505                    }
1506                }
1507            }
1508        }
1509        # Finish the load.
1510        my $retVal = $self->_FinishAll();
1511        return $retVal;
1512    }
1513    
1514    =head3 LoadFamilyData
1515    
1516    C<< my $stats = $spl->LoadFamilyData(); >>
1517    
1518    Load the protein families into Sprout.
1519    
1520    The following relations are loaded by this method.
1521    
1522        Family
1523        IsFamilyForFeature
1524    
1525    The source information for these relations is taken from the C<families_for_protein>,
1526    C<family_function>, and C<sz_family> methods of the B<FIG> object.
1527    
1528    =over 4
1529    
1530    =item RETURNS
1531    
1532    Returns a statistics object for the loads.
1533    
1534    =back
1535    
1536    =cut
1537    #: Return Type $%;
1538    sub LoadFamilyData {
1539        # Get this object instance.
1540        my ($self) = @_;
1541        # Get the FIG object.
1542        my $fig = $self->{fig};
1543        # Get the genome hash.
1544        my $genomeHash = $self->{genomes};
1545        # Create load objects for the tables we're loading.
1546        my $loadFamily = $self->_TableLoader('Family');
1547        my $loadIsFamilyForFeature = $self->_TableLoader('IsFamilyForFeature');
1548        if ($self->{options}->{loadOnly}) {
1549            Trace("Loading from existing files.") if T(2);
1550        } else {
1551            Trace("Generating family data.") if T(2);
1552            # Create a hash for the family IDs.
1553            my %familyHash = ();
1554          # Loop through the genomes.          # Loop through the genomes.
1555          my $line;          for my $genomeID (sort keys %{$genomeHash}) {
1556          for my $genomeID (keys %{$genomeHash}) {              Trace("Processing features for $genomeID.") if T(2);
1557              Trace("Processing $genomeID.") if T(3);              # Loop through this genome's PEGs.
1558              # Open the NMPDR group file for this genome.              for my $fid ($fig->all_features($genomeID, "peg")) {
1559              if (open(TMP, "<$FIG_Config::organisms/$genomeID/NMPDR") &&                  $loadIsFamilyForFeature->Add("features", 1);
1560                  defined($line = <TMP>)) {                  # Get this feature's families.
1561                  # Clean the line ending.                  my @families = $fig->families_for_protein($fid);
1562                  chomp $line;                  # Loop through the families, connecting them to the feature.
1563                  # Add the group to the table. Note that there can only be one group                  for my $family (@families) {
1564                  # per genome.                      $loadIsFamilyForFeature->Put($family, $fid);
1565                  $loadGenomeGroups->Put($genomeID, $line);                      # If this is a new family, create a record for it.
1566                        if (! exists $familyHash{$family}) {
1567                            $familyHash{$family} = 1;
1568                            $loadFamily->Add("families", 1);
1569                            my $size = $fig->sz_family($family);
1570                            my $func = $fig->family_function($family);
1571                            $loadFamily->Put($family, $size, $func);
1572                        }
1573                    }
1574              }              }
             close TMP;  
1575          }          }
1576      }      }
1577      # Finish the load.      # Finish the load.
# Line 1396  Line 1579 
1579      return $retVal;      return $retVal;
1580  }  }
1581    
1582    
1583    
1584  =head2 Internal Utility Methods  =head2 Internal Utility Methods
1585    
1586  =head3 TableLoader  =head3 TableLoader
# Line 1463  Line 1648 
1648      my $retVal = Stats->new();      my $retVal = Stats->new();
1649      # Get the loader list.      # Get the loader list.
1650      my $loadList = $self->{loaders};      my $loadList = $self->{loaders};
1651        # Create a hash to hold the statistics objects, keyed on relation name.
1652        my %loaderHash = ();
1653      # Loop through the list, finishing the loads. Note that if the finish fails, we die      # Loop through the list, finishing the loads. Note that if the finish fails, we die
1654      # ignominiously. At some future point, we want to make the loads restartable.      # ignominiously. At some future point, we want to make the loads more restartable.
1655      while (my $loader = pop @{$loadList}) {      while (my $loader = pop @{$loadList}) {
1656          # Get the relation name.          # Get the relation name.
1657          my $relName = $loader->RelName;          my $relName = $loader->RelName;
# Line 1475  Line 1662 
1662              # Here we really need to finish.              # Here we really need to finish.
1663              Trace("Finishing $relName.") if T(2);              Trace("Finishing $relName.") if T(2);
1664              my $stats = $loader->Finish();              my $stats = $loader->Finish();
1665                $loaderHash{$relName} = $stats;
1666            }
1667        }
1668        # Now we loop through again, actually loading the tables. We want to finish before
1669        # loading so that if something goes wrong at this point, all the load files are usable
1670        # and we don't have to redo all that work.
1671        for my $relName (sort keys %loaderHash) {
1672            # Get the statistics for this relation.
1673            my $stats = $loaderHash{$relName};
1674            # Check for a database load.
1675              if ($self->{options}->{dbLoad}) {              if ($self->{options}->{dbLoad}) {
1676                  # Here we want to use the load file just created to load the database.                  # Here we want to use the load file just created to load the database.
1677                  Trace("Loading relation $relName.") if T(2);                  Trace("Loading relation $relName.") if T(2);
# Line 1485  Line 1682 
1682              $retVal->Accumulate($stats);              $retVal->Accumulate($stats);
1683              Trace("Statistics for $relName:\n" . $stats->Show()) if T(2);              Trace("Statistics for $relName:\n" . $stats->Show()) if T(2);
1684          }          }
     }  
1685      # Return the load statistics.      # Return the load statistics.
1686      return $retVal;      return $retVal;
1687  }  }

Legend:
Removed from v.1.40  
changed lines
  Added in v.1.70

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3