[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.92, Mon Oct 16 07:41:50 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 3204  Line 3149 
3149      # Loop through the input triples.      # Loop through the input triples.
3150      my $n = length $sequence;      my $n = length $sequence;
3151      for (my $i = 0; $i < $n; $i += 3) {      for (my $i = 0; $i < $n; $i += 3) {
3152          # Get the current triple from the sequence.          # Get the current triple from the sequence. Note we convert to
3153          my $triple = substr($sequence, $i, 3);          # upper case to insure a match.
3154            my $triple = uc substr($sequence, $i, 3);
3155          # Translate it using the table.          # Translate it using the table.
3156          my $protein = "X";          my $protein = "X";
3157          if (exists $table->{$triple}) { $protein = $table->{$triple}; }          if (exists $table->{$triple}) { $protein = $table->{$triple}; }
# Line 3344  Line 3290 
3290      return $retVal;      return $retVal;
3291  }  }
3292    
3293    =head3 IsAllGenomes
3294    
3295    C<< my $flag = $sprout->IsAllGenomes(\@list, \@checkList); >>
3296    
3297    Return TRUE if all genomes in the second list are represented in the first list at
3298    least one. Otherwise, return FALSE. If the second list is omitted, the first list is
3299    compared to a list of all the genomes.
3300    
3301    =over 4
3302    
3303    =item list
3304    
3305    Reference to the list to be compared to the second list.
3306    
3307    =item checkList (optional)
3308    
3309    Reference to the comparison target list. Every genome ID in this list must occur at
3310    least once in the first list. If this parameter is omitted, a list of all the genomes
3311    is used.
3312    
3313    =item RETURN
3314    
3315    Returns TRUE if every item in the second list appears at least once in the
3316    first list, else FALSE.
3317    
3318    =back
3319    
3320    =cut
3321    
3322    sub IsAllGenomes {
3323        # Get the parameters.
3324        my ($self, $list, $checkList) = @_;
3325        # Supply the checklist if it was omitted.
3326        $checkList = [$self->Genomes()] if ! defined($checkList);
3327        # Create a hash of the original list.
3328        my %testList = map { $_ => 1 } @{$list};
3329        # Declare the return variable. We assume that the representation
3330        # is complete and stop at the first failure.
3331        my $retVal = 1;
3332        my $n = scalar @{$checkList};
3333        for (my $i = 0; $retVal && $i < $n; $i++) {
3334            if (! $testList{$checkList->[$i]}) {
3335                $retVal = 0;
3336            }
3337        }
3338        # Return the result.
3339        return $retVal;
3340    }
3341    
3342  =head3 GetGroups  =head3 GetGroups
3343    
3344  C<< my %groups = $sprout->GetGroups(\@groupList); >>  C<< my %groups = $sprout->GetGroups(\@groupList); >>
# Line 3648  Line 3643 
3643      return %retVal;      return %retVal;
3644  }  }
3645    
3646    =head3 AddProperty
3647    
3648    C<< my  = $sprout->AddProperty($featureID, $key, $value, $url); >>
3649    
3650    Add a new attribute value (Property) to a feature. In the SEED system, attributes can
3651    be added to almost any object. In Sprout, they can only be added to features. In
3652    Sprout, attributes are implemented using I<properties>. A property represents a key/value
3653    pair. If the particular key/value pair coming in is not already in the database, a new
3654    B<Property> record is created to hold it.
3655    
3656    =over 4
3657    
3658    =item peg
3659    
3660    ID of the feature to which the attribute is to be replied.
3661    
3662    =item key
3663    
3664    Name of the attribute (key).
3665    
3666    =item value
3667    
3668    Value of the attribute.
3669    
3670    =item url
3671    
3672    URL or text citation from which the property was obtained.
3673    
3674    =back
3675    
3676    =cut
3677    #: Return Type ;
3678    sub AddProperty {
3679        # Get the parameters.
3680        my ($self, $featureID, $key, $value, $url) = @_;
3681        # Declare the variable to hold the desired property ID.
3682        my $propID;
3683        # Attempt to find a property record for this key/value pair.
3684        my @properties = $self->GetFlat(['Property'],
3685                                       "Property(property-name) = ? AND Property(property-value) = ?",
3686                                       [$key, $value], 'Property(id)');
3687        if (@properties) {
3688            # Here the property is already in the database. We save its ID.
3689            $propID = $properties[0];
3690            # Here the property value does not exist. We need to generate an ID. It will be set
3691            # to a number one greater than the maximum value in the database. This call to
3692            # GetAll will stop after one record.
3693            my @maxProperty = $self->GetAll(['Property'], "ORDER BY Property(id) DESC", [], ['Property(id)'],
3694                                            1);
3695            $propID = $maxProperty[0]->[0] + 1;
3696            # Insert the new property value.
3697            $self->Insert('Property', { 'property-name' => $key, 'property-value' => $value, id => $propID });
3698        }
3699        # Now we connect the incoming feature to the property.
3700        $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });
3701    }
3702    
3703    =head2 Virtual Methods
3704    
3705    =head3 CleanKeywords
3706    
3707    C<< my $cleanedString = $sprout->CleanKeywords($searchExpression); >>
3708    
3709    Clean up a search expression or keyword list. This involves converting the periods
3710    in EC numbers to underscores, converting non-leading minus signs to underscores,
3711    a vertical bar or colon to an apostrophe, and forcing lower case for all alphabetic
3712    characters. In addition, any extra spaces are removed.
3713    
3714    =over 4
3715    
3716    =item searchExpression
3717    
3718    Search expression or keyword list to clean. Note that a search expression may
3719    contain boolean operators which need to be preserved. This includes leading
3720    minus signs.
3721    
3722    =item RETURN
3723    
3724    Cleaned expression or keyword list.
3725    
3726    =back
3727    
3728    =cut
3729    
3730    sub CleanKeywords {
3731        # Get the parameters.
3732        my ($self, $searchExpression) = @_;
3733        # Perform the standard cleanup.
3734        my $retVal = $self->ERDB::CleanKeywords($searchExpression);
3735        # Fix the periods in EC and TC numbers.
3736        $retVal =~ s/(\d+|\-)\.(\d+|-)\.(\d+|-)\.(\d+|-)/$1_$2_$3_$4/g;
3737        # Fix non-trailing periods.
3738        $retVal =~ s/\.(\w)/_$1/g;
3739        # Fix non-leading minus signs.
3740        $retVal =~ s/(\w)[\-]/$1_/g;
3741        # Fix the vertical bars and colons
3742        $retVal =~ s/(\w)[|:](\w)/$1'$2/g;
3743        # Return the result.
3744        return $retVal;
3745    }
3746    
3747  =head2 Internal Utility Methods  =head2 Internal Utility Methods
3748    
3749  =head3 ParseAssignment  =head3 ParseAssignment
# Line 3737  Line 3833 
3833      return $retVal;      return $retVal;
3834  }  }
3835    
 =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 });  
 }  
   
3836    
3837  1;  1;

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3