[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.7, Wed Jan 26 22:26:09 2005 UTC revision 1.8, Thu Jan 27 00:30:20 2005 UTC
# Line 2551  Line 2551 
2551    
2552  =head3 GetGroups  =head3 GetGroups
2553    
2554    C<< my %groups = $sprout->GetGroups(\@groupList); >>
2555    
2556    Return a hash mapping each group to the IDs of the genomes in the group.
2557    A list of groups may be specified, in which case only those groups will be
2558    shown. Alternatively, if no parameter is supplied, all groups will be
2559    included. Genomes that are not in any group are omitted.
2560    
2561  =cut  =cut
2562  #: Return Type %@;  #: Return Type %@;
2563  sub GetGroups {  sub GetGroups {
2564        # Get the parameters.
2565        my $self = shift @_;
2566        my ($groupList) = @_;
2567        # Declare the return value.
2568        my %retVal = ();
2569        # Determine whether we are getting all the groups or just some.
2570        if (defined $groupList) {
2571            # Here we have a group list. Loop through them individually,
2572            # getting a list of the relevant genomes.
2573            for my $group (@{$groupList}) {
2574                my @genomeIDs = $self->GetFlat(['Genome'], "Genome(group-name) = ?",
2575                    [$group], "Genome(id)");
2576                $retVal{$group} = \@genomeIDs;
2577            }
2578        } else {
2579            # Here we need all of the groups. In this case, we run through all
2580            # of the genome records, putting each one found into the appropriate
2581            # group. Note that we use a filter clause to insure that only genomes
2582            # in groups are included in the return set.
2583            my @genomes = $self->GetAll(['Genome'], "Genome(group-name) > ' '", [],
2584                                        ['Genome(id)', 'Genome(group-name)']);
2585            # Loop through the genomes found.
2586            for my $genome (@genomes) {
2587                # Pop this genome's ID off the current list.
2588                my @groups = @{$genome};
2589                my $genomeID = shift @groups;
2590                # Loop through the groups, adding the genome ID to each group's
2591                # list.
2592                for my $group (@groups) {
2593                    if (exists $retVal{$group}) {
2594                        push @{$retVal{$group}}, $genomeID;
2595                    } else {
2596                        $retVal{$group} = [$genomeID];
2597                    }
2598                }
2599            }
2600        }
2601        # Return the hash we just built.
2602        return %retVal;
2603  }  }
2604    
2605  =head2 Internal Utility Methods  =head2 Internal Utility Methods

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3