[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.19, Thu Oct 20 09:34:09 2005 UTC revision 1.30, Sun Mar 26 12:35:21 2006 UTC
# Line 171  Line 171 
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 198  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 216  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 268  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 311  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 389  Line 413 
413              }              }
414          }          }
415      }      }
416        }
417      # All done. Finish the load.      # All done. Finish the load.
418      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
419      return $retVal;      return $retVal;
# Line 410  Line 435 
435      FeatureTranslation      FeatureTranslation
436      FeatureUpstream      FeatureUpstream
437      IsLocatedIn      IsLocatedIn
438        HasFeature
439    
440  =over 4  =over 4
441    
# Line 426  Line 452 
452      my ($self) = @_;      my ($self) = @_;
453      # Get the FIG object.      # Get the FIG object.
454      my $fig = $self->{fig};      my $fig = $self->{fig};
     # Find out if this is a limited run.  
     my $limited = $self->{options}->{limitedFeatures};  
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 $loadIsLocatedIn = $self->_TableLoader('IsLocatedIn', $featureCount);      my $loadIsLocatedIn = $self->_TableLoader('IsLocatedIn', $self->PrimaryOnly);
460      my $loadFeatureAlias = $self->_TableLoader('FeatureAlias', $featureCount * 6);      my $loadFeatureAlias = $self->_TableLoader('FeatureAlias');
461      my ($loadFeatureLink, $loadFeatureTranslation, $loadFeatureUpstream);      my $loadFeatureLink = $self->_TableLoader('FeatureLink');
462      if (! $limited) {      my $loadFeatureTranslation = $self->_TableLoader('FeatureTranslation');
463          $loadFeatureLink = $self->_TableLoader('FeatureLink', $featureCount * 10);      my $loadFeatureUpstream = $self->_TableLoader('FeatureUpstream');
464          $loadFeatureTranslation = $self->_TableLoader('FeatureTranslation', $featureCount);      my $loadHasFeature = $self->_TableLoader('HasFeature');
         $loadFeatureUpstream = $self->_TableLoader('FeatureUpstream', $featureCount);  
     }  
465      # 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
466      # locations.      # locations.
467      my $chunkSize = $self->{sprout}->MaxSegment();      my $chunkSize = $self->{sprout}->MaxSegment();
468      Trace("Beginning feature data load.") if T(2);      if ($self->{options}->{loadOnly}) {
469            Trace("Loading from existing files.") if T(2);
470        } else {
471            Trace("Generating feature data.") if T(2);
472      # Now we loop through the genomes, generating the data for each one.      # Now we loop through the genomes, generating the data for each one.
473      for my $genomeID (sort keys %{$genomeHash}) {      for my $genomeID (sort keys %{$genomeHash}) {
474          Trace("Loading features for genome $genomeID.") if T(3);          Trace("Loading features for genome $genomeID.") if T(3);
# Line 459  Line 482 
482              my ($featureID, $locations, undef, $type) = @{$featureData};              my ($featureID, $locations, undef, $type) = @{$featureData};
483              # Create the feature record.              # Create the feature record.
484              $loadFeature->Put($featureID, 1, $type);              $loadFeature->Put($featureID, 1, $type);
485                    # Link it to the parent genome.
486                    $loadHasFeature->Put($genomeID, $featureID, $type);
487              # Create the aliases.              # Create the aliases.
488              for my $alias ($fig->feature_aliases($featureID)) {              for my $alias ($fig->feature_aliases($featureID)) {
489                  $loadFeatureAlias->Put($featureID, $alias);                  $loadFeatureAlias->Put($featureID, $alias);
490              }              }
             # The next stuff is for a full load only.  
             if (! $limited) {  
491                  # Get the links.                  # Get the links.
492                  my @links = $fig->fid_links($featureID);                  my @links = $fig->fid_links($featureID);
493                  for my $link (@links) {                  for my $link (@links) {
# Line 483  Line 506 
506                          $loadFeatureUpstream->Put($featureID, $upstream);                          $loadFeatureUpstream->Put($featureID, $upstream);
507                      }                      }
508                  }                  }
             }  
509              # This part is the roughest. We need to relate the features to contig              # This part is the roughest. We need to relate the features to contig
510              # locations, and the locations must be split so that none of them exceed              # locations, and the locations must be split so that none of them exceed
511              # the maximum segment size. This simplifies the genes_in_region processing              # the maximum segment size. This simplifies the genes_in_region processing
# Line 512  Line 534 
534              }              }
535          }          }
536      }      }
537        }
538      # Finish the loads.      # Finish the loads.
539      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
540      return $retVal;      return $retVal;
# Line 548  Line 571 
571      my $fig = $self->{fig};      my $fig = $self->{fig};
572      # Get the table of genome IDs.      # Get the table of genome IDs.
573      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
     my $featureCount = $genomeCount * 4000;  
