[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.35, Mon May 15 20:00:54 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 79  Line 80 
80  =item subsysFile  =item subsysFile
81    
82  Either the name of the file containing the list of trusted subsystems or a reference  Either the name of the file containing the list of trusted subsystems or a reference
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 NMPDR subsystems will be
84  considered trusted. Only subsystem data related to the trusted subsystems is loaded.  considered trusted. (A subsystem is considered NMPDR if it has a file named C<NMPDR>
85    in its data directory.) Only subsystem data related to the trusted subsystems is loaded.
86    
87    =item options
88    
89    Reference to a hash of command-line options.
90    
91  =back  =back
92    
# Line 88  Line 94 
94    
95  sub new {  sub new {
96      # Get the parameters.      # Get the parameters.
97      my ($class, $sprout, $fig, $genomeFile, $subsysFile) = @_;      my ($class, $sprout, $fig, $genomeFile, $subsysFile, $options) = @_;
98      # Load the list of genomes into a hash.      # Create the genome hash.
99      my %genomes;      my %genomes = ();
100        # We only need it if load-only is NOT specified.
101        if (! $options->{loadOnly}) {
102      if (! defined($genomeFile) || $genomeFile eq '') {      if (! defined($genomeFile) || $genomeFile eq '') {
103          # Here we want all the complete genomes and an access code of 1.          # Here we want all the complete genomes and an access code of 1.
104          my @genomeList = $fig->genomes(1);          my @genomeList = $fig->genomes(1);
# Line 124  Line 132 
132              Confess("Invalid genome parameter ($type) in SproutLoad constructor.");              Confess("Invalid genome parameter ($type) in SproutLoad constructor.");
133          }          }
134      }      }
135        }
136      # Load the list of trusted subsystems.      # Load the list of trusted subsystems.
137      my %subsystems = ();      my %subsystems = ();
138        # We only need it if load-only is NOT specified.
139        if (! $options->{loadOnly}) {
140      if (! defined $subsysFile || $subsysFile eq '') {      if (! defined $subsysFile || $subsysFile eq '') {
141          # Here we want all the subsystems.              # Here we want all the NMPDR subsystems. First we get the whole list.
142          %subsystems = map { $_ => 1 } $fig->all_subsystems();              my @subs = $fig->all_subsystems();
143                # Loop through, checking for the NMPDR file.
144                for my $sub (@subs) {
145                    if (-e "$FIG_Config::data/Subsystems/$sub/NMPDR") {
146                        $subsystems{$sub} = 1;
147                    }
148                }
149      } else {      } else {
150          my $type = ref $subsysFile;          my $type = ref $subsysFile;
151          if ($type eq 'ARRAY') {          if ($type eq 'ARRAY') {
# Line 148  Line 165 
165              Confess("Invalid subsystem parameter in SproutLoad constructor.");              Confess("Invalid subsystem parameter in SproutLoad constructor.");
166          }          }
167      }      }
168        }
169      # Get the data directory from the Sprout object.      # Get the data directory from the Sprout object.
170      my ($directory) = $sprout->LoadInfo();      my ($directory) = $sprout->LoadInfo();
171      # Create the Sprout load object.      # Create the Sprout load object.
# Line 158  Line 176 
176                    sprout => $sprout,                    sprout => $sprout,
177                    loadDirectory => $directory,                    loadDirectory => $directory,
178                    erdb => $sprout->{_erdb},                    erdb => $sprout->{_erdb},
179                    loaders => []                    loaders => [],
180                      options => $options
181                   };                   };
182      # Bless and return it.      # Bless and return it.
183      bless $retVal, $class;      bless $retVal, $class;
184      return $retVal;      return $retVal;
185  }  }
186    
187    =head3 LoadOnly
188    
189    C<< my $flag = $spl->LoadOnly; >>
190    
191    Return TRUE if we are in load-only mode, else FALSE.
192    
193    =cut
194    
195    sub LoadOnly {
196        my ($self) = @_;
197        return $self->{options}->{loadOnly};
198    }
199    
200    =head3 PrimaryOnly
201    
202    C<< my $flag = $spl->PrimaryOnly; >>
203    
204    Return TRUE if only the main entity is to be loaded, else FALSE.
205    
206    =cut
207    
208    sub PrimaryOnly {
209        my ($self) = @_;
210        return $self->{options}->{primaryOnly};
211    }
212    
213  =head3 LoadGenomeData  =head3 LoadGenomeData
214    
215  C<< my $stats = $spl->LoadGenomeData(); >>  C<< my $stats = $spl->LoadGenomeData(); >>
# Line 192  Line 237 
237    
238  =back  =back
239    
 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.)  
   
