[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.4, Tue Jan 25 01:36:09 2005 UTC revision 1.8, Thu Jan 27 00:30:20 2005 UTC
# Line 36  Line 36 
36    
37  #: Constructor SFXlate->new_sprout_only();  #: Constructor SFXlate->new_sprout_only();
38    
   
39  =head2 Public Methods  =head2 Public Methods
40    
41  =head3 new  =head3 new
# Line 424  Line 423 
423  =back  =back
424    
425  =cut  =cut
426  #: Return Type %;  #: Return Type $%;
427  sub LoadUpdate {  sub LoadUpdate {
428          # Get the parameters.          # Get the parameters.
429          my $self = shift @_;          my $self = shift @_;
# Line 1016  Line 1015 
1015  It has the format "XXXX\nset XXXX function to\nYYYYY". In this instance, XXXX is the user ID  It has the format "XXXX\nset XXXX function to\nYYYYY". In this instance, XXXX is the user ID
1016  and YYYYY is the functional assignment text. Its worth noting that we cannot filter on the content  and YYYYY is the functional assignment text. Its worth noting that we cannot filter on the content
1017  of the annotation itself because it's a text field; however, this is not a big problem because most  of the annotation itself because it's a text field; however, this is not a big problem because most
1018  features only have a small number of annotations.  features only have a small number of annotations. Finally, if a single user has multiple
1019    functional assignments, we will only keep the most recent one.
1020    
1021  =over 4  =over 4
1022    
# Line 1037  Line 1037 
1037          my $self = shift @_;          my $self = shift @_;
1038          my ($featureID) = @_;          my ($featureID) = @_;
1039          # Get all of the feature's annotations.          # Get all of the feature's annotations.
1040          my @query = $self->GetFlat(['IsTargetOfAnnotation', 'Annotation'],      my @query = $self->GetAll(['IsTargetOfAnnotation', 'Annotation'],
1041                                                      "IsTargetOfAnnotation(from-link) = ?",                                                      "IsTargetOfAnnotation(from-link) = ?",
1042                                                          [$featureID], 'Annotation(annotation)');                              [$featureID], ['Annotation(time)', 'Annotation(annotation)']);
1043          # Declare the return hash.          # Declare the return hash.
1044          my %retVal;          my %retVal;
1045        # Declare a hash for insuring we only make one assignment per user.
1046        my %timeHash = ();
1047        # Now we sort the assignments by timestamp in reverse.
1048        my @sortedQuery = sort { -($a->[0] <=> $b->[0]) } @query;
1049          # Loop until we run out of annotations.          # Loop until we run out of annotations.
1050          for my $text (@query) {      for my $annotation (@sortedQuery) {
1051            # Get the annotation fields.
1052            my ($timeStamp, $text) = @{$annotation};
1053                  # Check to see if this is a functional assignment.                  # Check to see if this is a functional assignment.
1054                  my ($user, $function) = ParseAssignment($text);                  my ($user, $function) = ParseAssignment($text);
1055                  if ($user) {          if ($user && ! exists $timeHash{$user}) {
1056                          # Here it is, so stuff it in the return hash.              # Here it is a functional assignment and there has been no
1057                # previous assignment for this user, so we stuff it in the
1058                # return hash.
1059                          $retVal{$function} = $user;                          $retVal{$function} = $user;
1060                # Insure we don't assign to this user again.
1061                $timeHash{$user} = 1;
1062                  }                  }
1063          }          }
1064          # Return the hash of assignments found.          # Return the hash of assignments found.
# Line 2539  Line 2549 
2549          return %retVal;          return %retVal;
2550  }  }
2551    
2552    =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
2562    #: Return Type %@;
2563    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
2606    
2607  =head3 ParseAssignment  =head3 ParseAssignment

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3