[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.19, Thu Oct 20 09:34:09 2005 UTC
# Line 10  Line 10 
10      use Sprout;      use Sprout;
11      use Stats;      use Stats;
12      use BasicLocation;      use BasicLocation;
13        use HTML;
14    
15  =head1 Sprout Load Methods  =head1 Sprout Load Methods
16    
# Line 51  Line 52 
52    
53  =head3 new  =head3 new
54    
55  C<< my $spl = SproutLoad->new($sprout, $fig, $genomeFile, $subsysFile); >>  C<< my $spl = SproutLoad->new($sprout, $fig, $genomeFile, $subsysFile, $options); >>
56    
57  Construct a new Sprout Loader object, specifying the two participating databases and  Construct a new Sprout Loader object, specifying the two participating databases and
58  the name of the files containing the list of genomes and subsystems to use.  the name of the files containing the list of genomes and subsystems to use.
# Line 82  Line 83 
83  to a list of subsystem names. If nothing is specified, all known subsystems will be  to a list of subsystem names. If nothing is specified, all known subsystems will be
84  considered trusted. Only subsystem data related to the trusted subsystems is loaded.  considered trusted. Only subsystem data related to the trusted subsystems is loaded.
85    
86    =item options
87    
88    Reference to a hash of command-line options.
89    
90  =back  =back
91    
92  =cut  =cut
93    
94  sub new {  sub new {
95      # Get the parameters.      # Get the parameters.
96      my ($class, $sprout, $fig, $genomeFile, $subsysFile) = @_;      my ($class, $sprout, $fig, $genomeFile, $subsysFile, $options) = @_;
97      # Load the list of genomes into a hash.      # Load the list of genomes into a hash.
98      my %genomes;      my %genomes;
99      if (! defined($genomeFile) || $genomeFile eq '') {      if (! defined($genomeFile) || $genomeFile eq '') {
# Line 158  Line 163 
163                    sprout => $sprout,                    sprout => $sprout,
164                    loadDirectory => $directory,                    loadDirectory => $directory,
165                    erdb => $sprout->{_erdb},                    erdb => $sprout->{_erdb},
166                    loaders => []                    loaders => [],
167                      options => $options
168                   };                   };
169      # Bless and return it.      # Bless and return it.
170      bless $retVal, $class;      bless $retVal, $class;
# Line 362  Line 368 
368                              # We store this evidence in the hash if the usage                              # We store this evidence in the hash if the usage
369                              # is nonzero or no prior evidence has been found. This                              # is nonzero or no prior evidence has been found. This
370                              # insures that if there is duplicate evidence, we                              # insures that if there is duplicate evidence, we
371                              # at least keep the meaningful ones. Only evidence is                              # at least keep the meaningful ones. Only evidence in
372                              # the hash makes it to the output.                              # the hash makes it to the output.
373                              if ($usage || ! exists $evidenceMap{$evidenceKey}) {                              if ($usage || ! exists $evidenceMap{$evidenceKey}) {
374                                  $evidenceMap{$evidenceKey} = $evidenceData;                                  $evidenceMap{$evidenceKey} = $evidenceData;
# Line 377  Line 383 
383                          $loadIsEvidencedBy->Put($coupleID, $evidenceID);                          $loadIsEvidencedBy->Put($coupleID, $evidenceID);
384                          # Connect it to the features.                          # Connect it to the features.
385                          $loadUsesAsEvidence->Put($evidenceID, $peg3, 1);                          $loadUsesAsEvidence->Put($evidenceID, $peg3, 1);
386                          $loadUsesAsEvidence->Put($evidenceID, $peg4, 1);                          $loadUsesAsEvidence->Put($evidenceID, $peg4, 2);
387                      }                      }
388                  }                  }
389              }              }
# Line 420  Line 426 
426      my ($self) = @_;      my ($self) = @_;
427      # Get the FIG object.      # Get the FIG object.
428      my $fig = $self->{fig};      my $fig = $self->{fig};
429        # Find out if this is a limited run.
430        my $limited = $self->{options}->{limitedFeatures};
431      # Get the table of genome IDs.      # Get the table of genome IDs.
432      my $genomeHash = $self->{genomes};      my $genomeHash = $self->{genomes};
433      my $genomeCount = (keys %{$genomeHash});      my $genomeCount = (keys %{$genomeHash});
434      my $featureCount = $genomeCount * 4000;      my $featureCount = $genomeCount * 4000;
435      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
436      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);  
437      my $loadIsLocatedIn = $self->_TableLoader('IsLocatedIn', $featureCount);      my $loadIsLocatedIn = $self->_TableLoader('IsLocatedIn', $featureCount);
438        my $loadFeatureAlias = $self->_TableLoader('FeatureAlias', $featureCount * 6);
439        my ($loadFeatureLink, $loadFeatureTranslation, $loadFeatureUpstream);
440        if (! $limited) {
441            $loadFeatureLink = $self->_TableLoader('FeatureLink', $featureCount * 10);
442            $loadFeatureTranslation = $self->_TableLoader('FeatureTranslation', $featureCount);
443            $loadFeatureUpstream = $self->_TableLoader('FeatureUpstream', $featureCount);
444        }
445      # 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
446      # locations.      # locations.
447      my $chunkSize = $self->{sprout}->MaxSegment();      my $chunkSize = $self->{sprout}->MaxSegment();
# Line 445  Line 456 
456          for my $featureData (@{$features}) {          for my $featureData (@{$features}) {
457              $loadFeature->Add("featureIn");              $loadFeature->Add("featureIn");
458              # Split the tuple.              # Split the tuple.
459              my ($featureID, $locations, $aliases, $type) = @{$featureData};              my ($featureID, $locations, undef, $type) = @{$featureData};
460              # Create the feature record.              # Create the feature record.
461              $loadFeature->Put($featureID, 1, $type);              $loadFeature->Put($featureID, 1, $type);
462              # Create the aliases.              # Create the aliases.
463              for my $alias (split /\s*,\s*/, $aliases) {              for my $alias ($fig->feature_aliases($featureID)) {
464                  $loadFeatureAlias->Put($featureID, $alias);                  $loadFeatureAlias->Put($featureID, $alias);
465              }              }
466                # The next stuff is for a full load only.
467                if (! $limited) {
468              # Get the links.              # Get the links.
469              my @links = $fig->fid_links($featureID);              my @links = $fig->fid_links($featureID);
470              for my $link (@links) {              for my $link (@links) {
# Line 470  Line 483 
483                      $loadFeatureUpstream->Put($featureID, $upstream);                      $loadFeatureUpstream->Put($featureID, $upstream);
484                  }                  }
485              }              }
486                }
487              # 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
488              # 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
489              # the maximum segment size. This simplifies the genes_in_region processing              # the maximum segment size. This simplifies the genes_in_region processing
490              # for Sprout.              # for Sprout.
491              my @locationList = split /\s*,\s*/, $locations;              my @locationList = split /\s*,\s*/, $locations;
492                # Create the location position indicator.
493                my $i = 1;
494              # Loop through the locations.              # Loop through the locations.
495              for my $location (@locationList) {              for my $location (@locationList) {
496                  # Parse the location.                  # Parse the location.
497                  my $locObject = BasicLocation->new($location);                  my $locObject = BasicLocation->new("$genomeID:$location");
498                  # Split it into a list of chunks.                  # Split it into a list of chunks.
499                  my @locOList = ();                  my @locOList = ();
500                  while (my $peeling = $locObject->Peel($chunkSize)) {                  while (my $peeling = $locObject->Peel($chunkSize)) {
# Line 488  Line 504 
504                  push @locOList, $locObject;                  push @locOList, $locObject;
505                  # Loop through the chunks, creating IsLocatedIn records. The variable                  # Loop through the chunks, creating IsLocatedIn records. The variable
506                  # "$i" will be used to keep the location index.                  # "$i" will be used to keep the location index.
                 my $i = 1;  
507                  for my $locChunk (@locOList) {                  for my $locChunk (@locOList) {
508                      $loadIsLocatedIn->Put($featureID, $locChunk->Contig, $locChunk->Left,                      $loadIsLocatedIn->Put($featureID, $locChunk->Contig, $locChunk->Left,
509                                            $locChunk->Dir, $locChunk->Length, $i);                                            $locChunk->Dir, $locChunk->Length, $i);
# Line 585  Line 600 
600    
601      Subsystem      Subsystem
602      Role      Role
603        RoleEC
604      SSCell      SSCell
605      ContainsFeature      ContainsFeature
606      IsGenomeOf      IsGenomeOf
# Line 592  Line 608 
608      OccursInSubsystem      OccursInSubsystem
609      ParticipatesIn      ParticipatesIn
610      HasSSCell      HasSSCell
611        Catalyzes
612        Reaction
613        ConsistsOfRoles
614        RoleSubset
615        HasRoleSubset
616        ConsistsOfGenomes
617        GenomeSubset
618        HasGenomeSubset
619    
620  =over 4  =over 4
621    
# Line 601  Line 625 
625    
626  =back  =back
627    
 B<TO DO>  
   
 Generate RoleName table?  
   
628  =cut  =cut
629  #: Return Type $%;  #: Return Type $%;
630  sub LoadSubsystemData {  sub LoadSubsystemData {
# Line 624  Line 644 
644      # Create load objects for each of the tables we're loading.      # Create load objects for each of the tables we're loading.
645      my $loadSubsystem = $self->_TableLoader('Subsystem', $subsysCount);      my $loadSubsystem = $self->_TableLoader('Subsystem', $subsysCount);
646      my $loadRole = $self->_TableLoader('Role', $featureCount * 6);      my $loadRole = $self->_TableLoader('Role', $featureCount * 6);
647        my $loadRoleEC = $self->_TableLoader('RoleEC', $featureCount * 6);
648      my $loadSSCell = $self->_TableLoader('SSCell', $featureCount * $genomeCount);      my $loadSSCell = $self->_TableLoader('SSCell', $featureCount * $genomeCount);
649      my $loadContainsFeature = $self->_TableLoader('ContainsFeature', $featureCount * $subsysCount);      my $loadContainsFeature = $self->_TableLoader('ContainsFeature', $featureCount * $subsysCount);
650      my $loadIsGenomeOf = $self->_TableLoader('IsGenomeOf', $featureCount * $genomeCount);      my $loadIsGenomeOf = $self->_TableLoader('IsGenomeOf', $featureCount * $genomeCount);
# Line 631  Line 652 
652      my $loadOccursInSubsystem = $self->_TableLoader('OccursInSubsystem', $featureCount * 6);      my $loadOccursInSubsystem = $self->_TableLoader('OccursInSubsystem', $featureCount * 6);
653      my $loadParticipatesIn = $self->_TableLoader('ParticipatesIn', $subsysCount * $genomeCount);      my $loadParticipatesIn = $self->_TableLoader('ParticipatesIn', $subsysCount * $genomeCount);
654      my $loadHasSSCell = $self->_TableLoader('HasSSCell', $featureCount * $genomeCount);      my $loadHasSSCell = $self->_TableLoader('HasSSCell', $featureCount * $genomeCount);
655        my $loadReaction = $self->_TableLoader('Reaction', $featureCount * $genomeCount);
656        my $loadCatalyzes = $self->_TableLoader('Catalyzes', $featureCount * $genomeCount);
657        my $loadRoleSubset = $self->_TableLoader('RoleSubset', $subsysCount * 50);
658        my $loadGenomeSubset = $self->_TableLoader('GenomeSubset', $subsysCount * 50);
659        my $loadConsistsOfRoles = $self->_TableLoader('ConsistsOfRoles', $featureCount * $genomeCount);
660        my $loadConsistsOfGenomes = $self->_TableLoader('ConsistsOfGenomes', $featureCount * $genomeCount);
661        my $loadHasRoleSubset = $self->_TableLoader('HasRoleSubset', $subsysCount * 50);
662        my $loadHasGenomeSubset = $self->_TableLoader('HasGenomeSubset', $subsysCount * 50);
663      Trace("Beginning subsystem data load.") if T(2);      Trace("Beginning subsystem data load.") if T(2);
664        # The reaction hash will contain a list of reactions for each role. When we're done,
665        # a complicated sort and merge will be used to generate the Reaction and Catalyzes
666        # tables.
667        my %reactionsToRoles = ();
668      # Loop through the subsystems. Our first task will be to create the      # Loop through the subsystems. Our first task will be to create the
669      # roles. We do this by looping through the subsystems and creating a      # roles. We do this by looping through the subsystems and creating a
670      # 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
671      # duplicates. As we move along, we'll connect the roles and subsystems.      # duplicates. As we move along, we'll connect the roles and subsystems
672        # and memorize up the reactions.
673        my ($genomeID, $roleID);
674      my %roleData = ();      my %roleData = ();
675      for my $subsysID (@subsysIDs) {      for my $subsysID (@subsysIDs) {
676          Trace("Creating subsystem $subsysID.") if T(3);          Trace("Creating subsystem $subsysID.") if T(3);
677          $loadSubsystem->Add("subsystemIn");          $loadSubsystem->Add("subsystemIn");
678            # Get the subsystem object.
679            my $sub = $fig->get_subsystem($subsysID);
680            # Get its reaction hash.
681            my $reactionHash = $sub->get_reactions();
682          # Create the subsystem record.          # Create the subsystem record.
683          $loadSubsystem->Put($subsysID);          my $curator = $sub->get_curator();
684          # Get the subsystem's roles.          my $notes = $sub->get_notes();
685          my @roles = $fig->subsystem_to_roles($subsysID);          $loadSubsystem->Put($subsysID, $curator, $notes);
686          # 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.
687          # a role record for it.          for (my $col = 0; defined($roleID = $sub->get_role($col)); $col++) {
688          for my $roleID (@roles) {              # Connect to this role.
689              $loadOccursInSubsystem->Add("roleIn");              $loadOccursInSubsystem->Add("roleIn");
690              $loadOccursInSubsystem->Put($roleID, $subsysID);              $loadOccursInSubsystem->Put($roleID, $subsysID, $col);
691                # If it's a new role, add it to the role table.
692              if (! exists $roleData{$roleID}) {              if (! exists $roleData{$roleID}) {
693                  $loadRole->Put($roleID);                  # Get the role's abbreviation.
694                    my $abbr = $sub->get_role_abbr($col);
695                    # Add the role.
696                    $loadRole->Put($roleID, $abbr);
697                  $roleData{$roleID} = 1;                  $roleData{$roleID} = 1;
698                    # Check for an EC number.
699                    if ($roleID =~ /\(EC ([^.]+\.[^.]+\.[^.]+\.[^)]+)\)\s*$/) {
700                        $loadRoleEC->Put($roleID, $1);
701                    }
702                    # Add the role's reactions.
703                    my $reactions = $reactionHash->{$roleID};
704                    for my $reactionID (@{$reactions}) {
705                        if (! exists $reactionsToRoles{$reactionID}) {
706                            # Here the reaction is brand-new, so we create its reaction
707                            # record.
708                            $loadReaction->Put($reactionID, $fig->reversible($reactionID));
709                            # We also create a blank list for it in the reaction hash.
710                            $reactionsToRoles{$reactionID} = [];
711                        }
712                        # Add the role to the reaction's role list.
713                        push @{$reactionsToRoles{$reactionID}}, $roleID;
714              }              }
715          }          }
716          # Now all roles for this subsystem have been filled in. We create the          }
717          # spreadsheet by matches roles to genomes. To do this, we need to          # Now we create the spreadsheet for the subsystem by matching roles to
718          # get the genomes on the sheet.          # genomes. Each genome is a row and each role is a column. We may need
719            # to actually create the roles as we find them.
720          Trace("Creating subsystem $subsysID spreadsheet.") if T(3);          Trace("Creating subsystem $subsysID spreadsheet.") if T(3);
721          my @genomes = map { $_->[0] } @{$fig->subsystem_genomes($subsysID)};          for (my $row = 0; defined($genomeID = $sub->get_genome($row)); $row++) {
722          for my $genomeID (@genomes) {              # Only proceed if this is one of our genomes.
             # Only process this genome if it's one of ours.  
723              if (exists $genomeHash->{$genomeID}) {              if (exists $genomeHash->{$genomeID}) {
724                  # Connect the genome to the subsystem.                  # Count the PEGs and cells found for verification purposes.
725                  $loadParticipatesIn->Put($genomeID, $subsysID);                  my $pegCount = 0;
726                    my $cellCount = 0;
727                    # Create a list for the PEGs we find. This list will be used
728                    # to generate cluster numbers.
729                    my @pegsFound = ();
730                    # Create a hash that maps spreadsheet IDs to PEGs. We will
731                    # use this to generate the ContainsFeature data after we have
732                    # the cluster numbers.
733                    my %cellPegs = ();
734                    # Get the genome's variant code for this subsystem.
735                    my $variantCode = $sub->get_variant_code($row);
736                  # 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
737                  # part of the spreadsheet cell ID.                  # part of the spreadsheet cell ID.
738                  for (my $i = 0; $i <= $#roles; $i++) {                  for (my $col = 0; defined($roleID = $sub->get_role($col)); $col++) {
                     my $role = $roles[$i];  
739                      # Get the features in the spreadsheet cell for this genome and role.                      # Get the features in the spreadsheet cell for this genome and role.
740                      my @pegs = $fig->pegs_in_subsystem_cell($subsysID, $genomeID, $i);                      my @pegs = $sub->get_pegs_from_cell($row, $col);
741                      # Only proceed if features exist.                      # Only proceed if features exist.
742                      if (@pegs > 0) {                      if (@pegs > 0) {
743                          # Create the spreadsheet cell.                          # Create the spreadsheet cell.
744                          my $cellID = "$subsysID:$genomeID:$i";                          $cellCount++;
745                            my $cellID = "$subsysID:$genomeID:$col";
746                          $loadSSCell->Put($cellID);                          $loadSSCell->Put($cellID);
747                          $loadIsGenomeOf->Put($genomeID, $cellID);                          $loadIsGenomeOf->Put($genomeID, $cellID);
748                          $loadIsRoleOf->Put($role, $cellID);                          $loadIsRoleOf->Put($roleID, $cellID);
749                          $loadHasSSCell->Put($subsysID, $cellID);                          $loadHasSSCell->Put($subsysID, $cellID);
750                          # Attach the features to it.                          # Remember its features.
751                          for my $pegID (@pegs) {                          push @pegsFound, @pegs;
752                              $loadContainsFeature->Put($cellID, $pegID);                          $cellPegs{$cellID} = \@pegs;
753                            $pegCount += @pegs;
754                        }
755                    }
756                    # If we found some cells for this genome, we need to compute clusters and
757                    # denote it participates in the subsystem.
758                    if ($pegCount > 0) {
759                        Trace("$pegCount PEGs in $cellCount cells for $genomeID.") if T(3);
760                        $loadParticipatesIn->Put($genomeID, $subsysID, $variantCode);
761                        # Partition the PEGs found into clusters.
762                        my @clusters = $fig->compute_clusters(\@pegsFound, $sub);
763                        # Create a hash mapping PEG IDs to cluster numbers.
764                        # We default to -1 for all of them.
765                        my %clusterOf = map { $_ => -1 } @pegsFound;
766                        for (my $i = 0; $i <= $#clusters; $i++) {
767                            my $subList = $clusters[$i];
768                            for my $peg (@{$subList}) {
769                                $clusterOf{$peg} = $i;
770                            }
771                        }
772                        # Create the ContainsFeature data.
773                        for my $cellID (keys %cellPegs) {
774                            my $cellList = $cellPegs{$cellID};
775                            for my $cellPeg (@$cellList) {
776                                $loadContainsFeature->Put($cellID, $cellPeg, $clusterOf{$cellPeg});
777                            }
778                        }
779                          }                          }
780                      }                      }
781                  }                  }
782            # Now we need to generate the subsets. The subset names must be concatenated to
783            # the subsystem name to make them unique keys. There are two types of subsets:
784            # genome subsets and role subsets. We do the role subsets first.
785            my @subsetNames = $sub->get_subset_names();
786            for my $subsetID (@subsetNames) {
787                # Create the subset record.
788                my $actualID = "$subsysID:$subsetID";
789                $loadRoleSubset->Put($actualID);
790                # Connect the subset to the subsystem.
791                $loadHasRoleSubset->Put($subsysID, $actualID);
792                # Connect the subset to its roles.
793                my @roles = $sub->get_subset($subsetID);
794                for my $roleID (@roles) {
795                    $loadConsistsOfRoles->Put($actualID, $roleID);
796                }
797            }
798            # Next the genome subsets.
799            @subsetNames = $sub->get_subset_namesR();
800            for my $subsetID (@subsetNames) {
801                # Create the subset record.
802                my $actualID = "$subsysID:$subsetID";
803                $loadGenomeSubset->Put($actualID);
804                # Connect the subset to the subsystem.
805                $loadHasGenomeSubset->Put($subsysID, $actualID);
806                # Connect the subset to its genomes.
807                my @genomes = $sub->get_subsetR($subsetID);
808                for my $genomeID (@genomes) {
809                    $loadConsistsOfGenomes->Put($actualID, $genomeID);
810                }
811            }
812        }
813        # Before we leave, we must create the Catalyzes table. The data is all stored in
814        # "reactionToRoles" hash.
815        for my $reactionID (keys %reactionsToRoles) {
816            # Get this reaction's list of roles. We sort it so we can merge out duplicates.
817            my @roles = sort @{$reactionsToRoles{$reactionID}};
818            my $lastRole = "";
819            # Loop through the roles, creating catalyzation records.
820            for my $thisRole (@roles) {
821                if ($thisRole ne $lastRole) {
822                    $loadCatalyzes->Put($thisRole, $reactionID);
823              }              }
824          }          }
825      }      }
# Line 913  Line 1049 
1049                      # Denote we've seen this timestamp.                      # Denote we've seen this timestamp.
1050                      $seenTimestamps{$time} = 1;                      $seenTimestamps{$time} = 1;
1051                  }                  }
1052                }
1053                  # Now loop through the real annotations.                  # Now loop through the real annotations.
1054                  for my $tuple ($fig->feature_annotations($peg, "raw")) {                  for my $tuple ($fig->feature_annotations($peg, "raw")) {
1055                      my ($fid, $timestamp, $user, $text) = @{$tuple};                      my ($fid, $timestamp, $user, $text) = @{$tuple};
# Line 927  Line 1064 
1064                      $text =~ s/Set master function/Set FIG function/s;                      $text =~ s/Set master function/Set FIG function/s;
1065                      # Insure the time stamp is valid.                      # Insure the time stamp is valid.
1066                      if ($timestamp =~ /^\d+$/) {                      if ($timestamp =~ /^\d+$/) {
1067                          # 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
1068                          while ($seenTimestamps{$timestamp}) {                      # the key is unique.
1069                              $timestamp++;                      my $keyStamp = $timestamp;
1070                        while ($seenTimestamps{$keyStamp}) {
1071                            $keyStamp++;
1072                          }                          }
1073                          $seenTimestamps{$timestamp} = 1;                      $seenTimestamps{$keyStamp} = 1;
1074                          my $annotationID = "$peg:$timestamp";                      my $annotationID = "$peg:$keyStamp";
1075                          # Insure the user exists.                          # Insure the user exists.
1076                          if (! $users{$user}) {                          if (! $users{$user}) {
1077                              $loadSproutUser->Put($user, "SEED user");                              $loadSproutUser->Put($user, "SEED user");
# Line 940  Line 1079 
1079                              $users{$user} = 1;                              $users{$user} = 1;
1080                          }                          }
1081                          # Generate the annotation.                          # Generate the annotation.
1082                          $loadAnnotation->Put($annotationID, $timestamp, "$user\\n$text");                      $loadAnnotation->Put($annotationID, $timestamp, $text);
1083                          $loadIsTargetOfAnnotation->Put($peg, $annotationID);                          $loadIsTargetOfAnnotation->Put($peg, $annotationID);
1084                          $loadMadeAnnotation->Put($user, $annotationID);                          $loadMadeAnnotation->Put($user, $annotationID);
1085                      } else {                      } else {
# Line 950  Line 1089 
1089                  }                  }
1090              }              }
1091          }          }
     }  