240  =cut  =cut
241  #: Return Type $%;  #: Return Type $%;
242  sub LoadGenomeData {  sub LoadGenomeData {
# Line 210  Line 247 
247      # Get the genome count.      # Get the genome count.
248      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
249      my $genomeCount = (keys %{$genomeHash});      my $genomeCount = (keys %{$genomeHash});
     Trace("Beginning genome data load.") if T(2);  
250      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
251      my $loadGenome = $self->_TableLoader('Genome', $genomeCount);      my $loadGenome = $self->_TableLoader('Genome');
252      my $loadHasContig = $self->_TableLoader('HasContig', $genomeCount * 300);      my $loadHasContig = $self->_TableLoader('HasContig', $self->PrimaryOnly);
253      my $loadContig = $self->_TableLoader('Contig', $genomeCount * 300);      my $loadContig = $self->_TableLoader('Contig', $self->PrimaryOnly);
254      my $loadIsMadeUpOf = $self->_TableLoader('IsMadeUpOf', $genomeCount * 60000);      my $loadIsMadeUpOf = $self->_TableLoader('IsMadeUpOf', $self->PrimaryOnly);
255      my $loadSequence = $self->_TableLoader('Sequence', $genomeCount * 60000);      my $loadSequence = $self->_TableLoader('Sequence', $self->PrimaryOnly);
256        if ($self->{options}->{loadOnly}) {
257            Trace("Loading from existing files.") if T(2);
258        } else {
259            Trace("Generating genome data.") if T(2);
260      # Now we loop through the genomes, generating the data for each one.      # Now we loop through the genomes, generating the data for each one.
261      for my $genomeID (sort keys %{$genomeHash}) {      for my $genomeID (sort keys %{$genomeHash}) {
262          Trace("Loading data for genome $genomeID.") if T(3);              Trace("Generating data for genome $genomeID.") if T(3);
263          $loadGenome->Add("genomeIn");          $loadGenome->Add("genomeIn");
264          # The access code comes in via the genome hash.          # The access code comes in via the genome hash.
265          my $accessCode = $genomeHash->{$genomeID};          my $accessCode = $genomeHash->{$genomeID};
266          # 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.  
267          my ($genus, $species, @extraData) = split / /, $self->{fig}->genus_species($genomeID);          my ($genus, $species, @extraData) = split / /, $self->{fig}->genus_species($genomeID);
268          my $extra = join " ", @extraData, "[$genomeID]";              my $extra = join " ", @extraData;
269          # Get the full taxonomy.          # Get the full taxonomy.
270          my $taxonomy = $fig->taxonomy_of($genomeID);          my $taxonomy = $fig->taxonomy_of($genomeID);
271          # Output the genome record.          # Output the genome record.
# Line 262  Line 301 
301              }              }
302          }          }
303      }      }
304        }
305      # Finish the loads.      # Finish the loads.
306      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
307      # Return the result.      # Return the result.
# Line 305  Line 345 
345      my $genomeCount = (keys %{$genomeFilter});      my $genomeCount = (keys %{$genomeFilter});
346      my $featureCount = $genomeCount * 4000;      my $featureCount = $genomeCount * 4000;
347      # Start the loads.      # Start the loads.
348      my $loadCoupling = $self->_TableLoader('Coupling', $featureCount * $genomeCount);      my $loadCoupling = $self->_TableLoader('Coupling');
349      my $loadIsEvidencedBy = $self->_TableLoader('IsEvidencedBy', $featureCount * 8000);      my $loadIsEvidencedBy = $self->_TableLoader('IsEvidencedBy', $self->PrimaryOnly);
350      my $loadPCH = $self->_TableLoader('PCH', $featureCount * 2000);      my $loadPCH = $self->_TableLoader('PCH', $self->PrimaryOnly);
351      my $loadParticipatesInCoupling = $self->_TableLoader('ParticipatesInCoupling', $featureCount * 2000);      my $loadParticipatesInCoupling = $self->_TableLoader('ParticipatesInCoupling', $self->PrimaryOnly);
352      my $loadUsesAsEvidence = $self->_TableLoader('UsesAsEvidence', $featureCount * 8000);      my $loadUsesAsEvidence = $self->_TableLoader('UsesAsEvidence', $self->PrimaryOnly);
353      Trace("Beginning coupling data load.") if T(2);      if ($self->{options}->{loadOnly}) {
354            Trace("Loading from existing files.") if T(2);
355        } else {
356            Trace("Generating coupling data.") if T(2);
357      # Loop through the genomes found.      # Loop through the genomes found.
358      for my $genome (sort keys %{$genomeFilter}) {      for my $genome (sort keys %{$genomeFilter}) {
359          Trace("Generating coupling data for $genome.") if T(3);          Trace("Generating coupling data for $genome.") if T(3);
# Line 362  Line 405 
405                              # We store this evidence in the hash if the usage                              # We store this evidence in the hash if the usage
406                              # is nonzero or no prior evidence has been found. This                              # is nonzero or no prior evidence has been found. This
407                              # insures that if there is duplicate evidence, we                              # insures that if there is duplicate evidence, we
408                              # at least keep the meaningful ones. Only evidence is                                  # at least keep the meaningful ones. Only evidence in
409                              # the hash makes it to the output.                              # the hash makes it to the output.
410                              if ($usage || ! exists $evidenceMap{$evidenceKey}) {                              if ($usage || ! exists $evidenceMap{$evidenceKey}) {
411                                  $evidenceMap{$evidenceKey} = $evidenceData;                                  $evidenceMap{$evidenceKey} = $evidenceData;
# Line 377  Line 420 
420                          $loadIsEvidencedBy->Put($coupleID, $evidenceID);                          $loadIsEvidencedBy->Put($coupleID, $evidenceID);
421                          # Connect it to the features.                          # Connect it to the features.
422                          $loadUsesAsEvidence->Put($evidenceID, $peg3, 1);                          $loadUsesAsEvidence->Put($evidenceID, $peg3, 1);
423                          $loadUsesAsEvidence->Put($evidenceID, $peg4, 1);                              $loadUsesAsEvidence->Put($evidenceID, $peg4, 2);
424                            }
425                      }                      }
426                  }                  }
427              }              }
# Line 404  Line 448 
448      FeatureTranslation      FeatureTranslation
449      FeatureUpstream      FeatureUpstream
450      IsLocatedIn      IsLocatedIn
451        HasFeature
452    
453  =over 4  =over 4
454    
# Line 422  Line 467 
467      my $fig = $self->{fig};      my $fig = $self->{fig};
468      # Get the table of genome IDs.      # Get the table of genome IDs.
469      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
     my $featureCount = $genomeCount * 4000;  
