[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.6, Sun Sep 11 17:09:46 2005 UTC revision 1.26, Mon Jan 30 21:57:02 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 51  Line 52 
52    
53  =head3 new  =head3 new
54    
55  C<< my $spl = SproutLoad->new($sprout, $fig, $genomeFile, $subsysFile); >>  C<< my $spl = SproutLoad->new($sprout, $fig, $genomeFile, $subsysFile, $options); >>
56    
57  Construct a new Sprout Loader object, specifying the two participating databases and  Construct a new Sprout Loader object, specifying the two participating databases and
58  the name of the files containing the list of genomes and subsystems to use.  the name of the files containing the list of genomes and subsystems to use.
# Line 82  Line 83 
83  to a list of subsystem names. If nothing is specified, all known subsystems will be  to a list of subsystem names. If nothing is specified, all known subsystems will be
84  considered trusted. Only subsystem data related to the trusted subsystems is loaded.  considered trusted. Only subsystem data related to the trusted subsystems is loaded.
85    
86    =item options
87    
88    Reference to a hash of command-line options.
89    
90  =back  =back
91    
92  =cut  =cut
93    
94  sub new {  sub new {
95      # Get the parameters.      # Get the parameters.
96      my ($class, $sprout, $fig, $genomeFile, $subsysFile) = @_;      my ($class, $sprout, $fig, $genomeFile, $subsysFile, $options) = @_;
97      # Load the list of genomes into a hash.      # Load the list of genomes into a hash.
98      my %genomes;      my %genomes;
99      if (! defined($genomeFile) || $genomeFile eq '') {      if (! defined($genomeFile) || $genomeFile eq '') {
# Line 158  Line 163 
163                    sprout => $sprout,                    sprout => $sprout,
164                    loadDirectory => $directory,                    loadDirectory => $directory,
165                    erdb => $sprout->{_erdb},                    erdb => $sprout->{_erdb},
166                    loaders => []                    loaders => [],
167                      options => $options
168                   };                   };
169      # Bless and return it.      # Bless and return it.
170      bless $retVal, $class;      bless $retVal, $class;
171      return $retVal;      return $retVal;
172  }  }
173    
174    =head3 LoadOnly
175    
176    C<< my $flag = $spl->LoadOnly; >>
177    
178    Return TRUE if we are in load-only mode, else FALSE.
179    
180    =cut
181    
182    sub LoadOnly {
183        my ($self) = @_;
184        return $self->{options}->{loadOnly};
185    }
186    
187    =head3 PrimaryOnly
188    
189    C<< my $flag = $spl->PrimaryOnly; >>
190    
191    Return TRUE if only the main entity is to be loaded, else FALSE.
192    
193    =cut
194    
195    sub PrimaryOnly {
196        my ($self) = @_;
197        return $self->{options}->{primaryOnly};
198    }
199    
200  =head3 LoadGenomeData  =head3 LoadGenomeData
201    
202  C<< my $stats = $spl->LoadGenomeData(); >>  C<< my $stats = $spl->LoadGenomeData(); >>
# Line 192  Line 224 
224    
225  =back  =back
226    
 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.)  
   
227  =cut  =cut
228  #: Return Type $%;  #: Return Type $%;
229  sub LoadGenomeData {  sub LoadGenomeData {
# Line 210  Line 234 
234      # Get the genome count.      # Get the genome count.
235      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
236      my $genomeCount = (keys %{$genomeHash});      my $genomeCount = (keys %{$genomeHash});
     Trace("Beginning genome data load.") if T(2);  
237      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
238      my $loadGenome = $self->_TableLoader('Genome', $genomeCount);      my $loadGenome = $self->_TableLoader('Genome');
239      my $loadHasContig = $self->_TableLoader('HasContig', $genomeCount * 300);      my $loadHasContig = $self->_TableLoader('HasContig', $self->PrimaryOnly);
240      my $loadContig = $self->_TableLoader('Contig', $genomeCount * 300);      my $loadContig = $self->_TableLoader('Contig', $self->PrimaryOnly);
241      my $loadIsMadeUpOf = $self->_TableLoader('IsMadeUpOf', $genomeCount * 60000);      my $loadIsMadeUpOf = $self->_TableLoader('IsMadeUpOf', $self->PrimaryOnly);
242      my $loadSequence = $self->_TableLoader('Sequence', $genomeCount * 60000);      my $loadSequence = $self->_TableLoader('Sequence', $self->PrimaryOnly);
243        if ($self->{options}->{loadOnly}) {
244            Trace("Loading from existing files.") if T(2);
245        } else {
246            Trace("Generating genome data.") if T(2);
247      # Now we loop through the genomes, generating the data for each one.      # Now we loop through the genomes, generating the data for each one.
248      for my $genomeID (sort keys %{$genomeHash}) {      for my $genomeID (sort keys %{$genomeHash}) {
249          Trace("Loading data for genome $genomeID.") if T(3);              Trace("Generating data for genome $genomeID.") if T(3);
250          $loadGenome->Add("genomeIn");          $loadGenome->Add("genomeIn");
251          # The access code comes in via the genome hash.          # The access code comes in via the genome hash.
252          my $accessCode = $genomeHash->{$genomeID};          my $accessCode = $genomeHash->{$genomeID};
# Line 262  Line 289 
289              }              }
290          }          }
291      }      }
292        }
293      # Finish the loads.      # Finish the loads.
294      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
295      # Return the result.      # Return the result.
# Line 305  Line 333 
333      my $genomeCount = (keys %{$genomeFilter});      my $genomeCount = (keys %{$genomeFilter});
334      my $featureCount = $genomeCount * 4000;      my $featureCount = $genomeCount * 4000;
335      # Start the loads.      # Start the loads.
336      my $loadCoupling = $self->_TableLoader('Coupling', $featureCount * $genomeCount);      my $loadCoupling = $self->_TableLoader('Coupling');
337      my $loadIsEvidencedBy = $self->_TableLoader('IsEvidencedBy', $featureCount * 8000);      my $loadIsEvidencedBy = $self->_TableLoader('IsEvidencedBy', $self->PrimaryOnly);
338      my $loadPCH = $self->_TableLoader('PCH', $featureCount * 2000);      my $loadPCH = $self->_TableLoader('PCH', $self->PrimaryOnly);
339      my $loadParticipatesInCoupling = $self->_TableLoader('ParticipatesInCoupling', $featureCount * 2000);      my $loadParticipatesInCoupling = $self->_TableLoader('ParticipatesInCoupling', $self->PrimaryOnly);
340      my $loadUsesAsEvidence = $self->_TableLoader('UsesAsEvidence', $featureCount * 8000);      my $loadUsesAsEvidence = $self->_TableLoader('UsesAsEvidence', $self->PrimaryOnly);
341      Trace("Beginning coupling data load.") if T(2);      if ($self->{options}->{loadOnly}) {
342            Trace("Loading from existing files.") if T(2);
343        } else {
344            Trace("Generating coupling data.") if T(2);
345      # Loop through the genomes found.      # Loop through the genomes found.
346      for my $genome (sort keys %{$genomeFilter}) {      for my $genome (sort keys %{$genomeFilter}) {
347          Trace("Generating coupling data for $genome.") if T(3);          Trace("Generating coupling data for $genome.") if T(3);
# Line 362  Line 393 
393                              # We store this evidence in the hash if the usage                              # We store this evidence in the hash if the usage
394                              # is nonzero or no prior evidence has been found. This                              # is nonzero or no prior evidence has been found. This
395                              # insures that if there is duplicate evidence, we                              # insures that if there is duplicate evidence, we
396                              # at least keep the meaningful ones. Only evidence is                                  # at least keep the meaningful ones. Only evidence in
397                              # the hash makes it to the output.                              # the hash makes it to the output.
398                              if ($usage || ! exists $evidenceMap{$evidenceKey}) {                              if ($usage || ! exists $evidenceMap{$evidenceKey}) {
399                                  $evidenceMap{$evidenceKey} = $evidenceData;                                  $evidenceMap{$evidenceKey} = $evidenceData;
# Line 377  Line 408 
408                          $loadIsEvidencedBy->Put($coupleID, $evidenceID);                          $loadIsEvidencedBy->Put($coupleID, $evidenceID);
409                          # Connect it to the features.                          # Connect it to the features.
410                          $loadUsesAsEvidence->Put($evidenceID, $peg3, 1);                          $loadUsesAsEvidence->Put($evidenceID, $peg3, 1);
411                          $loadUsesAsEvidence->Put($evidenceID, $peg4, 1);                              $loadUsesAsEvidence->Put($evidenceID, $peg4, 2);
412                            }
413                      }                      }
414                  }                  }
415              }              }
# Line 422  Line 454 
454      my $fig = $self->{fig};      my $fig = $self->{fig};
455      # Get the table of genome IDs.      # Get the table of genome IDs.
456      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
     my $featureCount = $genomeCount * 4000;  
