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

Diff of /Sprout/Sprout.pm

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

revision 1.60, Wed Jun 14 19:47:19 2006 UTC revision 1.69, Fri Jun 23 01:34:42 2006 UTC
# Line 375  Line 375 
375      # Get the genomes.      # Get the genomes.
376      my @genomes = $self->GetAll(['Genome'], $filterString, $params, ['Genome(id)',      my @genomes = $self->GetAll(['Genome'], $filterString, $params, ['Genome(id)',
377                                                                       'Genome(genus)',                                                                       'Genome(genus)',
378                                                                       'Genome(species)']);                                                                       'Genome(species)',
379                                                                         'Genome(unique-characterization)']);
380      # Sort them by name.      # Sort them by name.
381      my @sorted = sort { lc("$a->[1] $a->[2]") cmp lc("$b->[1] $b->[2]") } @genomes;      my @sorted = sort { lc("$a->[1] $a->[2]") cmp lc("$b->[1] $b->[2]") } @genomes;
382      # Loop through the genomes, creating the option tags.      # Loop through the genomes, creating the option tags.
383      for my $genomeData (@sorted) {      for my $genomeData (@sorted) {
384          # Get the data for this genome.          # Get the data for this genome.
385          my ($genomeID, $genus, $species) = @{$genomeData};          my ($genomeID, $genus, $species, $strain) = @{$genomeData};
386          # Get the contig count.          # Get the contig count.
387          my $count = $self->ContigCount($genomeID);          my $count = $self->ContigCount($genomeID);
388          my $counting = ($count == 1 ? "contig" : "contigs");          my $counting = ($count == 1 ? "contig" : "contigs");
389          # Build the option tag.          # Build the option tag.
390          $retVal .= "<option value=\"$genomeID\">$genus $species ($genomeID) [$count $counting]</option>\n";          $retVal .= "<option value=\"$genomeID\">$genus $species $strain ($genomeID) [$count $counting]</option>\n";
391      }      }
392      # Close the SELECT tag.      # Close the SELECT tag.
393      $retVal .= "</select>\n";      $retVal .= "</select>\n";
# Line 793  Line 794 
794      return @retVal;      return @retVal;
795  }  }
796    
797    =head3 GenomeLength
798    
799    C<< my $length = $sprout->GenomeLength($genomeID); >>
800    
801    Return the length of the specified genome in base pairs.
802    
803    =over 4
804    
805    =item genomeID
806    
807    ID of the genome whose base pair count is desired.
808    
809    =item RETURN
810    
811    Returns the number of base pairs in all the contigs of the specified
812    genome.
813    
814    =back
815    
816    =cut
817    
818    sub GenomeLength {
819        # Get the parameters.
820        my ($self, $genomeID) = @_;
821        # Declare the return variable.
822        my $retVal = 0;
823        # Get the genome's contig sequence lengths.
824        my @lens = $self->GetFlat(['HasContig', 'IsMadeUpOf'], 'HasContig(from-link) = ?',
825                           [$genomeID], 'IsMadeUpOf(len)');
826        # Sum the lengths.
827        map { $retVal += $_ } @lens;
828        # Return the result.
829        return $retVal;
830    }
831    
832    =head3 FeatureCount
833    
834    C<< my $count = $sprout->FeatureCount($genomeID, $type); >>
835    
836    Return the number of features of the specified type in the specified genome.
837    
838    =over 4
839    
840    =item genomeID
841    
842    ID of the genome whose feature count is desired.
843    
844    =item type
845    
846    Type of feature to count (eg. C<peg>, C<rna>, etc.).
847    
848    =item RETURN
849    
850    Returns the number of features of the specified type for the specified genome.
851    
852    =back
853    
854    =cut
855    
856    sub FeatureCount {
857        # Get the parameters.
858        my ($self, $genomeID, $type) = @_;
859        # Compute the count.
860        my $retVal = $self->GetCount(['HasFeature', 'Feature'],
861                                    "HasFeature(from-link) = ? AND Feature(feature-type) = ?",
862                                    [$genomeID, $type]);
863        # Return the result.
864        return $retVal;
865    }
866    
867    =head3 GenomeAssignments
868    
869    C<< my $fidHash = $sprout->GenomeAssignments($genomeID); >>
870    
871    Return a list of a genome's assigned features. The return hash will contain each
872    assigned feature of the genome mapped to the text of its most recent functional
873    assignment.
874    
875    =over 4
876    
877    =item genomeID
878    
879    ID of the genome whose functional assignments are desired.
880    
881    =item RETURN
882    
883    Returns a reference to a hash which maps each feature to its most recent
884    functional assignment.
885    
886    =back
887    
888    =cut
889    
890    sub GenomeAssignments {
891        # Get the parameters.
892        my ($self, $genomeID) = @_;
893        # Declare the return variable.
894        my $retVal = {};
895        # Query the genome's features and annotations. We'll put the oldest annotations
896        # first so that the last assignment to go into the hash will be the correct one.
897        my $query = $self->Get(['HasFeature', 'IsTargetOfAnnotation', 'Annotation'],
898                               "HasFeature(from-link) = ? ORDER BY Annotation(time)",
899                               [$genomeID]);
900        # Loop through the annotations.
901        while (my $data = $query->Fetch) {
902            # Get the feature ID and annotation text.
903            my ($fid, $annotation) = $data->Values(['HasFeature(to-link)',
904                                                    'Annotation(annotation)']);
905            # Check to see if this is an assignment. Note that the user really
906            # doesn't matter to us, other than we use it to determine whether or
907            # not this is an assignment.
908            my ($user, $assignment) = _ParseAssignment('fig', $annotation);
909            if ($user) {
910                # Here it's an assignment. We put it in the return hash, overwriting
911                # any older assignment that might be present.
912                $retVal->{$fid} = $assignment;
913            }
914        }
915        # Return the result.
916        return $retVal;
917    }
918    
919  =head3 ContigLength  =head3 ContigLength
920    
921  C<< my $length = $sprout->ContigLength($contigID); >>  C<< my $length = $sprout->ContigLength($contigID); >>
# Line 1546  Line 1669 
1669          # Get the other feature that participates in the coupling.          # Get the other feature that participates in the coupling.
1670          my ($otherFeatureID) = $self->GetFlat(['ParticipatesInCoupling'],          my ($otherFeatureID) = $self->GetFlat(['ParticipatesInCoupling'],
1671                                             "ParticipatesInCoupling(to-link) = ? AND ParticipatesInCoupling(from-link) <> ?",                                             "ParticipatesInCoupling(to-link) = ? AND ParticipatesInCoupling(from-link) <> ?",
1672                                             [$couplingID, $featureID], 'ParticipatesInCoupling(to-link)');                                             [$couplingID, $featureID], 'ParticipatesInCoupling(from-link)');
1673          # Attach the other feature's score to its ID.          # Attach the other feature's score to its ID.
1674          $retVal{$otherFeatureID} = $score;          $retVal{$otherFeatureID} = $score;
1675          $found = 1;          $found = 1;

Legend:
Removed from v.1.60  
changed lines
  Added in v.1.69

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3