574      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
575      my $loadIsBidirectionalBestHitOf = $self->_TableLoader('IsBidirectionalBestHitOf',      my $loadIsBidirectionalBestHitOf = $self->_TableLoader('IsBidirectionalBestHitOf');
576                                                             $featureCount * $genomeCount);      if ($self->{options}->{loadOnly}) {
577      Trace("Beginning BBH load.") if T(2);          Trace("Loading from existing files.") if T(2);
578        } else {
579            Trace("Generating BBH data.") if T(2);
580      # Now we loop through the genomes, generating the data for each one.      # Now we loop through the genomes, generating the data for each one.
581      for my $genomeID (sort keys %{$genomeHash}) {      for my $genomeID (sort keys %{$genomeHash}) {
582          $loadIsBidirectionalBestHitOf->Add("genomeIn");          $loadIsBidirectionalBestHitOf->Add("genomeIn");
# Line 579  Line 602 
602              }              }
603          }          }
604      }      }
605        }
606      # Finish the loads.      # Finish the loads.
607      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
608      return $retVal;      return $retVal;
# Line 608  Line 632 
632      OccursInSubsystem      OccursInSubsystem
633      ParticipatesIn      ParticipatesIn
634      HasSSCell      HasSSCell
     Catalyzes  
     Reaction  
635      ConsistsOfRoles      ConsistsOfRoles
636      RoleSubset      RoleSubset
637      HasRoleSubset      HasRoleSubset
638      ConsistsOfGenomes      ConsistsOfGenomes
639      GenomeSubset      GenomeSubset
640      HasGenomeSubset      HasGenomeSubset
641        Catalyzes
642        Diagram
643        RoleOccursIn
644    
645  =over 4  =over 4
646    
# Line 638  Line 663 
663      # Get the subsystem hash. This lists the subsystems we'll process.      # Get the subsystem hash. This lists the subsystems we'll process.
664      my $subsysHash = $self->{subsystems};      my $subsysHash = $self->{subsystems};
665      my @subsysIDs = sort keys %{$subsysHash};      my @subsysIDs = sort keys %{$subsysHash};
666      my $subsysCount = @subsysIDs;      # Get the map list.
667      my $genomeCount = (keys %{$genomeHash});      my @maps = $fig->all_maps;
     my $featureCount = $genomeCount * 4000;  
