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

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.28

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3