[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.21, Sun Feb 18 22:13:53 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 488  Line 488 
488                  # An ID without a key is a serious error.                  # An ID without a key is a serious error.
489                  my $lines = $retVal->Ask('linesIn');                  my $lines = $retVal->Ask('linesIn');
490                  Confess("Line $lines in $fileName has no attribute key.");                  Confess("Line $lines in $fileName has no attribute key.");
491                } elsif (! @values) {
492                    # A line with no values is not allowed.
493                    my $lines = $retVal->Ask('linesIn');
494                    Trace("Line $lines for key $key has no attribute values.") if T(1);
495                    $retVal->Add(skipped => 1);
496              } else {              } else {
497                  # The key contains a real part and an optional sub-part. We need the real part.                  # The key contains a real part and an optional sub-part. We need the real part.
498                  my ($realKey, $subKey) = $self->SplitKey($key);                  my ($realKey, $subKey) = $self->SplitKey($key);
# Line 1722  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
# Line 1840  Line 1912 
1912    
1913  =item RETURN  =item RETURN
1914    
1915  Returns a B<DBObject> for the attribute value's target object.  Returns a B<ERDBObject> for the attribute value's target object.
1916    
1917  =back  =back
1918    

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3