Package transsys :: Module utils
[hide private]
[frames] | no frames]

Module utils

source code

Miscellaneous utilities.

Classes [hide private]
  UniformRNG
Callable class producing random floating point values from a uniform distribution.
  transrnd
Random number generator class.
  RouletteWheel
Roulette wheel for evolutionary algorithms and similar purposes.
Functions [hide private]
boolean
is_nan(x)
Determine whether x is NaN.
source code
 
parse_int(f, label, allowNone=False)
retrieves an int from a line of the form:
source code
 
parse_float(f, label, allowNone=False)
retrieves a float from a line of the form:
source code
 
parse_string(f, label)
retrieves a string from a line of the form:
source code
 
parse_boolean(f, label, allowNone=False)
retrieves a boolean value from a line of the form:
source code
 
name_value_pair(x, label)
Encode a labelled quantity in a parseable way.
source code
String
tablecell(x)
Render x as a string suitable as an R table element.
source code
 
table_row(l)
Render elements of l as a whitespace separated row.
source code
String
dictionary_tablestring(d, row_format='# %s: %s\n')
Render a dictionary as a 'table', consisting of name/value rows, formatted by the format string.
source code
int
hamming_distance(s1, s2)
Compute the Hamming distance (number of different elements) between two strings (or other sequence types).
source code
float
inner_product(v1, v2)
Compute the inner product of two vectors.
source code
 
euclidean_distance_squared(v1, v2)
Compute the square of the Euclidean distance between v1 and v2.
source code
 
euclidean_distance(v1, v2)
Compute the Euclidean distance between v1 and v2.
source code
 
euclidean_norm_squared(v)
Compute the square of the euclidean norm of v.
source code
 
euclidean_norm(v)
Compute the euclidean norm of v.
source code
 
normalised_vector(v)
Normalise a vector.
source code
tuple
mean_and_stddev(l)
Compute mean and standard deviation of a list of floating point values.
source code
 
shannon_entropy(v)
Compute the Shannon entropy of v, normalised so components add up to 1, in bits.
source code
float
uncentered_correlation(x, y)
Uncentered correlation of x and y.
source code
float
correlation_coefficient(x, y)
Compute the Pearson correlation coefficient of x and y.
source code
 
randomise_transsys_values(transsys_program, random_function, gene_name_list=None, factor_name_list=None)
Randomise numerical values in value nodes by replacing them with values obtained from the random_function.
source code
 
interval_list(interval_size_list, x0=0.0)
Make a list of interval borders of contiguous intervals of given sizes.
source code
int
find_interval_index(x, borders)
Find the index of the interval within which x is located.
source code
list
unique(l)
Compute a nonredundant list of elements in l.
source code
Function Details [hide private]

is_nan(x)

source code 

Determine whether x is NaN.

This function is a temporary solution, to be replaced if and when python provides this functionality. The current implementation returns x != x; this works with current versions of python and Linux, but cannot be guaranteed to work generally.

Parameters:
  • x - the floating point object to be tested
Returns: boolean
True if x is NaN

parse_int(f, label, allowNone=False)

source code 

retrieves an int from a line of the form:


<label>: <int>

Raises an error if label is not matched or not followed by a colon (optionally flanked by whitespace) and an int.

parse_float(f, label, allowNone=False)

source code 

retrieves a float from a line of the form:


<label>: <float>

Raises an error if label is not matched or not followed by a colon (optionally flanked by whitespace) and a float.

parse_string(f, label)

source code 

retrieves a string from a line of the form:


<label>:<string>

Raises an error if label is not matched or not followed by a colon (optionally preceded by whitespace) and a (possibly empty) string.

parse_boolean(f, label, allowNone=False)

source code 

retrieves a boolean value from a line of the form:


<label>: <booleanvalue>

Raises an error if label is not matched or not followed by a colon (optionally flanked by whitespace) and a boolean value, i.e. True, False or, if allowed, None.

name_value_pair(x, label)

source code 

Encode a labelled quantity in a parseable way.

This function can be thought of as an inverse to parse_int, parse_float and parse_string.

Parameters:
  • x - the value to be encoded
  • label - the label to be used

tablecell(x)

source code 

Render x as a string suitable as an R table element.

Currently supported types are:

  • None, rendered as NA
  • int
  • float, formatted using '%1.17e' as a format string
  • boolean, rendered as TRUE or FALSE.
Parameters:
  • x - the value to be converted to a table element
Returns: String
a string representing x

dictionary_tablestring(d, row_format='# %s: %s\n')

source code 

Render a dictionary as a 'table', consisting of name/value rows, formatted by the format string.

The format string row_format must contain exactly two string format conversions.

Parameters:
  • d (dictionary) - the dictionary to be rendered as a table
  • row_format - the format string for the rows of the table @type row_format String
Returns: String
the table as a string

hamming_distance(s1, s2)

source code 

Compute the Hamming distance (number of different elements) between two strings (or other sequence types).

Notice that this function compares objects for identity, not for equality.

Parameters:
  • s1 - first sequence
  • s2 - second sequence
Returns: int
Hamming distance between s1 and s2

inner_product(v1, v2)

source code 

Compute the inner product of two vectors.

Parameters:
  • v1 - the first vector (any sequence consisting of numeric elements)
  • v2 - the second vector (a sequence of the same length)
Returns: float
the inner product of v1 and v2

normalised_vector(v)

source code 

Normalise a vector.

Computes a vector colinear with v and with unit length.

Returns:
the normalised vector

mean_and_stddev(l)

source code 

Compute mean and standard deviation of a list of floating point values.

Returns: tuple
the mean and the standard deviation

uncentered_correlation(x, y)

source code 

Uncentered correlation of x and y.

The uncentered correlation is the cosine of the angle of x and y. This amounts to computing the correlation, "but without centering".

Notice that this is not a proper correlation. This function is used as a similarity score of gene expression profiles by Eisen et.al., and it is provided only as a means to implement their approach.

Parameters:
  • x (iterable of numeric) - vector
  • y (iterable of numeric) - vector
Returns: float
cosine of angle of x and y

correlation_coefficient(x, y)

source code 

Compute the Pearson correlation coefficient of x and y.

Parameters:
  • x (iterable of numeric) - vector
  • y (iterable of numeric) - vector
Returns: float
Pearson correlation coefficient

randomise_transsys_values(transsys_program, random_function, gene_name_list=None, factor_name_list=None)

source code 

Randomise numerical values in value nodes by replacing them with values obtained from the random_function.

gene_name_list and factor_name_list identify the genes and the factors to have their numerical values randomised. The default value of None indicates that all genes / factors should be randomised.

find_interval_index(x, borders)

source code 

Find the index of the interval within which x is located.

Uses binary search.

Returns: int
index i such that borders[i] <= x < borders[i + 1], -1 if x < borders[0], len(borders) if x >= borders[-1].

unique(l)

source code 

Compute a nonredundant list of elements in l.

The order of elements is preserved. Redundant elements are determined by comparison, and the first element is placed in the nonredundant list. Notice that if elementa are equal but not identical (e.g. 0 and 0.0), only the first one in l appears in the unique list.

Parameters:
  • l (iterable) - a list or other iterable type
Returns: list
list of unique elements