[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.49, Wed Jun 21 03:36:03 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        Trace("Column header count is " . scalar(@headers) . ".") if T(4);
2175        # Determine whether we have a number or a name.
2176        if ($columnIdentifier =~ /^\d+$/) {
2177            # Here we have a number. Subtract 1 and validate the result.
2178            $retVal = $columnIdentifier - 1;
2179            if ($retVal < 0 || $retVal > $#headers) {
2180                Confess("Invalid column identifer \"$columnIdentifier\": value out of range.");
2181            }
2182        } else {
2183            # Here we have a name. We need to find it in the list.
2184            for (my $i = 0; $i <= $#headers && ! defined($retVal); $i++) {
2185                if ($headers[$i] eq $columnIdentifier) {
2186                    $retVal = $i;
2187                }
2188            }
2189            if (! defined($retVal)) {
2190                Confess("Invalid column identifier \"$columnIdentifier\": value not found.");
2191            }
2192        }
2193        # Return the result.
2194        return $retVal;
2195    }
2196    
2197    =head3 ParseColumns
2198    
2199    C<< my @columns = ERDB->ParseColumns($line); >>
2200    
2201    Convert the specified data line to a list of columns.
2202    
2203    =over 4
2204    
2205    =item line
2206    
2207    A data mining input, consisting of a tab-separated list of columns terminated by a
2208    new-line.
2209    
2210    =item RETURN
2211    
2212    Returns a list consisting of the column values.
2213    
2214    =back
2215    
2216    =cut
2217    
2218    sub ParseColumns {
2219        # Get the parameters.
2220        my ($self, $line) = @_;
2221        # Chop off the line-end.
2222        chomp $line;
2223        # Split it into a list.
2224        my @retVal = split(/\t/, $line);
2225        # Return the result.
2226        return @retVal;
2227    }
2228    
2229  =head2 Internal Utility Methods  =head2 Internal Utility Methods
2230    
2231  =head3 SetupSQL  =head3 SetupSQL

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3