[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.58, Tue Jun 6 05:07:15 2006 UTC revision 1.69, Fri Jun 23 01:34:42 2006 UTC
# Line 304  Line 304 
304      return ($arch, $bact, $euk, $vir, $env, $unk);      return ($arch, $bact, $euk, $vir, $env, $unk);
305  }  }
306    
307    =head3 ContigCount
308    
309    C<< my $count = $sprout->ContigCount($genomeID); >>
310    
311    Return the number of contigs for the specified genome ID.
312    
313    =over 4
314    
315    =item genomeID
316    
317    ID of the genome whose contig count is desired.
318    
319    =item RETURN
320    
321    Returns the number of contigs for the specified genome.
322    
323    =back
324    
325    =cut
326    
327    sub ContigCount {
328        # Get the parameters.
329        my ($self, $genomeID) = @_;
330        # Get the contig count.
331        my $retVal = $self->GetCount(['Contig', 'HasContig'], "HasContig(from-link) = ?", [$genomeID]);
332        # Return the result.
333        return $retVal;
334    }
335    
336    =head3 GeneMenu
337    
338    C<< my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params); >>
339    
340    Return an HTML select menu of genomes. Each genome will be an option in the menu,
341    and will be displayed by name with the ID and a contig count attached. The selection
342    value will be the genome ID. The genomes will be sorted by genus/species name.
343    
344    =over 4
345    
346    =item attributes
347    
348    Reference to a hash mapping attributes to values for the SELECT tag generated.
349    
350    =item filterString
351    
352    A filter string for use in selecting the genomes. The filter string must conform
353    to the rules for the C<< ERDB->Get >> method.
354    
355    =item params
356    
357    Reference to a list of values to be substituted in for the parameter marks in
358    the filter string.
359    
360    =item RETURN
361    
362    Returns an HTML select menu with the specified genomes as selectable options.
363    
364    =back
365    
366    =cut
367    
368    sub GeneMenu {
369        # Get the parameters.
370        my ($self, $attributes, $filterString, $params) = @_;
371        # Start the menu.
372        my $retVal = "<select " .
373            join(" ", map { "$_=\"$attributes->{$_}\"" } keys %{$attributes}) .
374            ">\n";
375        # Get the genomes.
376        my @genomes = $self->GetAll(['Genome'], $filterString, $params, ['Genome(id)',
377                                                                         'Genome(genus)',
378                                                                         'Genome(species)',
379                                                                         'Genome(unique-characterization)']);
380        # Sort them by name.
381        my @sorted = sort { lc("$a->[1] $a->[2]") cmp lc("$b->[1] $b->[2]") } @genomes;
382        # Loop through the genomes, creating the option tags.
383        for my $genomeData (@sorted) {
384            # Get the data for this genome.
385            my ($genomeID, $genus, $species, $strain) = @{$genomeData};
386            # Get the contig count.
387            my $count = $self->ContigCount($genomeID);
388            my $counting = ($count == 1 ? "contig" : "contigs");
389            # Build the option tag.
390            $retVal .= "<option value=\"$genomeID\">$genus $species $strain ($genomeID) [$count $counting]</option>\n";
391        }
392        # Close the SELECT tag.
393        $retVal .= "</select>\n";
394        # Return the result.
395        return $retVal;
396    }
397  =head3 Build  =head3 Build
398    
399  C<< $sprout->Build(); >>  C<< $sprout->Build(); >>
# Line 704  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 1454  Line 1666 
1666          # Get the ID and score of the coupling.          # Get the ID and score of the coupling.
1667          my ($couplingID, $score) = $clustering->Values(['Coupling(id)',          my ($couplingID, $score) = $clustering->Values(['Coupling(id)',
1668                                                          'Coupling(score)']);                                                          'Coupling(score)']);
1669          # The coupling ID contains the two feature IDs separated by a space. We use          # Get the other feature that participates in the coupling.
1670          # this information to find the ID of the other feature.          my ($otherFeatureID) = $self->GetFlat(['ParticipatesInCoupling'],
1671          my ($fid1, $fid2) = split / /, $couplingID;                                             "ParticipatesInCoupling(to-link) = ? AND ParticipatesInCoupling(from-link) <> ?",
1672          my $otherFeatureID = ($featureID eq $fid1 ? $fid2 : $fid1);                                             [$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.58  
changed lines
  Added in v.1.69

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3