[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.85, Tue Sep 19 00:14:04 2006 UTC revision 1.91, Sat Oct 14 18:12:48 2006 UTC
# Line 2679  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 2876  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 3253  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 3274  Line 3359 
3359          # Here we have a group list. Loop through them individually,          # Here we have a group list. Loop through them individually,
3360          # getting a list of the relevant genomes.          # getting a list of the relevant genomes.
3361          for my $group (@{$groupList}) {          for my $group (@{$groupList}) {
3362              my @genomeIDs = $self->GetFlat(['Genome'], "Genome(group-name) = ?",              my @genomeIDs = $self->GetFlat(['Genome'], "Genome(primary-group) = ?",
3363                  [$group], "Genome(id)");                  [$group], "Genome(id)");
3364              $retVal{$group} = \@genomeIDs;              $retVal{$group} = \@genomeIDs;
3365          }          }
# Line 3282  Line 3367 
3367          # Here we need all of the groups. In this case, we run through all          # Here we need all of the groups. In this case, we run through all
3368          # of the genome records, putting each one found into the appropriate          # of the genome records, putting each one found into the appropriate
3369          # group. Note that we use a filter clause to insure that only genomes          # group. Note that we use a filter clause to insure that only genomes
3370          # in groups are included in the return set.          # in real NMPDR groups are included in the return set.
3371          my @genomes = $self->GetAll(['Genome'], "Genome(group-name) > ' '", [],          my @genomes = $self->GetAll(['Genome'], "Genome(primary-group) <> ?",
3372                                      ['Genome(id)', 'Genome(group-name)']);                                      [$FIG_Config::otherGroup], ['Genome(id)', 'Genome(primary-group)']);
3373          # Loop through the genomes found.          # Loop through the genomes found.
3374          for my $genome (@genomes) {          for my $genome (@genomes) {
3375              # Pop this genome's ID off the current list.              # Pop this genome's ID off the current list.
# Line 3557  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 Virtual Methods
3703    
3704    =head3 CleanKeywords
3705    
3706    C<< my $cleanedString = $sprout->CleanKeywords($searchExpression); >>
3707    
3708    Clean up a search expression or keyword list. This involves converting the periods
3709    in EC numbers to underscores, converting non-leading minus signs to underscores,
3710    a vertical bar or colon to an apostrophe, and forcing lower case for all alphabetic
3711    characters. In addition, any extra spaces are removed.
3712    
3713    =over 4
3714    
3715    =item searchExpression
3716    
3717    Search expression or keyword list to clean. Note that a search expression may
3718    contain boolean operators which need to be preserved. This includes leading
3719    minus signs.
3720    
3721    =item RETURN
3722    
3723    Cleaned expression or keyword list.
3724    
3725    =back
3726    
3727    =cut
3728    
3729    sub CleanKeywords {
3730        # Get the parameters.
3731        my ($self, $searchExpression) = @_;
3732        # Perform the standard cleanup.
3733        my $retVal = $self->ERDB::CleanKeywords($searchExpression);
3734        # Fix the periods in EC and TC numbers.
3735        $retVal =~ s/(\d+|\-)\.(\d+|-)\.(\d+|-)\.(\d+|-)/$1_$2_$3_$4/g;
3736        # Fix non-trailing periods.
3737        $retVal =~ s/\.(\w)/_$1/g;
3738        # Fix non-leading minus signs.
3739        $retVal =~ s/(\w)[\-]/$1_/g;
3740        # Fix the vertical bars and colons
3741        $retVal =~ s/(\w)[|:](\w)/$1'$2/g;
3742        # Return the result.
3743        return $retVal;
3744    }
3745    
3746  =head2 Internal Utility Methods  =head2 Internal Utility Methods
3747    
3748  =head3 ParseAssignment  =head3 ParseAssignment
# Line 3646  Line 3832 
3832      return $retVal;      return $retVal;
3833  }  }
3834    
 =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 });  
 }  
   
3835    
3836  1;  1;

Legend:
Removed from v.1.85  
changed lines
  Added in v.1.91

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3