457      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
458      my $loadFeature = $self->_TableLoader('Feature', $featureCount);      my $loadFeature = $self->_TableLoader('Feature');
459      my $loadFeatureAlias = $self->_TableLoader('FeatureAlias', $featureCount * 6);      my $loadIsLocatedIn = $self->_TableLoader('IsLocatedIn', $self->PrimaryOnly);
460      my $loadFeatureLink = $self->_TableLoader('FeatureLink', $featureCount * 10);      my $loadFeatureAlias = $self->_TableLoader('FeatureAlias');
461      my $loadFeatureTranslation = $self->_TableLoader('FeatureTranslation', $featureCount);      my $loadFeatureLink = $self->_TableLoader('FeatureLink');
462      my $loadFeatureUpstream = $self->_TableLoader('FeatureUpstream', $featureCount);      my $loadFeatureTranslation = $self->_TableLoader('FeatureTranslation');
463      my $loadIsLocatedIn = $self->_TableLoader('IsLocatedIn', $featureCount);      my $loadFeatureUpstream = $self->_TableLoader('FeatureUpstream');
464      # 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
465      # locations.      # locations.
466      my $chunkSize = $self->{sprout}->MaxSegment();      my $chunkSize = $self->{sprout}->MaxSegment();
467      Trace("Beginning feature data load.") if T(2);      if ($self->{options}->{loadOnly}) {
468            Trace("Loading from existing files.") if T(2);
469        } else {
470            Trace("Generating feature data.") if T(2);
471      # Now we loop through the genomes, generating the data for each one.      # Now we loop through the genomes, generating the data for each one.
472      for my $genomeID (sort keys %{$genomeHash}) {      for my $genomeID (sort keys %{$genomeHash}) {
473          Trace("Loading features for genome $genomeID.") if T(3);          Trace("Loading features for genome $genomeID.") if T(3);
# Line 445  Line 478 
478          for my $featureData (@{$features}) {          for my $featureData (@{$features}) {
479              $loadFeature->Add("featureIn");              $loadFeature->Add("featureIn");
480              # Split the tuple.              # Split the tuple.
481              my ($featureID, $locations, $aliases, $type) = @{$featureData};                  my ($featureID, $locations, undef, $type) = @{$featureData};
482              # Create the feature record.              # Create the feature record.
483              $loadFeature->Put("$genomeID:$featureID", 1, $type);                  $loadFeature->Put($featureID, 1, $type);
484              # Create the aliases.              # Create the aliases.
485              for my $alias (split /\s*,\s*/, $aliases) {                  for my $alias ($fig->feature_aliases($featureID)) {
486                  $loadFeatureAlias->Put($featureID, $alias);                  $loadFeatureAlias->Put($featureID, $alias);
487              }              }
488              # Get the links.              # Get the links.
# Line 475  Line 508 
508              # the maximum segment size. This simplifies the genes_in_region processing              # the maximum segment size. This simplifies the genes_in_region processing
509              # for Sprout.              # for Sprout.
510              my @locationList = split /\s*,\s*/, $locations;              my @locationList = split /\s*,\s*/, $locations;
511                    # Create the location position indicator.
512                    my $i = 1;
513              # Loop through the locations.              # Loop through the locations.
514              for my $location (@locationList) {              for my $location (@locationList) {
515                  # Parse the location.                  # Parse the location.
516                  my $locObject = BasicLocation->new($location);                      my $locObject = BasicLocation->new("$genomeID:$location");
517                  # Split it into a list of chunks.                  # Split it into a list of chunks.
518                  my @locOList = ();                  my @locOList = ();
519                  while (my $peeling = $locObject->Peel($chunkSize)) {                  while (my $peeling = $locObject->Peel($chunkSize)) {
# Line 488  Line 523 
523                  push @locOList, $locObject;                  push @locOList, $locObject;
524                  # Loop through the chunks, creating IsLocatedIn records. The variable                  # Loop through the chunks, creating IsLocatedIn records. The variable
525                  # "$i" will be used to keep the location index.                  # "$i" will be used to keep the location index.
                 my $i = 1;  
526                  for my $locChunk (@locOList) {                  for my $locChunk (@locOList) {
527                      $loadIsLocatedIn->Put($featureID, $locChunk->Contig, $locChunk->Left,                      $loadIsLocatedIn->Put($featureID, $locChunk->Contig, $locChunk->Left,
528                                            $locChunk->Dir, $locChunk->Length, $i);                                            $locChunk->Dir, $locChunk->Length, $i);
# Line 497  Line 531 
531              }              }
532          }          }
533      }      }
534        }
535      # Finish the loads.      # Finish the loads.
536      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
537      return $retVal;      return $retVal;
# Line 533  Line 568 
568      my $fig = $self->{fig};      my $fig = $self->{fig};
569      # Get the table of genome IDs.      # Get the table of genome IDs.
570      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
     my $featureCount = $genomeCount * 4000;  
571      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
572      my $loadIsBidirectionalBestHitOf = $self->_TableLoader('IsBidirectionalBestHitOf',      my $loadIsBidirectionalBestHitOf = $self->_TableLoader('IsBidirectionalBestHitOf');
573                                                             $featureCount * $genomeCount);      if ($self->{options}->{loadOnly}) {
574      Trace("Beginning BBH load.") if T(2);          Trace("Loading from existing files.") if T(2);
575        } else {
576            Trace("Generating BBH data.") if T(2);
577      # Now we loop through the genomes, generating the data for each one.      # Now we loop through the genomes, generating the data for each one.
578      for my $genomeID (sort keys %{$genomeHash}) {      for my $genomeID (sort keys %{$genomeHash}) {
579          $loadIsBidirectionalBestHitOf->Add("genomeIn");          $loadIsBidirectionalBestHitOf->Add("genomeIn");
# Line 564  Line 599 
599              }              }
600          }          }
601      }      }
602        }
603      # Finish the loads.      # Finish the loads.
604      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
605      return $retVal;      return $retVal;
# Line 585  Line 621 
621    
622      Subsystem      Subsystem
623      Role      Role
624        RoleEC
625      SSCell      SSCell
626      ContainsFeature      ContainsFeature
627      IsGenomeOf      IsGenomeOf
# Line 592  Line 629 
629      OccursInSubsystem      OccursInSubsystem
630      ParticipatesIn      ParticipatesIn
631      HasSSCell      HasSSCell
632        ConsistsOfRoles
633        RoleSubset
634        HasRoleSubset
635        ConsistsOfGenomes
636        GenomeSubset
637        HasGenomeSubset
638        Catalyzes
639        Diagram
640        RoleOccursIn
641    
642  =over 4  =over 4
643    
# Line 601  Line 647 
647    
648  =back  =back
649    
 B<TO DO>  
   
 Generate RoleName table?  
   
