[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.8, Wed Sep 14 09:57:27 2005 UTC revision 1.20, Wed Nov 2 21:54:40 2005 UTC
# Line 10  Line 10 
10      use Sprout;      use Sprout;
11      use Stats;      use Stats;
12      use BasicLocation;      use BasicLocation;
13        use HTML;
14    
15  =head1 Sprout Load Methods  =head1 Sprout Load Methods
16    
# Line 367  Line 368 
368                              # We store this evidence in the hash if the usage                              # We store this evidence in the hash if the usage
369                              # is nonzero or no prior evidence has been found. This                              # is nonzero or no prior evidence has been found. This
370                              # insures that if there is duplicate evidence, we                              # insures that if there is duplicate evidence, we
371                              # at least keep the meaningful ones. Only evidence is                              # at least keep the meaningful ones. Only evidence in
372                              # the hash makes it to the output.                              # the hash makes it to the output.
373                              if ($usage || ! exists $evidenceMap{$evidenceKey}) {                              if ($usage || ! exists $evidenceMap{$evidenceKey}) {
374                                  $evidenceMap{$evidenceKey} = $evidenceData;                                  $evidenceMap{$evidenceKey} = $evidenceData;
# Line 382  Line 383 
383                          $loadIsEvidencedBy->Put($coupleID, $evidenceID);                          $loadIsEvidencedBy->Put($coupleID, $evidenceID);
384                          # Connect it to the features.                          # Connect it to the features.
385                          $loadUsesAsEvidence->Put($evidenceID, $peg3, 1);                          $loadUsesAsEvidence->Put($evidenceID, $peg3, 1);
386                          $loadUsesAsEvidence->Put($evidenceID, $peg4, 1);                          $loadUsesAsEvidence->Put($evidenceID, $peg4, 2);
387                      }                      }
388                  }                  }
389              }              }
# Line 434  Line 435 
435      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
436      my $loadFeature = $self->_TableLoader('Feature', $featureCount);      my $loadFeature = $self->_TableLoader('Feature', $featureCount);
437      my $loadIsLocatedIn = $self->_TableLoader('IsLocatedIn', $featureCount);      my $loadIsLocatedIn = $self->_TableLoader('IsLocatedIn', $featureCount);
438      my ($loadFeatureAlias, $loadFeatureLink, $loadFeatureTranslation, $loadFeatureUpstream);      my $loadFeatureAlias = $self->_TableLoader('FeatureAlias', $featureCount * 6);
439        my ($loadFeatureLink, $loadFeatureTranslation, $loadFeatureUpstream);
440      if (! $limited) {      if (! $limited) {
         $loadFeatureAlias = $self->_TableLoader('FeatureAlias', $featureCount * 6);  
441          $loadFeatureLink = $self->_TableLoader('FeatureLink', $featureCount * 10);          $loadFeatureLink = $self->_TableLoader('FeatureLink', $featureCount * 10);
442          $loadFeatureTranslation = $self->_TableLoader('FeatureTranslation', $featureCount);          $loadFeatureTranslation = $self->_TableLoader('FeatureTranslation', $featureCount);
443          $loadFeatureUpstream = $self->_TableLoader('FeatureUpstream', $featureCount);          $loadFeatureUpstream = $self->_TableLoader('FeatureUpstream', $featureCount);
# Line 455  Line 456 
456          for my $featureData (@{$features}) {          for my $featureData (@{$features}) {
457              $loadFeature->Add("featureIn");              $loadFeature->Add("featureIn");
458              # Split the tuple.              # Split the tuple.
459              my ($featureID, $locations, $aliases, $type) = @{$featureData};              my ($featureID, $locations, undef, $type) = @{$featureData};
460              # Create the feature record.              # Create the feature record.
461              $loadFeature->Put($featureID, 1, $type);              $loadFeature->Put($featureID, 1, $type);
             # The next stuff is for a full load only.  
             if (! $limited) {  
462                  # Create the aliases.                  # Create the aliases.
463                  for my $alias (split /\s*,\s*/, $aliases) {              for my $alias ($fig->feature_aliases($featureID)) {
464                      $loadFeatureAlias->Put($featureID, $alias);                      $loadFeatureAlias->Put($featureID, $alias);
465                  }                  }
466                # The next stuff is for a full load only.
467                if (! $limited) {
468                  # Get the links.                  # Get the links.
469                  my @links = $fig->fid_links($featureID);                  my @links = $fig->fid_links($featureID);
470                  for my $link (@links) {                  for my $link (@links) {
# Line 493  Line 494 
494              # Loop through the locations.              # Loop through the locations.
495              for my $location (@locationList) {              for my $location (@locationList) {
496                  # Parse the location.                  # Parse the location.
497                  my $locObject = BasicLocation->new($location);                  my $locObject = BasicLocation->new("$genomeID:$location");
498                  # Split it into a list of chunks.                  # Split it into a list of chunks.
499                  my @locOList = ();                  my @locOList = ();
500                  while (my $peeling = $locObject->Peel($chunkSize)) {                  while (my $peeling = $locObject->Peel($chunkSize)) {
# Line 599  Line 600 
600    
601      Subsystem      Subsystem
602      Role      Role
603        RoleEC
604      SSCell      SSCell
605      ContainsFeature      ContainsFeature
606      IsGenomeOf      IsGenomeOf
# Line 606  Line 608 
608      OccursInSubsystem      OccursInSubsystem
609      ParticipatesIn      ParticipatesIn
610      HasSSCell      HasSSCell
611        ConsistsOfRoles
612        RoleSubset
613        HasRoleSubset
614        ConsistsOfGenomes
615        GenomeSubset
616        HasGenomeSubset
617        Catalyzes
618    
619  =over 4  =over 4
620    
# Line 615  Line 624 
624    
625  =back  =back
626    
 B<TO DO>  
   
 Generate RoleName table?  
   
627  =cut  =cut
628  #: Return Type $%;  #: Return Type $%;
629  sub LoadSubsystemData {  sub LoadSubsystemData {
# Line 638  Line 643 
643      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
644      my $loadSubsystem = $self->_TableLoader('Subsystem', $subsysCount);      my $loadSubsystem = $self->_TableLoader('Subsystem', $subsysCount);
645      my $loadRole = $self->_TableLoader('Role', $featureCount * 6);      my $loadRole = $self->_TableLoader('Role', $featureCount * 6);
646        my $loadRoleEC = $self->_TableLoader('RoleEC', $featureCount * 6);
647        my $loadCatalyzes = $self->_TableLoader('Catalyzes', $genomeCount * $featureCount);
648      my $loadSSCell = $self->_TableLoader('SSCell', $featureCount * $genomeCount);      my $loadSSCell = $self->_TableLoader('SSCell', $featureCount * $genomeCount);
649      my $loadContainsFeature = $self->_TableLoader('ContainsFeature', $featureCount * $subsysCount);      my $loadContainsFeature = $self->_TableLoader('ContainsFeature', $featureCount * $subsysCount);
650      my $loadIsGenomeOf = $self->_TableLoader('IsGenomeOf', $featureCount * $genomeCount);      my $loadIsGenomeOf = $self->_TableLoader('IsGenomeOf', $featureCount * $genomeCount);
# Line 645  Line 652 
652      my $loadOccursInSubsystem = $self->_TableLoader('OccursInSubsystem', $featureCount * 6);      my $loadOccursInSubsystem = $self->_TableLoader('OccursInSubsystem', $featureCount * 6);
653      my $loadParticipatesIn = $self->_TableLoader('ParticipatesIn', $subsysCount * $genomeCount);      my $loadParticipatesIn = $self->_TableLoader('ParticipatesIn', $subsysCount * $genomeCount);
654      my $loadHasSSCell = $self->_TableLoader('HasSSCell', $featureCount * $genomeCount);      my $loadHasSSCell = $self->_TableLoader('HasSSCell', $featureCount * $genomeCount);
655        my $loadRoleSubset = $self->_TableLoader('RoleSubset', $subsysCount * 50);
656        my $loadGenomeSubset = $self->_TableLoader('GenomeSubset', $subsysCount * 50);
657        my $loadConsistsOfRoles = $self->_TableLoader('ConsistsOfRoles', $featureCount * $genomeCount);
658        my $loadConsistsOfGenomes = $self->_TableLoader('ConsistsOfGenomes', $featureCount * $genomeCount);
659        my $loadHasRoleSubset = $self->_TableLoader('HasRoleSubset', $subsysCount * 50);
660        my $loadHasGenomeSubset = $self->_TableLoader('HasGenomeSubset', $subsysCount * 50);
661      Trace("Beginning subsystem data load.") if T(2);      Trace("Beginning subsystem data load.") if T(2);
662        # This hash will contain the role for each EC. When we're done, this
663        # information will be used to generate the Catalyzes table.
664        my %ecToRoles = ();
665      # Loop through the subsystems. Our first task will be to create the      # Loop through the subsystems. Our first task will be to create the
666      # roles. We do this by looping through the subsystems and creating a      # roles. We do this by looping through the subsystems and creating a
667      # role hash. The hash tracks each role ID so that we don't create      # role hash. The hash tracks each role ID so that we don't create
668      # duplicates. As we move along, we'll connect the roles and subsystems.      # duplicates. As we move along, we'll connect the roles and subsystems
669        # and memorize up the reactions.
670        my ($genomeID, $roleID);
671      my %roleData = ();      my %roleData = ();
672      for my $subsysID (@subsysIDs) {      for my $subsysID (@subsysIDs) {
673          Trace("Creating subsystem $subsysID.") if T(3);          Trace("Creating subsystem $subsysID.") if T(3);
674          $loadSubsystem->Add("subsystemIn");          $loadSubsystem->Add("subsystemIn");
675            # Get the subsystem object.
676            my $sub = $fig->get_subsystem($subsysID);
677          # Create the subsystem record.          # Create the subsystem record.
678          $loadSubsystem->Put($subsysID);          my $curator = $sub->get_curator();
679          # Get the subsystem's roles.          my $notes = $sub->get_notes();
680          my @roles = $fig->subsystem_to_roles($subsysID);          $loadSubsystem->Put($subsysID, $curator, $notes);
681          # Connect the roles to the subsystem. If a role is new, we create          # Connect it to its roles. Each role is a column in the subsystem spreadsheet.
682          # a role record for it.          for (my $col = 0; defined($roleID = $sub->get_role($col)); $col++) {
683          for my $roleID (@roles) {              # Connect to this role.
684              $loadOccursInSubsystem->Add("roleIn");              $loadOccursInSubsystem->Add("roleIn");
685              $loadOccursInSubsystem->Put($roleID, $subsysID);              $loadOccursInSubsystem->Put($roleID, $subsysID, $col);
686                # If it's a new role, add it to the role table.
687              if (! exists $roleData{$roleID}) {              if (! exists $roleData{$roleID}) {
688                  $loadRole->Put($roleID);                  # Get the role's abbreviation.
689                    my $abbr = $sub->get_role_abbr($col);
690                    # Add the role.
691                    $loadRole->Put($roleID, $abbr);
692                  $roleData{$roleID} = 1;                  $roleData{$roleID} = 1;
693                    # Check for an EC number.
694                    if ($roleID =~ /\(EC ([^.]+\.[^.]+\.[^.]+\.[^)]+)\)\s*$/) {
695                        my $ec = $1;
696                        $loadRoleEC->Put($roleID, $ec);
697                        $ecToRoles{$ec} = $roleID;
698                    }
699              }              }
700          }          }
701          # Now all roles for this subsystem have been filled in. We create the          # Now we create the spreadsheet for the subsystem by matching roles to
702          # spreadsheet by matches roles to genomes. To do this, we need to          # genomes. Each genome is a row and each role is a column. We may need
703          # get the genomes on the sheet.          # to actually create the roles as we find them.
704          Trace("Creating subsystem $subsysID spreadsheet.") if T(3);          Trace("Creating subsystem $subsysID spreadsheet.") if T(3);
705          my @genomes = map { $_->[0] } @{$fig->subsystem_genomes($subsysID)};          for (my $row = 0; defined($genomeID = $sub->get_genome($row)); $row++) {
706          for my $genomeID (@genomes) {              # Only proceed if this is one of our genomes.
             # Only process this genome if it's one of ours.  
707              if (exists $genomeHash->{$genomeID}) {              if (exists $genomeHash->{$genomeID}) {
708                  # Connect the genome to the subsystem.                  # Count the PEGs and cells found for verification purposes.
709                  $loadParticipatesIn->Put($genomeID, $subsysID);                  my $pegCount = 0;
710                    my $cellCount = 0;
711                    # Create a list for the PEGs we find. This list will be used
712                    # to generate cluster numbers.
713                    my @pegsFound = ();
714                    # Create a hash that maps spreadsheet IDs to PEGs. We will
715                    # use this to generate the ContainsFeature data after we have
716                    # the cluster numbers.
717                    my %cellPegs = ();
718                    # Get the genome's variant code for this subsystem.
719                    my $variantCode = $sub->get_variant_code($row);
720                  # Loop through the subsystem's roles. We use an index because it is                  # Loop through the subsystem's roles. We use an index because it is
721                  # part of the spreadsheet cell ID.                  # part of the spreadsheet cell ID.
722                  for (my $i = 0; $i <= $#roles; $i++) {                  for (my $col = 0; defined($roleID = $sub->get_role($col)); $col++) {
                     my $role = $roles[$i];  
723                      # Get the features in the spreadsheet cell for this genome and role.                      # Get the features in the spreadsheet cell for this genome and role.
724                      my @pegs = $fig->pegs_in_subsystem_cell($subsysID, $genomeID, $i);                      my @pegs = $sub->get_pegs_from_cell($row, $col);
725                      # Only proceed if features exist.                      # Only proceed if features exist.
726                      if (@pegs > 0) {                      if (@pegs > 0) {
727                          # Create the spreadsheet cell.                          # Create the spreadsheet cell.
728                          my $cellID = "$subsysID:$genomeID:$i";                          $cellCount++;
729                            my $cellID = "$subsysID:$genomeID:$col";
730                          $loadSSCell->Put($cellID);                          $loadSSCell->Put($cellID);
731                          $loadIsGenomeOf->Put($genomeID, $cellID);                          $loadIsGenomeOf->Put($genomeID, $cellID);
732                          $loadIsRoleOf->Put($role, $cellID);                          $loadIsRoleOf->Put($roleID, $cellID);
733                          $loadHasSSCell->Put($subsysID, $cellID);                          $loadHasSSCell->Put($subsysID, $cellID);
734                          # Attach the features to it.                          # Remember its features.
735                          for my $pegID (@pegs) {                          push @pegsFound, @pegs;
736                              $loadContainsFeature->Put($cellID, $pegID);                          $cellPegs{$cellID} = \@pegs;
737                            $pegCount += @pegs;
738                        }
739                    }
740                    # If we found some cells for this genome, we need to compute clusters and
741                    # denote it participates in the subsystem.
742                    if ($pegCount > 0) {
743                        Trace("$pegCount PEGs in $cellCount cells for $genomeID.") if T(3);
744                        $loadParticipatesIn->Put($genomeID, $subsysID, $variantCode);
745                        # Partition the PEGs found into clusters.
746                        my @clusters = $fig->compute_clusters(\@pegsFound, $sub);
747                        # Create a hash mapping PEG IDs to cluster numbers.
748                        # We default to -1 for all of them.
749                        my %clusterOf = map { $_ => -1 } @pegsFound;
750                        for (my $i = 0; $i <= $#clusters; $i++) {
751                            my $subList = $clusters[$i];
752                            for my $peg (@{$subList}) {
753                                $clusterOf{$peg} = $i;
754                            }
755                        }
756                        # Create the ContainsFeature data.
757                        for my $cellID (keys %cellPegs) {
758                            my $cellList = $cellPegs{$cellID};
759                            for my $cellPeg (@$cellList) {
760                                $loadContainsFeature->Put($cellID, $cellPeg, $clusterOf{$cellPeg});
761                            }
762                          }                          }
763                      }                      }
764                  }                  }
765              }              }
766            # Now we need to generate the subsets. The subset names must be concatenated to
767            # the subsystem name to make them unique keys. There are two types of subsets:
768            # genome subsets and role subsets. We do the role subsets first.
769            my @subsetNames = $sub->get_subset_names();
770            for my $subsetID (@subsetNames) {
771                # Create the subset record.
772                my $actualID = "$subsysID:$subsetID";
773                $loadRoleSubset->Put($actualID);
774                # Connect the subset to the subsystem.
775                $loadHasRoleSubset->Put($subsysID, $actualID);
776                # Connect the subset to its roles.
777                my @roles = $sub->get_subset($subsetID);
778                for my $roleID (@roles) {
779                    $loadConsistsOfRoles->Put($actualID, $roleID);
780                }
781            }
782            # Next the genome subsets.
783            @subsetNames = $sub->get_subset_namesR();
784            for my $subsetID (@subsetNames) {
785                # Create the subset record.
786                my $actualID = "$subsysID:$subsetID";
787                $loadGenomeSubset->Put($actualID);
788                # Connect the subset to the subsystem.
789                $loadHasGenomeSubset->Put($subsysID, $actualID);
790                # Connect the subset to its genomes.
791                my @genomes = $sub->get_subsetR($subsetID);
792                for my $genomeID (@genomes) {
793                    $loadConsistsOfGenomes->Put($actualID, $genomeID);
794                }
795            }
796        }
797        # Before we leave, we must create the Catalyzes table. We start with the reactions,
798        # then use the "ecToRoles" table to convert EC numbers to role IDs.
799        my @reactions = $fig->all_reactions();
800        for my $reactionID (@reactions) {
801            # Get this reaction's list of roles. The results will be EC numbers.
802            my @roles = $fig->catalyzed_by($reactionID);
803            # Loop through the roles, creating catalyzation records.
804            for my $thisRole (@roles) {
805                if (exists $ecToRoles{$thisRole}) {
806                    $loadCatalyzes->Put($ecToRoles{$thisRole}, $reactionID);
807                }
808          }          }
809      }      }
810      # Finish the load.      # Finish the load.
# Line 927  Line 1033 
1033                      # Denote we've seen this timestamp.                      # Denote we've seen this timestamp.
1034                      $seenTimestamps{$time} = 1;                      $seenTimestamps{$time} = 1;
1035                  }                  }
1036                }
1037                  # Now loop through the real annotations.                  # Now loop through the real annotations.
1038                  for my $tuple ($fig->feature_annotations($peg, "raw")) {                  for my $tuple ($fig->feature_annotations($peg, "raw")) {
1039                      my ($fid, $timestamp, $user, $text) = @{$tuple};                      my ($fid, $timestamp, $user, $text) = @{$tuple};
# Line 941  Line 1048 
1048                      $text =~ s/Set master function/Set FIG function/s;                      $text =~ s/Set master function/Set FIG function/s;
1049                      # Insure the time stamp is valid.                      # Insure the time stamp is valid.
1050                      if ($timestamp =~ /^\d+$/) {                      if ($timestamp =~ /^\d+$/) {
1051                          # Here it's a number. We need to insure it's unique.                      # Here it's a number. We need to insure the one we use to form
1052                          while ($seenTimestamps{$timestamp}) {                      # the key is unique.
1053                              $timestamp++;                      my $keyStamp = $timestamp;
1054                        while ($seenTimestamps{$keyStamp}) {
1055                            $keyStamp++;
1056                          }                          }
1057                          $seenTimestamps{$timestamp} = 1;                      $seenTimestamps{$keyStamp} = 1;
1058                          my $annotationID = "$peg:$timestamp";                      my $annotationID = "$peg:$keyStamp";
1059                          # Insure the user exists.                          # Insure the user exists.
1060                          if (! $users{$user}) {                          if (! $users{$user}) {
1061                              $loadSproutUser->Put($user, "SEED user");                              $loadSproutUser->Put($user, "SEED user");
# Line 954  Line 1063 
1063                              $users{$user} = 1;                              $users{$user} = 1;
1064                          }                          }
1065                          # Generate the annotation.                          # Generate the annotation.
1066                          $loadAnnotation->Put($annotationID, $timestamp, "$user\\n$text");                      $loadAnnotation->Put($annotationID, $timestamp, $text);
1067                          $loadIsTargetOfAnnotation->Put($peg, $annotationID);                          $loadIsTargetOfAnnotation->Put($peg, $annotationID);
1068                          $loadMadeAnnotation->Put($user, $annotationID);                          $loadMadeAnnotation->Put($user, $annotationID);
1069                      } else {                      } else {
# Line 964  Line 1073 
1073                  }                  }
1074              }              }
1075          }          }
     }  
1076      # Finish the load.      # Finish the load.
1077      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
1078      return $retVal;      return $retVal;
# Line 1024  Line 1132 
1132              chomp $line;              chomp $line;
1133              my($sourceID, $desc, $url) = split(/\t/,$line);              my($sourceID, $desc, $url) = split(/\t/,$line);
1134              $loadComesFrom->Put($genomeID, $sourceID);              $loadComesFrom->Put($genomeID, $sourceID);
1135              if ($url && ! exists $sourceURL{$genomeID}) {              if ($url && ! exists $sourceURL{$sourceID}) {
1136                  $loadSourceURL->Put($sourceID, $url);                  $loadSourceURL->Put($sourceID, $url);
1137                  $sourceURL{$sourceID} = 1;                  $sourceURL{$sourceID} = 1;
1138              }              }
1139              if ($desc && ! exists $sourceDesc{$sourceID}) {              if ($desc) {
1140                  $loadSource->Put($sourceID, $desc);                  $sourceDesc{$sourceID} = $desc;
1141                  $sourceDesc{$sourceID} = 1;              } elsif (! exists $sourceDesc{$sourceID}) {
1142                    $sourceDesc{$sourceID} = $sourceID;
1143              }              }
1144          }          }
1145          close TMP;          close TMP;
1146      }      }
1147        # Write the source descriptions.
1148        for my $sourceID (keys %sourceDesc) {
1149            $loadSource->Put($sourceID, $sourceDesc{$sourceID});
1150        }
1151      # Finish the load.      # Finish the load.
1152      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
1153      return $retVal;      return $retVal;
# Line 1116  Line 1229 
1229      return $retVal;      return $retVal;
1230  }  }
1231    
1232    
1233    =head3 LoadReactionData
1234    
1235    C<< my $stats = $spl->LoadReactionData(); >>
1236    
1237    Load the reaction data from FIG into Sprout.
1238    
1239    Reaction data connects reactions to the compounds that participate in them.
1240    
1241    The following relations are loaded by this method.
1242    
1243        Reaction
1244        ReactionURL
1245        Compound
1246        CompoundName
1247        CompoundCAS
1248        IsAComponentOf
1249    
1250    This method proceeds reaction by reaction rather than genome by genome.
1251    
1252    =over 4
1253    
1254    =item RETURNS
1255    
1256    Returns a statistics object for the loads.
1257    
1258    =back
1259    
1260    =cut
1261    #: Return Type $%;
1262    sub LoadReactionData {
1263        # Get this object instance.
1264        my ($self) = @_;
1265        # Get the FIG object.
1266        my $fig = $self->{fig};
1267        # Get the genome hash.
1268        my $genomeHash = $self->{genomes};
1269        my $genomeCount = (keys %{$genomeHash});
1270        # Create load objects for each of the tables we're loading.
1271        my $loadReaction = $self->_TableLoader('Reaction', $genomeCount * 4000);
1272        my $loadReactionURL = $self->_TableLoader('ReactionURL', $genomeCount * 4000);
1273        my $loadCompound = $self->_TableLoader('Compound', $genomeCount * 4000);
1274        my $loadCompoundName = $self->_TableLoader('CompoundName', $genomeCount * 8000);
1275        my $loadCompoundCAS = $self->_TableLoader('CompoundCAS', $genomeCount * 4000);
1276        my $loadIsAComponentOf = $self->_TableLoader('IsAComponentOf', $genomeCount * 12000);
1277        Trace("Beginning reaction/compound data load.") if T(2);
1278        # First we create the compounds.
1279        my @compounds = $fig->all_compounds();
1280        for my $cid (@compounds) {
1281            # Check for names.
1282            my @names = $fig->names_of_compound($cid);
1283            # Each name will be given a priority number, starting with 1.
1284            my $prio = 1;
1285            for my $name (@names) {
1286                $loadCompoundName->Put($cid, $name, $prio++);
1287            }
1288            # Create the main compound record. Note that the first name
1289            # becomes the label.
1290            my $label = (@names > 0 ? $names[0] : $cid);
1291            $loadCompound->Put($cid, $label);
1292            # Check for a CAS ID.
1293            my $cas = $fig->cas($cid);
1294            if ($cas) {
1295                $loadCompoundCAS->Put($cid, $cas);
1296            }
1297        }
1298        # All the compounds are set up, so we need to loop through the reactions next. First,
1299        # we initialize the discriminator index. This is a single integer used to insure
1300        # duplicate elements in a reaction are not accidentally collapsed.
1301        my $discrim = 0;
1302        my @reactions = $fig->all_reactions();
1303        for my $reactionID (@reactions) {
1304            # Create the reaction record.
1305            $loadReaction->Put($reactionID, $fig->reversible($reactionID));
1306            # Compute the reaction's URL.
1307            my $url = HTML::reaction_link($reactionID);
1308            # Put it in the ReactionURL table.
1309            $loadReactionURL->Put($reactionID, $url);
1310            # Now we need all of the reaction's compounds. We get these in two phases,
1311            # substrates first and then products.
1312            for my $product (0, 1) {
1313                # Get the compounds of the current type for the current reaction. FIG will
1314                # give us 3-tuples: [ID, stoichiometry, main-flag]. At this time we do not
1315                # have location data in SEED, so it defaults to the empty string.
1316                my @compounds = $fig->reaction2comp($reactionID, $product);
1317                for my $compData (@compounds) {
1318                    # Extract the compound data from the current tuple.
1319                    my ($cid, $stoich, $main) = @{$compData};
1320                    # Link the compound to the reaction.
1321                    $loadIsAComponentOf->Put($cid, $reactionID, $discrim++, "", $main,
1322                                             $product, $stoich);
1323                }
1324            }
1325        }
1326        # Finish the load.
1327        my $retVal = $self->_FinishAll();
1328        return $retVal;
1329    }
1330    
1331  =head3 LoadGroupData  =head3 LoadGroupData
1332    
1333  C<< my $stats = $spl->LoadGroupData(); >>  C<< my $stats = $spl->LoadGroupData(); >>
# Line 1239  Line 1451 
1451      # 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
1452      # ignominiously. At some future point, we want to make the loads restartable.      # ignominiously. At some future point, we want to make the loads restartable.
1453      while (my $loader = pop @{$loadList}) {      while (my $loader = pop @{$loadList}) {
1454            # Trace the fact that we're cleaning up.
1455            my $relName = $loader->RelName;
1456            Trace("Finishing load for $relName.") if T(2);
1457          my $stats = $loader->Finish();          my $stats = $loader->Finish();
1458            if ($self->{options}->{dbLoad}) {
1459                # Here we want to use the load file just created to load the database.
1460                Trace("Loading relation $relName.") if T(2);
1461                my $newStats = $self->{sprout}->LoadUpdate(1, [$relName]);
1462                # Accumulate the statistics from the DB load.
1463                $stats->Accumulate($newStats);
1464            }
1465          $retVal->Accumulate($stats);          $retVal->Accumulate($stats);
         my $relName = $loader->RelName;  
1466          Trace("Statistics for $relName:\n" . $stats->Show()) if T(2);          Trace("Statistics for $relName:\n" . $stats->Show()) if T(2);
1467      }      }
1468      # Return the load statistics.      # Return the load statistics.

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.20

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3