668      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
669      my $loadSubsystem = $self->_TableLoader('Subsystem', $subsysCount);      my $loadDiagram = $self->_TableLoader('Diagram', $self->PrimaryOnly);
670      my $loadRole = $self->_TableLoader('Role', $featureCount * 6);      my $loadRoleOccursIn = $self->_TableLoader('RoleOccursIn', $self->PrimaryOnly);
671      my $loadRoleEC = $self->_TableLoader('RoleEC', $featureCount * 6);      my $loadSubsystem = $self->_TableLoader('Subsystem');
672      my $loadSSCell = $self->_TableLoader('SSCell', $featureCount * $genomeCount);      my $loadRole = $self->_TableLoader('Role', $self->PrimaryOnly);
673      my $loadContainsFeature = $self->_TableLoader('ContainsFeature', $featureCount * $subsysCount);      my $loadRoleEC = $self->_TableLoader('RoleEC', $self->PrimaryOnly);
674      my $loadIsGenomeOf = $self->_TableLoader('IsGenomeOf', $featureCount * $genomeCount);      my $loadCatalyzes = $self->_TableLoader('Catalyzes', $self->PrimaryOnly);
675      my $loadIsRoleOf = $self->_TableLoader('IsRoleOf', $featureCount * $genomeCount);      my $loadSSCell = $self->_TableLoader('SSCell', $self->PrimaryOnly);
676      my $loadOccursInSubsystem = $self->_TableLoader('OccursInSubsystem', $featureCount * 6);      my $loadContainsFeature = $self->_TableLoader('ContainsFeature', $self->PrimaryOnly);
677      my $loadParticipatesIn = $self->_TableLoader('ParticipatesIn', $subsysCount * $genomeCount);      my $loadIsGenomeOf = $self->_TableLoader('IsGenomeOf', $self->PrimaryOnly);
678      my $loadHasSSCell = $self->_TableLoader('HasSSCell', $featureCount * $genomeCount);      my $loadIsRoleOf = $self->_TableLoader('IsRoleOf', $self->PrimaryOnly);
679      my $loadReaction = $self->_TableLoader('Reaction', $featureCount * $genomeCount);      my $loadOccursInSubsystem = $self->_TableLoader('OccursInSubsystem', $self->PrimaryOnly);
680      my $loadCatalyzes = $self->_TableLoader('Catalyzes', $featureCount * $genomeCount);      my $loadParticipatesIn = $self->_TableLoader('ParticipatesIn', $self->PrimaryOnly);
681      my $loadRoleSubset = $self->_TableLoader('RoleSubset', $subsysCount * 50);      my $loadHasSSCell = $self->_TableLoader('HasSSCell', $self->PrimaryOnly);
682      my $loadGenomeSubset = $self->_TableLoader('GenomeSubset', $subsysCount * 50);      my $loadRoleSubset = $self->_TableLoader('RoleSubset', $self->PrimaryOnly);
683      my $loadConsistsOfRoles = $self->_TableLoader('ConsistsOfRoles', $featureCount * $genomeCount);      my $loadGenomeSubset = $self->_TableLoader('GenomeSubset', $self->PrimaryOnly);
684      my $loadConsistsOfGenomes = $self->_TableLoader('ConsistsOfGenomes', $featureCount * $genomeCount);      my $loadConsistsOfRoles = $self->_TableLoader('ConsistsOfRoles', $self->PrimaryOnly);
685      my $loadHasRoleSubset = $self->_TableLoader('HasRoleSubset', $subsysCount * 50);      my $loadConsistsOfGenomes = $self->_TableLoader('ConsistsOfGenomes', $self->PrimaryOnly);
686      my $loadHasGenomeSubset = $self->_TableLoader('HasGenomeSubset', $subsysCount * 50);      my $loadHasRoleSubset = $self->_TableLoader('HasRoleSubset', $self->PrimaryOnly);
687      Trace("Beginning subsystem data load.") if T(2);      my $loadHasGenomeSubset = $self->_TableLoader('HasGenomeSubset', $self->PrimaryOnly);
688      # The reaction hash will contain a list of reactions for each role. When we're done,      if ($self->{options}->{loadOnly}) {
689      # a complicated sort and merge will be used to generate the Reaction and Catalyzes          Trace("Loading from existing files.") if T(2);
690      # tables.      } else {
691      my %reactionsToRoles = ();          Trace("Generating subsystem data.") if T(2);
692            # This hash will contain the role for each EC. When we're done, this
693            # information will be used to generate the Catalyzes table.
694            my %ecToRoles = ();
695      # Loop through the subsystems. Our first task will be to create the      # Loop through the subsystems. Our first task will be to create the
696      # roles. We do this by looping through the subsystems and creating a      # roles. We do this by looping through the subsystems and creating a
697      # 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
# Line 677  Line 704 
704          $loadSubsystem->Add("subsystemIn");          $loadSubsystem->Add("subsystemIn");
705          # Get the subsystem object.          # Get the subsystem object.
706          my $sub = $fig->get_subsystem($subsysID);          my $sub = $fig->get_subsystem($subsysID);
         # Get its reaction hash.  
         my $reactionHash = $sub->get_reactions();  