470      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
471      my $loadFeature = $self->_TableLoader('Feature', $featureCount);      my $loadFeature = $self->_TableLoader('Feature');
472      my $loadFeatureAlias = $self->_TableLoader('FeatureAlias', $featureCount * 6);      my $loadIsLocatedIn = $self->_TableLoader('IsLocatedIn', $self->PrimaryOnly);
473      my $loadFeatureLink = $self->_TableLoader('FeatureLink', $featureCount * 10);      my $loadFeatureAlias = $self->_TableLoader('FeatureAlias');
474      my $loadFeatureTranslation = $self->_TableLoader('FeatureTranslation', $featureCount);      my $loadFeatureLink = $self->_TableLoader('FeatureLink');
475      my $loadFeatureUpstream = $self->_TableLoader('FeatureUpstream', $featureCount);      my $loadFeatureTranslation = $self->_TableLoader('FeatureTranslation');
476      my $loadIsLocatedIn = $self->_TableLoader('IsLocatedIn', $featureCount);      my $loadFeatureUpstream = $self->_TableLoader('FeatureUpstream');
477        my $loadHasFeature = $self->_TableLoader('HasFeature');
478      # 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
479      # locations.      # locations.
480      my $chunkSize = $self->{sprout}->MaxSegment();      my $chunkSize = $self->{sprout}->MaxSegment();
481      Trace("Beginning feature data load.") if T(2);      if ($self->{options}->{loadOnly}) {
482            Trace("Loading from existing files.") if T(2);
483        } else {
484            Trace("Generating feature data.") if T(2);
485      # Now we loop through the genomes, generating the data for each one.      # Now we loop through the genomes, generating the data for each one.
486      for my $genomeID (sort keys %{$genomeHash}) {      for my $genomeID (sort keys %{$genomeHash}) {
487          Trace("Loading features for genome $genomeID.") if T(3);          Trace("Loading features for genome $genomeID.") if T(3);
# Line 445  Line 492 
492          for my $featureData (@{$features}) {          for my $featureData (@{$features}) {
493              $loadFeature->Add("featureIn");              $loadFeature->Add("featureIn");
494              # Split the tuple.              # Split the tuple.
495              my ($featureID, $locations, $aliases, $type) = @{$featureData};                  my ($featureID, $locations, undef, $type) = @{$featureData};
496              # Create the feature record.              # Create the feature record.
497              $loadFeature->Put($featureID, 1, $type);              $loadFeature->Put($featureID, 1, $type);
498                    # Link it to the parent genome.
499                    $loadHasFeature->Put($genomeID, $featureID, $type);
500              # Create the aliases.              # Create the aliases.
501              for my $alias (split /\s*,\s*/, $aliases) {                  for my $alias ($fig->feature_aliases($featureID)) {
502                  $loadFeatureAlias->Put($featureID, $alias);                  $loadFeatureAlias->Put($featureID, $alias);
503              }              }
504              # Get the links.              # Get the links.
# Line 475  Line 524 
524              # the maximum segment size. This simplifies the genes_in_region processing              # the maximum segment size. This simplifies the genes_in_region processing
525              # for Sprout.              # for Sprout.
526              my @locationList = split /\s*,\s*/, $locations;              my @locationList = split /\s*,\s*/, $locations;
527                    # Create the location position indicator.
528                    my $i = 1;
529              # Loop through the locations.              # Loop through the locations.
530              for my $location (@locationList) {              for my $location (@locationList) {
531                  # Parse the location.                  # Parse the location.
532                  my $locObject = BasicLocation->new($location);                      my $locObject = BasicLocation->new("$genomeID:$location");
533                  # Split it into a list of chunks.                  # Split it into a list of chunks.
534                  my @locOList = ();                  my @locOList = ();
535                  while (my $peeling = $locObject->Peel($chunkSize)) {                  while (my $peeling = $locObject->Peel($chunkSize)) {
# Line 488  Line 539 
539                  push @locOList, $locObject;                  push @locOList, $locObject;
540                  # Loop through the chunks, creating IsLocatedIn records. The variable                  # Loop through the chunks, creating IsLocatedIn records. The variable
541                  # "$i" will be used to keep the location index.                  # "$i" will be used to keep the location index.
                 my $i = 1;  
542                  for my $locChunk (@locOList) {                  for my $locChunk (@locOList) {
543                      $loadIsLocatedIn->Put($featureID, $locChunk->Contig, $locChunk->Left,                      $loadIsLocatedIn->Put($featureID, $locChunk->Contig, $locChunk->Left,
544                                            $locChunk->Dir, $locChunk->Length, $i);                                            $locChunk->Dir, $locChunk->Length, $i);
# Line 497  Line 547 
547              }              }
548          }          }
549      }      }
550        }
551      # Finish the loads.      # Finish the loads.
552      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
553      return $retVal;      return $retVal;
# Line 533  Line 584 
584      my $fig = $self->{fig};      my $fig = $self->{fig};
585      # Get the table of genome IDs.      # Get the table of genome IDs.
586      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
     my $featureCount = $genomeCount * 4000;  
587      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
588      my $loadIsBidirectionalBestHitOf = $self->_TableLoader('IsBidirectionalBestHitOf',      my $loadIsBidirectionalBestHitOf = $self->_TableLoader('IsBidirectionalBestHitOf');
589                                                             $featureCount * $genomeCount);      if ($self->{options}->{loadOnly}) {
590      Trace("Beginning BBH load.") if T(2);          Trace("Loading from existing files.") if T(2);
591        } else {
592            Trace("Generating BBH data.") if T(2);
593      # Now we loop through the genomes, generating the data for each one.      # Now we loop through the genomes, generating the data for each one.
594      for my $genomeID (sort keys %{$genomeHash}) {      for my $genomeID (sort keys %{$genomeHash}) {
595          $loadIsBidirectionalBestHitOf->Add("genomeIn");          $loadIsBidirectionalBestHitOf->Add("genomeIn");
# Line 564  Line 615 
615              }              }
616          }          }
617      }      }
618        }
619      # Finish the loads.      # Finish the loads.
620      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
621      return $retVal;      return $retVal;
# Line 585  Line 637 
637    
638      Subsystem      Subsystem
639      Role      Role
640        RoleEC
641      SSCell      SSCell
642      ContainsFeature      ContainsFeature
643      IsGenomeOf      IsGenomeOf
# Line 592  Line 645 
645      OccursInSubsystem      OccursInSubsystem
646      ParticipatesIn      ParticipatesIn
647      HasSSCell      HasSSCell
648        ConsistsOfRoles
649        RoleSubset
650        HasRoleSubset
651        ConsistsOfGenomes
652        GenomeSubset
653        HasGenomeSubset
654        Catalyzes
655        Diagram
656        RoleOccursIn
657    
658  =over 4  =over 4
659    
# Line 601  Line 663 
663    
664  =back  =back
665    
 B<TO DO>  
   
 Generate RoleName table?  
   
