[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.2, Tue Oct 18 20:06:22 2005 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 140  Line 144 
144              my @reactions = $sprout->GetFlat(['Catalyzes'], 'Catalyzes(from-link) = ?',              my @reactions = $sprout->GetFlat(['Catalyzes'], 'Catalyzes(from-link) = ?',
145                                               [$roleID], 'Catalyzes(to-link)');                                               [$roleID], 'Catalyzes(to-link)');
146              # Put them in the reaction hash.              # Put them in the reaction hash.
147                if (@reactions > 0) {
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 220  Line 231 
231      my ($self, $gidx) = @_;      my ($self, $gidx) = @_;
232      # Extract the variant code for the specified row index. It is the second      # Extract the variant code for the specified row index. It is the second
233      # element of the tuple from the "genomes" member.      # element of the tuple from the "genomes" member.
234      my $retVal = $self->{genomes}->{$gidx}->[1];      my $retVal = $self->{genomes}->[$gidx]->[1];
235      return $retVal;      return $retVal;
236  }  }
237    
# Line 457  Line 468 
468  =item pegID  =item pegID
469    
470  ID of the PEG whose cluster number is desired.  ID of the PEG whose cluster number is desired.
471  TODO: items  
472    =item RETURN
473    
474    Returns the appropriate cluster number.
475    
476  =back  =back
477    
# Line 528  Line 542 
542          }          }
543      }      }
544      # Construct the spreadsheet cell ID from the information we have.      # Construct the spreadsheet cell ID from the information we have.
545      my $cellID = $self->{name} . ":$genomeID:$colIdx";      my $cellID = $sprout->DigestKey($self->{name} . ":$genomeID:$colIdx");
546      # Get the list of PEG IDs and cluster numbers for the indicated cell.      # Get the list of PEG IDs and cluster numbers for the indicated cell.
547      my @pegList = $sprout->GetAll(['ContainsFeature'], 'ContainsFeature(from-link) = ?',      my @pegList = $sprout->GetAll(['ContainsFeature'], 'ContainsFeature(from-link) = ?',
548                                    [$cellID], ['ContainsFeature(to-link)',                                    [$cellID], ['ContainsFeature(to-link)',
# Line 545  Line 559 
559      return @retVal;      return @retVal;
560  }  }
561    
 1;  
562    
563    
564    =head3 get_diagrams
565    
566    C<< my @list = $sub->get_diagrams(); >>
567    
568    Return a list of the diagrams associated with this subsystem. Each diagram
569    is represented in the return list as a 4-tuple C<[diagram_id, diagram_name,
570    page_link, img_link]> where
571    
572    =over 4
573    
574    =item diagram_id
575    
576    ID code for this diagram.
577    
578    =item diagram_name
579    
580    Displayable name of the diagram.
581    
582    =item page_link
583    
584    URL of an HTML page containing information about the diagram.
585    
586    =item img_link
587    
588    URL of an HTML page containing an image for the diagram.
589    
590    =back
591    
592    Note that the URLs are in fact for CGI scripts with parameters that point them
593    to the correct place. Though Sprout has diagram information in it, it has
594    no relationship to the diagrams displayed in SEED, so the work is done entirely
595    on the SEED side.
596    
597    =cut
598    
599    sub get_diagrams {
600        # Get the parameters.
601        my ($self) = @_;
602        # Get the diagram IDs.
603        my @diagramIDs = Subsystem::GetDiagramIDs($self->{dir});
604        Trace("Diagram IDs are " . join(", ", @diagramIDs)) if T(3);
605        # Create the return variable.
606        my @retVal = ();
607        # Loop through the diagram IDs.
608        for my $diagramID (@diagramIDs) {
609            Trace("Processing diagram $diagramID.") if T(3);
610            my ($name, $link, $imgLink) = $self->get_diagram($diagramID);
611            Trace("Diagram $name URLs are \"$link\" and \"$imgLink\".") if T(3);
612            push @retVal, [$diagramID, $name, $link, $imgLink];
613        }
614        # Return the result.
615        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;

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3