[Bio] / Sprout / CustomAttributes.pm Repository:
ViewVC logotype

Diff of /Sprout/CustomAttributes.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.23, Mon Apr 23 06:26:54 2007 UTC revision 1.24, Fri Apr 27 22:17:39 2007 UTC
# Line 387  Line 387 
387  =head3 LoadAttributesFrom  =head3 LoadAttributesFrom
388    
389  C<< my $stats = $attrDB->LoadAttributesFrom($fileName, %options); >>  C<< my $stats = $attrDB->LoadAttributesFrom($fileName, %options); >>
390    s
391  Load attributes from the specified tab-delimited file. Each line of the file must  Load attributes from the specified tab-delimited file. Each line of the file must
392  contain an object ID in the first column, an attribute key name in the second  contain an object ID in the first column, an attribute key name in the second
393  column, and attribute values in the remaining columns. The attribute values will  column, and attribute values in the remaining columns. The attribute values will
# Line 1727  Line 1727 
1727      return sort @groups;      return sort @groups;
1728  }  }
1729    
1730    =head3 QueryAttributes
1731    
1732    C<< my @attributeData = $ca->QueryAttributes($filter, $filterParms); >>
1733    
1734    Return the attribute data based on an SQL filter clause. In the filter clause,
1735    the name C<$object> should be used for the object ID, C<$key> should be used for
1736    the key name, C<$subkey> for the subkey value, and C<$value> for the value field.
1737    
1738    =over 4
1739    
1740    =item filter
1741    
1742    Filter clause in the standard ERDB format, except that the field names are C<$object> for
1743    the object ID field, C<$key> for the key name field, C<$subkey> for the subkey field,
1744    and C<$value> for the value field. This abstraction enables us to hide the details of
1745    the database construction from the user.
1746    
1747    =item filterParms
1748    
1749    Parameters for the filter clause.
1750    
1751    =item RETURN
1752    
1753    Returns a list of tuples. Each tuple consists of an object ID, a key (with optional subkey), and
1754    one or more attribute values.
1755    
1756    =back
1757    
1758    =cut
1759    
1760    # This hash is used to drive the substitution process.
1761    my %AttributeParms = (object => 'HasValueFor(to-link)',
1762                          key    => 'HasValueFor(from-link)',
1763                          subkey => 'HasValueFor(subkey)',
1764                          value  => 'HasValueFor(value)');
1765    
1766    sub QueryAttributes {
1767        # Get the parameters.
1768        my ($self, $filter, $filterParms) = @_;
1769        # Declare the return variable.
1770        my @retVal = ();
1771        # Make sue we have filter parameters.
1772        my $realParms = (defined($filterParms) ? $filterParms : []);
1773        # Create the query by converting the filter.
1774        my $realFilter = $filter;
1775        for my $name (keys %AttributeParms) {
1776            $realFilter =~ s/\$$name/$AttributeParms{$name}/g;
1777        }
1778        my $query = $self->Get(['HasValueFor'], $realFilter, $realParms);
1779        # Loop through the results, forming the output attribute tuples.
1780        while (my $result = $query->Fetch()) {
1781            # Get the four values from this query result row.
1782            my ($objectID, $key, $subkey, $value) = $result->Values([$AttributeParms{object},
1783                                                                    $AttributeParms{key},
1784                                                                    $AttributeParms{subkey},
1785                                                                    $AttributeParms{value}]);
1786            # Combine the key and the subkey.
1787            my $realKey = ($subkey ? $key . $self->{splitter} . $subkey : $key);
1788            # Split the value.
1789            my @values = split $self->{splitter}, $value;
1790            # Output the result.
1791            push @retVal, [$objectID, $realKey, @values];
1792        }
1793        # Return the result.
1794        return @retVal;
1795    }
1796    
1797  =head2 Key and ID Manipulation Methods  =head2 Key and ID Manipulation Methods
1798    
1799  =head3 ParseID  =head3 ParseID

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.24

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3