[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.88, Wed Sep 27 12:34:46 2006 UTC revision 1.90, Fri Sep 29 15:10:05 2006 UTC
# Line 2710  Line 2710 
2710      # Try to find the ID.      # Try to find the ID.
2711      my ($retVal) = $self->GetFlat(['Property'],      my ($retVal) = $self->GetFlat(['Property'],
2712                                    "Property(property-name) = ? AND Property(property-value) = ?",                                    "Property(property-name) = ? AND Property(property-value) = ?",
2713                                    [$propName, $propValue]);                                    [$propName, $propValue], 'Property(id)');
2714      # Return the result.      # Return the result.
2715      return $retVal;      return $retVal;
2716  }  }
# Line 3289  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 3593  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 3682  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.88  
changed lines
  Added in v.1.90

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3