[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.86, Sun Sep 24 17:14:16 2006 UTC revision 1.90, Fri Sep 29 15:10:05 2006 UTC
# Line 438  Line 438 
438      $self->CreateTables();      $self->CreateTables();
439  }  }
440    
 =head3 NmpdrGenomeMenu  
   
 C<< my $htmlText = $sprout->NmpdrGenomeMenu(\%options, \@selected); >>  
   
 This method creates a hierarchical HTML menu for NMPDR genomes organized by category. The  
 category indicates the low-level NMPDR group. Organizing the genomes in this way makes it  
 easier to select all genomes from a particular category.  
   
 =over 4  
   
 =item options  
   
 Reference to a hash containing the options to be applied to the C<SELECT> tag form the menu.  
 Typical options would include C<name> to specify the field name, C<multiple> to specify  
 that multiple selections are allowed, and C<size> to set the number of rows to display  
 in the menu.  
   
 =item selected  
   
 Reference to a list containing the IDs of the genomes to be pre-selected. If the menu  
 is not intended to allow multiple selections, the list should be a singleton. If the  
 list is empty, nothing will be pre-selected.  
   
 =item RETURN  
   
 Returns the HTML text to generate a C<SELECT> menu inside a form.  
   
 =back  
   
 =cut  
   
 sub NmpdrGenomeMenu {  
     # Get the parameters.  
     my ($self, $options, $selected) = @_;  
     # Get a list of all the genomes in group order. In fact, we only need them ordered  
     # by name (genus,species,strain), but putting primary-group in front enables us to  
     # take advantage of an existing index.  
     my @genomeList = $self->GetAll(['Genome'],  
                                    "ORDER BY Genome(primary-group), Genome(genus), Genome(species), Genome(unique-characterization)",  
                                    [], ['Genome(primary-group)', 'Genome(id)',  
                                         'Genome(genus)', 'Genome(species)',  
                                         'Genome(unique-characterization)']);  
     # Create a hash to organize the genomes by group. Each group will contain a list of  
     # 2-tuples, the first element being the genome ID and the second being the genome  
     # name.  
     my %groupHash = ();  
     for my $genome (@genomeList) {  
         # Get the genome data.  
         my ($group, $genomeID, $genus, $species, $strain) = @{$genome};  
         # Form the genome name.  
         my $name = "$genus $species";  
         if ($strain) {  
             $name .= " $strain";  
         }  
         # Push the genome into the group's list.  
         push @{$groupHash{$group}}, [$genomeID, $name];  
     }  
     # Now we are ready to unroll the menu out of the group hash. First, we sort the groups, putting  
     # the supporting-genome group last.  
     my @groups = sort grep { $_ ne $FIG_Config::otherGroup } keys %groupHash;  
     push @groups, $FIG_Config::otherGroup;  
     # Next, create a hash that specifies the pre-selected entries.  
     my %selectedHash = map { $_ => 1 } @{$selected};  
     # Create the SELECT tag and stuff it into the output array.  
     my $select = "<" . join(" ", 'SELECT', map { "$_=\"$options->{$_}\"" } keys %{$options}) . ">";  
     my @lines = ($select);  
     # Loop through the groups.  
     for my $group (@groups) {  
         # Create the option group tag.  
         my $tag = "<OPTGROUP name=\"$group\">";  
         push @lines, "  $tag";  
         # Get the genomes in the group.  
         for my $genome (@{$groupHash{$group}}) {  
             my ($genomeID, $name) = @{$genome};  
             # See if it's selected.  
             my $select = ($selectedHash{$genomeID} ? " selected" : "");  
             # Generate the option tag.  
             my $optionTag = "<OPTION value=\"$genomeID\"$select>$name</OPTION>";  
             push @lines, "    $optionTag";  
         }  
         # Close the option group.  
         push @lines, "  </OPTGROUP>";  
     }  
     # Close the SELECT tag.  
     push @lines, "</SELECT>";  
     # Assemble the lines into a string.  
     my $retVal = join("\n", @lines, "");  
     # Return the result.  
     return $retVal;  
 }  
   
