cobra.flux_analysis.fast_snp
============================

.. py:module:: cobra.flux_analysis.fast_snp

.. autoapi-nested-parse::

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



Functions
---------

.. autoapisummary::

   cobra.flux_analysis.fast_snp._solve_snv
   cobra.flux_analysis.fast_snp._create_fast_snp_problem
   cobra.flux_analysis.fast_snp._project
   cobra.flux_analysis.fast_snp._get_condition_vector
   cobra.flux_analysis.fast_snp.nullspace_fast_snp


Module Contents
---------------

.. py:function:: _solve_snv(weights: numpy.ndarray, model: optlang.interface.Model, v_list: List[optlang.interface.Variable], positive: bool) -> numpy.ndarray

   Optimize Fast-SNP step for given weights and direction.


.. py:function:: _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]]

   Create an optimization problem for Fast-SNP algorithm.


.. py:function:: _project(N: numpy.ndarray, w: numpy.ndarray) -> numpy.ndarray

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


.. py:function:: _get_condition_vector(N: numpy.ndarray) -> numpy.ndarray

   Get a random Fast-SNP nonzero condition vector.


.. py:function:: 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

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

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

   :param solver: The solver interface to use for the optimization problem.
                  You can use `model.problem` to get the solver interface.
   :type solver: "optlang.interface"
   :param S: The matrix for which the nullspace is computed.
             `S` should be a 2-D array.
   :type S: numpy.ndarray
   :param directions: 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
   :type directions: numpy.ndarray
   :param v_bound: The bound for the variables in the optimization problem (default 1e4).
   :type v_bound: float, optional
   :param zero_cutoff: The cutoff value to consider a coordinate value as zero (default 1e-6).
   :type zero_cutoff: float, optional
   :param bias: The bias for the non-zero constraint in the optimization problem
                (default 1).
   :type bias: float, optional
   :param required_stop_checks_num: The number of random checks to pass to prove that basis
                                    could not be expanded (default 3).
   :type required_stop_checks_num: int, optional

   :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.
   :rtype: numpy.ndarray

   .. rubric:: References

   .. [1] Fast-SNP: a fast matrix pre-processing algorithm for efficient
      loopless flux optimization of metabolic models. Saa PA, Nielsen LK.
      Bioinformatics. 2016 Dec;32(24):3807–3814. doi: 10.1093/bioinformatics/btw555.