650  =cut  =cut
651  #: Return Type $%;  #: Return Type $%;
652  sub LoadSubsystemData {  sub LoadSubsystemData {
# Line 618  Line 660 
660      # Get the subsystem hash. This lists the subsystems we'll process.      # Get the subsystem hash. This lists the subsystems we'll process.
661      my $subsysHash = $self->{subsystems};      my $subsysHash = $self->{subsystems};
662      my @subsysIDs = sort keys %{$subsysHash};      my @subsysIDs = sort keys %{$subsysHash};
663      my $subsysCount = @subsysIDs;      # Get the map list.
664      my $genomeCount = (keys %{$genomeHash});      my @maps = $fig->all_maps;
     my $featureCount = $genomeCount * 4000;  
665      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
666      my $loadSubsystem = $self->_TableLoader('Subsystem', $subsysCount);      my $loadDiagram = $self->_TableLoader('Diagram', $self->PrimaryOnly);
667      my $loadRole = $self->_TableLoader('Role', $featureCount * 6);      my $loadRoleOccursIn = $self->_TableLoader('RoleOccursIn', $self->PrimaryOnly);
668      my $loadSSCell = $self->_TableLoader('SSCell', $featureCount * $genomeCount);      my $loadSubsystem = $self->_TableLoader('Subsystem');
669      my $loadContainsFeature = $self->_TableLoader('ContainsFeature', $featureCount * $subsysCount);      my $loadRole = $self->_TableLoader('Role', $self->PrimaryOnly);
670      my $loadIsGenomeOf = $self->_TableLoader('IsGenomeOf', $featureCount * $genomeCount);      my $loadRoleEC = $self->_TableLoader('RoleEC', $self->PrimaryOnly);
671      my $loadIsRoleOf = $self->_TableLoader('IsRoleOf', $featureCount * $genomeCount);      my $loadCatalyzes = $self->_TableLoader('Catalyzes', $self->PrimaryOnly);
672      my $loadOccursInSubsystem = $self->_TableLoader('OccursInSubsystem', $featureCount * 6);      my $loadSSCell = $self->_TableLoader('SSCell', $self->PrimaryOnly);
673      my $loadParticipatesIn = $self->_TableLoader('ParticipatesIn', $subsysCount * $genomeCount);      my $loadContainsFeature = $self->_TableLoader('ContainsFeature', $self->PrimaryOnly);
674      my $loadHasSSCell = $self->_TableLoader('HasSSCell', $featureCount * $genomeCount);      my $loadIsGenomeOf = $self->_TableLoader('IsGenomeOf', $self->PrimaryOnly);
675      Trace("Beginning subsystem data load.") if T(2);      my $loadIsRoleOf = $self->_TableLoader('IsRoleOf', $self->PrimaryOnly);
676        my $loadOccursInSubsystem = $self->_TableLoader('OccursInSubsystem', $self->PrimaryOnly);
677        my $loadParticipatesIn = $self->_TableLoader('ParticipatesIn', $self->PrimaryOnly);
678        my $loadHasSSCell = $self->_TableLoader('HasSSCell', $self->PrimaryOnly);
679        my $loadRoleSubset = $self->_TableLoader('RoleSubset', $self->PrimaryOnly);
680        my $loadGenomeSubset = $self->_TableLoader('GenomeSubset', $self->PrimaryOnly);
681        my $loadConsistsOfRoles = $self->_TableLoader('ConsistsOfRoles', $self->PrimaryOnly);
682        my $loadConsistsOfGenomes = $self->_TableLoader('ConsistsOfGenomes', $self->PrimaryOnly);
683        my $loadHasRoleSubset = $self->_TableLoader('HasRoleSubset', $self->PrimaryOnly);
684        my $loadHasGenomeSubset = $self->_TableLoader('HasGenomeSubset', $self->PrimaryOnly);
685        if ($self->{options}->{loadOnly}) {
686            Trace("Loading from existing files.") if T(2);
687        } else {
688            Trace("Generating subsystem data.") if T(2);
689            # This hash will contain the role for each EC. When we're done, this
690            # information will be used to generate the Catalyzes table.
691            my %ecToRoles = ();
692      # Loop through the subsystems. Our first task will be to create the      # Loop through the subsystems. Our first task will be to create the
693      # roles. We do this by looping through the subsystems and creating a      # roles. We do this by looping through the subsystems and creating a
694      # 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
695      # duplicates. As we move along, we'll connect the roles and subsystems.          # duplicates. As we move along, we'll connect the roles and subsystems
696            # and memorize up the reactions.
697            my ($genomeID, $roleID);
698      my %roleData = ();      my %roleData = ();
699      for my $subsysID (@subsysIDs) {      for my $subsysID (@subsysIDs) {
700          Trace("Creating subsystem $subsysID.") if T(3);          Trace("Creating subsystem $subsysID.") if T(3);
701          $loadSubsystem->Add("subsystemIn");          $loadSubsystem->Add("subsystemIn");
702                # Get the subsystem object.
703                my $sub = $fig->get_subsystem($subsysID);
704          # Create the subsystem record.          # Create the subsystem record.
705          $loadSubsystem->Put($subsysID);              my $curator = $sub->get_curator();
706          # Get the subsystem's roles.              my $notes = $sub->get_notes();
707          my @roles = $fig->subsystem_to_roles($subsysID);              $loadSubsystem->Put($subsysID, $curator, $notes);
708          # 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.
709          # a role record for it.              for (my $col = 0; defined($roleID = $sub->get_role($col)); $col++) {
710          for my $roleID (@roles) {                  # Connect to this role.
711              $loadOccursInSubsystem->Add("roleIn");              $loadOccursInSubsystem->Add("roleIn");
712              $loadOccursInSubsystem->Put($roleID, $subsysID);                  $loadOccursInSubsystem->Put($roleID, $subsysID, $col);
713                    # If it's a new role, add it to the role table.
714              if (! exists $roleData{$roleID}) {              if (! exists $roleData{$roleID}) {
715                  $loadRole->Put($roleID);                      # Get the role's abbreviation.
716                        my $abbr = $sub->get_role_abbr($col);
717                        # Add the role.
718                        $loadRole->Put($roleID, $abbr);
719                  $roleData{$roleID} = 1;                  $roleData{$roleID} = 1;
720                        # Check for an EC number.
721                        if ($roleID =~ /\(EC ([^.]+\.[^.]+\.[^.]+\.[^)]+)\)\s*$/) {
722                            my $ec = $1;
723                            $loadRoleEC->Put($roleID, $ec);
724                            $ecToRoles{$ec} = $roleID;
725                        }
726              }              }
727          }          }
728          # 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
729          # 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
730          # get the genomes on the sheet.              # to actually create the roles as we find them.
731          Trace("Creating subsystem $subsysID spreadsheet.") if T(3);          Trace("Creating subsystem $subsysID spreadsheet.") if T(3);
732          my @genomes = map { $_->[0] } @{$fig->subsystem_genomes($subsysID)};              for (my $row = 0; defined($genomeID = $sub->get_genome($row)); $row++) {
733          for my $genomeID (@genomes) {                  # Only proceed if this is one of our genomes.
             # Only process this genome if it's one of ours.  
734              if (exists $genomeHash->{$genomeID}) {              if (exists $genomeHash->{$genomeID}) {
735                  # Connect the genome to the subsystem.                      # Count the PEGs and cells found for verification purposes.
736                  $loadParticipatesIn->Put($genomeID, $subsysID);                      my $pegCount = 0;
737                        my $cellCount = 0;
738                        # Create a list for the PEGs we find. This list will be used
739                        # to generate cluster numbers.
740                        my @pegsFound = ();
741                        # Create a hash that maps spreadsheet IDs to PEGs. We will
742                        # use this to generate the ContainsFeature data after we have
743                        # the cluster numbers.
744                        my %cellPegs = ();
745                        # Get the genome's variant code for this subsystem.
746                        my $variantCode = $sub->get_variant_code($row);
747                  # 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
748                  # part of the spreadsheet cell ID.                  # part of the spreadsheet cell ID.
749                  for (my $i = 0; $i <= $#roles; $i++) {                      for (my $col = 0; defined($roleID = $sub->get_role($col)); $col++) {
                     my $role = $roles[$i];  
750                      # Get the features in the spreadsheet cell for this genome and role.                      # Get the features in the spreadsheet cell for this genome and role.
751                      my @pegs = $fig->pegs_in_subsystem_cell($subsysID, $genomeID, $i);                          my @pegs = $sub->get_pegs_from_cell($row, $col);
752                      # Only proceed if features exist.                      # Only proceed if features exist.
753                      if (@pegs > 0) {                      if (@pegs > 0) {
754                          # Create the spreadsheet cell.                          # Create the spreadsheet cell.
755                          my $cellID = "$subsysID:$genomeID:$i";                              $cellCount++;
756                                my $cellID = "$subsysID:$genomeID:$col";
757                          $loadSSCell->Put($cellID);                          $loadSSCell->Put($cellID);
758                          $loadIsGenomeOf->Put($genomeID, $cellID);                          $loadIsGenomeOf->Put($genomeID, $cellID);
759                          $loadIsRoleOf->Put($role, $cellID);                              $loadIsRoleOf->Put($roleID, $cellID);
760                          $loadHasSSCell->Put($subsysID, $cellID);                          $loadHasSSCell->Put($subsysID, $cellID);
761                          # Attach the features to it.                              # Remember its features.
762                          for my $pegID (@pegs) {                              push @pegsFound, @pegs;
763                              $loadContainsFeature->Put($cellID, $pegID);                              $cellPegs{$cellID} = \@pegs;
764                                $pegCount += @pegs;
765                            }
766                        }
767                        # If we found some cells for this genome, we need to compute clusters and
768                        # denote it participates in the subsystem.
769                        if ($pegCount > 0) {
770                            Trace("$pegCount PEGs in $cellCount cells for $genomeID.") if T(3);
771                            $loadParticipatesIn->Put($genomeID, $subsysID, $variantCode);
772                            # Partition the PEGs found into clusters.
773                            my @clusters = $fig->compute_clusters(\@pegsFound, $sub);
774                            # Create a hash mapping PEG IDs to cluster numbers.
775                            # We default to -1 for all of them.
776                            my %clusterOf = map { $_ => -1 } @pegsFound;
777                            for (my $i = 0; $i <= $#clusters; $i++) {
778                                my $subList = $clusters[$i];
779                                for my $peg (@{$subList}) {
780                                    $clusterOf{$peg} = $i;
781                                }
782                            }
783                            # Create the ContainsFeature data.
784                            for my $cellID (keys %cellPegs) {
785                                my $cellList = $cellPegs{$cellID};
786                                for my $cellPeg (@$cellList) {
787                                    $loadContainsFeature->Put($cellID, $cellPeg, $clusterOf{$cellPeg});
788                          }                          }
789                      }                      }
790                  }                  }
791              }              }
792          }          }
793                # Now we need to generate the subsets. The subset names must be concatenated to
794                # the subsystem name to make them unique keys. There are two types of subsets:
795                # genome subsets and role subsets. We do the role subsets first.
796                my @subsetNames = $sub->get_subset_names();
797                for my $subsetID (@subsetNames) {
798                    # Create the subset record.
799                    my $actualID = "$subsysID:$subsetID";
800                    $loadRoleSubset->Put($actualID);
801                    # Connect the subset to the subsystem.
802                    $loadHasRoleSubset->Put($subsysID, $actualID);
803                    # Connect the subset to its roles.
804                    my @roles = $sub->get_subset($subsetID);
805                    for my $roleID (@roles) {
806                        $loadConsistsOfRoles->Put($actualID, $roleID);
807      }      }
     # Finish the load.  
     my $retVal = $self->_FinishAll();  
     return $retVal;  
808  }  }
809                # Next the genome subsets.
810  =head3 LoadDiagramData              @subsetNames = $sub->get_subset_namesR();
811                for my $subsetID (@subsetNames) {
812  C<< my $stats = $spl->LoadDiagramData(); >>                  # Create the subset record.
813                    my $actualID = "$subsysID:$subsetID";
814  Load the diagram data from FIG into Sprout.                  $loadGenomeSubset->Put($actualID);
815                    # Connect the subset to the subsystem.
816  Diagrams are used to organize functional roles. The diagram shows the                  $loadHasGenomeSubset->Put($subsysID, $actualID);
817  connections between chemicals that interact with a subsystem.                  # Connect the subset to its genomes.
818                    my @genomes = $sub->get_subsetR($subsetID);
819  The following relations are loaded by this method.                  for my $genomeID (@genomes) {
820                        $loadConsistsOfGenomes->Put($actualID, $genomeID);
821      Diagram                  }
822      RoleOccursIn              }
823            }
824  =over 4          # Now we loop through the diagrams. We need to create the diagram records
825            # and link each diagram to its roles. Note that only roles which occur
826  =item RETURNS          # in subsystems (and therefore appear in the %ecToRoles hash) are
827            # included.
828  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) {  
829          Trace("Loading diagram $map.") if T(3);          Trace("Loading diagram $map.") if T(3);
830          # Get the diagram's descriptive name.          # Get the diagram's descriptive name.
831          my $name = $fig->map_name($map);          my $name = $fig->map_name($map);
# Line 740  Line 834 
834          # A hash is used to prevent duplicates.          # A hash is used to prevent duplicates.
835          my %roleHash = ();          my %roleHash = ();
836          for my $role ($fig->map_to_ecs($map)) {          for my $role ($fig->map_to_ecs($map)) {
837              if (! $roleHash{$role}) {                  if (exists $ecToRoles{$role} && ! $roleHash{$role}) {
838                  $loadRoleOccursIn->Put($role, $map);                      $loadRoleOccursIn->Put($ecToRoles{$role}, $map);
839                  $roleHash{$role} = 1;                  $roleHash{$role} = 1;
840              }              }
841          }          }
842      }      }
843            # Before we leave, we must create the Catalyzes table. We start with the reactions,
844            # then use the "ecToRoles" table to convert EC numbers to role IDs.
845            my @reactions = $fig->all_reactions();
846            for my $reactionID (@reactions) {
847                # Get this reaction's list of roles. The results will be EC numbers.
848                my @roles = $fig->catalyzed_by($reactionID);
849                # Loop through the roles, creating catalyzation records.
850                for my $thisRole (@roles) {
851                    if (exists $ecToRoles{$thisRole}) {
852                        $loadCatalyzes->Put($ecToRoles{$thisRole}, $reactionID);
853                    }
854                }
855            }
856        }
857      # Finish the load.      # Finish the load.
858      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
859      return $retVal;      return $retVal;
# Line 787  Line 895 
895      my $fig = $self->{fig};      my $fig = $self->{fig};
896      # Get the genome hash.      # Get the genome hash.
897      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
898      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
899      my $loadProperty = $self->_TableLoader('Property', $genomeCount * 1500);      my $loadProperty = $self->_TableLoader('Property');
900      my $loadHasProperty = $self->_TableLoader('HasProperty', $genomeCount * 1500);      my $loadHasProperty = $self->_TableLoader('HasProperty', $self->PrimaryOnly);
901      Trace("Beginning property data load.") if T(2);      if ($self->{options}->{loadOnly}) {
902            Trace("Loading from existing files.") if T(2);
903        } else {
904            Trace("Generating property data.") if T(2);
905      # Create a hash for storing property IDs.      # Create a hash for storing property IDs.
906      my %propertyKeys = ();      my %propertyKeys = ();
907      my $nextID = 1;      my $nextID = 1;
908      # Loop through the genomes.      # Loop through the genomes.
909      for my $genomeID (keys %{$genomeHash}) {      for my $genomeID (keys %{$genomeHash}) {
910          $loadProperty->Add("genomeIn");          $loadProperty->Add("genomeIn");
911                Trace("Generating properties for $genomeID.") if T(3);
912          # 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
913          # tuples returned by "all_features_detailed". We use "all_features_detailed"          # tuples returned by "all_features_detailed". We use "all_features_detailed"
914          # rather than "all_features" because we want all features regardless of type.          # rather than "all_features" because we want all features regardless of type.
915          my @features = map { $_->[0] } @{$fig->all_features_detailed($genomeID)};          my @features = map { $_->[0] } @{$fig->all_features_detailed($genomeID)};
916                my $featureCount = 0;
917                my $propertyCount = 0;
918          # Loop through the features, creating HasProperty records.          # Loop through the features, creating HasProperty records.
919          for my $fid (@features) {          for my $fid (@features) {
             $loadProperty->Add("featureIn");  
920              # 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
921              # to insure we do not get any genome attributes.              # to insure we do not get any genome attributes.
922              my @attributeList = $fig->get_attributes($fid, '', '', '');              my @attributeList = $fig->get_attributes($fid, '', '', '');
923                    if (scalar @attributeList) {
924                        $featureCount++;
925                    }
926              # Loop through the attributes.              # Loop through the attributes.
927              for my $tuple (@attributeList) {              for my $tuple (@attributeList) {
928                        $propertyCount++;
929                  # 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,
930                  # since it will always be the same as the value if "$fid".                  # since it will always be the same as the value if "$fid".
931                  my (undef, $key, $value, $url) = @{$tuple};                  my (undef, $key, $value, $url) = @{$tuple};
# Line 831  Line 947 
947                  $loadHasProperty->Put($fid, $propertyID, $url);                  $loadHasProperty->Put($fid, $propertyID, $url);
948              }              }
949          }          }
950                # Update the statistics.
951                Trace("$propertyCount attributes processed for $featureCount features.") if T(3);
952                $loadHasProperty->Add("featuresIn", $featureCount);
953                $loadHasProperty->Add("propertiesIn", $propertyCount);
954            }
955      }      }
956      # Finish the load.      # Finish the load.
957      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
# Line 871  Line 992 
992      my $fig = $self->{fig};      my $fig = $self->{fig};
993      # Get the genome hash.      # Get the genome hash.
994      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
995      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
996      my $loadAnnotation = $self->_TableLoader('Annotation', $genomeCount * 4000);      my $loadAnnotation = $self->_TableLoader('Annotation');
997      my $loadIsTargetOfAnnotation = $self->_TableLoader('IsTargetOfAnnotation', $genomeCount * 4000);      my $loadIsTargetOfAnnotation = $self->_TableLoader('IsTargetOfAnnotation', $self->PrimaryOnly);
998      my $loadSproutUser = $self->_TableLoader('SproutUser', 100);      my $loadSproutUser = $self->_TableLoader('SproutUser', $self->PrimaryOnly);
999      my $loadUserAccess = $self->_TableLoader('UserAccess', 1000);      my $loadUserAccess = $self->_TableLoader('UserAccess', $self->PrimaryOnly);
1000      my $loadMadeAnnotation = $self->_TableLoader('MadeAnnotation', $genomeCount * 4000);      my $loadMadeAnnotation = $self->_TableLoader('MadeAnnotation', $self->PrimaryOnly);
1001      Trace("Beginning annotation data load.") if T(2);      if ($self->{options}->{loadOnly}) {
1002            Trace("Loading from existing files.") if T(2);
1003        } else {
1004            Trace("Generating annotation data.") if T(2);
1005      # 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
1006      # user records.      # user records.
1007      my %users = ( FIG => 1, master => 1 );      my %users = ( FIG => 1, master => 1 );
# Line 899  Line 1022 
1022              # 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
1023              # from showing up for a single PEG's annotations.              # from showing up for a single PEG's annotations.
1024              my %seenTimestamps = ();              my %seenTimestamps = ();
1025              # 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.  
1026                  for my $tuple ($fig->feature_annotations($peg, "raw")) {                  for my $tuple ($fig->feature_annotations($peg, "raw")) {
1027                      my ($fid, $timestamp, $user, $text) = @{$tuple};                      my ($fid, $timestamp, $user, $text) = @{$tuple};
1028                      # Here we fix up the annotation text. "\r" is removed,                      # Here we fix up the annotation text. "\r" is removed,
# Line 927  Line 1036 
1036                      $text =~ s/Set master function/Set FIG function/s;                      $text =~ s/Set master function/Set FIG function/s;
1037                      # Insure the time stamp is valid.                      # Insure the time stamp is valid.
1038                      if ($timestamp =~ /^\d+$/) {                      if ($timestamp =~ /^\d+$/) {
1039                          # 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
1040                          while ($seenTimestamps{$timestamp}) {                          # the key is unique.
1041                              $timestamp++;                          my $keyStamp = $timestamp;
1042                            while ($seenTimestamps{$keyStamp}) {
1043                                $keyStamp++;
1044                          }                          }
1045                          $seenTimestamps{$timestamp} = 1;                          $seenTimestamps{$keyStamp} = 1;
1046                          my $annotationID = "$peg:$timestamp";                          my $annotationID = "$peg:$keyStamp";
1047                          # Insure the user exists.                          # Insure the user exists.
1048                          if (! $users{$user}) {                          if (! $users{$user}) {
1049                              $loadSproutUser->Put($user, "SEED user");                              $loadSproutUser->Put($user, "SEED user");
# Line 940  Line 1051 
1051                              $users{$user} = 1;                              $users{$user} = 1;
1052                          }                          }
1053                          # Generate the annotation.                          # Generate the annotation.
1054                          $loadAnnotation->Put($annotationID, $timestamp, "$user\\n$text");                          $loadAnnotation->Put($annotationID, $timestamp, $text);
1055                          $loadIsTargetOfAnnotation->Put($peg, $annotationID);                          $loadIsTargetOfAnnotation->Put($peg, $annotationID);
1056                          $loadMadeAnnotation->Put($user, $annotationID);                          $loadMadeAnnotation->Put($user, $annotationID);
1057                      } else {                      } else {
# Line 991  Line 1102 
1102      my $fig = $self->{fig};      my $fig = $self->{fig};
1103      # Get the genome hash.      # Get the genome hash.
1104      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
1105      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
1106      my $loadComesFrom = $self->_TableLoader('ComesFrom', $genomeCount * 4);      my $loadComesFrom = $self->_TableLoader('ComesFrom', $self->PrimaryOnly);
1107      my $loadSource = $self->_TableLoader('Source', $genomeCount * 4);      my $loadSource = $self->_TableLoader('Source');
1108      my $loadSourceURL = $self->_TableLoader('SourceURL', $genomeCount * 8);      my $loadSourceURL = $self->_TableLoader('SourceURL');
1109      Trace("Beginning source data load.") if T(2);      if ($self->{options}->{loadOnly}) {
1110            Trace("Loading from existing files.") if T(2);
1111        } else {
1112            Trace("Generating annotation data.") if T(2);
1113      # Create hashes to collect the Source information.      # Create hashes to collect the Source information.
1114      my %sourceURL = ();      my %sourceURL = ();
1115      my %sourceDesc = ();      my %sourceDesc = ();
# Line 1010  Line 1123 
1123              chomp $line;              chomp $line;
1124              my($sourceID, $desc, $url) = split(/\t/,$line);              my($sourceID, $desc, $url) = split(/\t/,$line);
1125              $loadComesFrom->Put($genomeID, $sourceID);              $loadComesFrom->Put($genomeID, $sourceID);
1126              if ($url && ! exists $sourceURL{$genomeID}) {                  if ($url && ! exists $sourceURL{$sourceID}) {
1127                  $loadSourceURL->Put($sourceID, $url);                  $loadSourceURL->Put($sourceID, $url);
1128                  $sourceURL{$sourceID} = 1;                  $sourceURL{$sourceID} = 1;
1129              }              }
1130              if ($desc && ! exists $sourceDesc{$sourceID}) {                  if ($desc) {
1131                  $loadSource->Put($sourceID, $desc);                      $sourceDesc{$sourceID} = $desc;
1132                  $sourceDesc{$sourceID} = 1;                  } elsif (! exists $sourceDesc{$sourceID}) {
1133                        $sourceDesc{$sourceID} = $sourceID;
1134              }              }
1135          }          }
1136          close TMP;          close TMP;
1137      }      }
1138            # Write the source descriptions.
1139            for my $sourceID (keys %sourceDesc) {
1140                $loadSource->Put($sourceID, $sourceDesc{$sourceID});
1141            }
1142        }
1143      # Finish the load.      # Finish the load.
1144      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
1145      return $retVal;      return $retVal;
# Line 1060  Line 1179 
1179      my $fig = $self->{fig};      my $fig = $self->{fig};
1180      # Get the genome hash.      # Get the genome hash.
1181      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
1182      # 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
1183      # it the key.      # it the key.
1184      my %speciesHash = map { $fig->genus_species($_) => $_ } (keys %{$genomeHash});      my %speciesHash = map { $fig->genus_species($_) => $_ } (keys %{$genomeHash});
1185      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
1186      my $loadExternalAliasFunc = $self->_TableLoader('ExternalAliasFunc', $genomeCount * 4000);      my $loadExternalAliasFunc = $self->_TableLoader('ExternalAliasFunc');
1187      my $loadExternalAliasOrg = $self->_TableLoader('ExternalAliasOrg', $genomeCount * 4000);      my $loadExternalAliasOrg = $self->_TableLoader('ExternalAliasOrg');
1188      Trace("Beginning external data load.") if T(2);      if ($self->{options}->{loadOnly}) {
1189            Trace("Loading from existing files.") if T(2);
1190        } else {
1191            Trace("Generating external data.") if T(2);
1192      # 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.
1193      Open(\*ORGS, "<$FIG_Config::global/ext_org.table");      Open(\*ORGS, "<$FIG_Config::global/ext_org.table");
1194      my $orgLine;      my $orgLine;
# Line 1097  Line 1218 
1218              $loadExternalAliasFunc->Put(@funcFields[0,1]);              $loadExternalAliasFunc->Put(@funcFields[0,1]);
1219          }          }
1220      }      }
1221        }
1222        # Finish the load.
1223        my $retVal = $self->_FinishAll();
1224        return $retVal;
1225    }
1226    
1227    
1228    =head3 LoadReactionData
1229    
1230    C<< my $stats = $spl->LoadReactionData(); >>
1231    
1232    Load the reaction data from FIG into Sprout.
1233    
1234    Reaction data connects reactions to the compounds that participate in them.
1235    
1236    The following relations are loaded by this method.
1237    
1238        Reaction
1239        ReactionURL
1240        Compound
1241        CompoundName
1242        CompoundCAS
1243        IsAComponentOf
1244    
1245    This method proceeds reaction by reaction rather than genome by genome.
1246    
1247    =over 4
1248    
1249    =item RETURNS
1250    
1251    Returns a statistics object for the loads.
1252    
1253    =back
1254    
1255    =cut
1256    #: Return Type $%;
1257    sub LoadReactionData {
1258        # Get this object instance.
1259        my ($self) = @_;
1260        # Get the FIG object.
1261        my $fig = $self->{fig};
1262        # Create load objects for each of the tables we're loading.
1263        my $loadReaction = $self->_TableLoader('Reaction');
1264        my $loadReactionURL = $self->_TableLoader('ReactionURL', $self->PrimaryOnly);
1265        my $loadCompound = $self->_TableLoader('Compound', $self->PrimaryOnly);
1266        my $loadCompoundName = $self->_TableLoader('CompoundName', $self->PrimaryOnly);
1267        my $loadCompoundCAS = $self->_TableLoader('CompoundCAS', $self->PrimaryOnly);
1268        my $loadIsAComponentOf = $self->_TableLoader('IsAComponentOf', $self->PrimaryOnly);
1269        if ($self->{options}->{loadOnly}) {
1270            Trace("Loading from existing files.") if T(2);
1271        } else {
1272            Trace("Generating annotation data.") if T(2);
1273            # First we create the compounds.
1274            my @compounds = $fig->all_compounds();
1275            for my $cid (@compounds) {
1276                # Check for names.
1277                my @names = $fig->names_of_compound($cid);
1278                # Each name will be given a priority number, starting with 1.
1279                my $prio = 1;
1280                for my $name (@names) {
1281                    $loadCompoundName->Put($cid, $name, $prio++);
1282                }
1283                # Create the main compound record. Note that the first name
1284                # becomes the label.
1285                my $label = (@names > 0 ? $names[0] : $cid);
1286                $loadCompound->Put($cid, $label);
1287                # Check for a CAS ID.
1288                my $cas = $fig->cas($cid);
1289                if ($cas) {
1290                    $loadCompoundCAS->Put($cid, $cas);
1291                }
1292            }
1293            # All the compounds are set up, so we need to loop through the reactions next. First,
1294            # we initialize the discriminator index. This is a single integer used to insure
1295            # duplicate elements in a reaction are not accidentally collapsed.
1296            my $discrim = 0;
1297            my @reactions = $fig->all_reactions();
1298            for my $reactionID (@reactions) {
1299                # Create the reaction record.
1300                $loadReaction->Put($reactionID, $fig->reversible($reactionID));
1301                # Compute the reaction's URL.
1302                my $url = HTML::reaction_link($reactionID);
1303                # Put it in the ReactionURL table.
1304                $loadReactionURL->Put($reactionID, $url);
1305                # Now we need all of the reaction's compounds. We get these in two phases,
1306                # substrates first and then products.
1307                for my $product (0, 1) {
1308                    # Get the compounds of the current type for the current reaction. FIG will
1309                    # give us 3-tuples: [ID, stoichiometry, main-flag]. At this time we do not
1310                    # have location data in SEED, so it defaults to the empty string.
1311                    my @compounds = $fig->reaction2comp($reactionID, $product);
1312                    for my $compData (@compounds) {
1313                        # Extract the compound data from the current tuple.
1314                        my ($cid, $stoich, $main) = @{$compData};
1315                        # Link the compound to the reaction.
1316                        $loadIsAComponentOf->Put($cid, $reactionID, $discrim++, "", $main,
1317                                                 $product, $stoich);
1318                    }
1319                }
1320            }
1321        }
1322      # Finish the load.      # Finish the load.
1323      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
1324      return $retVal;      return $retVal;
# Line 1132  Line 1354 
1354      my $fig = $self->{fig};      my $fig = $self->{fig};
1355      # Get the genome hash.      # Get the genome hash.
1356      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
1357      # Create a load object for the table we're loading.      # Create a load object for the table we're loading.
1358      my $loadGenomeGroups = $self->_TableLoader('GenomeGroups', $genomeCount * 4);      my $loadGenomeGroups = $self->_TableLoader('GenomeGroups');
1359      Trace("Beginning group data load.") if T(2);      if ($self->{options}->{loadOnly}) {
1360            Trace("Loading from existing files.") if T(2);
1361        } else {
1362            Trace("Generating group data.") if T(2);
1363      # Loop through the genomes.      # Loop through the genomes.
1364      my $line;      my $line;
1365      for my $genomeID (keys %{$genomeHash}) {      for my $genomeID (keys %{$genomeHash}) {
# Line 1151  Line 1375 
1375          }          }
1376          close TMP;          close TMP;
1377      }      }
1378        }
1379      # Finish the load.      # Finish the load.
1380      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
1381      return $retVal;      return $retVal;
# Line 1172  Line 1397 
1397    
1398  Name of the table (relation) being loaded.  Name of the table (relation) being loaded.
1399    
1400  =item rowCount (optional)  =item ignore
1401    
1402  Estimated maximum number of rows in the table.  TRUE if the table should be ignored entirely, else FALSE.
1403    
1404  =item RETURN  =item RETURN
1405    
# Line 1186  Line 1411 
1411    
1412  sub _TableLoader {  sub _TableLoader {
1413      # Get the parameters.      # Get the parameters.
1414      my ($self, $tableName, $rowCount) = @_;      my ($self, $tableName, $ignore) = @_;
1415      # Create the load object.      # Create the load object.
1416      my $retVal = ERDBLoad->new($self->{erdb}, $tableName, $self->{loadDirectory}, $rowCount);      my $retVal = ERDBLoad->new($self->{erdb}, $tableName, $self->{loadDirectory}, $self->LoadOnly,
1417                                   $ignore);
1418      # Cache it in the loader list.      # Cache it in the loader list.
1419      push @{$self->{loaders}}, $retVal;      push @{$self->{loaders}}, $retVal;
1420      # Return it to the caller.      # Return it to the caller.
# Line 1225  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            # Get the relation name.
1455            my $relName = $loader->RelName;
1456            # Check the ignore flag.
1457            if ($loader->Ignore) {
1458                Trace("Relation $relName not loaded.") if T(2);
1459            } else {
1460                # Here we really need to finish.
1461                Trace("Finishing $relName.") if T(2);
1462          my $stats = $loader->Finish();          my $stats = $loader->Finish();
1463                if ($self->{options}->{dbLoad} && ! $loader->Ignore) {
1464                    # Here we want to use the load file just created to load the database.
1465                    Trace("Loading relation $relName.") if T(2);
1466                    my $newStats = $self->{sprout}->LoadUpdate(1, [$relName]);
1467                    # Accumulate the statistics from the DB load.
1468                    $stats->Accumulate($newStats);
1469                }
1470          $retVal->Accumulate($stats);          $retVal->Accumulate($stats);
         my $relName = $loader->RelName;  
1471          Trace("Statistics for $relName:\n" . $stats->Show()) if T(2);          Trace("Statistics for $relName:\n" . $stats->Show()) if T(2);
1472      }      }
1473        }
1474      # Return the load statistics.      # Return the load statistics.
1475      return $retVal;      return $retVal;
1476  }  }

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3