[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.8, Sun Jun 18 05:50:10 2006 UTC revision 1.9, Tue Oct 17 18:45:58 2006 UTC
# Line 56  Line 56 
56    
57  List of [roleID, abbreviation] tuples in column order.  List of [roleID, abbreviation] tuples in column order.
58    
59    =item dir
60    
61    Directory root for the diagram and image files.
62    
63  =item reactionHash  =item reactionHash
64    
65  Map of role IDs to a list of the reactions catalyzed by the role.  Map of role IDs to a list of the reactions catalyzed by the role.
# Line 144  Line 148 
148                  $reactionHash{$roleID} = \@reactions;                  $reactionHash{$roleID} = \@reactions;
149              }              }
150          }          }
151            # Find the subsystem directory.
152            my $subDir = Subsystem::get_dir_from_name($subName);
153            Trace("Subsystem directory is $subDir.") if T(3);
154          # Create the subsystem object.          # Create the subsystem object.
155          $retVal = {          $retVal = {
156                      # Name of the subsystem. This is needed for any further database                      # Name of the subsystem. This is needed for any further database
157                      # accesses required.                      # accesses required.
158                      name => $subName,                      name => $subName,
159                        # Directory root for diagram and image files.
160                        dir => $subDir,
161                      # Name of the subsystem's official curator.                      # Name of the subsystem's official curator.
162                      curator => $curator,                      curator => $curator,
163                      # General notes about the subsystem.                      # General notes about the subsystem.
# Line 590  Line 599 
599  sub get_diagrams {  sub get_diagrams {
600      # Get the parameters.      # Get the parameters.
601      my ($self) = @_;      my ($self) = @_;
     # Find the subsystem directory.  
     my $subDir = Subsystem::get_dir_from_name($self->{name});  
     Trace("Subsystem directory is $subDir.") if T(3);  
602      # Get the diagram IDs.      # Get the diagram IDs.
603      my @diagramIDs = Subsystem::GetDiagramIDs($subDir);      my @diagramIDs = Subsystem::GetDiagramIDs($self->{dir});
604      Trace("Diagram IDs are " . join(", ", @diagramIDs)) if T(3);      Trace("Diagram IDs are " . join(", ", @diagramIDs)) if T(3);
605      # Create the return variable.      # Create the return variable.
606      my @retVal = ();      my @retVal = ();
607      # Loop through the diagram IDs.      # Loop through the diagram IDs.
608      for my $diagramID (@diagramIDs) {      for my $diagramID (@diagramIDs) {
609          Trace("Processing diagram $diagramID.") if T(3);          Trace("Processing diagram $diagramID.") if T(3);
610          # Get the diagram name.          my ($name, $link, $imgLink) = $self->get_diagram($diagramID);
611          my $name = Subsystem::GetDiagramName($subDir, $diagramID);          Trace("Diagram $name URLs are \"$link\" and \"$imgLink\".") if T(3);
         Trace("Diagram name is $name.") if T(3);  
         # Get the URLs.  
         my ($link, $imgLink) = Subsystem::ComputeDiagramURLs($self->{name},  
                                                                  $diagramID);  
         Trace("Diagram URLs are \"$link\" and \"$imgLink\".") if T(3);  
612          push @retVal, [$diagramID, $name, $link, $imgLink];          push @retVal, [$diagramID, $name, $link, $imgLink];
613      }      }
614      # Return the result.      # Return the result.
615      return @retVal;      return @retVal;
616  }  }
617    
618    =head3 get_diagram
619    
620    C<< my ($name, $pageURL, $imgURL) = $sub->get_diagram($id); >>
621    
622    Get the information (if any) for the specified diagram. The diagram corresponds
623    to a subdirectory of the subsystem's C<diagrams> directory. For example, if the
624    diagram ID is C<d03>, the diagram's subdirectory would be C<$dir/diagrams/d03>,
625    where I<$dir> is the subsystem directory. The diagram's name is extracted from
626    a tiny file containing the name, and then the links are computed using the
627    subsystem name and the diagram ID. The parameters are as follows.
628    
629    =over 4
630    
631    =item id
632    
633    ID code for the desired diagram.
634    
635    =item RETURN
636    
637    Returns a three-element list. The first element is the diagram name, the second
638    a URL for displaying information about the diagram, and the third a URL for
639    displaying the diagram image.
640    
641    =back
642    
643    =cut
644    
645    sub get_diagram {
646        my($self, $id) = @_;
647        my $name = Subsystem::GetDiagramName($self->{dir}, $id);
648        my ($link, $img_link) = Subsystem::ComputeDiagramURLs($self->{name}, $id, 1);
649        return($name, $link, $img_link);
650    }
651    
652    
653    =head3 get_diagram_html_file
654    
655    C<< my $fileName = $sub->get_diagram_html_file($id); >>
656    
657    Get the HTML file (if any) for the specified diagram. The diagram corresponds
658    to a subdirectory of the subsystem's C<diagrams> directory. For example, if the
659    diagram ID is C<d03>, the diagram's subdirectory would be C<$dir/diagrams/d03>,
660    where I<$dir> is the subsystem directory. If an HTML file exists, it will be
661    named C<diagram.html> in the diagram directory.  The parameters are as follows.
662    
663    =over 4
664    
665    =item id
666    
667    ID code for the desired diagram.
668    
669    =item RETURN
670    
671    Returns the name of an HTML diagram file, or C<undef> if no such file exists.
672    
673    =back
674    
675    =cut
676    
677    sub get_diagram_html_file {
678        my ($self, $id) = @_;
679        my $retVal;
680        my $ddir = "$self->{dir}/diagrams/$id";
681        if (-d $ddir) {
682            my $html = "$ddir/diagram.html";
683            if (-f $html) {
684                $retVal = $html;
685            }
686        }
687        return $retVal;
688    }
689    
690    =head3 get_name
691    
692    C<< my $name = $sub->get_name(); >>
693    
694    Return the name of this subsystem.
695    
696    =cut
697    
698    sub get_name {
699        # Get the parameters.
700        my ($self) = @_;
701        # Return the result.
702        return $self->{name};
703    }
704    
705    =head3 open_diagram_image
706    
707    C<< my ($type, $fh) = $sub->open_diagram_image($id); >>
708    
709    Open a diagram's image file and return the type and file handle.
710    
711    =over 4
712    
713    =item id
714    
715    ID of the desired diagram
716    
717    =item RETURN
718    
719    Returns a 2-tuple containing the diagram's MIME type and an open filehandle
720    for the diagram's data. If the diagram does not exist, the type will be
721    returned as <undef>.
722    
723    =back
724    
725    =cut
726    
727    sub open_diagram_image {
728        # Get the parameters.
729        my ($self, $id) = @_;
730        # Declare the return variables.
731        my ($type, $fh);
732        # Get the diagram directory.
733        my $img_base = "$self->{dir}/diagrams/$id/diagram";
734        # Get a list of file extensions and types.
735        my %types = (png => "image/png",
736                     gif => "image/gif",
737                     jpg => "image/jpeg");
738        # This is my new syntax for the for-each-while loop.
739        # We loop until we run out of keys or come up with a type value.
740        for my $ext (keys %types) { last if (defined $type);
741            my $myType = $types{$ext};
742            # Compute a file name for this diagram.
743            my $file = "$img_base.$ext";
744            # If it exists, try to open it.
745            if (-f $file) {
746                $fh = Open(undef, "<$file");
747                $type = $myType;
748            }
749        }
750        # Return the result.
751        return ($type, $fh);
752    }
753    
754    
755  1;  1;

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3