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

Diff of /Sprout/ERDB.pm

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

revision 1.46, Thu Jun 8 19:42:06 2006 UTC revision 1.48, Wed Jun 21 03:12:20 2006 UTC
# Line 1391  Line 1391 
1391  would return the number of genomes for the genus I<homo>. It is conceivable, however,  would return the number of genomes for the genus I<homo>. It is conceivable, however,
1392  to use it to return records based on a join. For example,  to use it to return records based on a join. For example,
1393    
1394      my $count = $erdb->GetCount(['Feature', 'Genome'], 'Genome(genus-species) LIKE ?',      my $count = $erdb->GetCount(['HasFeature', 'Genome'], 'Genome(genus-species) LIKE ?',
1395                                  ['homo %']);                                  ['homo %']);
1396    
1397  would return the number of features for genomes in the genus I<homo>. Note that  would return the number of features for genomes in the genus I<homo>. Note that
# Line 1433  Line 1433 
1433      my ($self, $objectNames, $filter, $params) = @_;      my ($self, $objectNames, $filter, $params) = @_;
1434      # Declare the return variable.      # Declare the return variable.
1435      my $retVal;      my $retVal;
1436        # Find out if we're counting an entity or a relationship.
1437        my $countedField;
1438        if ($self->IsEntity($objectNames->[0])) {
1439            $countedField = "id";
1440        } else {
1441            # For a relationship we count the to-link because it's usually more
1442            # numerous. Note we're automatically converting to the SQL form
1443            # of the field name (to_link vs. to-link).
1444            $countedField = "to_link";
1445        }
1446      # Create the SQL command suffix to get the desired records.      # Create the SQL command suffix to get the desired records.
1447      my ($suffix, $mappedNameListRef, $mappedNameHashRef) = $self->_SetupSQL($objectNames,      my ($suffix, $mappedNameListRef, $mappedNameHashRef) = $self->_SetupSQL($objectNames,
1448                                                                              $filter);                                                                              $filter);
1449      # Prefix it with text telling it we want a record count.      # Prefix it with text telling it we want a record count.
1450      my $firstObject = $mappedNameListRef->[0];      my $firstObject = $mappedNameListRef->[0];
1451      my $command = "SELECT COUNT($firstObject.id) $suffix";      my $command = "SELECT COUNT($firstObject.$countedField) $suffix";
1452      # Prepare and execute the command.      # Prepare and execute the command.
1453      my $sth = $self->_GetStatementHandle($command, $params);      my $sth = $self->_GetStatementHandle($command, $params);
1454      # Get the count value.      # Get the count value.
# Line 2062  Line 2072 
2072      return $objectData->{Fields};      return $objectData->{Fields};
2073  }  }
2074    
2075    =head2 Data Mining Methods
2076    
2077  =head3 GetUsefulCrossValues  =head3 GetUsefulCrossValues
2078    
2079  C<< my @attrNames = $sprout->GetUsefulCrossValues($sourceEntity, $relationship); >>  C<< my @attrNames = $sprout->GetUsefulCrossValues($sourceEntity, $relationship); >>
# Line 2123  Line 2135 
2135      return @retVal;      return @retVal;
2136  }  }
2137    
2138    =head3 FindColumn
2139    
2140    C<< my $colIndex = ERDB::FindColumn($headerLine, $columnIdentifier); >>
2141    
2142    Return the location a desired column in a data mining header line. The data
2143    mining header line is a tab-separated list of column names. The column
2144    identifier is either the numerical index of a column or the actual column
2145    name.
2146    
2147    =over 4
2148    
2149    =item headerLine
2150    
2151    The header line from a data mining command, which consists of a tab-separated
2152    list of column names.
2153    
2154    =item columnIdentifier
2155    
2156    Either the ordinal number of the desired column (1-based), or the name of the
2157    desired column.
2158    
2159    =item RETURN
2160    
2161    Returns the array index (0-based) of the desired column.
2162    
2163    =back
2164    
2165    =cut
2166    
2167    sub FindColumn {
2168        # Get the parameters.
2169        my ($headerLine, $columnIdentifier) = @_;
2170        # Declare the return variable.
2171        my $retVal;
2172        # Split the header line into column names.
2173        my @headers = ParseColumns($headerLine);
2174        # Determine whether we have a number or a name.
2175        if ($columnIdentifier =~ /^\d+$/) {
2176            # Here we have a number. Subtract 1 and validate the result.
2177            $retVal = $columnIdentifier - 1;
2178            if ($retVal < 0 || $retVal > $#headers) {
2179                Confess("Invalid column identifer \"$columnIdentifier\": value out of range.");
2180            }
2181        } else {
2182            # Here we have a name. We need to find it in the list.
2183            for (my $i = 0; $i <= $#headers && ! defined($retVal); $i++) {
2184                if ($headers[$i] eq $columnIdentifier) {
2185                    $retVal = $i;
2186                }
2187            }
2188            if (! defined($retVal)) {
2189                Confess("Invalid column identifier \"$columnIdentifier\": value not found.");
2190            }
2191        }
2192        # Return the result.
2193        return $retVal;
2194    }
2195    
2196    =head3 ParseColumns
2197    
2198    C<< my @columns = ERDB->ParseColumns($line); >>
2199    
2200    Convert the specified data line to a list of columns.
2201    
2202    =over 4
2203    
2204    =item line
2205    
2206    A data mining input, consisting of a tab-separated list of columns terminated by a
2207    new-line.
2208    
2209    =item RETURN
2210    
2211    Returns a list consisting of the column values.
2212    
2213    =back
2214    
2215    =cut
2216    
2217    sub ParseColumns {
2218        # Get the parameters.
2219        my ($self, $line) = @_;
2220        # Chop off the line-end.
2221        chomp $line;
2222        # Split it into a list.
2223        my @retVal = split(/\t/, $line);
2224        # Return the result.
2225        return @retVal;
2226    }
2227    
2228  =head2 Internal Utility Methods  =head2 Internal Utility Methods
2229    
2230  =head3 SetupSQL  =head3 SetupSQL

Legend:
Removed from v.1.46  
changed lines
  Added in v.1.48

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3