cobra.flux_analysis.fast_snp#

Provides Fast-SNP algorithm implementation for finding nullspace basis of matrix.

Functions#

_solve_snv(→ numpy.ndarray)

Optimize Fast-SNP step for given weights and direction.

_create_fast_snp_problem(...)

Create an optimization problem for Fast-SNP algorithm.

_project(→ numpy.ndarray)

Project vector w to the complement of the row space of N.

_get_condition_vector(→ numpy.ndarray)

Get a random Fast-SNP nonzero condition vector.

nullspace_fast_snp(→ numpy.ndarray)

Compute an approximate basis for the nullspace of S with coordinate directions.

Module Contents#

cobra.flux_analysis.fast_snp._solve_snv(weights: numpy.ndarray, model: optlang.interface.Model, v_list: List[optlang.interface.Variable], positive: bool) numpy.ndarray[source]#

Optimize Fast-SNP step for given weights and direction.

cobra.flux_analysis.fast_snp._create_fast_snp_problem(solver: optlang.interface, S: numpy.ndarray, directions: numpy.ndarray, v_bound: float, zero_cutoff: float, bias: float) Tuple[optlang.interface.Model, List[optlang.interface.Variable]][source]#

Create an optimization problem for Fast-SNP algorithm.

cobra.flux_analysis.fast_snp._project(N: numpy.ndarray, w: numpy.ndarray) numpy.ndarray[source]#

Project vector w to the complement of the row space of N.

cobra.flux_analysis.fast_snp._get_condition_vector(N: numpy.ndarray) numpy.ndarray[source]#

Get a random Fast-SNP nonzero condition vector.

cobra.flux_analysis.fast_snp.nullspace_fast_snp(solver: optlang.interface, S: numpy.ndarray, directions: numpy.ndarray, v_bound: float = 10000.0, zero_cutoff: float = 1e-06, bias: float = 1, required_stop_checks_num: int = 3) numpy.ndarray[source]#

Compute an approximate basis for the nullspace of S with coordinate directions.

The algorithm used by this function is described in [1].

Parameters:
  • solver ("optlang.interface") – The solver interface to use for the optimization problem. You can use model.problem to get the solver interface.

  • S (numpy.ndarray) – The matrix for which the nullspace is computed. S should be a 2-D array.

  • directions (numpy.ndarray) –

    A 2-D array with shape (k, 2) where k is the number of columns in S. This array specifies the directions of coordinates. Each row should be:

    • [0, 0] for coordinates that can be only zero

    • [0, 1] for coordinates that can be only positive

    • [-1, 0] for coordinates that can be only negative

    • [-1, 1] for coordinates that can be both positive and negative

  • v_bound (float, optional) – The bound for the variables in the optimization problem (default 1e4).

  • zero_cutoff (float, optional) – The cutoff value to consider a coordinate value as zero (default 1e-6).

  • bias (float, optional) – The bias for the non-zero constraint in the optimization problem (default 1).

  • required_stop_checks_num (int, optional) – The number of random checks to pass to prove that basis could not be expanded (default 3).

Returns:

If S is an array with shape (m, k), then an array with shape (k, n) will be returned, where n is the dimension of the nullspace of S with directions. Each column of this array is a basis vector for the nullspace; each element in numpy.dot(S, column) will be approximately zero. Each coordinate in the column will have an allowed sign according to the directions parameter.

Return type:

numpy.ndarray

References