441  =head3 Genomes  =head3 Genomes
442    
443  C<< my @genomes = $sprout->Genomes(); >>  C<< my @genomes = $sprout->Genomes(); >>
# Line 2770  Line 2679 
2679      return $retVal;      return $retVal;
2680  }  }
2681    
2682    =head3 PropertyID
2683    
2684    C<< my $id = $sprout->PropertyID($propName, $propValue); >>
2685    
2686    Return the ID of the specified property name and value pair, if the
2687    pair exists.
2688    
2689    =over 4
2690    
2691    =item propName
2692    
2693    Name of the desired property.
2694    
2695    =item propValue
2696    
2697    Value expected for the desired property.
2698    
2699    =item RETURN
2700    
2701    Returns the ID of the name/value pair, or C<undef> if the pair does not exist.
2702    
2703    =back
2704    
2705    =cut
2706    
2707    sub PropertyID {
2708        # Get the parameters.
2709        my ($self, $propName, $propValue) = @_;
2710        # Try to find the ID.
2711        my ($retVal) = $self->GetFlat(['Property'],
2712                                      "Property(property-name) = ? AND Property(property-value) = ?",
2713                                      [$propName, $propValue], 'Property(id)');
2714        # Return the result.
2715        return $retVal;
2716    }
2717    
2718  =head3 MergedAnnotations  =head3 MergedAnnotations
2719    
2720  C<< my @annotationList = $sprout->MergedAnnotations(\@list); >>  C<< my @annotationList = $sprout->MergedAnnotations(\@list); >>
# Line 2967  Line 2912 
2912      # Get the parameters.      # Get the parameters.
2913      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
2914      # Get the list of names.      # Get the list of names.
2915      my @retVal = $self->GetFlat(['ContainsFeature', 'HasSSCell'], "ContainsFeature(to-link) = ?",      my @retVal = $self->GetFlat(['HasRoleInSubsystem'], "HasRoleInSubsystem(from-link) = ?",
2916                                  [$featureID], 'HasSSCell(from-link)');                                  [$featureID], 'HasRoleInSubsystem(to-link)');
2917      # Return the result.      # Return the result, sorted.
2918      return @retVal;      return sort @retVal;
2919  }  }
2920    
2921  =head3 GenomeSubsystemData  =head3 GenomeSubsystemData
# Line 3344  Line 3289 
3289      return $retVal;      return $retVal;
3290  }  }
3291    
3292    =head3 IsAllGenomes
3293    
3294    C<< my $flag = $sprout->IsAllGenomes(\@list, \@checkList); >>
3295    
3296    Return TRUE if all genomes in the second list are represented in the first list at
3297    least one. Otherwise, return FALSE. If the second list is omitted, the first list is
3298    compared to a list of all the genomes.
3299    
3300    =over 4
3301    
3302    =item list
3303    
3304    Reference to the list to be compared to the second list.
3305    
3306    =item checkList (optional)
3307    
3308    Reference to the comparison target list. Every genome ID in this list must occur at
3309    least once in the first list. If this parameter is omitted, a list of all the genomes
3310    is used.
3311    
3312    =item RETURN
3313    
3314    Returns TRUE if every item in the second list appears at least once in the
3315    first list, else FALSE.
3316    
3317    =back
3318    
3319    =cut
3320    
3321    sub IsAllGenomes {
3322        # Get the parameters.
3323        my ($self, $list, $checkList) = @_;
3324        # Supply the checklist if it was omitted.
3325        $checkList = [$self->Genomes()] if ! defined($checkList);
3326        # Create a hash of the original list.
3327        my %testList = map { $_ => 1 } @{$list};
3328        # Declare the return variable. We assume that the representation
3329        # is complete and stop at the first failure.
3330        my $retVal = 1;
3331        my $n = scalar @{$checkList};
3332        for (my $i = 0; $retVal && $i < $n; $i++) {
3333            if (! $testList{$checkList->[$i]}) {
3334                $retVal = 0;
3335            }
3336        }
3337        # Return the result.
3338        return $retVal;
3339    }
3340    
3341  =head3 GetGroups  =head3 GetGroups
3342    
3343  C<< my %groups = $sprout->GetGroups(\@groupList); >>  C<< my %groups = $sprout->GetGroups(\@groupList); >>
# Line 3648  Line 3642 
3642      return %retVal;      return %retVal;
3643  }  }
3644    
3645    =head3 AddProperty
3646    
3647    C<< my  = $sprout->AddProperty($featureID, $key, $value, $url); >>
3648    
3649    Add a new attribute value (Property) to a feature. In the SEED system, attributes can
3650    be added to almost any object. In Sprout, they can only be added to features. In
3651    Sprout, attributes are implemented using I<properties>. A property represents a key/value
3652    pair. If the particular key/value pair coming in is not already in the database, a new
3653    B<Property> record is created to hold it.
3654    
3655    =over 4
3656    
3657    =item peg
3658    
3659    ID of the feature to which the attribute is to be replied.
3660    
3661    =item key
3662    
3663    Name of the attribute (key).
3664    
3665    =item value
3666    
3667    Value of the attribute.
3668    
3669    =item url
3670    
3671    URL or text citation from which the property was obtained.
3672    
3673    =back
3674    
3675    =cut
3676    #: Return Type ;
3677    sub AddProperty {
3678        # Get the parameters.
3679        my ($self, $featureID, $key, $value, $url) = @_;
3680        # Declare the variable to hold the desired property ID.
3681        my $propID;
3682        # Attempt to find a property record for this key/value pair.
3683        my @properties = $self->GetFlat(['Property'],
3684                                       "Property(property-name) = ? AND Property(property-value) = ?",
3685                                       [$key, $value], 'Property(id)');
3686        if (@properties) {
3687            # Here the property is already in the database. We save its ID.
3688            $propID = $properties[0];
3689            # Here the property value does not exist. We need to generate an ID. It will be set
3690            # to a number one greater than the maximum value in the database. This call to
3691            # GetAll will stop after one record.
3692            my @maxProperty = $self->GetAll(['Property'], "ORDER BY Property(id) DESC", [], ['Property(id)'],
3693                                            1);
3694            $propID = $maxProperty[0]->[0] + 1;
3695            # Insert the new property value.
3696            $self->Insert('Property', { 'property-name' => $key, 'property-value' => $value, id => $propID });
3697        }
3698        # Now we connect the incoming feature to the property.
3699        $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });
3700    }
3701    
3702  =head2 Internal Utility Methods  =head2 Internal Utility Methods
3703    
3704  =head3 ParseAssignment  =head3 ParseAssignment
# Line 3737  Line 3788 
3788      return $retVal;      return $retVal;
3789  }  }
3790    
 =head3 AddProperty  
   
 C<< my  = $sprout->AddProperty($featureID, $key, $value, $url); >>  
   
 Add a new attribute value (Property) to a feature. In the SEED system, attributes can  
 be added to almost any object. In Sprout, they can only be added to features. In  
 Sprout, attributes are implemented using I<properties>. A property represents a key/value  
 pair. If the particular key/value pair coming in is not already in the database, a new  
 B<Property> record is created to hold it.  
   
 =over 4  
   
 =item peg  
   
 ID of the feature to which the attribute is to be replied.  
   
 =item key  
   
 Name of the attribute (key).  
   
 =item value  
   
 Value of the attribute.  
   
 =item url  
   
 URL or text citation from which the property was obtained.  
   
 =back  
   
 =cut  
 #: Return Type ;  
 sub AddProperty {  
     # Get the parameters.  
     my ($self, $featureID, $key, $value, $url) = @_;  
     # Declare the variable to hold the desired property ID.  
     my $propID;  
     # Attempt to find a property record for this key/value pair.  
     my @properties = $self->GetFlat(['Property'],  
                                    "Property(property-name) = ? AND Property(property-value) = ?",  
                                    [$key, $value], 'Property(id)');  
     if (@properties) {  
         # Here the property is already in the database. We save its ID.  
         $propID = $properties[0];  
         # Here the property value does not exist. We need to generate an ID. It will be set  
         # to a number one greater than the maximum value in the database. This call to  
         # GetAll will stop after one record.  
         my @maxProperty = $self->GetAll(['Property'], "ORDER BY Property(id) DESC", [], ['Property(id)'],  
                                         1);  
         $propID = $maxProperty[0]->[0] + 1;  
         # Insert the new property value.  
         $self->Insert('Property', { 'property-name' => $key, 'property-value' => $value, id => $propID });  
     }  
     # Now we connect the incoming feature to the property.  
     $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });  
 }  
   
3791    
3792  1;  1;

Legend:
Removed from v.1.86  
changed lines
  Added in v.1.90

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3