666  =cut  =cut
667  #: Return Type $%;  #: Return Type $%;
668  sub LoadSubsystemData {  sub LoadSubsystemData {
# Line 618  Line 676 
676      # Get the subsystem hash. This lists the subsystems we'll process.      # Get the subsystem hash. This lists the subsystems we'll process.
677      my $subsysHash = $self->{subsystems};      my $subsysHash = $self->{subsystems};
678      my @subsysIDs = sort keys %{$subsysHash};      my @subsysIDs = sort keys %{$subsysHash};
679      my $subsysCount = @subsysIDs;      # Get the map list.
680      my $genomeCount = (keys %{$genomeHash});      my @maps = $fig->all_maps;
     my $featureCount = $genomeCount * 4000;  
681      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
682      my $loadSubsystem = $self->_TableLoader('Subsystem', $subsysCount);      my $loadDiagram = $self->_TableLoader('Diagram', $self->PrimaryOnly);
683      my $loadRole = $self->_TableLoader('Role', $featureCount * 6);      my $loadRoleOccursIn = $self->_TableLoader('RoleOccursIn', $self->PrimaryOnly);
684      my $loadSSCell = $self->_TableLoader('SSCell', $featureCount * $genomeCount);      my $loadSubsystem = $self->_TableLoader('Subsystem');
685      my $loadContainsFeature = $self->_TableLoader('ContainsFeature', $featureCount * $subsysCount);      my $loadRole = $self->_TableLoader('Role', $self->PrimaryOnly);
686      my $loadIsGenomeOf = $self->_TableLoader('IsGenomeOf', $featureCount * $genomeCount);      my $loadRoleEC = $self->_TableLoader('RoleEC', $self->PrimaryOnly);
687      my $loadIsRoleOf = $self->_TableLoader('IsRoleOf', $featureCount * $genomeCount);      my $loadCatalyzes = $self->_TableLoader('Catalyzes', $self->PrimaryOnly);
688      my $loadOccursInSubsystem = $self->_TableLoader('OccursInSubsystem', $featureCount * 6);      my $loadSSCell = $self->_TableLoader('SSCell', $self->PrimaryOnly);
689      my $loadParticipatesIn = $self->_TableLoader('ParticipatesIn', $subsysCount * $genomeCount);      my $loadContainsFeature = $self->_TableLoader('ContainsFeature', $self->PrimaryOnly);
690      my $loadHasSSCell = $self->_TableLoader('HasSSCell', $featureCount * $genomeCount);      my $loadIsGenomeOf = $self->_TableLoader('IsGenomeOf', $self->PrimaryOnly);
691      Trace("Beginning subsystem data load.") if T(2);      my $loadIsRoleOf = $self->_TableLoader('IsRoleOf', $self->PrimaryOnly);
692        my $loadOccursInSubsystem = $self->_TableLoader('OccursInSubsystem', $self->PrimaryOnly);
693        my $loadParticipatesIn = $self->_TableLoader('ParticipatesIn', $self->PrimaryOnly);
694        my $loadHasSSCell = $self->_TableLoader('HasSSCell', $self->PrimaryOnly);
695        my $loadRoleSubset = $self->_TableLoader('RoleSubset', $self->PrimaryOnly);
696        my $loadGenomeSubset = $self->_TableLoader('GenomeSubset', $self->PrimaryOnly);
697        my $loadConsistsOfRoles = $self->_TableLoader('ConsistsOfRoles', $self->PrimaryOnly);
698        my $loadConsistsOfGenomes = $self->_TableLoader('ConsistsOfGenomes', $self->PrimaryOnly);
699        my $loadHasRoleSubset = $self->_TableLoader('HasRoleSubset', $self->PrimaryOnly);
700        my $loadHasGenomeSubset = $self->_TableLoader('HasGenomeSubset', $self->PrimaryOnly);
701        if ($self->{options}->{loadOnly}) {
702            Trace("Loading from existing files.") if T(2);
703        } else {
704            Trace("Generating subsystem data.") if T(2);
705            # This hash will contain the role for each EC. When we're done, this
706            # information will be used to generate the Catalyzes table.
707            my %ecToRoles = ();
708      # Loop through the subsystems. Our first task will be to create the      # Loop through the subsystems. Our first task will be to create the
709      # roles. We do this by looping through the subsystems and creating a      # roles. We do this by looping through the subsystems and creating a
710      # 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
711      # duplicates. As we move along, we'll connect the roles and subsystems.          # duplicates. As we move along, we'll connect the roles and subsystems
712            # and memorize up the reactions.
713            my ($genomeID, $roleID);
714      my %roleData = ();      my %roleData = ();
715      for my $subsysID (@subsysIDs) {      for my $subsysID (@subsysIDs) {
716                # Get the subsystem object.
717                my $sub = $fig->get_subsystem($subsysID);
718                # Only proceed if the subsystem has a spreadsheet.
719                if (! $sub->{empty_ss}) {
720          Trace("Creating subsystem $subsysID.") if T(3);          Trace("Creating subsystem $subsysID.") if T(3);
721          $loadSubsystem->Add("subsystemIn");          $loadSubsystem->Add("subsystemIn");
722          # Create the subsystem record.          # Create the subsystem record.
723          $loadSubsystem->Put($subsysID);                  my $curator = $sub->get_curator();
724          # Get the subsystem's roles.                  my $notes = $sub->get_notes();
725          my @roles = $fig->subsystem_to_roles($subsysID);                  $loadSubsystem->Put($subsysID, $curator, $notes);
726          # 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.
727          # a role record for it.                  for (my $col = 0; defined($roleID = $sub->get_role($col)); $col++) {
728          for my $roleID (@roles) {                      # Connect to this role.
729              $loadOccursInSubsystem->Add("roleIn");              $loadOccursInSubsystem->Add("roleIn");
730              $loadOccursInSubsystem->Put($roleID, $subsysID);                      $loadOccursInSubsystem->Put($roleID, $subsysID, $col);
731                        # If it's a new role, add it to the role table.
732              if (! exists $roleData{$roleID}) {              if (! exists $roleData{$roleID}) {
733                  $loadRole->Put($roleID);                          # Get the role's abbreviation.
734                            my $abbr = $sub->get_role_abbr($col);
735                            # Add the role.
736                            $loadRole->Put($roleID, $abbr);
737                  $roleData{$roleID} = 1;                  $roleData{$roleID} = 1;
738                            # Check for an EC number.
739                            if ($roleID =~ /\(EC ([^.]+\.[^.]+\.[^.]+\.[^)]+)\)\s*$/) {
740                                my $ec = $1;
741                                $loadRoleEC->Put($roleID, $ec);
742                                $ecToRoles{$ec} = $roleID;
743                            }
744              }              }
745          }          }
746          # 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
747          # 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
748          # get the genomes on the sheet.                  # to actually create the roles as we find them.
749          Trace("Creating subsystem $subsysID spreadsheet.") if T(3);          Trace("Creating subsystem $subsysID spreadsheet.") if T(3);
750          my @genomes = map { $_->[0] } @{$fig->subsystem_genomes($subsysID)};                  for (my $row = 0; defined($genomeID = $sub->get_genome($row)); $row++) {
751          for my $genomeID (@genomes) {                      # Only proceed if this is one of our genomes.
             # Only process this genome if it's one of ours.  
752              if (exists $genomeHash->{$genomeID}) {              if (exists $genomeHash->{$genomeID}) {
753                  # Connect the genome to the subsystem.                          # Count the PEGs and cells found for verification purposes.
754                  $loadParticipatesIn->Put($genomeID, $subsysID);                          my $pegCount = 0;
755                            my $cellCount = 0;
756                            # Create a list for the PEGs we find. This list will be used
757                            # to generate cluster numbers.
758                            my @pegsFound = ();
759                            # Create a hash that maps spreadsheet IDs to PEGs. We will
760                            # use this to generate the ContainsFeature data after we have
761                            # the cluster numbers.
762                            my %cellPegs = ();
763                            # Get the genome's variant code for this subsystem.
764                            my $variantCode = $sub->get_variant_code($row);
765                  # 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
766                  # part of the spreadsheet cell ID.                  # part of the spreadsheet cell ID.
767                  for (my $i = 0; $i <= $#roles; $i++) {                          for (my $col = 0; defined($roleID = $sub->get_role($col)); $col++) {
                     my $role = $roles[$i];  
768                      # Get the features in the spreadsheet cell for this genome and role.                      # Get the features in the spreadsheet cell for this genome and role.
769                      my @pegs = $fig->pegs_in_subsystem_cell($subsysID, $genomeID, $i);                              my @pegs = $sub->get_pegs_from_cell($row, $col);
770                      # Only proceed if features exist.                      # Only proceed if features exist.
771                      if (@pegs > 0) {                      if (@pegs > 0) {
772                          # Create the spreadsheet cell.                          # Create the spreadsheet cell.
773                          my $cellID = "$subsysID:$genomeID:$i";                                  $cellCount++;
774                                    my $cellID = "$subsysID:$genomeID:$col";
775                          $loadSSCell->Put($cellID);                          $loadSSCell->Put($cellID);
776                          $loadIsGenomeOf->Put($genomeID, $cellID);                          $loadIsGenomeOf->Put($genomeID, $cellID);
777                          $loadIsRoleOf->Put($role, $cellID);                                  $loadIsRoleOf->Put($roleID, $cellID);
778                          $loadHasSSCell->Put($subsysID, $cellID);                          $loadHasSSCell->Put($subsysID, $cellID);
779                          # Attach the features to it.                                  # Remember its features.
780                          for my $pegID (@pegs) {                                  push @pegsFound, @pegs;
781                              $loadContainsFeature->Put($cellID, $pegID);                                  $cellPegs{$cellID} = \@pegs;
782                                    $pegCount += @pegs;
783                                }
784                            }
785                            # If we found some cells for this genome, we need to compute clusters and
786                            # denote it participates in the subsystem.
787                            if ($pegCount > 0) {
788                                Trace("$pegCount PEGs in $cellCount cells for $genomeID.") if T(3);
789                                $loadParticipatesIn->Put($genomeID, $subsysID, $variantCode);
790                                # Partition the PEGs found into clusters.
791                                my @clusters = $fig->compute_clusters(\@pegsFound, $sub);
792                                # Create a hash mapping PEG IDs to cluster numbers.
793                                # We default to -1 for all of them.
794                                my %clusterOf = map { $_ => -1 } @pegsFound;
795                                for (my $i = 0; $i <= $#clusters; $i++) {
796                                    my $subList = $clusters[$i];
797                                    for my $peg (@{$subList}) {
798                                        $clusterOf{$peg} = $i;
799                                    }
800                                }
801                                # Create the ContainsFeature data.
802                                for my $cellID (keys %cellPegs) {
803                                    my $cellList = $cellPegs{$cellID};
804                                    for my $cellPeg (@$cellList) {
805                                        $loadContainsFeature->Put($cellID, $cellPeg, $clusterOf{$cellPeg});
806                          }                          }
807                      }                      }
808                  }                  }
809              }              }
810          }          }
811                    # Now we need to generate the subsets. The subset names must be concatenated to
812                    # the subsystem name to make them unique keys. There are two types of subsets:
813                    # genome subsets and role subsets. We do the role subsets first.
814                    my @subsetNames = $sub->get_subset_names();
815                    for my $subsetID (@subsetNames) {
816                        # Create the subset record.
817                        my $actualID = "$subsysID:$subsetID";
818                        $loadRoleSubset->Put($actualID);
819                        # Connect the subset to the subsystem.
820                        $loadHasRoleSubset->Put($subsysID, $actualID);
821                        # Connect the subset to its roles.
822                        my @roles = $sub->get_subsetC_roles($subsetID);
823                        for my $roleID (@roles) {
824                            $loadConsistsOfRoles->Put($actualID, $roleID);
825      }      }
     # Finish the load.  
     my $retVal = $self->_FinishAll();  
     return $retVal;  
826  }  }
827                    # Next the genome subsets.
828  =head3 LoadDiagramData                  @subsetNames = $sub->get_subset_namesR();
829                    for my $subsetID (@subsetNames) {
830  C<< my $stats = $spl->LoadDiagramData(); >>                      # Create the subset record.
831                        my $actualID = "$subsysID:$subsetID";
832  Load the diagram data from FIG into Sprout.                      $loadGenomeSubset->Put($actualID);
833                        # Connect the subset to the subsystem.
834  Diagrams are used to organize functional roles. The diagram shows the                      $loadHasGenomeSubset->Put($subsysID, $actualID);
835  connections between chemicals that interact with a subsystem.                      # Connect the subset to its genomes.
836                        my @genomes = $sub->get_subsetR($subsetID);
837  The following relations are loaded by this method.                      for my $genomeID (@genomes) {
838                            $loadConsistsOfGenomes->Put($actualID, $genomeID);
839      Diagram                      }
840      RoleOccursIn                  }
841                }
842  =over 4              # Now we loop through the diagrams. We need to create the diagram records
843                # and link each diagram to its roles. Note that only roles which occur
844  =item RETURNS              # in subsystems (and therefore appear in the %ecToRoles hash) are
845                # included.
846  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) {  
847          Trace("Loading diagram $map.") if T(3);          Trace("Loading diagram $map.") if T(3);
848          # Get the diagram's descriptive name.          # Get the diagram's descriptive name.
849          my $name = $fig->map_name($map);          my $name = $fig->map_name($map);
# Line 740  Line 852 
852          # A hash is used to prevent duplicates.          # A hash is used to prevent duplicates.
853          my %roleHash = ();          my %roleHash = ();
854          for my $role ($fig->map_to_ecs($map)) {          for my $role ($fig->map_to_ecs($map)) {
855              if (! $roleHash{$role}) {                      if (exists $ecToRoles{$role} && ! $roleHash{$role}) {
856                  $loadRoleOccursIn->Put($role, $map);                          $loadRoleOccursIn->Put($ecToRoles{$role}, $map);
857                  $roleHash{$role} = 1;                  $roleHash{$role} = 1;
858              }              }
859          }          }
860      }      }
861                # Before we leave, we must create the Catalyzes table. We start with the reactions,
862                # then use the "ecToRoles" table to convert EC numbers to role IDs.
863                my @reactions = $fig->all_reactions();
864                for my $reactionID (@reactions) {
865                    # Get this reaction's list of roles. The results will be EC numbers.
866                    my @roles = $fig->catalyzed_by($reactionID);
867                    # Loop through the roles, creating catalyzation records.
868                    for my $thisRole (@roles) {
869                        if (exists $ecToRoles{$thisRole}) {
870                            $loadCatalyzes->Put($ecToRoles{$thisRole}, $reactionID);
871                        }
872                    }
873                }
874            }
875        }
876      # Finish the load.      # Finish the load.
877      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
878      return $retVal;      return $retVal;
# Line 787  Line 914 
914      my $fig = $self->{fig};      my $fig = $self->{fig};
915      # Get the genome hash.      # Get the genome hash.
916      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
917      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
918      my $loadProperty = $self->_TableLoader('Property', $genomeCount * 1500);      my $loadProperty = $self->_TableLoader('Property');
919      my $loadHasProperty = $self->_TableLoader('HasProperty', $genomeCount * 1500);      my $loadHasProperty = $self->_TableLoader('HasProperty', $self->PrimaryOnly);
920      Trace("Beginning property data load.") if T(2);      if ($self->{options}->{loadOnly}) {
921            Trace("Loading from existing files.") if T(2);
922        } else {
923            Trace("Generating property data.") if T(2);
924      # Create a hash for storing property IDs.      # Create a hash for storing property IDs.
925      my %propertyKeys = ();      my %propertyKeys = ();
926      my $nextID = 1;      my $nextID = 1;
927      # Loop through the genomes.      # Loop through the genomes.
928      for my $genomeID (keys %{$genomeHash}) {      for my $genomeID (keys %{$genomeHash}) {
929          $loadProperty->Add("genomeIn");          $loadProperty->Add("genomeIn");
930                Trace("Generating properties for $genomeID.") if T(3);
931          # 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
932          # tuples returned by "all_features_detailed". We use "all_features_detailed"          # tuples returned by "all_features_detailed". We use "all_features_detailed"
933          # rather than "all_features" because we want all features regardless of type.          # rather than "all_features" because we want all features regardless of type.
934          my @features = map { $_->[0] } @{$fig->all_features_detailed($genomeID)};          my @features = map { $_->[0] } @{$fig->all_features_detailed($genomeID)};
935                my $featureCount = 0;
936                my $propertyCount = 0;
937          # Loop through the features, creating HasProperty records.          # Loop through the features, creating HasProperty records.
938          for my $fid (@features) {          for my $fid (@features) {
             $loadProperty->Add("featureIn");  
939              # 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
940              # to insure we do not get any genome attributes.              # to insure we do not get any genome attributes.
941              my @attributeList = $fig->get_attributes($fid, '', '', '');              my @attributeList = $fig->get_attributes($fid, '', '', '');
942                    if (scalar @attributeList) {
943                        $featureCount++;
944                    }
945              # Loop through the attributes.              # Loop through the attributes.
946              for my $tuple (@attributeList) {              for my $tuple (@attributeList) {
947                        $propertyCount++;
948                  # 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,
949                  # since it will always be the same as the value if "$fid".                  # since it will always be the same as the value if "$fid".
950                  my (undef, $key, $value, $url) = @{$tuple};                  my (undef, $key, $value, $url) = @{$tuple};
# Line 831  Line 966 
966                  $loadHasProperty->Put($fid, $propertyID, $url);                  $loadHasProperty->Put($fid, $propertyID, $url);
967              }              }
968          }          }
969                # Update the statistics.
970                Trace("$propertyCount attributes processed for $featureCount features.") if T(3);
971                $loadHasProperty->Add("featuresIn", $featureCount);
972                $loadHasProperty->Add("propertiesIn", $propertyCount);
973            }
974      }      }
975      # Finish the load.      # Finish the load.
976      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
# Line 871  Line 1011 
1011      my $fig = $self->{fig};      my $fig = $self->{fig};
1012      # Get the genome hash.      # Get the genome hash.
1013      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
1014      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
1015      my $loadAnnotation = $self->_TableLoader('Annotation', $genomeCount * 4000);      my $loadAnnotation = $self->_TableLoader('Annotation');
1016      my $loadIsTargetOfAnnotation = $self->_TableLoader('IsTargetOfAnnotation', $genomeCount * 4000);      my $loadIsTargetOfAnnotation = $self->_TableLoader('IsTargetOfAnnotation', $self->PrimaryOnly);
1017      my $loadSproutUser = $self->_TableLoader('SproutUser', 100);      my $loadSproutUser = $self->_TableLoader('SproutUser', $self->PrimaryOnly);
1018      my $loadUserAccess = $self->_TableLoader('UserAccess', 1000);      my $loadUserAccess = $self->_TableLoader('UserAccess', $self->PrimaryOnly);
1019      my $loadMadeAnnotation = $self->_TableLoader('MadeAnnotation', $genomeCount * 4000);      my $loadMadeAnnotation = $self->_TableLoader('MadeAnnotation', $self->PrimaryOnly);
1020      Trace("Beginning annotation data load.") if T(2);      if ($self->{options}->{loadOnly}) {
1021            Trace("Loading from existing files.") if T(2);
1022        } else {
1023            Trace("Generating annotation data.") if T(2);
1024      # 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
1025      # user records.      # user records.
1026      my %users = ( FIG => 1, master => 1 );      my %users = ( FIG => 1, master => 1 );
# Line 899  Line 1041 
1041              # 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
1042              # from showing up for a single PEG's annotations.              # from showing up for a single PEG's annotations.
1043              my %seenTimestamps = ();              my %seenTimestamps = ();
1044              # 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.  
1045                  for my $tuple ($fig->feature_annotations($peg, "raw")) {                  for my $tuple ($fig->feature_annotations($peg, "raw")) {
1046                      my ($fid, $timestamp, $user, $text) = @{$tuple};                      my ($fid, $timestamp, $user, $text) = @{$tuple};
1047                      # Here we fix up the annotation text. "\r" is removed,                      # Here we fix up the annotation text. "\r" is removed,
# Line 927  Line 1055 
1055                      $text =~ s/Set master function/Set FIG function/s;                      $text =~ s/Set master function/Set FIG function/s;
1056                      # Insure the time stamp is valid.                      # Insure the time stamp is valid.
1057                      if ($timestamp =~ /^\d+$/) {                      if ($timestamp =~ /^\d+$/) {
1058                          # 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
1059                          while ($seenTimestamps{$timestamp}) {                          # the key is unique.
1060                              $timestamp++;                          my $keyStamp = $timestamp;
1061                            while ($seenTimestamps{$keyStamp}) {
1062                                $keyStamp++;
1063                          }                          }
1064                          $seenTimestamps{$timestamp} = 1;                          $seenTimestamps{$keyStamp} = 1;
1065                          my $annotationID = "$peg:$timestamp";                          my $annotationID = "$peg:$keyStamp";
1066                          # Insure the user exists.                          # Insure the user exists.
1067                          if (! $users{$user}) {                          if (! $users{$user}) {
1068                              $loadSproutUser->Put($user, "SEED user");                              $loadSproutUser->Put($user, "SEED user");
# Line 940  Line 1070 
1070                              $users{$user} = 1;                              $users{$user} = 1;
1071                          }                          }
1072                          # Generate the annotation.                          # Generate the annotation.
1073                          $loadAnnotation->Put($annotationID, $timestamp, "$user\\n$text");                          $loadAnnotation->Put($annotationID, $timestamp, $text);
1074                          $loadIsTargetOfAnnotation->Put($peg, $annotationID);                          $loadIsTargetOfAnnotation->Put($peg, $annotationID);
1075                          $loadMadeAnnotation->Put($user, $annotationID);                          $loadMadeAnnotation->Put($user, $annotationID);
1076                      } else {                      } else {
# Line 991  Line 1121 
1121      my $fig = $self->{fig};      my $fig = $self->{fig};
1122      # Get the genome hash.      # Get the genome hash.
1123      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
1124      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
1125      my $loadComesFrom = $self->_TableLoader('ComesFrom', $genomeCount * 4);      my $loadComesFrom = $self->_TableLoader('ComesFrom', $self->PrimaryOnly);
1126      my $loadSource = $self->_TableLoader('Source', $genomeCount * 4);      my $loadSource = $self->_TableLoader('Source');
1127      my $loadSourceURL = $self->_TableLoader('SourceURL', $genomeCount * 8);      my $loadSourceURL = $self->_TableLoader('SourceURL');
1128      Trace("Beginning source data load.") if T(2);      if ($self->{options}->{loadOnly}) {
1129            Trace("Loading from existing files.") if T(2);
1130        } else {
1131            Trace("Generating annotation data.") if T(2);
1132      # Create hashes to collect the Source information.      # Create hashes to collect the Source information.
1133      my %sourceURL = ();      my %sourceURL = ();
1134      my %sourceDesc = ();      my %sourceDesc = ();
# Line 1010  Line 1142 
1142              chomp $line;              chomp $line;
1143              my($sourceID, $desc, $url) = split(/\t/,$line);              my($sourceID, $desc, $url) = split(/\t/,$line);
1144              $loadComesFrom->Put($genomeID, $sourceID);              $loadComesFrom->Put($genomeID, $sourceID);
1145              if ($url && ! exists $sourceURL{$genomeID}) {                  if ($url && ! exists $sourceURL{$sourceID}) {
1146                  $loadSourceURL->Put($sourceID, $url);                  $loadSourceURL->Put($sourceID, $url);
1147                  $sourceURL{$sourceID} = 1;                  $sourceURL{$sourceID} = 1;
1148              }              }
1149              if ($desc && ! exists $sourceDesc{$sourceID}) {                  if ($desc) {
1150                  $loadSource->Put($sourceID, $desc);                      $sourceDesc{$sourceID} = $desc;
1151                  $sourceDesc{$sourceID} = 1;                  } elsif (! exists $sourceDesc{$sourceID}) {
1152                        $sourceDesc{$sourceID} = $sourceID;
1153              }              }
1154          }          }
1155          close TMP;          close TMP;
1156      }      }
1157            # Write the source descriptions.
1158            for my $sourceID (keys %sourceDesc) {
1159                $loadSource->Put($sourceID, $sourceDesc{$sourceID});
1160            }
1161        }
1162      # Finish the load.      # Finish the load.
1163      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
1164      return $retVal;      return $retVal;
# Line 1060  Line 1198 
1198      my $fig = $self->{fig};      my $fig = $self->{fig};
1199      # Get the genome hash.      # Get the genome hash.
1200      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
1201      # 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
1202      # it the key.      # it the key.
1203      my %speciesHash = map { $fig->genus_species($_) => $_ } (keys %{$genomeHash});      my %speciesHash = map { $fig->genus_species($_) => $_ } (keys %{$genomeHash});
1204      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
1205      my $loadExternalAliasFunc = $self->_TableLoader('ExternalAliasFunc', $genomeCount * 4000);      my $loadExternalAliasFunc = $self->_TableLoader('ExternalAliasFunc');
1206      my $loadExternalAliasOrg = $self->_TableLoader('ExternalAliasOrg', $genomeCount * 4000);      my $loadExternalAliasOrg = $self->_TableLoader('ExternalAliasOrg');
1207      Trace("Beginning external data load.") if T(2);      if ($self->{options}->{loadOnly}) {
1208            Trace("Loading from existing files.") if T(2);
1209        } else {
1210            Trace("Generating external data.") if T(2);
1211      # 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.
1212      Open(\*ORGS, "<$FIG_Config::global/ext_org.table");      Open(\*ORGS, "<$FIG_Config::global/ext_org.table");
1213      my $orgLine;      my $orgLine;
# Line 1097  Line 1237 
1237              $loadExternalAliasFunc->Put(@funcFields[0,1]);              $loadExternalAliasFunc->Put(@funcFields[0,1]);
1238          }          }
1239      }      }
1240        }
1241        # Finish the load.
1242        my $retVal = $self->_FinishAll();
1243        return $retVal;
1244    }
1245    
1246    
1247    =head3 LoadReactionData
1248    
1249    C<< my $stats = $spl->LoadReactionData(); >>
1250    
1251    Load the reaction data from FIG into Sprout.
1252    
1253    Reaction data connects reactions to the compounds that participate in them.
1254    
1255    The following relations are loaded by this method.
1256    
1257        Reaction
1258        ReactionURL
1259        Compound
1260        CompoundName
1261        CompoundCAS
1262        IsAComponentOf
1263    
1264    This method proceeds reaction by reaction rather than genome by genome.
1265    
1266    =over 4
1267    
1268    =item RETURNS
1269    
1270    Returns a statistics object for the loads.
1271    
1272    =back
1273    
1274    =cut
1275    #: Return Type $%;
1276    sub LoadReactionData {
1277        # Get this object instance.
1278        my ($self) = @_;
1279        # Get the FIG object.
1280        my $fig = $self->{fig};
1281        # Create load objects for each of the tables we're loading.
1282        my $loadReaction = $self->_TableLoader('Reaction');
1283        my $loadReactionURL = $self->_TableLoader('ReactionURL', $self->PrimaryOnly);
1284        my $loadCompound = $self->_TableLoader('Compound', $self->PrimaryOnly);
1285        my $loadCompoundName = $self->_TableLoader('CompoundName', $self->PrimaryOnly);
1286        my $loadCompoundCAS = $self->_TableLoader('CompoundCAS', $self->PrimaryOnly);
1287        my $loadIsAComponentOf = $self->_TableLoader('IsAComponentOf', $self->PrimaryOnly);
1288        if ($self->{options}->{loadOnly}) {
1289            Trace("Loading from existing files.") if T(2);
1290        } else {
1291            Trace("Generating annotation data.") if T(2);
1292            # First we create the compounds.
1293            my @compounds = $fig->all_compounds();
1294            for my $cid (@compounds) {
1295                # Check for names.
1296                my @names = $fig->names_of_compound($cid);
1297                # Each name will be given a priority number, starting with 1.
1298                my $prio = 1;
1299                for my $name (@names) {
1300                    $loadCompoundName->Put($cid, $name, $prio++);
1301                }
1302                # Create the main compound record. Note that the first name
1303                # becomes the label.
1304                my $label = (@names > 0 ? $names[0] : $cid);
1305                $loadCompound->Put($cid, $label);
1306                # Check for a CAS ID.
1307                my $cas = $fig->cas($cid);
1308                if ($cas) {
1309                    $loadCompoundCAS->Put($cid, $cas);
1310                }
1311            }
1312            # All the compounds are set up, so we need to loop through the reactions next. First,
1313            # we initialize the discriminator index. This is a single integer used to insure
1314            # duplicate elements in a reaction are not accidentally collapsed.
1315            my $discrim = 0;
1316            my @reactions = $fig->all_reactions();
1317            for my $reactionID (@reactions) {
1318                # Create the reaction record.
1319                $loadReaction->Put($reactionID, $fig->reversible($reactionID));
1320                # Compute the reaction's URL.
1321                my $url = HTML::reaction_link($reactionID);
1322                # Put it in the ReactionURL table.
1323                $loadReactionURL->Put($reactionID, $url);
1324                # Now we need all of the reaction's compounds. We get these in two phases,
1325                # substrates first and then products.
1326                for my $product (0, 1) {
1327                    # Get the compounds of the current type for the current reaction. FIG will
1328                    # give us 3-tuples: [ID, stoichiometry, main-flag]. At this time we do not
1329                    # have location data in SEED, so it defaults to the empty string.
1330                    my @compounds = $fig->reaction2comp($reactionID, $product);
1331                    for my $compData (@compounds) {
1332                        # Extract the compound data from the current tuple.
1333                        my ($cid, $stoich, $main) = @{$compData};
1334                        # Link the compound to the reaction.
1335                        $loadIsAComponentOf->Put($cid, $reactionID, $discrim++, "", $main,
1336                                                 $product, $stoich);
1337                    }
1338                }
1339            }
1340        }
1341      # Finish the load.      # Finish the load.
1342      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
1343      return $retVal;      return $retVal;
# Line 1132  Line 1373 
1373      my $fig = $self->{fig};      my $fig = $self->{fig};
1374      # Get the genome hash.      # Get the genome hash.
1375      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
     my $genomeCount = (keys %{$genomeHash});  
1376      # Create a load object for the table we're loading.      # Create a load object for the table we're loading.
1377      my $loadGenomeGroups = $self->_TableLoader('GenomeGroups', $genomeCount * 4);      my $loadGenomeGroups = $self->_TableLoader('GenomeGroups');
1378      Trace("Beginning group data load.") if T(2);      if ($self->{options}->{loadOnly}) {
1379            Trace("Loading from existing files.") if T(2);
1380        } else {
1381            Trace("Generating group data.") if T(2);
1382      # Loop through the genomes.      # Loop through the genomes.
1383      my $line;      my $line;
1384      for my $genomeID (keys %{$genomeHash}) {      for my $genomeID (keys %{$genomeHash}) {
# Line 1151  Line 1394 
1394          }          }
1395          close TMP;          close TMP;
1396      }      }
1397        }
1398      # Finish the load.      # Finish the load.
1399      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
1400      return $retVal;      return $retVal;
# Line 1172  Line 1416 
1416    
1417  Name of the table (relation) being loaded.  Name of the table (relation) being loaded.
1418    
1419  =item rowCount (optional)  =item ignore
1420    
1421  Estimated maximum number of rows in the table.  TRUE if the table should be ignored entirely, else FALSE.
1422    
1423  =item RETURN  =item RETURN
1424    
# Line 1186  Line 1430 
1430    
1431  sub _TableLoader {  sub _TableLoader {
1432      # Get the parameters.      # Get the parameters.
1433      my ($self, $tableName, $rowCount) = @_;      my ($self, $tableName, $ignore) = @_;
1434      # Create the load object.      # Create the load object.
1435      my $retVal = ERDBLoad->new($self->{erdb}, $tableName, $self->{loadDirectory}, $rowCount);      my $retVal = ERDBLoad->new($self->{erdb}, $tableName, $self->{loadDirectory}, $self->LoadOnly,
1436                                   $ignore);
1437      # Cache it in the loader list.      # Cache it in the loader list.
1438      push @{$self->{loaders}}, $retVal;      push @{$self->{loaders}}, $retVal;
1439      # Return it to the caller.      # Return it to the caller.
# Line 1225  Line 1470 
1470      # 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
1471      # ignominiously. At some future point, we want to make the loads restartable.      # ignominiously. At some future point, we want to make the loads restartable.
1472      while (my $loader = pop @{$loadList}) {      while (my $loader = pop @{$loadList}) {
1473            # Get the relation name.
1474            my $relName = $loader->RelName;
1475            # Check the ignore flag.
1476            if ($loader->Ignore) {
1477                Trace("Relation $relName not loaded.") if T(2);
1478            } else {
1479                # Here we really need to finish.
1480                Trace("Finishing $relName.") if T(2);
1481          my $stats = $loader->Finish();          my $stats = $loader->Finish();
1482                if ($self->{options}->{dbLoad}) {
1483                    # Here we want to use the load file just created to load the database.
1484                    Trace("Loading relation $relName.") if T(2);
1485                    my $newStats = $self->{sprout}->LoadUpdate(1, [$relName]);
1486                    # Accumulate the statistics from the DB load.
1487                    $stats->Accumulate($newStats);
1488                }
1489          $retVal->Accumulate($stats);          $retVal->Accumulate($stats);
         my $relName = $loader->RelName;  
1490          Trace("Statistics for $relName:\n" . $stats->Show()) if T(2);          Trace("Statistics for $relName:\n" . $stats->Show()) if T(2);
1491      }      }
1492        }
1493      # Return the load statistics.      # Return the load statistics.
1494      return $retVal;      return $retVal;
1495  }  }

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3