[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.18, Tue Jun 28 21:34:15 2005 UTC revision 1.19, Sun Aug 14 23:32:08 2005 UTC
# Line 2226  Line 2226 
2226      return @retVal;      return @retVal;
2227  }  }
2228    
2229    =head3 GetProperties
2230    
2231    C<< my @list = $sprout->GetProperties($fid, $key, $value, $url); >>
2232    
2233    Return a list of the properties with the specified characteristics.
2234    
2235    Properties are arbitrary key-value pairs associated with a feature. (At some point they
2236    will also be associated with genomes.) A property value is represented by a 4-tuple of
2237    the form B<($fid, $key, $value, $url)>. These exactly correspond to the parameter
2238    
2239    =over 4
2240    
2241    =item fid
2242    
2243    ID of the feature possessing the property.
2244    
2245    =item key
2246    
2247    Name or key of the property.
2248    
2249    =item value
2250    
2251    Value of the property.
2252    
2253    =item url
2254    
2255    URL of the document that indicated the property should have this particular value, or an
2256    empty string if no such document exists.
2257    
2258    =back
2259    
2260    The parameters act as a filter for the desired data. Any non-null parameter will
2261    automatically match all the tuples returned. So, specifying just the I<$fid> will
2262    return all the properties of the specified feature; similarly, specifying the I<$key>
2263    and I<$value> parameters will return all the features having the specified property
2264    value.
2265    
2266    A single property key can have many values, representing different ideas about the
2267    feature in question. For example, one paper may declare that a feature C<fig|83333.1.peg.10> is
2268    virulent, and another may declare that it is not virulent. A query about the virulence of
2269    C<fig|83333.1.peg.10> would be coded as
2270    
2271        my @list = $sprout->GetProperties('fig|83333.1.peg.10', 'virulence', '', '');
2272    
2273    Here the I<$value> and I<$url> fields are left blank, indicating that those fields are
2274    not to be filtered. The tuples returned would be
2275    
2276        ('fig|83333.1.peg.10', 'virulence', 'yes', 'http://www.somewhere.edu/first.paper.pdf')
2277        ('fig|83333.1.peg.10', 'virulence', 'no', 'http://www.somewhere.edu/second.paper.pdf')
2278    
2279    =cut
2280    #: Return Type @@;
2281    sub GetProperties {
2282        # Get the parameters.
2283        my ($self, @parms) = @_;
2284        # Declare the return variable.
2285        my @retVal = ();
2286        # Now we need to create a WHERE clause that will get us the data we want. First,
2287        # we create a list of the columns containing the data for each parameter.
2288        my @colNames = ('HasProperty(from-link)', 'Property(property-name)',
2289                        'Property(property-value)', 'HasProperty(evidence)');
2290        # Now we build the WHERE clause and the list of parameter values.
2291        my @where = ();
2292        my @values = ();
2293        for (my $i = 0; $i <= $#colNames; $i++) {
2294            my $parm = $parms[$i];
2295            if (defined $parm && ($parm ne '')) {
2296                push @where, "$colNames[$i] = ?";
2297                push @values, $parm;
2298            }
2299        }
2300        # Format the WHERE clause.
2301        my $filter = (@values > 0 ? (join " AND ", @where) : undef);
2302        # Ask for all the propertie values with the desired characteristics.
2303        my $query = $self->Get(['HasProperty', 'Property'], $filter, \@values);
2304        while (my $valueObject = $query->Fetch()) {
2305            my @tuple = $valueObject->Values(\@colNames);
2306            push @retVal, \@tuple;
2307        }
2308        # Return the result.
2309        return @retVal;
2310    }
2311    
2312  =head3 FeatureProperties  =head3 FeatureProperties
2313    
2314  C<< my @properties = $sprout->FeatureProperties($featureID); >>  C<< my @properties = $sprout->FeatureProperties($featureID); >>
# Line 3108  Line 3191 
3191      $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });      $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });
3192  }  }
3193    
3194    
3195    
3196  1;  1;

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3