[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.5, Fri Sep 9 14:55:01 2005 UTC revision 1.15, Fri Sep 16 04:12:05 2005 UTC
# Line 51  Line 51 
51    
52  =head3 new  =head3 new
53    
54  C<< my $spl = SproutLoad->new($sprout, $fig, $genomeFile, $subsysFile); >>  C<< my $spl = SproutLoad->new($sprout, $fig, $genomeFile, $subsysFile, $options); >>
55    
56  Construct a new Sprout Loader object, specifying the two participating databases and  Construct a new Sprout Loader object, specifying the two participating databases and
57  the name of the files containing the list of genomes and subsystems to use.  the name of the files containing the list of genomes and subsystems to use.
# Line 82  Line 82 
82  to a list of subsystem names. If nothing is specified, all known subsystems will be  to a list of subsystem names. If nothing is specified, all known subsystems will be
83  considered trusted. Only subsystem data related to the trusted subsystems is loaded.  considered trusted. Only subsystem data related to the trusted subsystems is loaded.
84    
85    =item options
86    
87    Reference to a hash of command-line options.
88    
89  =back  =back
90    
91  =cut  =cut
92    
93  sub new {  sub new {
94      # Get the parameters.      # Get the parameters.
95      my ($class, $sprout, $fig, $genomeFile, $subsysFile) = @_;      my ($class, $sprout, $fig, $genomeFile, $subsysFile, $options) = @_;
96      # Load the list of genomes into a hash.      # Load the list of genomes into a hash.
97      my %genomes;      my %genomes;
98      if (! defined($genomeFile) || $genomeFile eq '') {      if (! defined($genomeFile) || $genomeFile eq '') {
# Line 158  Line 162 
162                    sprout => $sprout,                    sprout => $sprout,
163                    loadDirectory => $directory,                    loadDirectory => $directory,
164                    erdb => $sprout->{_erdb},                    erdb => $sprout->{_erdb},
165                    loaders => []                    loaders => [],
166                      options => $options
167                   };                   };
168      # Bless and return it.      # Bless and return it.
169      bless $retVal, $class;      bless $retVal, $class;
# Line 220  Line 225 
225      # Now we loop through the genomes, generating the data for each one.      # Now we loop through the genomes, generating the data for each one.
226      for my $genomeID (sort keys %{$genomeHash}) {      for my $genomeID (sort keys %{$genomeHash}) {
227          Trace("Loading data for genome $genomeID.") if T(3);          Trace("Loading data for genome $genomeID.") if T(3);
228            $loadGenome->Add("genomeIn");
229          # The access code comes in via the genome hash.          # The access code comes in via the genome hash.
230          my $accessCode = $genomeHash->{$genomeID};          my $accessCode = $genomeHash->{$genomeID};
231          # Get the genus, species, and strain from the scientific name. Note that we append          # Get the genus, species, and strain from the scientific name. Note that we append
# Line 235  Line 241 
241          my @contigs = $fig->all_contigs($genomeID);          my @contigs = $fig->all_contigs($genomeID);
242          for my $contigID (@contigs) {          for my $contigID (@contigs) {
243              Trace("Processing contig $contigID for $genomeID.") if T(4);              Trace("Processing contig $contigID for $genomeID.") if T(4);
244                $loadContig->Add("contigIn");
245                $loadSequence->Add("contigIn");
246              # Create the contig ID.              # Create the contig ID.
247              my $sproutContigID = "$genomeID:$contigID";              my $sproutContigID = "$genomeID:$contigID";
248              # Create the contig record and relate it to the genome.              # Create the contig record and relate it to the genome.
# Line 246  Line 254 
254              # Now we get the sequence a chunk at a time.              # Now we get the sequence a chunk at a time.
255              my $contigLen = $fig->contig_ln($genomeID, $contigID);              my $contigLen = $fig->contig_ln($genomeID, $contigID);
256              for (my $i = 1; $i <= $contigLen; $i += $chunkSize) {              for (my $i = 1; $i <= $contigLen; $i += $chunkSize) {
257                    $loadSequence->Add("chunkIn");
258                  # Compute the endpoint of this chunk.                  # Compute the endpoint of this chunk.
259                  my $end = FIG::min($i + $chunkSize - 1, $contigLen);                  my $end = FIG::min($i + $chunkSize - 1, $contigLen);
260                  # Get the actual DNA.                  # Get the actual DNA.
# Line 310  Line 319 
319      # Loop through the genomes found.      # Loop through the genomes found.
320      for my $genome (sort keys %{$genomeFilter}) {      for my $genome (sort keys %{$genomeFilter}) {
321          Trace("Generating coupling data for $genome.") if T(3);          Trace("Generating coupling data for $genome.") if T(3);
322            $loadCoupling->Add("genomeIn");
323          # Create a hash table for holding coupled pairs. We use this to prevent          # Create a hash table for holding coupled pairs. We use this to prevent
324          # duplicates. For example, if A is coupled to B, we don't want to also          # duplicates. For example, if A is coupled to B, we don't want to also
325          # assert that B is coupled to A, because we already know it. Fortunately,          # assert that B is coupled to A, because we already know it. Fortunately,
# Line 320  Line 330 
330          my @pegs = $fig->pegs_of($genome);          my @pegs = $fig->pegs_of($genome);
331          # Loop through the PEGs.          # Loop through the PEGs.
332          for my $peg1 (@pegs) {          for my $peg1 (@pegs) {
333                $loadCoupling->Add("pegIn");
334              Trace("Processing PEG $peg1 for $genome.") if T(4);              Trace("Processing PEG $peg1 for $genome.") if T(4);
335              # Get a list of the coupled PEGs.              # Get a list of the coupled PEGs.
336              my @couplings = $fig->coupled_to($peg1);              my @couplings = $fig->coupled_to($peg1);
# Line 330  Line 341 
341                  # Compute the coupling ID.                  # Compute the coupling ID.
342                  my $coupleID = Sprout::CouplingID($peg1, $peg2);                  my $coupleID = Sprout::CouplingID($peg1, $peg2);
343                  if (! exists $dupHash{$coupleID}) {                  if (! exists $dupHash{$coupleID}) {
344                        $loadCoupling->Add("couplingIn");
345                      # Here we have a new coupling to store in the load files.                      # Here we have a new coupling to store in the load files.
346                      Trace("Storing coupling ($coupleID) with score $score.") if T(4);                      Trace("Storing coupling ($coupleID) with score $score.") if T(4);
347                      # Ensure we don't do this again.                      # Ensure we don't do this again.
# Line 345  Line 357 
357                      my %evidenceMap = ();                      my %evidenceMap = ();
358                      # Process each evidence item.                      # Process each evidence item.
359                      for my $evidenceData (@evidence) {                      for my $evidenceData (@evidence) {
360                            $loadPCH->Add("evidenceIn");
361                          my ($peg3, $peg4, $usage) = @{$evidenceData};                          my ($peg3, $peg4, $usage) = @{$evidenceData};
362                          # Only proceed if the evidence is from a Sprout                          # Only proceed if the evidence is from a Sprout
363                          # genome.                          # genome.
364                          if ($genomeFilter->{$fig->genome_of($peg3)}) {                          if ($genomeFilter->{$fig->genome_of($peg3)}) {
365                                $loadUsesAsEvidence->Add("evidenceChosen");
366                              my $evidenceKey = "$coupleID $peg3 $peg4";                              my $evidenceKey = "$coupleID $peg3 $peg4";
367                              # We store this evidence in the hash if the usage                              # We store this evidence in the hash if the usage
368                              # is nonzero or no prior evidence has been found. This                              # is nonzero or no prior evidence has been found. This
# Line 411  Line 425 
425      my ($self) = @_;      my ($self) = @_;
426      # Get the FIG object.      # Get the FIG object.
427      my $fig = $self->{fig};      my $fig = $self->{fig};
428        # Find out if this is a limited run.
429        my $limited = $self->{options}->{limitedFeatures};
430      # Get the table of genome IDs.      # Get the table of genome IDs.
431      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
432      my $genomeCount = (keys %{$genomeHash});      my $genomeCount = (keys %{$genomeHash});
433      my $featureCount = $genomeCount * 4000;      my $featureCount = $genomeCount * 4000;
434      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
435      my $loadFeature = $self->_TableLoader('Feature', $featureCount);      my $loadFeature = $self->_TableLoader('Feature', $featureCount);
     my $loadFeatureAlias = $self->_TableLoader('FeatureAlias', $featureCount * 6);  
     my $loadFeatureLink = $self->_TableLoader('FeatureLink', $featureCount * 10);  
     my $loadFeatureTranslation = $self->_TableLoader('FeatureTranslation', $featureCount);  
     my $loadFeatureUpstream = $self->_TableLoader('FeatureUpstream', $featureCount);  
436      my $loadIsLocatedIn = $self->_TableLoader('IsLocatedIn', $featureCount);      my $loadIsLocatedIn = $self->_TableLoader('IsLocatedIn', $featureCount);
437        my $loadFeatureAlias = $self->_TableLoader('FeatureAlias', $featureCount * 6);
438        my ($loadFeatureLink, $loadFeatureTranslation, $loadFeatureUpstream);
439        if (! $limited) {
440            $loadFeatureLink = $self->_TableLoader('FeatureLink', $featureCount * 10);
441            $loadFeatureTranslation = $self->_TableLoader('FeatureTranslation', $featureCount);
442            $loadFeatureUpstream = $self->_TableLoader('FeatureUpstream', $featureCount);
443        }
444      # 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
445      # locations.      # locations.
446      my $chunkSize = $self->{sprout}->MaxSegment();      my $chunkSize = $self->{sprout}->MaxSegment();
# Line 429  Line 448 
448      # Now we loop through the genomes, generating the data for each one.      # Now we loop through the genomes, generating the data for each one.
449      for my $genomeID (sort keys %{$genomeHash}) {      for my $genomeID (sort keys %{$genomeHash}) {
450          Trace("Loading features for genome $genomeID.") if T(3);          Trace("Loading features for genome $genomeID.") if T(3);
451            $loadFeature->Add("genomeIn");
452          # Get the feature list for this genome.          # Get the feature list for this genome.
453          my $features = $fig->all_features_detailed($genomeID);          my $features = $fig->all_features_detailed($genomeID);
454          # Loop through the features.          # Loop through the features.
455          for my $featureData (@{$features}) {          for my $featureData (@{$features}) {
456                $loadFeature->Add("featureIn");
457              # Split the tuple.              # Split the tuple.
458              my ($featureID, $locations, $aliases, $type) = @{$featureData};              my ($featureID, $locations, undef, $type) = @{$featureData};
459              # Create the feature record.              # Create the feature record.
460              $loadFeature->Put("$genomeID:$featureID", 1, $type);              $loadFeature->Put($featureID, 1, $type);
461              # Create the aliases.              # Create the aliases.
462              for my $alias (split /\s*,\s*/, $aliases) {              for my $alias ($fig->feature_aliases($featureID)) {
463                  $loadFeatureAlias->Put($featureID, $alias);                  $loadFeatureAlias->Put($featureID, $alias);
464              }              }
465                # The next stuff is for a full load only.
466                if (! $limited) {
467              # Get the links.              # Get the links.
468              my @links = $fig->fid_links($featureID);              my @links = $fig->fid_links($featureID);
469              for my $link (@links) {              for my $link (@links) {
# Line 448  Line 471 
471              }              }
472              # If this is a peg, generate the translation and the upstream.              # If this is a peg, generate the translation and the upstream.
473              if ($type eq 'peg') {              if ($type eq 'peg') {
474                        $loadFeatureTranslation->Add("pegIn");
475                  my $translation = $fig->get_translation($featureID);                  my $translation = $fig->get_translation($featureID);
476                  if ($translation) {                  if ($translation) {
477                      $loadFeatureTranslation->Put($featureID, $translation);                      $loadFeatureTranslation->Put($featureID, $translation);
# Line 458  Line 482 
482                      $loadFeatureUpstream->Put($featureID, $upstream);                      $loadFeatureUpstream->Put($featureID, $upstream);
483                  }                  }
484              }              }
485                }
486              # 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
487              # 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
488              # the maximum segment size. This simplifies the genes_in_region processing              # the maximum segment size. This simplifies the genes_in_region processing
489              # for Sprout.              # for Sprout.
490              my @locationList = split /\s*,\s*/, $locations;              my @locationList = split /\s*,\s*/, $locations;
491                # Create the location position indicator.
492                my $i = 1;
493              # Loop through the locations.              # Loop through the locations.
494              for my $location (@locationList) {              for my $location (@locationList) {
495                  # Parse the location.                  # Parse the location.
496                  my $locObject = BasicLocation->new($location);                  my $locObject = BasicLocation->new("$genomeID:$location");
497                  # Split it into a list of chunks.                  # Split it into a list of chunks.
498                  my @locOList = ();                  my @locOList = ();
499                  while (my $peeling = $locObject->Peel($chunkSize)) {                  while (my $peeling = $locObject->Peel($chunkSize)) {
500                        $loadIsLocatedIn->Add("peeling");
501                      push @locOList, $peeling;                      push @locOList, $peeling;
502                  }                  }
503                  push @locOList, $locObject;                  push @locOList, $locObject;
504                  # Loop through the chunks, creating IsLocatedIn records. The variable                  # Loop through the chunks, creating IsLocatedIn records. The variable
505                  # "$i" will be used to keep the location index.                  # "$i" will be used to keep the location index.
                 my $i = 1;  
506                  for my $locChunk (@locOList) {                  for my $locChunk (@locOList) {
507                      $loadIsLocatedIn->Put($featureID, $locChunk->Contig, $locChunk->Left,                      $loadIsLocatedIn->Put($featureID, $locChunk->Contig, $locChunk->Left,
508                                            $locChunk->Dir, $locChunk->Length, $i);                                            $locChunk->Dir, $locChunk->Length, $i);
# Line 528  Line 555 
555      Trace("Beginning BBH load.") if T(2);      Trace("Beginning BBH load.") if T(2);
556      # Now we loop through the genomes, generating the data for each one.      # Now we loop through the genomes, generating the data for each one.
557      for my $genomeID (sort keys %{$genomeHash}) {      for my $genomeID (sort keys %{$genomeHash}) {
558            $loadIsBidirectionalBestHitOf->Add("genomeIn");
559          Trace("Processing features for genome $genomeID.") if T(3);          Trace("Processing features for genome $genomeID.") if T(3);
560          # Get the feature list for this genome.          # Get the feature list for this genome.
561          my $features = $fig->all_features_detailed($genomeID);          my $features = $fig->all_features_detailed($genomeID);
# Line 622  Line 650 
650      # roles. We do this by looping through the subsystems and creating a      # roles. We do this by looping through the subsystems and creating a
651      # 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
652      # duplicates. As we move along, we'll connect the roles and subsystems.      # duplicates. As we move along, we'll connect the roles and subsystems.
653        my ($genomeID, $roleID);
654      my %roleData = ();      my %roleData = ();
655      for my $subsysID (@subsysIDs) {      for my $subsysID (@subsysIDs) {
656          Trace("Creating subsystem $subsysID.") if T(3);          Trace("Creating subsystem $subsysID.") if T(3);
657            $loadSubsystem->Add("subsystemIn");
658          # Create the subsystem record.          # Create the subsystem record.
659          $loadSubsystem->Put($subsysID);          $loadSubsystem->Put($subsysID);
660          # Get the subsystem's roles.          # Get the subsystem object.
661          my @roles = $fig->subsys_to_roles($subsysID);          my $sub = $fig->get_subsystem($subsysID);
662          # Connect the roles to the subsystem. If a role is new, we create          # Connect it to its roles.
663          # a role record for it.          for (my $col = 0; defined($roleID = $sub->get_role($col)); $col++) {
664          for my $roleID (@roles) {              $loadOccursInSubsystem->Add("roleIn");
665              $loadOccursInSubsystem->Put($roleID, $subsysID);              $loadOccursInSubsystem->Put($roleID, $subsysID);
666              if (! exists $roleData{$roleID}) {              if (! exists $roleData{$roleID}) {
667                  $loadRole->Put($roleID);                  $loadRole->Put($roleID);
668                  $roleData{$roleID} = 1;                  $roleData{$roleID} = 1;
669              }              }
670          }          }
671          # 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
672          # 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
673          # get the genomes on the sheet.          # to actually create the roles as we find them.
674          Trace("Creating subsystem $subsysID spreadsheet.") if T(3);          Trace("Creating subsystem $subsysID spreadsheet.") if T(3);
675          my @genomes = map { $_->[0] } @{$fig->subsystem_genomes($subsysID)};          for (my $row = 0; defined($genomeID = $sub->get_genome($row)); $row++) {
676          for my $genomeID (@genomes) {              # Only proceed if this is one of our genomes.
             # Only process this genome if it's one of ours.  
677              if (exists $genomeHash->{$genomeID}) {              if (exists $genomeHash->{$genomeID}) {
678                  # Connect the genome to the subsystem.                  # Count the PEGs and cells found for verification purposes.
679                  $loadParticipatesIn->Put($genomeID, $subsysID);                  my $pegCount = 0;
680                    my $cellCount = 0;
681                  # 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
682                  # part of the spreadsheet cell ID.                  # part of the spreadsheet cell ID.
683                  for (my $i = 0; $i <= $#roles; $i++) {                  for (my $col = 0; defined($roleID = $sub->get_role($col)); $col++) {
                     my $role = $roles[$i];  
684                      # Get the features in the spreadsheet cell for this genome and role.                      # Get the features in the spreadsheet cell for this genome and role.
685                      my @pegs = $fig->pegs_in_subsystem_coll($subsysID, $genomeID, $i);                      my @pegs = $sub->get_pegs_from_cell($row, $col);
686                      # Only proceed if features exist.                      # Only proceed if features exist.
687                      if (@pegs > 0) {                      if (@pegs > 0) {
688                          # Create the spreadsheet cell.                          # Create the spreadsheet cell.
689                          my $cellID = "$subsysID:$genomeID:$i";                          $cellCount++;
690                            my $cellID = "$subsysID:$genomeID:$col";
691                          $loadSSCell->Put($cellID);                          $loadSSCell->Put($cellID);
692                          $loadIsGenomeOf->Put($genomeID, $cellID);                          $loadIsGenomeOf->Put($genomeID, $cellID);
693                          $loadIsRoleOf->Put($role, $cellID);                          $loadIsRoleOf->Put($roleID, $cellID);
694                          $loadHasSSCell->Put($subsysID, $cellID);                          $loadHasSSCell->Put($subsysID, $cellID);
695                          # Attach the features to it.                          # Attach the features to it.
696                          for my $pegID (@pegs) {                          for my $pegID (@pegs) {
697                              $loadContainsFeature->Put($cellID, $pegID);                              $loadContainsFeature->Put($cellID, $pegID);
698                                $pegCount++;
699                          }                          }
700                      }                      }
701                  }                  }
702                    # If we found some cells for this genome, denote it participates in the
703                    # subsystem.
704                    if ($pegCount > 0) {
705                        Trace("$pegCount PEGs in $cellCount cells for $genomeID.") if T(3);
706                        $loadParticipatesIn->Put($genomeID, $subsysID);
707                    }
708              }              }
709          }          }
710      }      }
# Line 781  Line 818 
818      my $nextID = 1;      my $nextID = 1;
819      # Loop through the genomes.      # Loop through the genomes.
820      for my $genomeID (keys %{$genomeHash}) {      for my $genomeID (keys %{$genomeHash}) {
821            $loadProperty->Add("genomeIn");
822          # 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
823          # tuples returned by "all_features_detailed". We use "all_features_detailed"          # tuples returned by "all_features_detailed". We use "all_features_detailed"
824          # rather than "all_features" because we want all features regardless of type.          # rather than "all_features" because we want all features regardless of type.
825          my @features = map { $_->[0] } @{$fig->all_features_detailed($genomeID)};          my @features = map { $_->[0] } @{$fig->all_features_detailed($genomeID)};
826          # Loop through the features, creating HasProperty records.          # Loop through the features, creating HasProperty records.
827          for my $fid (@features) {          for my $fid (@features) {
828                $loadProperty->Add("featureIn");
829              # 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
830              # to insure we do not get any genome attributes.              # to insure we do not get any genome attributes.
831              my @attributeList = $fig->get_attributes($fid, '', '', '');              my @attributeList = $fig->get_attributes($fid, '', '', '');
# Line 872  Line 911 
911      # Get the current time.      # Get the current time.
912      my $time = time();      my $time = time();
913      # Loop through the genomes.      # Loop through the genomes.
914      for my $genomeID (%{$genomeHash}) {      for my $genomeID (sort keys %{$genomeHash}) {
915          Trace("Processing $genomeID.") if T(3);          Trace("Processing $genomeID.") if T(3);
916          # Get the genome's PEGs.          # Get the genome's PEGs.
917          my @pegs = $fig->pegs_of($genomeID);          my @pegs = $fig->pegs_of($genomeID);
# Line 897  Line 936 
936                  }                  }
937                  # Now loop through the real annotations.                  # Now loop through the real annotations.
938                  for my $tuple ($fig->feature_annotations($peg, "raw")) {                  for my $tuple ($fig->feature_annotations($peg, "raw")) {
939                      my ($fid, $timestamp, $user, $text) = $tuple;                      my ($fid, $timestamp, $user, $text) = @{$tuple};
940                      # Here we fix up the annotation text. "\r" is removed,                      # Here we fix up the annotation text. "\r" is removed,
941                      # and "\t" and "\n" are escaped. Note we use the "s"                      # and "\t" and "\n" are escaped. Note we use the "s"
942                      # modifier so that new-lines inside the text do not                      # modifier so that new-lines inside the text do not
# Line 984  Line 1023 
1023      my %sourceDesc = ();      my %sourceDesc = ();
1024      # Loop through the genomes.      # Loop through the genomes.
1025      my $line;      my $line;
1026      for my $genomeID (%{$genomeHash}) {      for my $genomeID (sort keys %{$genomeHash}) {
1027          Trace("Processing $genomeID.") if T(3);          Trace("Processing $genomeID.") if T(3);
1028          # Open the project file.          # Open the project file.
1029          if ((open(TMP, "<$FIG_Config::organisms/$genomeID/PROJECT")) &&          if ((open(TMP, "<$FIG_Config::organisms/$genomeID/PROJECT")) &&
1030              defined($line = <TMP>)) {              defined($line = <TMP>)) {
1031              chomp $line;              chomp $line;
1032              my($sourceID, $desc, $url) = split(/\t/,$_);              my($sourceID, $desc, $url) = split(/\t/,$line);
1033              $loadComesFrom->Put($genomeID, $sourceID);              $loadComesFrom->Put($genomeID, $sourceID);
1034              if ($url && ! exists $sourceURL{$genomeID}) {              if ($url && ! exists $sourceURL{$genomeID}) {
1035                  $loadSourceURL->Put($sourceID, $url);                  $loadSourceURL->Put($sourceID, $url);
# Line 1008  Line 1047 
1047      return $retVal;      return $retVal;
1048  }  }
1049    
1050    =head3 LoadExternalData
1051    
1052    C<< my $stats = $spl->LoadExternalData(); >>
1053    
1054    Load the external data from FIG into Sprout.
1055    
1056    External data contains information about external feature IDs.
1057    
1058    The following relations are loaded by this method.
1059    
1060        ExternalAliasFunc
1061        ExternalAliasOrg
1062    
1063    The support for external IDs in FIG is hidden beneath layers of other data, so
1064    we access the SEED files directly to create these tables. This is also one of
1065    the few load methods that does not proceed genome by genome.
1066    
1067    =over 4
1068    
1069    =item RETURNS
1070    
1071    Returns a statistics object for the loads.
1072    
1073    =back
1074    
1075    =cut
1076    #: Return Type $%;
1077    sub LoadExternalData {
1078        # Get this object instance.
1079        my ($self) = @_;
1080        # Get the FIG object.
1081        my $fig = $self->{fig};
1082        # Get the genome hash.
1083        my $genomeHash = $self->{genomes};
1084        my $genomeCount = (keys %{$genomeHash});
1085        # Convert the genome hash. We'll get the genus and species for each genome and make
1086        # it the key.
1087        my %speciesHash = map { $fig->genus_species($_) => $_ } (keys %{$genomeHash});
1088        # Create load objects for each of the tables we're loading.
1089        my $loadExternalAliasFunc = $self->_TableLoader('ExternalAliasFunc', $genomeCount * 4000);
1090        my $loadExternalAliasOrg = $self->_TableLoader('ExternalAliasOrg', $genomeCount * 4000);
1091        Trace("Beginning external data load.") if T(2);
1092        # We loop through the files one at a time. First, the organism file.
1093        Open(\*ORGS, "<$FIG_Config::global/ext_org.table");
1094        my $orgLine;
1095        while (defined($orgLine = <ORGS>)) {
1096            # Clean the input line.
1097            chomp $orgLine;
1098            # Parse the organism name.
1099            my ($protID, $name) = split /\s*\t\s*/, $orgLine;
1100            $loadExternalAliasOrg->Put($protID, $name);
1101        }
1102        close ORGS;
1103        # Now the function file.
1104        my $funcLine;
1105        Open(\*FUNCS, "<$FIG_Config::global/ext_func.table");
1106        while (defined($funcLine = <FUNCS>)) {
1107            # Clean the line ending.
1108            chomp $funcLine;
1109            # Only proceed if the line is non-blank.
1110            if ($funcLine) {
1111                # Split it into fields.
1112                my @funcFields = split /\s*\t\s*/, $funcLine;
1113                # If there's an EC number, append it to the description.
1114                if ($#funcFields >= 2 && $funcFields[2] =~ /^(EC .*\S)/) {
1115                    $funcFields[1] .= " $1";
1116                }
1117                # Output the function line.
1118                $loadExternalAliasFunc->Put(@funcFields[0,1]);
1119            }
1120        }
1121        # Finish the load.
1122        my $retVal = $self->_FinishAll();
1123        return $retVal;
1124    }
1125    
1126  =head3 LoadGroupData  =head3 LoadGroupData
1127    
# Line 1045  Line 1159 
1159      Trace("Beginning group data load.") if T(2);      Trace("Beginning group data load.") if T(2);
1160      # Loop through the genomes.      # Loop through the genomes.
1161      my $line;      my $line;
1162      for my $genomeID (%{$genomeHash}) {      for my $genomeID (keys %{$genomeHash}) {
1163          Trace("Processing $genomeID.") if T(3);          Trace("Processing $genomeID.") if T(3);
1164          # Open the NMPDR group file for this genome.          # Open the NMPDR group file for this genome.
1165          if (open(TMP, "<$FIG_Config::organisms/$genomeID/NMPDR") &&          if (open(TMP, "<$FIG_Config::organisms/$genomeID/NMPDR") &&
1166              defined($line = <TMP>)) {              defined($line = <TMP>)) {
1167              # Clean the line ending.              # Clean the line ending.
1168              chomp;              chomp $line;
1169              # Add the group to the table. Note that there can only be one group              # Add the group to the table. Note that there can only be one group
1170              # per genome.              # per genome.
1171              $loadGenomeGroups->Put($genomeID, $line);              $loadGenomeGroups->Put($genomeID, $line);

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.15

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3