[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.33, Sat May 13 04:11:23 2006 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 131  Line 132 
132      # Load the list of trusted subsystems.      # Load the list of trusted subsystems.
133      my %subsystems = ();      my %subsystems = ();
134      if (! defined $subsysFile || $subsysFile eq '') {      if (! defined $subsysFile || $subsysFile eq '') {
135          # Here we want all the subsystems.          # Here we want all the NMPDR subsystems. First we get the whole list.
136          %subsystems = map { $_ => 1 } $fig->all_subsystems();          my @subs = $fig->all_subsystems();
137            # Loop through, checking for the NMPDR file.
138            for my $sub (@subs) {
139                if (-e "$FIG_Config::data/Subsystems/$sub/NMPDR") {
140                    $subsystems{$sub} = 1;
141                }
142            }
143      } else {      } else {
144          my $type = ref $subsysFile;          my $type = ref $subsysFile;
145          if ($type eq 'ARRAY') {          if ($type eq 'ARRAY') {
# Line 170  Line 177 
177      return $retVal;      return $retVal;
178  }  }
179    
180    =head3 LoadOnly
181    
182    C<< my $flag = $spl->LoadOnly; >>
183    
184    Return TRUE if we are in load-only mode, else FALSE.
185    
186    =cut
187    
188    sub LoadOnly {
189        my ($self) = @_;
190        return $self->{options}->{loadOnly};
191    }
192    
193    =head3 PrimaryOnly
194    
195    C<< my $flag = $spl->PrimaryOnly; >>
196    
197    Return TRUE if only the main entity is to be loaded, else FALSE.
198    
199    =cut
200    
201    sub PrimaryOnly {
202        my ($self) = @_;
203        return $self->{options}->{primaryOnly};
204    }
205    
206  =head3 LoadGenomeData  =head3 LoadGenomeData
207    
208  C<< my $stats = $spl->LoadGenomeData(); >>  C<< my $stats = $spl->LoadGenomeData(); >>
# Line 197  Line 230 
230    
231  =back  =back
232    
 B<TO DO>  
   
 Real quality vectors instead of C<unknown> for everything.  
   
 GenomeGroup relation. (The original script took group information from the C<NMPDR> file  
 in each genome's main directory, but no such file exists anywhere in my version of the  
 data store.)  
   
233  =cut  =cut
234  #: Return Type $%;  #: Return Type $%;
235  sub LoadGenomeData {  sub LoadGenomeData {
# Line 215  Line 240 
240      # Get the genome count.      # Get the genome count.
241      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
242      my $genomeCount = (keys %{$genomeHash});      my $genomeCount = (keys %{$genomeHash});
     Trace("Beginning genome data load.") if T(2);  
243      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
244      my $loadGenome = $self->_TableLoader('Genome', $genomeCount);      my $loadGenome = $self->_TableLoader('Genome');
245      my $loadHasContig = $self->_TableLoader('HasContig', $genomeCount * 300);      my $loadHasContig = $self->_TableLoader('HasContig', $self->PrimaryOnly);
246      my $loadContig = $self->_TableLoader('Contig', $genomeCount * 300);      my $loadContig = $self->_TableLoader('Contig', $self->PrimaryOnly);
247      my $loadIsMadeUpOf = $self->_TableLoader('IsMadeUpOf', $genomeCount * 60000);      my $loadIsMadeUpOf = $self->_TableLoader('IsMadeUpOf', $self->PrimaryOnly);
248      my $loadSequence = $self->_TableLoader('Sequence', $genomeCount * 60000);      my $loadSequence = $self->_TableLoader('Sequence', $self->PrimaryOnly);
249        if ($self->{options}->{loadOnly}) {
250            Trace("Loading from existing files.") if T(2);
251        } else {
252            Trace("Generating genome data.") if T(2);
253      # Now we loop through the genomes, generating the data for each one.      # Now we loop through the genomes, generating the data for each one.
254      for my $genomeID (sort keys %{$genomeHash}) {      for my $genomeID (sort keys %{$genomeHash}) {
255          Trace("Loading data for genome $genomeID.") if T(3);              Trace("Generating data for genome $genomeID.") if T(3);
256          $loadGenome->Add("genomeIn");          $loadGenome->Add("genomeIn");
257          # The access code comes in via the genome hash.          # The access code comes in via the genome hash.
258          my $accessCode = $genomeHash->{$genomeID};          my $accessCode = $genomeHash->{$genomeID};
259          # Get the genus, species, and strain from the scientific name. Note that we append              # Get the genus, species, and strain from the scientific name.
         # the genome ID to the strain. In some cases this is the totality of the strain name.  
260          my ($genus, $species, @extraData) = split / /, $self->{fig}->genus_species($genomeID);          my ($genus, $species, @extraData) = split / /, $self->{fig}->genus_species($genomeID);
261          my $extra = join " ", @extraData, "[$genomeID]";              my $extra = join " ", @extraData;
262          # Get the full taxonomy.          # Get the full taxonomy.
263          my $taxonomy = $fig->taxonomy_of($genomeID);          my $taxonomy = $fig->taxonomy_of($genomeID);
264          # Output the genome record.          # Output the genome record.
# Line 267  Line 294 
294              }              }
295          }          }
296      }      }
297        }
298      # Finish the loads.      # Finish the loads.
299      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
300      # Return the result.      # Return the result.
# Line 310  Line 338 
338      my $genomeCount = (keys %{$genomeFilter});      my $genomeCount = (keys %{$genomeFilter});
339      my $featureCount = $genomeCount * 4000;      my $featureCount = $genomeCount * 4000;
340      # Start the loads.      # Start the loads.
341      my $loadCoupling = $self->_TableLoader('Coupling', $featureCount * $genomeCount);      my $loadCoupling = $self->_TableLoader('Coupling');
342      my $loadIsEvidencedBy = $self->_TableLoader('IsEvidencedBy', $featureCount * 8000);      my $loadIsEvidencedBy = $self->_TableLoader('IsEvidencedBy', $self->PrimaryOnly);
343      my $loadPCH = $self->_TableLoader('PCH', $featureCount * 2000);      my $loadPCH = $self->_TableLoader('PCH', $self->PrimaryOnly);
344      my $loadParticipatesInCoupling = $self->_TableLoader('ParticipatesInCoupling', $featureCount * 2000);      my $loadParticipatesInCoupling = $self->_TableLoader('ParticipatesInCoupling', $self->PrimaryOnly);
345      my $loadUsesAsEvidence = $self->_TableLoader('UsesAsEvidence', $featureCount * 8000);      my $loadUsesAsEvidence = $self->_TableLoader('UsesAsEvidence', $self->PrimaryOnly);
346      Trace("Beginning coupling data load.") if T(2);      if ($self->{options}->{loadOnly}) {
347            Trace("Loading from existing files.") if T(2);
348        } else {
349            Trace("Generating coupling data.") if T(2);
350      # Loop through the genomes found.      # Loop through the genomes found.
351      for my $genome (sort keys %{$genomeFilter}) {      for my $genome (sort keys %{$genomeFilter}) {
352          Trace("Generating coupling data for $genome.") if T(3);          Trace("Generating coupling data for $genome.") if T(3);
# Line 367  Line 398 
398                              # We store this evidence in the hash if the usage                              # We store this evidence in the hash if the usage
399                              # is nonzero or no prior evidence has been found. This                              # is nonzero or no prior evidence has been found. This
400                              # insures that if there is duplicate evidence, we                              # insures that if there is duplicate evidence, we
401                              # at least keep the meaningful ones. Only evidence is                                  # at least keep the meaningful ones. Only evidence in
402                              # the hash makes it to the output.                              # the hash makes it to the output.
403                              if ($usage || ! exists $evidenceMap{$evidenceKey}) {                              if ($usage || ! exists $evidenceMap{$evidenceKey}) {
404                                  $evidenceMap{$evidenceKey} = $evidenceData;                                  $evidenceMap{$evidenceKey} = $evidenceData;
# Line 382  Line 413 
413                          $loadIsEvidencedBy->Put($coupleID, $evidenceID);                          $loadIsEvidencedBy->Put($coupleID, $evidenceID);
414                          # Connect it to the features.                          # Connect it to the features.
415                          $loadUsesAsEvidence->Put($evidenceID, $peg3, 1);                          $loadUsesAsEvidence->Put($evidenceID, $peg3, 1);
416                          $loadUsesAsEvidence->Put($evidenceID, $peg4, 1);                              $loadUsesAsEvidence->Put($evidenceID, $peg4, 2);
417                            }
418                      }                      }
419                  }                  }
420              }              }
# Line 409  Line 441 
441      FeatureTranslation      FeatureTranslation
442      FeatureUpstream      FeatureUpstream
443      IsLocatedIn      IsLocatedIn
444        HasFeature
445    
446  =over 4  =over 4
447    
# Line 425  Line 458 
458      my ($self) = @_;      my ($self) = @_;
459      # Get the FIG object.      # Get the FIG object.
460      my $fig = $self->{fig};      my $fig = $self->{fig};
     # Find out if this is a limited run.  
     my $limited = $self->{options}->{limitedFeatures};  
