[Bio] / Sprout / SproutSubsys.pm Repository:
ViewVC logotype

Diff of /Sprout/SproutSubsys.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.15, Wed Jun 11 17:48:03 2008 UTC revision 1.19, Tue Sep 16 18:45:06 2008 UTC
# Line 84  Line 84 
84    
85  =head3 new  =head3 new
86    
87      my $sub = Subsystem->new($subName, $sprout);      my $sub = SproutSubsys->new($subName, $sprout);
88    
89  Load the subsystem.  Load the subsystem.
90    
# Line 118  Line 118 
118          Confess("Subsystem \"$subName\" not found in database.");          Confess("Subsystem \"$subName\" not found in database.");
119      } else {      } else {
120          # We've found it, so get the major data.          # We've found it, so get the major data.
121          my ($curator, $notes, $description) = $subsystemObject->Values(['Subsystem(curator)', 'Subsystem(notes)',          my ($curator, $notes, $description, $version) = $subsystemObject->Values(['Subsystem(curator)', 'Subsystem(notes)',
122                                                                          'Subsystem(description)']);                                                              'Subsystem(description)', 'Subsystem(version)']);
123          # Get the genome IDs and variant codes for the rows. The list returned          # Get the genome IDs and variant codes for the rows. The list returned
124          # by GetAll will be a list of 2-tuples, each consisting of a genome ID          # by GetAll will be a list of 2-tuples, each consisting of a genome ID
125          # and a subsystem variant code.          # and a subsystem variant code.
# Line 136  Line 136 
136          # 2-tuples will be ordered by the spreadsheet column number.          # 2-tuples will be ordered by the spreadsheet column number.
137          my @roles = $sprout->GetAll(['OccursInSubsystem'],          my @roles = $sprout->GetAll(['OccursInSubsystem'],
138                                      'OccursInSubsystem(to-link) = ? ORDER BY OccursInSubsystem(column-number)',                                      'OccursInSubsystem(to-link) = ? ORDER BY OccursInSubsystem(column-number)',
139                                      [$subName], ['OccursInSubsystem(from-link)', 'OccursInSubsystem(abbr)']);                                      [$subName], ['OccursInSubsystem(from-link)', 'OccursInSubsystem(abbr)',
140          # Now we need to create the role ID directory and the reaction hash.                                                   'OccursInSubsystem(auxiliary)']);
141          # The role ID directory maps role IDs and their abbreviations to column numbers.          # Now we need to create the role ID directory, which maps role IDs and their
142          # The reaction hash maps a role ID to a list of the IDs for the reactions it          # abbreviations to column numbers.
         # catalyzes.  
143          my %roleHash = ();          my %roleHash = ();
144          my %abbrHash = ();          my %abbrHash = ();
145          my %reactionHash = ();          my %auxHash = ();
146          for ($idx = 0; $idx <= $#roles; $idx++) {          for ($idx = 0; $idx <= $#roles; $idx++) {
147              # Get the role ID and abbreviation for this column's role.              # Get the role ID, aux flag, and abbreviation for this column's role.
148              my ($roleID, $abbr) = @{$roles[$idx]};              my ($roleID, $abbr, $aux) = @{$roles[$idx]};
149              # Put them both in the role directory.              # Put the ID and abbreviation in the role directory.
150              $roleHash{$roleID} = $idx;              $roleHash{$roleID} = $idx;
151              $roleHash{$abbr} = $idx;              $roleHash{$abbr} = $idx;
152                # Put the aux flag in the aux hash.
153                $auxHash{$roleID} = $aux;
154              # Put the full name in the abbreviation directory.              # Put the full name in the abbreviation directory.
155              $abbrHash{$abbr} = $roleID;              $abbrHash{$abbr} = $roleID;
             # Get this role's reactions.  
             my @reactions = $sprout->GetFlat(['Catalyzes'], 'Catalyzes(from-link) = ?',  
                                              [$roleID], 'Catalyzes(to-link)');  
             # Put them in the reaction hash.  
             if (@reactions > 0) {  
                 $reactionHash{$roleID} = \@reactions;  
             }  
156          }          }
157          # Find the subsystem directory.          # Find the subsystem directory.
158          my $subDir = Subsystem::get_dir_from_name($subName);          my $subDir = Subsystem::get_dir_from_name($subName);
# Line 188  Line 182 
182                      colorHash => {},                      colorHash => {},
183                      # Map of abbreviations to role names.                      # Map of abbreviations to role names.
184                      abbrHash => \%abbrHash,                      abbrHash => \%abbrHash,
185                        # Map of auxiliary rols.
186                        auxHash => \%auxHash,
187                      # Map of role IDs to reactions.                      # Map of role IDs to reactions.
188                      reactionHash => \%reactionHash,                      reactionHash => undef,
189                        # Version number.
190                        version => $version,
191                  };                  };
192          # Bless and return it.          # Bless and return it.
193          bless $retVal, $class;          bless $retVal, $class;
# Line 197  Line 195 
195      return $retVal;      return $retVal;
196  }  }
197    
198    =head3 is_aux_role
199    
200        my $flag = $sub->is_aux_role($roleID);
201    
202    Return TRUE if the specified role is auxiliary to this subsystem, FALSE
203    if it is essential to it.
204    
205    =over 4
206    
207    =item roleID
208    
209    ID of the relevant role.
210    
211    =item RETURN
212    
213    Returns TRUE if the specified role is auxiliary, else FALSE.
214    
215    =back
216    
217    =cut
218    
219    sub is_aux_role {
220        # Get the parameters.
221        my ($self, $roleID) = @_;
222        # Declare the return variable.
223        my $retVal = $self->{auxHash}->{$roleID};
224        # Return the result.
225        return $retVal;
226    }
227    
228    
229  =head3 get_row  =head3 get_row
230    
231      my $rowData = $sub->get_row($rowIndex);      my $rowData = $sub->get_row($rowIndex);
# Line 482  Line 511 
511  sub get_reactions {  sub get_reactions {
512      # Get the parameters.      # Get the parameters.
513      my ($self) = @_;      my ($self) = @_;
514      # Return the reaction hash member.      # Do we already have a reaction hash?
515      return $self->{reactionHash};      my $retVal = $self->{reactionHash};
516        if (! $retVal) {
517            # No, so we'll build it.
518            $retVal = {};
519            my $sprout = $self->{sprout};
520            for my $roleID ($self->get_roles()) {
521                # Get this role's reactions.
522                my @reactions = $sprout->GetFlat(['Catalyzes'], 'Catalyzes(from-link) = ?',
523                                                 [$roleID], 'Catalyzes(to-link)');
524                # Put them in the reaction hash.
525                if (@reactions > 0) {
526                    $retVal->{$roleID} = \@reactions;
527                }
528            }
529            # Save it for future use.
530            $self->{reactionHash} = $retVal;
531        }
532        # Return the reaction hash.
533        return $retVal;
534  }  }
535    
536  =head3 get_subset_namesC  =head3 get_subset_namesC
# Line 574  Line 621 
621  =item RETURN  =item RETURN
622    
623  Returns a hash mapping reactions in the subsystem to pegs in the  Returns a hash mapping reactions in the subsystem to pegs in the
624  specified genome, or C<undef> if the genome is not found in the  specified genome, or an empty hash if the genome is not found in the
625  subsystem.  subsystem.
626    
627  =back  =back
# Line 582  Line 629 
629  =cut  =cut
630    
631  sub get_hope_reactions_for_genome {  sub get_hope_reactions_for_genome {
632        # Get the parameters.
633      my($self, $genome) = @_;      my($self, $genome) = @_;
634      my $index = $self->{genome_index}->{$genome};      # Declare the return variable.
635        my %retVal;
636        # Look for the genome in our spreadsheet.
637        my $index = $self->get_genome_index($genome);
638        # Only proceed if we found it.
639      if (defined $index) {      if (defined $index) {
640            # Extract the roles.
641          my @roles = $self->get_roles;          my @roles = $self->get_roles;
642          my %hope_reactions = $self->get_hope_reactions;          # Get the hope reaction hash. For each role, this gives us a list
643            # of reactions.
644          my %ss_reactions;          my %hope_reactions = $self->get_hope_reactions();
645            # Loop through the cells in this genome's role.
646          foreach my $role (@roles)          for my $role (@roles) {
647          {              # Get the features in this role's cell.
648              my @peg_list = $self->get_pegs_from_cell($genome,$role);              my @peg_list = $self->get_pegs_from_cell($genome,$role);
649                # Only proceed if we have hope reactions AND pegs for this role.
650              if (defined $hope_reactions{$role} && scalar @peg_list > 0)              if (defined $hope_reactions{$role} && scalar @peg_list > 0) {
651                    # Loop through the reactions, pushing the pegs in this cell onto
652              {                  # the reaction's peg list.
653                  foreach my $reaction (@{$hope_reactions{$role}})                  for my $reaction (@{$hope_reactions{$role}}) {
654                  {                      push @{$retVal{$reaction}}, @peg_list;
                     push @{$ss_reactions{$reaction}}, @peg_list;  
                 }  
655              }              }
656          }          }
   
         return %ss_reactions;  
657      }      }
     else {  
         return undef;  
658      }      }
659        # Return the result.
660        return %retVal;
661  }  }
662    
663    
# Line 632  Line 681 
681    
682  =cut  =cut
683    
684  sub get_hope_additional_reactions  sub get_hope_additional_reactions {
685  {      # Get the parameters.
686      my($self,$scenario_name) = @_;      my($self,$scenario_name) = @_;
687      Trace("Hope additional reactions not available in NMPDR.") if T(0);      # Ask the database for this scenario's additional reactions.
688      my @retVal;      my @retVal = $self->{sprout}->GetFlat(['IncludesReaction'], "IncludesReaction(from-link) = ?",
689                                              [$scenario_name], 'IncludesReaction(to-link)');
690      return @retVal;      return @retVal;
691  }  }
692    
# Line 657  Line 707 
707      # Try to get the hope reactions from the object.      # Try to get the hope reactions from the object.
708      my $retVal = $self->{hopeReactions};      my $retVal = $self->{hopeReactions};
709      if (! defined($retVal)) {      if (! defined($retVal)) {
710          # They do not exist, so we must create them.          # They do not exist, so we must create them. Make a copy of the role-to-reaction
711          $retVal = FIGRules::GetHopeReactions($self, $self->{dir});          # hash.
712            my %hopeHash = %{$self->get_reactions()};
713          # Insure we have it if we need it again.          # Insure we have it if we need it again.
714            $retVal = \%hopeHash;
715          $self->{hopeReactions} = $retVal;          $self->{hopeReactions} = $retVal;
716      }      }
717      # Return the result.      # Return the result.
718      return %{$retVal};      return %{$retVal};
719  }  }
720    
721    =head3 get_hope_reaction_notes
722    
723        my %roleHash = $sub->get_hope_reaction_notes();
724    
725    Return a hash mapping the roles of the subsystem to any existing notes
726    about the relevant reactions.
727    
728    =cut
729    
730    sub get_hope_reaction_notes {
731        # Get the parameters.
732        my ($self) = @_;
733        # Declare the return variable.
734        my %retVal;
735        # Get the database object.
736        my $sprout = $self->{sprout};
737        # Get our name.
738        my $ssName = $self->{name};
739        # Loop through the roles, getting each role's hope notes.
740        for my $role ($self->get_roles()) {
741            my ($note) = $self->get_hop_reaction_note($role);
742            # If this role had a nonempty note, stuff it in the hash.
743            if ($note) {
744                $retVal{$role} = $note;
745            }
746        }
747        # Return the result.
748        return %retVal;
749    }
750    
751    =head3 get_hope_reaction_note
752    
753        my $note = $sub->get_hope_reaction_note($role);
754    
755    Return the text note about the curation of the scenario reactions
756    relating to this role.
757    
758    =over 4
759    
760    =item role
761    
762    ID of the role whose note is desired.
763    
764    =item RETURN
765    
766    Returns the relevant role's note for this subsystem's hope reactions, or FALSE (empty string
767    or undefined) if no such note was found.
768    
769    =back
770    
771    =cut
772    
773    sub get_hope_reaction_note {
774        # Get the parameters.
775        my ($self, $role) = @_;
776        # Ask the database for the note.
777        my ($retVal) = $self->{sprout}->GetFlat(['OccursInSubsystem'],
778                                                "OccursInSubsystem(from-link) = ? AND OccursInSubsystem(to-link) = ?",
779                                                [$role, $self->{name}], 'OccursInSubsystem(hope-reaction-note)');
780        # Return the result.
781        return $retVal;
782    }
783    
784  =head3 get_role_index  =head3 get_role_index
785    
786      my $idx = $sub->get_role_index($role);      my $idx = $sub->get_role_index($role);
# Line 1053  Line 1168 
1168    my $image_map = $self->get_diagram_html_file($id);    my $image_map = $self->get_diagram_html_file($id);
1169    if ($image_map) {    if ($image_map) {
1170      Trace("Image map found for diagram $id at $image_map.") if T(3);      Trace("Image map found for diagram $id at $image_map.") if T(3);
1171      open(IN, "$image_map") or Confess("Unable to open file $image_map.");      Open(\*IN, "<$image_map");
1172      my $header = <IN>;      my $header = <IN>;
1173      close(IN);      close(IN);
1174    

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3