707          # Create the subsystem record.          # Create the subsystem record.
708          my $curator = $sub->get_curator();          my $curator = $sub->get_curator();
709          my $notes = $sub->get_notes();          my $notes = $sub->get_notes();
# Line 697  Line 722 
722                  $roleData{$roleID} = 1;                  $roleData{$roleID} = 1;
723                  # Check for an EC number.                  # Check for an EC number.
724                  if ($roleID =~ /\(EC ([^.]+\.[^.]+\.[^.]+\.[^)]+)\)\s*$/) {                  if ($roleID =~ /\(EC ([^.]+\.[^.]+\.[^.]+\.[^)]+)\)\s*$/) {
725                      $loadRoleEC->Put($roleID, $1);                          my $ec = $1;
726                  }                          $loadRoleEC->Put($roleID, $ec);
727                  # Add the role's reactions.                          $ecToRoles{$ec} = $roleID;
                 my $reactions = $reactionHash->{$roleID};  
                 for my $reactionID (@{$reactions}) {  
                     if (! exists $reactionsToRoles{$reactionID}) {  
                         # Here the reaction is brand-new, so we create its reaction  
                         # record.  
                         $loadReaction->Put($reactionID, $fig->reversible($reactionID));  
                         # We also create a blank list for it in the reaction hash.  
                         $reactionsToRoles{$reactionID} = [];  
                     }  
                     # Add the role to the reaction's role list.  
                     push @{$reactionsToRoles{$reactionID}}, $roleID;  
728                  }                  }
729              }              }
730          }          }
# Line 790  Line 804 
804              # Connect the subset to the subsystem.              # Connect the subset to the subsystem.
805              $loadHasRoleSubset->Put($subsysID, $actualID);              $loadHasRoleSubset->Put($subsysID, $actualID);
806              # Connect the subset to its roles.              # Connect the subset to its roles.
807              my @roles = $sub->get_subset($subsetID);                  my @roles = $sub->get_subsetC_roles($subsetID);
808              for my $roleID (@roles) {              for my $roleID (@roles) {
809                  $loadConsistsOfRoles->Put($actualID, $roleID);                  $loadConsistsOfRoles->Put($actualID, $roleID);
810              }              }
# Line 810  Line 824 
824              }              }
825          }          }
826      }      }
827      # Before we leave, we must create the Catalyzes table. The data is all stored in          # Now we loop through the diagrams. We need to create the diagram records
828      # "reactionToRoles" hash.          # and link each diagram to its roles. Note that only roles which occur
829      for my $reactionID (keys %reactionsToRoles) {          # in subsystems (and therefore appear in the %ecToRoles hash) are
830          # Get this reaction's list of roles. We sort it so we can merge out duplicates.          # included.
831          my @roles = sort @{$reactionsToRoles{$reactionID}};          for my $map (@maps) {
         my $lastRole = "";  
         # Loop through the roles, creating catalyzation records.  
         for my $thisRole (@roles) {  
             if ($thisRole ne $lastRole) {  
                 $loadCatalyzes->Put($thisRole, $reactionID);  
             }  
         }  
     }  
     # Finish the load.  
     my $retVal = $self->_FinishAll();  
     return $retVal;  
 }  
   
 =head3 LoadDiagramData  
   
 C<< my $stats = $spl->LoadDiagramData(); >>  
   
 Load the diagram data from FIG into Sprout.  
   
 Diagrams are used to organize functional roles. The diagram shows the  
 connections between chemicals that interact with a subsystem.  
   
 The following relations are loaded by this method.  
   
     Diagram  
     RoleOccursIn  
   
 =over 4  
   
 =item RETURNS  
   
 Returns a statistics object for the loads.  
   
 =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) {  
832          Trace("Loading diagram $map.") if T(3);          Trace("Loading diagram $map.") if T(3);
833          # Get the diagram's descriptive name.          # Get the diagram's descriptive name.
834          my $name = $fig->map_name($map);          my $name = $fig->map_name($map);
# Line 876  Line 837 
837          # A hash is used to prevent duplicates.          # A hash is used to prevent duplicates.
838          my %roleHash = ();          my %roleHash = ();
839          for my $role ($fig->map_to_ecs($map)) {          for my $role ($fig->map_to_ecs($map)) {
840              if (! $roleHash{$role}) {                  if (exists $ecToRoles{$role} && ! $roleHash{$role}) {
841                  $loadRoleOccursIn->Put($role, $map);                      $loadRoleOccursIn->Put($ecToRoles{$role}, $map);
842                  $roleHash{$role} = 1;                  $roleHash{$role} = 1;
843              }              }
844          }          }
845      }      }
846            # Before we leave, we must create the Catalyzes table. We start with the reactions,
847            # then use the "ecToRoles" table to convert EC numbers to role IDs.
848            my @reactions = $fig->all_reactions();
849            for my $reactionID (@reactions) {
850                # Get this reaction's list of roles. The results will be EC numbers.
851                my @roles = $fig->catalyzed_by($reactionID);
852                # Loop through the roles, creating catalyzation records.
853                for my $thisRole (@roles) {
854                    if (exists $ecToRoles{$thisRole}) {
855                        $loadCatalyzes->Put($ecToRoles{$thisRole}, $reactionID);
856                    }
857                }
858            }
859        }
860      # Finish the load.      # Finish the load.
861      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
862      return $retVal;      return $retVal;
# Line 923  Line 898 
898      my $fig = $self->{fig};      my $fig = $self->{fig};
899      # Get the genome hash.      # Get the genome hash.
900      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
901      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
902      my $loadProperty = $self->_TableLoader('Property', $genomeCount * 1500);      my $loadProperty = $self->_TableLoader('Property');
903      my $loadHasProperty = $self->_TableLoader('HasProperty', $genomeCount * 1500);      my $loadHasProperty = $self->_TableLoader('HasProperty', $self->PrimaryOnly);
904      Trace("Beginning property data load.") if T(2);      if ($self->{options}->{loadOnly}) {
905            Trace("Loading from existing files.") if T(2);
906        } else {
907            Trace("Generating property data.") if T(2);
908      # Create a hash for storing property IDs.      # Create a hash for storing property IDs.
909      my %propertyKeys = ();      my %propertyKeys = ();
910      my $nextID = 1;      my $nextID = 1;
911      # Loop through the genomes.      # Loop through the genomes.
912      for my $genomeID (keys %{$genomeHash}) {      for my $genomeID (keys %{$genomeHash}) {
913          $loadProperty->Add("genomeIn");          $loadProperty->Add("genomeIn");
914                Trace("Generating properties for $genomeID.") if T(3);
915          # 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
916          # tuples returned by "all_features_detailed". We use "all_features_detailed"          # tuples returned by "all_features_detailed". We use "all_features_detailed"
917          # rather than "all_features" because we want all features regardless of type.          # rather than "all_features" because we want all features regardless of type.
918          my @features = map { $_->[0] } @{$fig->all_features_detailed($genomeID)};          my @features = map { $_->[0] } @{$fig->all_features_detailed($genomeID)};
919                my $featureCount = 0;
920                my $propertyCount = 0;
921          # Loop through the features, creating HasProperty records.          # Loop through the features, creating HasProperty records.
922          for my $fid (@features) {          for my $fid (@features) {
             $loadProperty->Add("featureIn");  
923              # 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
924              # to insure we do not get any genome attributes.              # to insure we do not get any genome attributes.
925              my @attributeList = $fig->get_attributes($fid, '', '', '');              my @attributeList = $fig->get_attributes($fid, '', '', '');
926                    if (scalar @attributeList) {
927                        $featureCount++;
928                    }
929              # Loop through the attributes.              # Loop through the attributes.
930              for my $tuple (@attributeList) {              for my $tuple (@attributeList) {
931                        $propertyCount++;
932                  # 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,
933                  # since it will always be the same as the value if "$fid".                  # since it will always be the same as the value if "$fid".
934                  my (undef, $key, $value, $url) = @{$tuple};                  my (undef, $key, $value, $url) = @{$tuple};
# Line 967  Line 950 
950                  $loadHasProperty->Put($fid, $propertyID, $url);                  $loadHasProperty->Put($fid, $propertyID, $url);
951              }              }
952          }          }
953                # Update the statistics.
954                Trace("$propertyCount attributes processed for $featureCount features.") if T(3);
955                $loadHasProperty->Add("featuresIn", $featureCount);
956                $loadHasProperty->Add("propertiesIn", $propertyCount);
957            }
958      }      }
959      # Finish the load.      # Finish the load.
960      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
# Line 1007  Line 995 
995      my $fig = $self->{fig};      my $fig = $self->{fig};
996      # Get the genome hash.      # Get the genome hash.
997      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
998      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
999      my $loadAnnotation = $self->_TableLoader('Annotation', $genomeCount * 4000);      my $loadAnnotation = $self->_TableLoader('Annotation');
1000      my $loadIsTargetOfAnnotation = $self->_TableLoader('IsTargetOfAnnotation', $genomeCount * 4000);      my $loadIsTargetOfAnnotation = $self->_TableLoader('IsTargetOfAnnotation', $self->PrimaryOnly);
1001      my $loadSproutUser = $self->_TableLoader('SproutUser', 100);      my $loadSproutUser = $self->_TableLoader('SproutUser', $self->PrimaryOnly);
1002      my $loadUserAccess = $self->_TableLoader('UserAccess', 1000);      my $loadUserAccess = $self->_TableLoader('UserAccess', $self->PrimaryOnly);
1003      my $loadMadeAnnotation = $self->_TableLoader('MadeAnnotation', $genomeCount * 4000);      my $loadMadeAnnotation = $self->_TableLoader('MadeAnnotation', $self->PrimaryOnly);
1004      Trace("Beginning annotation data load.") if T(2);      if ($self->{options}->{loadOnly}) {
1005            Trace("Loading from existing files.") if T(2);
1006        } else {
1007            Trace("Generating annotation data.") if T(2);
1008      # 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
1009      # user records.      # user records.
1010      my %users = ( FIG => 1, master => 1 );      my %users = ( FIG => 1, master => 1 );
# Line 1035  Line 1025 
1025              # 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
1026              # from showing up for a single PEG's annotations.              # from showing up for a single PEG's annotations.
1027              my %seenTimestamps = ();              my %seenTimestamps = ();
1028              # 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.  
1029              for my $tuple ($fig->feature_annotations($peg, "raw")) {              for my $tuple ($fig->feature_annotations($peg, "raw")) {
1030                  my ($fid, $timestamp, $user, $text) = @{$tuple};                  my ($fid, $timestamp, $user, $text) = @{$tuple};
1031                  # Here we fix up the annotation text. "\r" is removed,                  # Here we fix up the annotation text. "\r" is removed,
# Line 1089  Line 1064 
1064              }              }
1065          }          }
1066      }      }
1067        }
1068      # Finish the load.      # Finish the load.
1069      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
1070      return $retVal;      return $retVal;
# Line 1129  Line 1105 
1105      my $fig = $self->{fig};      my $fig = $self->{fig};
1106      # Get the genome hash.      # Get the genome hash.
1107      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
1108      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
1109      my $loadComesFrom = $self->_TableLoader('ComesFrom', $genomeCount * 4);      my $loadComesFrom = $self->_TableLoader('ComesFrom', $self->PrimaryOnly);
1110      my $loadSource = $self->_TableLoader('Source', $genomeCount * 4);      my $loadSource = $self->_TableLoader('Source');
1111      my $loadSourceURL = $self->_TableLoader('SourceURL', $genomeCount * 8);      my $loadSourceURL = $self->_TableLoader('SourceURL');
1112      Trace("Beginning source data load.") if T(2);      if ($self->{options}->{loadOnly}) {
1113            Trace("Loading from existing files.") if T(2);
1114        } else {
1115            Trace("Generating annotation data.") if T(2);
1116      # Create hashes to collect the Source information.      # Create hashes to collect the Source information.
1117      my %sourceURL = ();      my %sourceURL = ();
1118      my %sourceDesc = ();      my %sourceDesc = ();
# Line 1164  Line 1142 
1142      for my $sourceID (keys %sourceDesc) {      for my $sourceID (keys %sourceDesc) {
1143          $loadSource->Put($sourceID, $sourceDesc{$sourceID});          $loadSource->Put($sourceID, $sourceDesc{$sourceID});
1144      }      }
1145        }
1146      # Finish the load.      # Finish the load.
1147      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
1148      return $retVal;      return $retVal;
# Line 1203  Line 1182 
1182      my $fig = $self->{fig};      my $fig = $self->{fig};
1183      # Get the genome hash.      # Get the genome hash.
1184      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
1185      # 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
1186      # it the key.      # it the key.
1187      my %speciesHash = map { $fig->genus_species($_) => $_ } (keys %{$genomeHash});      my %speciesHash = map { $fig->genus_species($_) => $_ } (keys %{$genomeHash});
1188      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
1189      my $loadExternalAliasFunc = $self->_TableLoader('ExternalAliasFunc', $genomeCount * 4000);      my $loadExternalAliasFunc = $self->_TableLoader('ExternalAliasFunc');
1190      my $loadExternalAliasOrg = $self->_TableLoader('ExternalAliasOrg', $genomeCount * 4000);      my $loadExternalAliasOrg = $self->_TableLoader('ExternalAliasOrg');
1191      Trace("Beginning external data load.") if T(2);      if ($self->{options}->{loadOnly}) {
1192            Trace("Loading from existing files.") if T(2);
1193        } else {
1194            Trace("Generating external data.") if T(2);
1195      # 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.
1196      Open(\*ORGS, "<$FIG_Config::global/ext_org.table");      Open(\*ORGS, "<$FIG_Config::global/ext_org.table");
1197      my $orgLine;      my $orgLine;
# Line 1240  Line 1221 
1221              $loadExternalAliasFunc->Put(@funcFields[0,1]);              $loadExternalAliasFunc->Put(@funcFields[0,1]);
1222          }          }
1223      }      }
1224        }
1225      # Finish the load.      # Finish the load.
1226      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
1227      return $retVal;      return $retVal;
# Line 1256  Line 1238 
1238    
1239  The following relations are loaded by this method.  The following relations are loaded by this method.
1240    
1241        Reaction
1242      ReactionURL      ReactionURL
1243      Compound      Compound
1244      CompoundName      CompoundName
# Line 1279  Line 1262 
1262      my ($self) = @_;      my ($self) = @_;
1263      # Get the FIG object.      # Get the FIG object.
1264      my $fig = $self->{fig};      my $fig = $self->{fig};
     # Get the genome hash.  
     my $genomeHash = $self->{genomes};  
     my $genomeCount = (keys %{$genomeHash});  