461      # Get the table of genome IDs.      # Get the table of genome IDs.
462      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
     my $featureCount = $genomeCount * 4000;  
463      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
464      my $loadFeature = $self->_TableLoader('Feature', $featureCount);      my $loadFeature = $self->_TableLoader('Feature');
465      my $loadIsLocatedIn = $self->_TableLoader('IsLocatedIn', $featureCount);      my $loadIsLocatedIn = $self->_TableLoader('IsLocatedIn', $self->PrimaryOnly);
466      my ($loadFeatureAlias, $loadFeatureLink, $loadFeatureTranslation, $loadFeatureUpstream);      my $loadFeatureAlias = $self->_TableLoader('FeatureAlias');
467      if (! $limited) {      my $loadFeatureLink = $self->_TableLoader('FeatureLink');
468          $loadFeatureAlias = $self->_TableLoader('FeatureAlias', $featureCount * 6);      my $loadFeatureTranslation = $self->_TableLoader('FeatureTranslation');
469          $loadFeatureLink = $self->_TableLoader('FeatureLink', $featureCount * 10);      my $loadFeatureUpstream = $self->_TableLoader('FeatureUpstream');
470          $loadFeatureTranslation = $self->_TableLoader('FeatureTranslation', $featureCount);      my $loadHasFeature = $self->_TableLoader('HasFeature');
         $loadFeatureUpstream = $self->_TableLoader('FeatureUpstream', $featureCount);  
     }  
471      # 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
472      # locations.      # locations.
473      my $chunkSize = $self->{sprout}->MaxSegment();      my $chunkSize = $self->{sprout}->MaxSegment();
474      Trace("Beginning feature data load.") if T(2);      if ($self->{options}->{loadOnly}) {
475            Trace("Loading from existing files.") if T(2);
476        } else {
477            Trace("Generating feature data.") if T(2);
478      # Now we loop through the genomes, generating the data for each one.      # Now we loop through the genomes, generating the data for each one.
479      for my $genomeID (sort keys %{$genomeHash}) {      for my $genomeID (sort keys %{$genomeHash}) {
480          Trace("Loading features for genome $genomeID.") if T(3);          Trace("Loading features for genome $genomeID.") if T(3);
# Line 455  Line 485 
485          for my $featureData (@{$features}) {          for my $featureData (@{$features}) {
486              $loadFeature->Add("featureIn");              $loadFeature->Add("featureIn");
487              # Split the tuple.              # Split the tuple.
488              my ($featureID, $locations, $aliases, $type) = @{$featureData};                  my ($featureID, $locations, undef, $type) = @{$featureData};
489              # Create the feature record.              # Create the feature record.
490              $loadFeature->Put($featureID, 1, $type);              $loadFeature->Put($featureID, 1, $type);
491              # The next stuff is for a full load only.                  # Link it to the parent genome.
492              if (! $limited) {                  $loadHasFeature->Put($genomeID, $featureID, $type);
493                  # Create the aliases.                  # Create the aliases.
494                  for my $alias (split /\s*,\s*/, $aliases) {                  for my $alias ($fig->feature_aliases($featureID)) {
495                      $loadFeatureAlias->Put($featureID, $alias);                      $loadFeatureAlias->Put($featureID, $alias);
496                  }                  }
497                  # Get the links.                  # Get the links.
# Line 482  Line 512 
512                          $loadFeatureUpstream->Put($featureID, $upstream);                          $loadFeatureUpstream->Put($featureID, $upstream);
513                      }                      }
514                  }                  }
             }  
515              # 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
516              # 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
517              # the maximum segment size. This simplifies the genes_in_region processing              # the maximum segment size. This simplifies the genes_in_region processing
# Line 493  Line 522 
522              # Loop through the locations.              # Loop through the locations.
523              for my $location (@locationList) {              for my $location (@locationList) {
524                  # Parse the location.                  # Parse the location.
525                  my $locObject = BasicLocation->new($location);                      my $locObject = BasicLocation->new("$genomeID:$location");
526                  # Split it into a list of chunks.                  # Split it into a list of chunks.
527                  my @locOList = ();                  my @locOList = ();
528                  while (my $peeling = $locObject->Peel($chunkSize)) {                  while (my $peeling = $locObject->Peel($chunkSize)) {
# Line 511  Line 540 
540              }              }
541          }          }
542      }      }
543        }
544      # Finish the loads.      # Finish the loads.
545      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
546      return $retVal;      return $retVal;
# Line 547  Line 577 
577      my $fig = $self->{fig};      my $fig = $self->{fig};
578      # Get the table of genome IDs.      # Get the table of genome IDs.
579      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
     my $featureCount = $genomeCount * 4000;  