1092      # Finish the load.      # Finish the load.
1093      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
1094      return $retVal;      return $retVal;
# Line 1010  Line 1148 
1148              chomp $line;              chomp $line;
1149              my($sourceID, $desc, $url) = split(/\t/,$line);              my($sourceID, $desc, $url) = split(/\t/,$line);
1150              $loadComesFrom->Put($genomeID, $sourceID);              $loadComesFrom->Put($genomeID, $sourceID);
1151              if ($url && ! exists $sourceURL{$genomeID}) {              if ($url && ! exists $sourceURL{$sourceID}) {
1152                  $loadSourceURL->Put($sourceID, $url);                  $loadSourceURL->Put($sourceID, $url);
1153                  $sourceURL{$sourceID} = 1;                  $sourceURL{$sourceID} = 1;
1154              }              }
1155              if ($desc && ! exists $sourceDesc{$sourceID}) {              if ($desc) {
1156                  $loadSource->Put($sourceID, $desc);                  $sourceDesc{$sourceID} = $desc;
1157                  $sourceDesc{$sourceID} = 1;              } elsif (! exists $sourceDesc{$sourceID}) {
1158                    $sourceDesc{$sourceID} = $sourceID;
1159              }              }
1160          }          }
1161          close TMP;          close TMP;
1162      }      }
1163        # Write the source descriptions.
1164        for my $sourceID (keys %sourceDesc) {
1165            $loadSource->Put($sourceID, $sourceDesc{$sourceID});
1166        }
1167      # Finish the load.      # Finish the load.
1168      my $retVal = $self->_FinishAll();      my $retVal = $self->_FinishAll();
1169      return $retVal;      return $retVal;
# Line 1102  Line 1245 
1245      return $retVal;      return $retVal;
1246  }  }
1247    
1248    
1249    =head3 LoadReactionData
1250    
1251    C<< my $stats = $spl->LoadReactionData(); >>
1252    
1253    Load the reaction data from FIG into Sprout.
1254    
1255    Reaction data connects reactions to the compounds that participate in them.
1256    
1257    The following relations are loaded by this method.
1258    
1259        ReactionURL
1260        Compound
1261        CompoundName
1262        CompoundCAS
1263        IsAComponentOf
1264    
1265    This method proceeds reaction by reaction rather than genome by genome.
1266    
1267    =over 4
1268    
1269    =item RETURNS
1270    
1271    Returns a statistics object for the loads.
1272    
1273    =back
1274    
1275    =cut
1276    #: Return Type $%;
1277    sub LoadReactionData {
1278        # Get this object instance.
1279        my ($self) = @_;
1280        # Get the FIG object.
1281        my $fig = $self->{fig};
1282        # Get the genome hash.
1283        my $genomeHash = $self->{genomes};
1284        my $genomeCount = (keys %{$genomeHash});
1285        # Create load objects for each of the tables we're loading.
1286        my $loadReactionURL = $self->_TableLoader('ReactionURL', $genomeCount * 4000);
1287        my $loadCompound = $self->_TableLoader('Compound', $genomeCount * 4000);
1288        my $loadCompoundName = $self->_TableLoader('CompoundName', $genomeCount * 8000);
1289        my $loadCompoundCAS = $self->_TableLoader('CompoundCAS', $genomeCount * 4000);
1290        my $loadIsAComponentOf = $self->_TableLoader('IsAComponentOf', $genomeCount * 12000);
1291        Trace("Beginning reaction/compound data load.") if T(2);
1292        # Create a hash to remember the compounds we've generated in the compound table.
1293        my %compoundHash = ();
1294        # Loop through the reactions.
1295        my @reactions = $fig->all_reactions();
1296        for my $reactionID (@reactions) {
1297            # Compute the reaction's URL.
1298            my $url = HTML::reaction_link($reactionID);
1299            # Put it in the ReactionURL table.
1300            $loadReactionURL->Put($reactionID, $url);
1301            # Now we need all of the reaction's compounds. We get these in two phases,
1302            # substrates first and then products.
1303            for my $product (0, 1) {
1304                # Get the compounds of the current type for the current reaction. FIG will
1305                # give us 3-tuples: [ID, Stoichometry, main-flag]. At this time we do not
1306                # have location data in SEED, so it defaults to the empty string.
1307                my @compounds = $fig->reaction2comp($reactionID, $product);
1308                for my $compData (@compounds) {
1309                    # Extract the compound data from the current tuple.
1310                    my ($cid, $stoich, $main) = @{$compData};
1311                    # Link the compound to the reaction.
1312                    $loadIsAComponentOf->Put($cid, $reactionID, "", $main, $product, $stoich);
1313                    # If this is a new compound, we need to create its table entries.
1314                    if (! exists $compoundHash{$cid}) {
1315                        $compoundHash{$cid} = 1;
1316                        # Create the main compound record and denote we've done it.
1317                        $loadCompound->Put($cid);
1318                        # Check for a CAS ID.
1319                        my $cas = $fig->cas($cid);
1320                        if ($cas) {
1321                            $loadCompoundCAS->Put($cid, $cas);
1322                        }
1323                        # Check for names.
1324                        my @names = $fig->names_of_compound($cid);
1325                        # Each name will be given a priority number, starting with 1.
1326                        my $prio = 0;
1327                        for my $name (@names) {
1328                            $loadCompoundName->Put($cid, $name, $prio++);
1329                        }
1330                    }
1331                }
1332            }
1333        }
1334        # Finish the load.
1335        my $retVal = $self->_FinishAll();
1336        return $retVal;
1337    }
1338    
1339  =head3 LoadGroupData  =head3 LoadGroupData
1340    
1341  C<< my $stats = $spl->LoadGroupData(); >>  C<< my $stats = $spl->LoadGroupData(); >>
# Line 1225  Line 1459 
1459      # 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
1460      # ignominiously. At some future point, we want to make the loads restartable.      # ignominiously. At some future point, we want to make the loads restartable.
1461      while (my $loader = pop @{$loadList}) {      while (my $loader = pop @{$loadList}) {
1462            # Trace the fact that we're cleaning up.
1463            my $relName = $loader->RelName;
1464            Trace("Finishing load for $relName.") if T(2);
1465          my $stats = $loader->Finish();          my $stats = $loader->Finish();
1466            if ($self->{options}->{dbLoad}) {
1467                # Here we want to use the load file just created to load the database.
1468                Trace("Loading relation $relName.") if T(2);
1469                my $newStats = $self->{sprout}->LoadUpdate(1, [$relName]);
1470                # Accumulate the statistics from the DB load.
1471                $stats->Accumulate($newStats);
1472            }
1473          $retVal->Accumulate($stats);          $retVal->Accumulate($stats);
         my $relName = $loader->RelName;  
1474          Trace("Statistics for $relName:\n" . $stats->Show()) if T(2);          Trace("Statistics for $relName:\n" . $stats->Show()) if T(2);
1475      }      }
1476      # Return the load statistics.      # Return the load statistics.

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3