1265      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
1266      my $loadReactionURL = $self->_TableLoader('ReactionURL', $genomeCount * 4000);      my $loadReaction = $self->_TableLoader('Reaction');
1267      my $loadCompound = $self->_TableLoader('Compound', $genomeCount * 4000);      my $loadReactionURL = $self->_TableLoader('ReactionURL', $self->PrimaryOnly);
1268      my $loadCompoundName = $self->_TableLoader('CompoundName', $genomeCount * 8000);      my $loadCompound = $self->_TableLoader('Compound', $self->PrimaryOnly);
1269      my $loadCompoundCAS = $self->_TableLoader('CompoundCAS', $genomeCount * 4000);      my $loadCompoundName = $self->_TableLoader('CompoundName', $self->PrimaryOnly);
1270      my $loadIsAComponentOf = $self->_TableLoader('IsAComponentOf', $genomeCount * 12000);      my $loadCompoundCAS = $self->_TableLoader('CompoundCAS', $self->PrimaryOnly);
1271      Trace("Beginning reaction/compound data load.") if T(2);      my $loadIsAComponentOf = $self->_TableLoader('IsAComponentOf', $self->PrimaryOnly);
1272      # Create a hash to remember the compounds we've generated in the compound table.      if ($self->{options}->{loadOnly}) {
1273      my %compoundHash = ();          Trace("Loading from existing files.") if T(2);
1274      # Loop through the reactions.      } else {
1275            Trace("Generating annotation data.") if T(2);
1276            # First we create the compounds.
1277            my @compounds = $fig->all_compounds();
1278            for my $cid (@compounds) {
1279                # Check for names.
1280                my @names = $fig->names_of_compound($cid);
1281                # Each name will be given a priority number, starting with 1.
1282                my $prio = 1;
1283                for my $name (@names) {
1284                    $loadCompoundName->Put($cid, $name, $prio++);
1285                }
1286                # Create the main compound record. Note that the first name
1287                # becomes the label.
1288                my $label = (@names > 0 ? $names[0] : $cid);
1289                $loadCompound->Put($cid, $label);
1290                # Check for a CAS ID.
1291                my $cas = $fig->cas($cid);
1292                if ($cas) {
1293                    $loadCompoundCAS->Put($cid, $cas);
1294                }
1295            }
1296            # All the compounds are set up, so we need to loop through the reactions next. First,
1297            # we initialize the discriminator index. This is a single integer used to insure
1298            # duplicate elements in a reaction are not accidentally collapsed.
1299            my $discrim = 0;
1300      my @reactions = $fig->all_reactions();      my @reactions = $fig->all_reactions();
1301      for my $reactionID (@reactions) {      for my $reactionID (@reactions) {
1302                # Create the reaction record.
1303                $loadReaction->Put($reactionID, $fig->reversible($reactionID));
1304          # Compute the reaction's URL.          # Compute the reaction's URL.
1305          my $url = HTML::reaction_link($reactionID);          my $url = HTML::reaction_link($reactionID);
1306          # Put it in the ReactionURL table.          # Put it in the ReactionURL table.
# Line 1302  Line 1309 
1309          # substrates first and then products.          # substrates first and then products.
1310          for my $product (0, 1) {          for my $product (0, 1) {
1311              # Get the compounds of the current type for the current reaction. FIG will              # Get the compounds of the current type for the current reaction. FIG will
1312              # give us 3-tuples: [ID, Stoichometry, main-flag]. At this time we do not                  # give us 3-tuples: [ID, stoichiometry, main-flag]. At this time we do not
1313              # have location data in SEED, so it defaults to the empty string.              # have location data in SEED, so it defaults to the empty string.
1314              my @compounds = $fig->reaction2comp($reactionID, $product);              my @compounds = $fig->reaction2comp($reactionID, $product);
1315              for my $compData (@compounds) {              for my $compData (@compounds) {
1316                  # Extract the compound data from the current tuple.                  # Extract the compound data from the current tuple.
1317                  my ($cid, $stoich, $main) = @{$compData};                  my ($cid, $stoich, $main) = @{$compData};
1318                  # Link the compound to the reaction.                  # Link the compound to the reaction.
1319                  $loadIsAComponentOf->Put($cid, $reactionID, "", $main, $product, $stoich);                      $loadIsAComponentOf->Put($cid, $reactionID, $discrim++, "", $main,
1320                  # If this is a new compound, we need to create its table entries.                                               $product, $stoich);
                 if (! exists $compoundHash{$cid}) {  
                     $compoundHash{$cid} = 1;  
                     # Create the main compound record and denote we've done it.  
                     $loadCompound->Put($cid);  
                     # Check for a CAS ID.  
                     my $cas = $fig->cas($cid);  
                     if ($cas) {  
                         $loadCompoundCAS->Put($cid, $cas);  
                     }  
                     # Check for names.  
                     my @names = $fig->names_of_compound($cid);  
                     # Each name will be given a priority number, starting with 1.  
                     my $prio = 0;  
                     for my $name (@names) {  
                         $loadCompoundName->Put($cid, $name, $prio++);  
                     }  
1321                  }                  }
1322              }              }
1323          }          }
# Line 1366  Line 1357 
1357      my $fig = $self->{fig};      my $fig = $self->{fig};
1358      # Get the genome hash.      # Get the genome hash.
1359      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
1360      # Create a load object for the table we're loading.      # Create a load object for the table we're loading.
1361      my $loadGenomeGroups = $self->_TableLoader('GenomeGroups', $genomeCount * 4);      my $loadGenomeGroups = $self->_TableLoader('GenomeGroups');
1362      Trace("Beginning group data load.") if T(2);      if ($self->{options}->{loadOnly}) {
1363            Trace("Loading from existing files.") if T(2);
1364        } else {
1365            Trace("Generating group data.") if T(2);
1366      # Loop through the genomes.      # Loop through the genomes.
1367      my $line;      my $line;
1368      for my $genomeID (keys %{$genomeHash}) {      for my $genomeID (keys %{$genomeHash}) {
# Line 1385  Line 1378 
1378          }          }
1379          close TMP;          close TMP;
1380      }      }
1381        }
1382      # Finish the load.      # Finish the load.
1383      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
1384      return $retVal;      return $retVal;
# Line 1406  Line 1400 
1400    
1401  Name of the table (relation) being loaded.  Name of the table (relation) being loaded.
1402    
1403  =item rowCount (optional)  =item ignore
1404    
1405  Estimated maximum number of rows in the table.  TRUE if the table should be ignored entirely, else FALSE.
1406    
1407  =item RETURN  =item RETURN
1408    
# Line 1420  Line 1414 
1414    
1415  sub _TableLoader {  sub _TableLoader {
1416      # Get the parameters.      # Get the parameters.
1417      my ($self, $tableName, $rowCount) = @_;      my ($self, $tableName, $ignore) = @_;
1418      # Create the load object.      # Create the load object.
1419      my $retVal = ERDBLoad->new($self->{erdb}, $tableName, $self->{loadDirectory}, $rowCount);      my $retVal = ERDBLoad->new($self->{erdb}, $tableName, $self->{loadDirectory}, $self->LoadOnly,
1420                                   $ignore);
1421      # Cache it in the loader list.      # Cache it in the loader list.
1422      push @{$self->{loaders}}, $retVal;      push @{$self->{loaders}}, $retVal;
1423      # Return it to the caller.      # Return it to the caller.
# Line 1459  Line 1454 
1454      # 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
1455      # ignominiously. At some future point, we want to make the loads restartable.      # ignominiously. At some future point, we want to make the loads restartable.
1456      while (my $loader = pop @{$loadList}) {      while (my $loader = pop @{$loadList}) {
1457          # Trace the fact that we're cleaning up.          # Get the relation name.
1458          my $relName = $loader->RelName;          my $relName = $loader->RelName;
1459          Trace("Finishing load for $relName.") if T(2);          # Check the ignore flag.
1460            if ($loader->Ignore) {
1461                Trace("Relation $relName not loaded.") if T(2);
1462            } else {
1463                # Here we really need to finish.
1464                Trace("Finishing $relName.") if T(2);
1465          my $stats = $loader->Finish();          my $stats = $loader->Finish();
1466          if ($self->{options}->{dbLoad}) {          if ($self->{options}->{dbLoad}) {
1467              # Here we want to use the load file just created to load the database.              # Here we want to use the load file just created to load the database.
# Line 1473  Line 1473 
1473          $retVal->Accumulate($stats);          $retVal->Accumulate($stats);
1474          Trace("Statistics for $relName:\n" . $stats->Show()) if T(2);          Trace("Statistics for $relName:\n" . $stats->Show()) if T(2);
1475      }      }
1476        }
1477      # Return the load statistics.      # Return the load statistics.
1478      return $retVal;      return $retVal;
1479  }  }

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.30

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3