580      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
581      my $loadIsBidirectionalBestHitOf = $self->_TableLoader('IsBidirectionalBestHitOf',      my $loadIsBidirectionalBestHitOf = $self->_TableLoader('IsBidirectionalBestHitOf');
582                                                             $featureCount * $genomeCount);      if ($self->{options}->{loadOnly}) {
583      Trace("Beginning BBH load.") if T(2);          Trace("Loading from existing files.") if T(2);
584        } else {
585            Trace("Generating BBH data.") if T(2);
586      # Now we loop through the genomes, generating the data for each one.      # Now we loop through the genomes, generating the data for each one.
587      for my $genomeID (sort keys %{$genomeHash}) {      for my $genomeID (sort keys %{$genomeHash}) {
588          $loadIsBidirectionalBestHitOf->Add("genomeIn");          $loadIsBidirectionalBestHitOf->Add("genomeIn");
# Line 578  Line 608 
608              }              }
609          }          }
610      }      }
611        }
612      # Finish the loads.      # Finish the loads.
613      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
614      return $retVal;      return $retVal;
# Line 599  Line 630 
630    
631      Subsystem      Subsystem
632      Role      Role
633        RoleEC
634      SSCell      SSCell
635      ContainsFeature      ContainsFeature
636      IsGenomeOf      IsGenomeOf
# Line 606  Line 638 
638      OccursInSubsystem      OccursInSubsystem
639      ParticipatesIn      ParticipatesIn
640      HasSSCell      HasSSCell
641        ConsistsOfRoles
642        RoleSubset
643        HasRoleSubset
644        ConsistsOfGenomes
645        GenomeSubset
646        HasGenomeSubset
647        Catalyzes
648        Diagram
649        RoleOccursIn
650    
651  =over 4  =over 4
652    
# Line 615  Line 656 
656    
657  =back  =back
658    
 B<TO DO>  
   
 Generate RoleName table?  
   
659  =cut  =cut
660  #: Return Type $%;  #: Return Type $%;
661  sub LoadSubsystemData {  sub LoadSubsystemData {
# Line 632  Line 669 
669      # Get the subsystem hash. This lists the subsystems we'll process.      # Get the subsystem hash. This lists the subsystems we'll process.
670      my $subsysHash = $self->{subsystems};      my $subsysHash = $self->{subsystems};
671      my @subsysIDs = sort keys %{$subsysHash};      my @subsysIDs = sort keys %{$subsysHash};
672      my $subsysCount = @subsysIDs;      # Get the map list.
673      my $genomeCount = (keys %{$genomeHash});      my @maps = $fig->all_maps;
     my $featureCount = $genomeCount * 4000;  
674      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
675      my $loadSubsystem = $self->_TableLoader('Subsystem', $subsysCount);      my $loadDiagram = $self->_TableLoader('Diagram', $self->PrimaryOnly);
676      my $loadRole = $self->_TableLoader('Role', $featureCount * 6);      my $loadRoleOccursIn = $self->_TableLoader('RoleOccursIn', $self->PrimaryOnly);
677      my $loadSSCell = $self->_TableLoader('SSCell', $featureCount * $genomeCount);      my $loadSubsystem = $self->_TableLoader('Subsystem');
678      my $loadContainsFeature = $self->_TableLoader('ContainsFeature', $featureCount * $subsysCount);      my $loadRole = $self->_TableLoader('Role', $self->PrimaryOnly);
679      my $loadIsGenomeOf = $self->_TableLoader('IsGenomeOf', $featureCount * $genomeCount);      my $loadRoleEC = $self->_TableLoader('RoleEC', $self->PrimaryOnly);
680      my $loadIsRoleOf = $self->_TableLoader('IsRoleOf', $featureCount * $genomeCount);      my $loadCatalyzes = $self->_TableLoader('Catalyzes', $self->PrimaryOnly);
681      my $loadOccursInSubsystem = $self->_TableLoader('OccursInSubsystem', $featureCount * 6);      my $loadSSCell = $self->_TableLoader('SSCell', $self->PrimaryOnly);
682      my $loadParticipatesIn = $self->_TableLoader('ParticipatesIn', $subsysCount * $genomeCount);      my $loadContainsFeature = $self->_TableLoader('ContainsFeature', $self->PrimaryOnly);
683      my $loadHasSSCell = $self->_TableLoader('HasSSCell', $featureCount * $genomeCount);      my $loadIsGenomeOf = $self->_TableLoader('IsGenomeOf', $self->PrimaryOnly);
684      Trace("Beginning subsystem data load.") if T(2);      my $loadIsRoleOf = $self->_TableLoader('IsRoleOf', $self->PrimaryOnly);
685        my $loadOccursInSubsystem = $self->_TableLoader('OccursInSubsystem', $self->PrimaryOnly);
686        my $loadParticipatesIn = $self->_TableLoader('ParticipatesIn', $self->PrimaryOnly);
687        my $loadHasSSCell = $self->_TableLoader('HasSSCell', $self->PrimaryOnly);
688        my $loadRoleSubset = $self->_TableLoader('RoleSubset', $self->PrimaryOnly);
689        my $loadGenomeSubset = $self->_TableLoader('GenomeSubset', $self->PrimaryOnly);
690        my $loadConsistsOfRoles = $self->_TableLoader('ConsistsOfRoles', $self->PrimaryOnly);
691        my $loadConsistsOfGenomes = $self->_TableLoader('ConsistsOfGenomes', $self->PrimaryOnly);
692        my $loadHasRoleSubset = $self->_TableLoader('HasRoleSubset', $self->PrimaryOnly);
693        my $loadHasGenomeSubset = $self->_TableLoader('HasGenomeSubset', $self->PrimaryOnly);
694        if ($self->{options}->{loadOnly}) {
695            Trace("Loading from existing files.") if T(2);
696        } else {
697            Trace("Generating subsystem data.") if T(2);
698            # This hash will contain the role for each EC. When we're done, this
699            # information will be used to generate the Catalyzes table.
700            my %ecToRoles = ();
701      # Loop through the subsystems. Our first task will be to create the      # Loop through the subsystems. Our first task will be to create the
702      # roles. We do this by looping through the subsystems and creating a      # roles. We do this by looping through the subsystems and creating a
703      # 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
704      # duplicates. As we move along, we'll connect the roles and subsystems.          # duplicates. As we move along, we'll connect the roles and subsystems
705            # and memorize up the reactions.
706            my ($genomeID, $roleID);
707      my %roleData = ();      my %roleData = ();
708      for my $subsysID (@subsysIDs) {      for my $subsysID (@subsysIDs) {
709                # Get the subsystem object.
710                my $sub = $fig->get_subsystem($subsysID);
711                # Only proceed if the subsystem has a spreadsheet.
712                if (! $sub->{empty_ss}) {
713          Trace("Creating subsystem $subsysID.") if T(3);          Trace("Creating subsystem $subsysID.") if T(3);
714          $loadSubsystem->Add("subsystemIn");          $loadSubsystem->Add("subsystemIn");
715          # Create the subsystem record.          # Create the subsystem record.
716          $loadSubsystem->Put($subsysID);                  my $curator = $sub->get_curator();
717          # Get the subsystem's roles.                  my $notes = $sub->get_notes();
718          my @roles = $fig->subsystem_to_roles($subsysID);                  $loadSubsystem->Put($subsysID, $curator, $notes);
719          # 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.
720          # a role record for it.                  for (my $col = 0; defined($roleID = $sub->get_role($col)); $col++) {
721          for my $roleID (@roles) {                      # Connect to this role.
722              $loadOccursInSubsystem->Add("roleIn");              $loadOccursInSubsystem->Add("roleIn");
723              $loadOccursInSubsystem->Put($roleID, $subsysID);                      $loadOccursInSubsystem->Put($roleID, $subsysID, $col);
724                        # If it's a new role, add it to the role table.
725              if (! exists $roleData{$roleID}) {              if (! exists $roleData{$roleID}) {
726                  $loadRole->Put($roleID);                          # Get the role's abbreviation.
727                            my $abbr = $sub->get_role_abbr($col);
728                            # Add the role.
729                            $loadRole->Put($roleID, $abbr);
730                  $roleData{$roleID} = 1;                  $roleData{$roleID} = 1;
731                            # Check for an EC number.
732                            if ($roleID =~ /\(EC ([^.]+\.[^.]+\.[^.]+\.[^)]+)\)\s*$/) {
733                                my $ec = $1;
734                                $loadRoleEC->Put($roleID, $ec);
735                                $ecToRoles{$ec} = $roleID;
736              }              }
737          }          }
738          # Now all roles for this subsystem have been filled in. We create the                  }
739          # spreadsheet by matches roles to genomes. To do this, we need to                  # Now we create the spreadsheet for the subsystem by matching roles to
740          # get the genomes on the sheet.                  # genomes. Each genome is a row and each role is a column. We may need
741                    # to actually create the roles as we find them.
742          Trace("Creating subsystem $subsysID spreadsheet.") if T(3);          Trace("Creating subsystem $subsysID spreadsheet.") if T(3);
743          my @genomes = map { $_->[0] } @{$fig->subsystem_genomes($subsysID)};                  for (my $row = 0; defined($genomeID = $sub->get_genome($row)); $row++) {
744          for my $genomeID (@genomes) {                      # Only proceed if this is one of our genomes.
             # Only process this genome if it's one of ours.  
745              if (exists $genomeHash->{$genomeID}) {              if (exists $genomeHash->{$genomeID}) {
746                  # Connect the genome to the subsystem.                          # Count the PEGs and cells found for verification purposes.
747                  $loadParticipatesIn->Put($genomeID, $subsysID);                          my $pegCount = 0;
748                            my $cellCount = 0;
749                            # Create a list for the PEGs we find. This list will be used
750                            # to generate cluster numbers.
751                            my @pegsFound = ();
752                            # Create a hash that maps spreadsheet IDs to PEGs. We will
753                            # use this to generate the ContainsFeature data after we have
754                            # the cluster numbers.
755                            my %cellPegs = ();
756                            # Get the genome's variant code for this subsystem.
757                            my $variantCode = $sub->get_variant_code($row);
758                  # 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
759                  # part of the spreadsheet cell ID.                  # part of the spreadsheet cell ID.
760                  for (my $i = 0; $i <= $#roles; $i++) {                          for (my $col = 0; defined($roleID = $sub->get_role($col)); $col++) {
                     my $role = $roles[$i];  
761                      # Get the features in the spreadsheet cell for this genome and role.                      # Get the features in the spreadsheet cell for this genome and role.
762                      my @pegs = $fig->pegs_in_subsystem_cell($subsysID, $genomeID, $i);                              my @pegs = $sub->get_pegs_from_cell($row, $col);
763                      # Only proceed if features exist.                      # Only proceed if features exist.
764                      if (@pegs > 0) {                      if (@pegs > 0) {
765                          # Create the spreadsheet cell.                          # Create the spreadsheet cell.
766                          my $cellID = "$subsysID:$genomeID:$i";                                  $cellCount++;
767                                    my $cellID = "$subsysID:$genomeID:$col";
768                          $loadSSCell->Put($cellID);                          $loadSSCell->Put($cellID);
769                          $loadIsGenomeOf->Put($genomeID, $cellID);                          $loadIsGenomeOf->Put($genomeID, $cellID);
770                          $loadIsRoleOf->Put($role, $cellID);                                  $loadIsRoleOf->Put($roleID, $cellID);
771                          $loadHasSSCell->Put($subsysID, $cellID);                          $loadHasSSCell->Put($subsysID, $cellID);
772                          # Attach the features to it.                                  # Remember its features.
773                          for my $pegID (@pegs) {                                  push @pegsFound, @pegs;
774                              $loadContainsFeature->Put($cellID, $pegID);                                  $cellPegs{$cellID} = \@pegs;
775                                    $pegCount += @pegs;
776                                }
777                            }
778                            # If we found some cells for this genome, we need to compute clusters and
779                            # denote it participates in the subsystem.
780                            if ($pegCount > 0) {
781                                Trace("$pegCount PEGs in $cellCount cells for $genomeID.") if T(3);
782                                $loadParticipatesIn->Put($genomeID, $subsysID, $variantCode);
783                                # Partition the PEGs found into clusters.
784                                my @clusters = $fig->compute_clusters(\@pegsFound, $sub);
785                                # Create a hash mapping PEG IDs to cluster numbers.
786                                # We default to -1 for all of them.
787                                my %clusterOf = map { $_ => -1 } @pegsFound;
788                                for (my $i = 0; $i <= $#clusters; $i++) {
789                                    my $subList = $clusters[$i];
790                                    for my $peg (@{$subList}) {
791                                        $clusterOf{$peg} = $i;
792                                    }
793                                }
794                                # Create the ContainsFeature data.
795                                for my $cellID (keys %cellPegs) {
796                                    my $cellList = $cellPegs{$cellID};
797                                    for my $cellPeg (@$cellList) {
798                                        $loadContainsFeature->Put($cellID, $cellPeg, $clusterOf{$cellPeg});
799                          }                          }
800                      }                      }
801                  }                  }
802              }              }
803          }          }
804                    # Now we need to generate the subsets. The subset names must be concatenated to
805                    # the subsystem name to make them unique keys. There are two types of subsets:
806                    # genome subsets and role subsets. We do the role subsets first.
807                    my @subsetNames = $sub->get_subset_names();
808                    for my $subsetID (@subsetNames) {
809                        # Create the subset record.
810                        my $actualID = "$subsysID:$subsetID";
811                        $loadRoleSubset->Put($actualID);
812                        # Connect the subset to the subsystem.
813                        $loadHasRoleSubset->Put($subsysID, $actualID);
814                        # Connect the subset to its roles.
815                        my @roles = $sub->get_subsetC_roles($subsetID);
816                        for my $roleID (@roles) {
817                            $loadConsistsOfRoles->Put($actualID, $roleID);
818      }      }
     # Finish the load.  
     my $retVal = $self->_FinishAll();  
     return $retVal;  
819  }  }
820                    # Next the genome subsets.
821  =head3 LoadDiagramData                  @subsetNames = $sub->get_subset_namesR();
822                    for my $subsetID (@subsetNames) {
823  C<< my $stats = $spl->LoadDiagramData(); >>                      # Create the subset record.
824                        my $actualID = "$subsysID:$subsetID";
825  Load the diagram data from FIG into Sprout.                      $loadGenomeSubset->Put($actualID);
826                        # Connect the subset to the subsystem.
827  Diagrams are used to organize functional roles. The diagram shows the                      $loadHasGenomeSubset->Put($subsysID, $actualID);
828  connections between chemicals that interact with a subsystem.                      # Connect the subset to its genomes.
829                        my @genomes = $sub->get_subsetR($subsetID);
830  The following relations are loaded by this method.                      for my $genomeID (@genomes) {
831                            $loadConsistsOfGenomes->Put($actualID, $genomeID);
832      Diagram                      }
833      RoleOccursIn                  }
834                }
835  =over 4              # Now we loop through the diagrams. We need to create the diagram records
836                # and link each diagram to its roles. Note that only roles which occur
837  =item RETURNS              # in subsystems (and therefore appear in the %ecToRoles hash) are
838                # included.
839  Returns a statistics object for the loads.              for my $map (@maps) {
   
 =back  
   
 =cut  
 #: Return Type $%;  
 sub LoadDiagramData {  
     # Get this object instance.  
     my ($self) = @_;  
     # Get the FIG object.  
     my $fig = $self->{fig};  
     # Get the map list.  
     my @maps = $fig->all_maps;  
     my $mapCount = @maps;  
     my $genomeCount = (keys %{$self->{genomes}});  
     my $featureCount = $genomeCount * 4000;  
     # Create load objects for each of the tables we're loading.  
     my $loadDiagram = $self->_TableLoader('Diagram', $mapCount);  
     my $loadRoleOccursIn = $self->_TableLoader('RoleOccursIn', $featureCount * 6);  
     Trace("Beginning diagram data load.") if T(2);  
     # Loop through the diagrams.  
     for my $map ($fig->all_maps) {  
840          Trace("Loading diagram $map.") if T(3);          Trace("Loading diagram $map.") if T(3);
841          # Get the diagram's descriptive name.          # Get the diagram's descriptive name.
842          my $name = $fig->map_name($map);          my $name = $fig->map_name($map);
# Line 754  Line 845 
845          # A hash is used to prevent duplicates.          # A hash is used to prevent duplicates.
846          my %roleHash = ();          my %roleHash = ();
847          for my $role ($fig->map_to_ecs($map)) {          for my $role ($fig->map_to_ecs($map)) {
848              if (! $roleHash{$role}) {                      if (exists $ecToRoles{$role} && ! $roleHash{$role}) {
849                  $loadRoleOccursIn->Put($role, $map);                          $loadRoleOccursIn->Put($ecToRoles{$role}, $map);
850                  $roleHash{$role} = 1;                  $roleHash{$role} = 1;
851              }              }
852          }          }
853      }      }
854                # Before we leave, we must create the Catalyzes table. We start with the reactions,
855                # then use the "ecToRoles" table to convert EC numbers to role IDs.
856                my @reactions = $fig->all_reactions();
857                for my $reactionID (@reactions) {
858                    # Get this reaction's list of roles. The results will be EC numbers.
859                    my @roles = $fig->catalyzed_by($reactionID);
860                    # Loop through the roles, creating catalyzation records.
861                    for my $thisRole (@roles) {
862                        if (exists $ecToRoles{$thisRole}) {
863                            $loadCatalyzes->Put($ecToRoles{$thisRole}, $reactionID);
864                        }
865                    }
866                }
867            }
868        }
869      # Finish the load.      # Finish the load.
870      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
871      return $retVal;      return $retVal;
# Line 801  Line 907 
907      my $fig = $self->{fig};      my $fig = $self->{fig};
908      # Get the genome hash.      # Get the genome hash.
909      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
910      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
911      my $loadProperty = $self->_TableLoader('Property', $genomeCount * 1500);      my $loadProperty = $self->_TableLoader('Property');
912      my $loadHasProperty = $self->_TableLoader('HasProperty', $genomeCount * 1500);      my $loadHasProperty = $self->_TableLoader('HasProperty', $self->PrimaryOnly);
913      Trace("Beginning property data load.") if T(2);      if ($self->{options}->{loadOnly}) {
914            Trace("Loading from existing files.") if T(2);
915        } else {
916            Trace("Generating property data.") if T(2);
917      # Create a hash for storing property IDs.      # Create a hash for storing property IDs.
918      my %propertyKeys = ();      my %propertyKeys = ();
919      my $nextID = 1;      my $nextID = 1;
920      # Loop through the genomes.      # Loop through the genomes.
921      for my $genomeID (keys %{$genomeHash}) {      for my $genomeID (keys %{$genomeHash}) {
922          $loadProperty->Add("genomeIn");          $loadProperty->Add("genomeIn");
923                Trace("Generating properties for $genomeID.") if T(3);
924          # 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
925          # tuples returned by "all_features_detailed". We use "all_features_detailed"          # tuples returned by "all_features_detailed". We use "all_features_detailed"
926          # rather than "all_features" because we want all features regardless of type.          # rather than "all_features" because we want all features regardless of type.
927          my @features = map { $_->[0] } @{$fig->all_features_detailed($genomeID)};          my @features = map { $_->[0] } @{$fig->all_features_detailed($genomeID)};
928                my $featureCount = 0;
929                my $propertyCount = 0;
930          # Loop through the features, creating HasProperty records.          # Loop through the features, creating HasProperty records.
931          for my $fid (@features) {          for my $fid (@features) {
             $loadProperty->Add("featureIn");  
932              # Get all attributes for this feature. We do this one feature at a time              # Get all attributes for this feature. We do this one feature at a time
933              # to insure we do not get any genome attributes.              # to insure we do not get any genome attributes.
934              my @attributeList = $fig->get_attributes($fid, '', '', '');              my @attributeList = $fig->get_attributes($fid, '', '', '');
935                    if (scalar @attributeList) {
936                        $featureCount++;
937                    }
938              # Loop through the attributes.              # Loop through the attributes.
939              for my $tuple (@attributeList) {              for my $tuple (@attributeList) {
940                        $propertyCount++;
941                  # Get this attribute value's data. Note that we throw away the FID,                  # Get this attribute value's data. Note that we throw away the FID,
942                  # since it will always be the same as the value if "$fid".                  # since it will always be the same as the value if "$fid".
943                  my (undef, $key, $value, $url) = @{$tuple};                  my (undef, $key, $value, $url) = @{$tuple};
# Line 845  Line 959 
959                  $loadHasProperty->Put($fid, $propertyID, $url);                  $loadHasProperty->Put($fid, $propertyID, $url);
960              }              }
961          }          }
962                # Update the statistics.
963                Trace("$propertyCount attributes processed for $featureCount features.") if T(3);
964                $loadHasProperty->Add("featuresIn", $featureCount);
965                $loadHasProperty->Add("propertiesIn", $propertyCount);
966            }
967      }      }
968      # Finish the load.      # Finish the load.
969      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
# Line 885  Line 1004 
1004      my $fig = $self->{fig};      my $fig = $self->{fig};
1005      # Get the genome hash.      # Get the genome hash.
1006      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
1007      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
1008      my $loadAnnotation = $self->_TableLoader('Annotation', $genomeCount * 4000);      my $loadAnnotation = $self->_TableLoader('Annotation');
1009      my $loadIsTargetOfAnnotation = $self->_TableLoader('IsTargetOfAnnotation', $genomeCount * 4000);      my $loadIsTargetOfAnnotation = $self->_TableLoader('IsTargetOfAnnotation', $self->PrimaryOnly);
1010      my $loadSproutUser = $self->_TableLoader('SproutUser', 100);      my $loadSproutUser = $self->_TableLoader('SproutUser', $self->PrimaryOnly);
1011      my $loadUserAccess = $self->_TableLoader('UserAccess', 1000);      my $loadUserAccess = $self->_TableLoader('UserAccess', $self->PrimaryOnly);
1012      my $loadMadeAnnotation = $self->_TableLoader('MadeAnnotation', $genomeCount * 4000);      my $loadMadeAnnotation = $self->_TableLoader('MadeAnnotation', $self->PrimaryOnly);
1013      Trace("Beginning annotation data load.") if T(2);      if ($self->{options}->{loadOnly}) {
1014            Trace("Loading from existing files.") if T(2);
1015        } else {
1016            Trace("Generating annotation data.") if T(2);
1017      # Create a hash of user names. We'll use this to prevent us from generating duplicate      # Create a hash of user names. We'll use this to prevent us from generating duplicate
1018      # user records.      # user records.
1019      my %users = ( FIG => 1, master => 1 );      my %users = ( FIG => 1, master => 1 );
# Line 913  Line 1034 
1034              # Create a hash of timestamps. We use this to prevent duplicate time stamps              # Create a hash of timestamps. We use this to prevent duplicate time stamps
1035              # from showing up for a single PEG's annotations.              # from showing up for a single PEG's annotations.
1036              my %seenTimestamps = ();              my %seenTimestamps = ();
1037              # Check for a functional assignment.                  # Loop through the annotations.
             my $func = $fig->function_of($peg);  
             if ($func) {  
                 # If this is NOT a hypothetical assignment, we create an  
                 # assignment annotation for it.  
                 if (! FIG::hypo($peg)) {  
                     # Note that we double the slashes so that what goes into the database is  
                     # a new-line escape sequence rather than an actual new-line.  
                     $loadAnnotation->Put("$peg:$time", $time, "FIG\\nSet function to\\n$func");  
                     $loadIsTargetOfAnnotation->Put($peg, "$peg:$time");  
                     $loadMadeAnnotation->Put("FIG", "$peg:$time");  
                     # Denote we've seen this timestamp.  
                     $seenTimestamps{$time} = 1;  
                 }  
                 # 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};
1040                      # Here we fix up the annotation text. "\r" is removed,                      # Here we fix up the annotation text. "\r" is removed,
# 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 1005  Line 1114 
1114      my $fig = $self->{fig};      my $fig = $self->{fig};
1115      # Get the genome hash.      # Get the genome hash.
1116      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
1117      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
1118      my $loadComesFrom = $self->_TableLoader('ComesFrom', $genomeCount * 4);      my $loadComesFrom = $self->_TableLoader('ComesFrom', $self->PrimaryOnly);
1119      my $loadSource = $self->_TableLoader('Source', $genomeCount * 4);      my $loadSource = $self->_TableLoader('Source');
1120      my $loadSourceURL = $self->_TableLoader('SourceURL', $genomeCount * 8);      my $loadSourceURL = $self->_TableLoader('SourceURL');
1121      Trace("Beginning source data load.") if T(2);      if ($self->{options}->{loadOnly}) {
1122            Trace("Loading from existing files.") if T(2);
1123        } else {
1124            Trace("Generating annotation data.") if T(2);
1125      # Create hashes to collect the Source information.      # Create hashes to collect the Source information.
1126      my %sourceURL = ();      my %sourceURL = ();
1127      my %sourceDesc = ();      my %sourceDesc = ();
# Line 1024  Line 1135 
1135              chomp $line;              chomp $line;
1136              my($sourceID, $desc, $url) = split(/\t/,$line);              my($sourceID, $desc, $url) = split(/\t/,$line);
1137              $loadComesFrom->Put($genomeID, $sourceID);              $loadComesFrom->Put($genomeID, $sourceID);
1138              if ($url && ! exists $sourceURL{$genomeID}) {                  if ($url && ! exists $sourceURL{$sourceID}) {
1139                  $loadSourceURL->Put($sourceID, $url);                  $loadSourceURL->Put($sourceID, $url);
1140                  $sourceURL{$sourceID} = 1;                  $sourceURL{$sourceID} = 1;
1141              }              }
1142              if ($desc && ! exists $sourceDesc{$sourceID}) {                  if ($desc) {
1143                  $loadSource->Put($sourceID, $desc);                      $sourceDesc{$sourceID} = $desc;
1144                  $sourceDesc{$sourceID} = 1;                  } elsif (! exists $sourceDesc{$sourceID}) {
1145                        $sourceDesc{$sourceID} = $sourceID;
1146              }              }
1147          }          }
1148          close TMP;          close TMP;
1149      }      }
1150            # Write the source descriptions.
1151            for my $sourceID (keys %sourceDesc) {
1152                $loadSource->Put($sourceID, $sourceDesc{$sourceID});
1153            }
1154        }
1155      # Finish the load.      # Finish the load.
1156      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
1157      return $retVal;      return $retVal;
# Line 1074  Line 1191 
1191      my $fig = $self->{fig};      my $fig = $self->{fig};
1192      # Get the genome hash.      # Get the genome hash.
1193      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
1194      # Convert the genome hash. We'll get the genus and species for each genome and make      # Convert the genome hash. We'll get the genus and species for each genome and make
1195      # it the key.      # it the key.
1196      my %speciesHash = map { $fig->genus_species($_) => $_ } (keys %{$genomeHash});      my %speciesHash = map { $fig->genus_species($_) => $_ } (keys %{$genomeHash});
1197      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
1198      my $loadExternalAliasFunc = $self->_TableLoader('ExternalAliasFunc', $genomeCount * 4000);      my $loadExternalAliasFunc = $self->_TableLoader('ExternalAliasFunc');
1199      my $loadExternalAliasOrg = $self->_TableLoader('ExternalAliasOrg', $genomeCount * 4000);      my $loadExternalAliasOrg = $self->_TableLoader('ExternalAliasOrg');
1200      Trace("Beginning external data load.") if T(2);      if ($self->{options}->{loadOnly}) {
1201            Trace("Loading from existing files.") if T(2);
1202        } else {
1203            Trace("Generating external data.") if T(2);
1204      # 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.
1205      Open(\*ORGS, "<$FIG_Config::global/ext_org.table");      Open(\*ORGS, "<$FIG_Config::global/ext_org.table");
1206      my $orgLine;      my $orgLine;
# Line 1111  Line 1230 
1230              $loadExternalAliasFunc->Put(@funcFields[0,1]);              $loadExternalAliasFunc->Put(@funcFields[0,1]);
1231          }          }
1232      }      }
1233        }
1234        # Finish the load.
1235        my $retVal = $self->_FinishAll();
1236        return $retVal;
1237    }
1238    
1239    
1240    =head3 LoadReactionData
1241    
1242    C<< my $stats = $spl->LoadReactionData(); >>
1243    
1244    Load the reaction data from FIG into Sprout.
1245    
1246    Reaction data connects reactions to the compounds that participate in them.
1247    
1248    The following relations are loaded by this method.
1249    
1250        Reaction
1251        ReactionURL
1252        Compound
1253        CompoundName
1254        CompoundCAS
1255        IsAComponentOf
1256    
1257    This method proceeds reaction by reaction rather than genome by genome.
1258    
1259    =over 4
1260    
1261    =item RETURNS
1262    
1263    Returns a statistics object for the loads.
1264    
1265    =back
1266    
1267    =cut
1268    #: Return Type $%;
1269    sub LoadReactionData {
1270        # Get this object instance.
1271        my ($self) = @_;
1272        # Get the FIG object.
1273        my $fig = $self->{fig};
1274        # Create load objects for each of the tables we're loading.
1275        my $loadReaction = $self->_TableLoader('Reaction');
1276        my $loadReactionURL = $self->_TableLoader('ReactionURL', $self->PrimaryOnly);
1277        my $loadCompound = $self->_TableLoader('Compound', $self->PrimaryOnly);
1278        my $loadCompoundName = $self->_TableLoader('CompoundName', $self->PrimaryOnly);
1279        my $loadCompoundCAS = $self->_TableLoader('CompoundCAS', $self->PrimaryOnly);
1280        my $loadIsAComponentOf = $self->_TableLoader('IsAComponentOf', $self->PrimaryOnly);
1281        if ($self->{options}->{loadOnly}) {
1282            Trace("Loading from existing files.") if T(2);
1283        } else {
1284            Trace("Generating annotation data.") if T(2);
1285            # First we create the compounds.
1286            my @compounds = $fig->all_compounds();
1287            for my $cid (@compounds) {
1288                # Check for names.
1289                my @names = $fig->names_of_compound($cid);
1290                # Each name will be given a priority number, starting with 1.
1291                my $prio = 1;
1292                for my $name (@names) {
1293                    $loadCompoundName->Put($cid, $name, $prio++);
1294                }
1295                # Create the main compound record. Note that the first name
1296                # becomes the label.
1297                my $label = (@names > 0 ? $names[0] : $cid);
1298                $loadCompound->Put($cid, $label);
1299                # Check for a CAS ID.
1300                my $cas = $fig->cas($cid);
1301                if ($cas) {
1302                    $loadCompoundCAS->Put($cid, $cas);
1303                }
1304            }
1305            # All the compounds are set up, so we need to loop through the reactions next. First,
1306            # we initialize the discriminator index. This is a single integer used to insure
1307            # duplicate elements in a reaction are not accidentally collapsed.
1308            my $discrim = 0;
1309            my @reactions = $fig->all_reactions();
1310            for my $reactionID (@reactions) {
1311                # Create the reaction record.
1312                $loadReaction->Put($reactionID, $fig->reversible($reactionID));
1313                # Compute the reaction's URL.
1314                my $url = HTML::reaction_link($reactionID);
1315                # Put it in the ReactionURL table.
1316                $loadReactionURL->Put($reactionID, $url);
1317                # Now we need all of the reaction's compounds. We get these in two phases,
1318                # substrates first and then products.
1319                for my $product (0, 1) {
1320                    # Get the compounds of the current type for the current reaction. FIG will
1321                    # give us 3-tuples: [ID, stoichiometry, main-flag]. At this time we do not
1322                    # have location data in SEED, so it defaults to the empty string.
1323                    my @compounds = $fig->reaction2comp($reactionID, $product);
1324                    for my $compData (@compounds) {
1325                        # Extract the compound data from the current tuple.
1326                        my ($cid, $stoich, $main) = @{$compData};
1327                        # Link the compound to the reaction.
1328                        $loadIsAComponentOf->Put($cid, $reactionID, $discrim++, "", $main,
1329                                                 $product, $stoich);
1330                    }
1331                }
1332            }
1333        }
1334      # Finish the load.      # Finish the load.
1335      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
1336      return $retVal;      return $retVal;
# Line 1146  Line 1366 
1366      my $fig = $self->{fig};      my $fig = $self->{fig};
1367      # Get the genome hash.      # Get the genome hash.
1368      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
1369      # Create a load object for the table we're loading.      # Create a load object for the table we're loading.
1370      my $loadGenomeGroups = $self->_TableLoader('GenomeGroups', $genomeCount * 4);      my $loadGenomeGroups = $self->_TableLoader('GenomeGroups');
1371      Trace("Beginning group data load.") if T(2);      if ($self->{options}->{loadOnly}) {
1372            Trace("Loading from existing files.") if T(2);
1373        } else {
1374            Trace("Generating group data.") if T(2);
1375      # Loop through the genomes.      # Loop through the genomes.
1376      my $line;      my $line;
1377      for my $genomeID (keys %{$genomeHash}) {      for my $genomeID (keys %{$genomeHash}) {
# Line 1165  Line 1387 
1387          }          }
1388          close TMP;          close TMP;
1389      }      }
1390        }
1391      # Finish the load.      # Finish the load.
1392      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
1393      return $retVal;      return $retVal;
# Line 1186  Line 1409 
1409    
1410  Name of the table (relation) being loaded.  Name of the table (relation) being loaded.
1411    
1412  =item rowCount (optional)  =item ignore
1413    
1414  Estimated maximum number of rows in the table.  TRUE if the table should be ignored entirely, else FALSE.
1415    
1416  =item RETURN  =item RETURN
1417    
# Line 1200  Line 1423 
1423    
1424  sub _TableLoader {  sub _TableLoader {
1425      # Get the parameters.      # Get the parameters.
1426      my ($self, $tableName, $rowCount) = @_;      my ($self, $tableName, $ignore) = @_;
1427      # Create the load object.      # Create the load object.
1428      my $retVal = ERDBLoad->new($self->{erdb}, $tableName, $self->{loadDirectory}, $rowCount);      my $retVal = ERDBLoad->new($self->{erdb}, $tableName, $self->{loadDirectory}, $self->LoadOnly,
1429                                   $ignore);
1430      # Cache it in the loader list.      # Cache it in the loader list.
1431      push @{$self->{loaders}}, $retVal;      push @{$self->{loaders}}, $retVal;
1432      # Return it to the caller.      # Return it to the caller.
# Line 1239  Line 1463 
1463      # 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
1464      # ignominiously. At some future point, we want to make the loads restartable.      # ignominiously. At some future point, we want to make the loads restartable.
1465      while (my $loader = pop @{$loadList}) {      while (my $loader = pop @{$loadList}) {
1466            # Get the relation name.
1467            my $relName = $loader->RelName;
1468            # Check the ignore flag.
1469            if ($loader->Ignore) {
1470                Trace("Relation $relName not loaded.") if T(2);
1471            } else {
1472                # Here we really need to finish.
1473                Trace("Finishing $relName.") if T(2);
1474          my $stats = $loader->Finish();          my $stats = $loader->Finish();
1475                if ($self->{options}->{dbLoad}) {
1476                    # Here we want to use the load file just created to load the database.
1477                    Trace("Loading relation $relName.") if T(2);
1478                    my $newStats = $self->{sprout}->LoadUpdate(1, [$relName]);
1479                    # Accumulate the statistics from the DB load.
1480                    $stats->Accumulate($newStats);
1481                }
1482          $retVal->Accumulate($stats);          $retVal->Accumulate($stats);
         my $relName = $loader->RelName;  
1483          Trace("Statistics for $relName:\n" . $stats->Show()) if T(2);          Trace("Statistics for $relName:\n" . $stats->Show()) if T(2);
1484      }      }
1485        }
1486      # Return the load statistics.      # Return the load statistics.
1487      return $retVal;      return $retVal;
1488  }  }

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3