Skip to content

Commit

Permalink
Merge pull request #590 from opencobra/fix-matrix
Browse files Browse the repository at this point in the history
fix: remove redundant test case
  • Loading branch information
Midnighter committed Jan 24, 2019
2 parents 92fed21 + a916da0 commit 1511f96
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 70 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ History

Next Release
------------
* Remove 'Steady-state flux solution vectors' test case.
* Improve the descriptions of stoichiometric matrix test cases.
* Fix the discovery or orphan and dead-end metabolites.
* Improve detection of metabolites that are not consumed or not produced by
only opening exchange reactions not other boundary reactions.
Expand Down
1 change: 0 additions & 1 deletion memote/suite/templates/test_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ cards:
cases:
- test_absolute_extreme_coefficient_ratio
- test_number_independent_conservation_relations
- test_number_steady_state_flux_solutions
- test_matrix_rank
- test_degrees_of_freedom
experimental:
Expand Down
57 changes: 16 additions & 41 deletions memote/suite/tests/test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
format_type="percent")
def test_absolute_extreme_coefficient_ratio(model, threshold=1e9):
"""
Show ratio of the absolute largest and smallest non-zero coefficients.
Show the ratio of the absolute largest and smallest non-zero coefficients.
This test will return the absolute largest and smallest, non-zero
coefficients from the S-Matrix. A large ratio of these values may point to
potential numerical issues when trying to solve the underlying system of
equations.
coefficients of the stoichiometric matrix. A large ratio of these values
may point to potential numerical issues when trying to solve different
mathematical optimization problems such as flux-balance analysis.
To pass this test the ratio should not exceed 10^9. This threshold has
been selected based on experience, and is likely to be adapted when more
Expand All @@ -55,13 +55,12 @@ def test_absolute_extreme_coefficient_ratio(model, threshold=1e9):
format_type="raw")
def test_number_independent_conservation_relations(model):
"""
Show number of independent conservation relations in the model.
Show the number of independent conservation relations in the model.
This test will return the number of conservation relations, i.e.
conservation pools through the left null space of the S-Matrix.
This test is not scored, as the dimension of the left null space
depends on the S-Matrix constructed, which is system-specific.
This test will return the number of conservation relations, i.e.,
conservation pools through the left null space of the stoichiometric
matrix. This test is not scored, as the dimension of the left null space
is system-specific.
"""
ann = test_number_independent_conservation_relations.annotation
Expand All @@ -71,35 +70,13 @@ def test_number_independent_conservation_relations(model):
ann["data"]))


@annotate(title="Steady-state Flux Solution Vectors",
format_type="raw")
def test_number_steady_state_flux_solutions(model):
"""
Show number of independent steady-state flux solution vectors for model.
This test will return the number of independent steady-state flux solution
vector through the null space of the S-Matrix.
This test is not scored, as the dimension of the null space depends on the
S-Matrix constructed, which is system-specific.
"""
ann = test_number_steady_state_flux_solutions.annotation
ann["data"] = matrix.number_steady_state_flux_solutions(model)
ann["message"] = wrapper.fill(
"""The number of independent steady-state flux solution vectors is {}.
""".format(ann["data"]))


@annotate(title="Rank", format_type="raw")
def test_matrix_rank(model):
"""
Show rank of the S-Matrix.
This test will return the rank of the S-Matrix of the model.
Show the rank of the stoichiometric matrix.
This test is not scored, as the rank depends on the S-Matrix constructed,
which is system-specific.
The rank of the stoichiometric matrix is system specific. It is
calculated using singular value decomposition (SVD).
"""
ann = test_matrix_rank.annotation
Expand All @@ -111,13 +88,11 @@ def test_matrix_rank(model):
@annotate(title="Degrees Of Freedom", format_type="raw")
def test_degrees_of_freedom(model):
"""
Show degrees of freedom of the S-Matrix.
This test will return the degrees of freedom, i.e. "free variables" of the
S-Matrix.
Show the degrees of freedom of the stoichiometric matrix.
This test is not scored, as the degrees of freedom depends on S-Matrix
constructed, which is system-specific.
The degrees of freedom of the stoichiometric matrix, i.e., the number
of 'free variables' is system specific and corresponds to the dimension
of the right nullspace of the matrix.
"""
ann = test_degrees_of_freedom.annotation
Expand Down
2 changes: 1 addition & 1 deletion memote/support/consistency_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def stoichiometry_matrix(metabolites, reactions):

def rank(matrix, atol=1e-13, rtol=0):
"""
Estimate the rank, i.e. the dimension of the column space, of a matrix.
Estimate the rank, i.e., the dimension of the column space, of a matrix.
The algorithm used by this function is based on the singular value
decomposition of `stoichiometry_matrix`.
Expand Down
29 changes: 12 additions & 17 deletions memote/support/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,24 @@

def absolute_extreme_coefficient_ratio(model):
"""
Return the absolute max and absolute non-zero min coefficients.
Return the maximum and minimum absolute, non-zero coefficients.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
"""
# S-Matrix with absolute values:
s_matrix, _, _ = con_helpers.stoichiometry_matrix(
model.metabolites, model.reactions
)
abs_matrix = np.absolute(s_matrix)

absolute_max_coef = np.amax(abs_matrix)
absolute_non_zero_min_coef = abs_matrix[abs_matrix > 0].min()

return (absolute_max_coef, absolute_non_zero_min_coef)
abs_matrix = np.abs(s_matrix)
return abs_matrix.max(), abs_matrix[abs_matrix > 0].min()


def number_independent_conservation_relations(model):
"""
Return the amount of conserved metabolic pools.
Return the number of conserved metabolite pools.
Parameters
----------
Expand Down Expand Up @@ -100,22 +95,22 @@ def matrix_rank(model):

def degrees_of_freedom(model):
"""
Return the degrees of freedom, i.e. number of "free variables".
Return the degrees of freedom, i.e., number of "free variables".
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
Notes:
------
Notes
-----
This specifically refers to the dimensionality of the right nullspace
of the S matrix, as dim(Null(S)) corresponds directly to the number of
free variables in the system [1]_. The forumla used calculates this using
the rank-nullity theorem [2]_.
of the stoichiometric matrix, as dim(Null(S)) corresponds directly to the
number of free variables in the system [1]_. The formula used calculates
this using the rank-nullity theorem [2]_.
References:
-----------
References
----------
.. [1] Fukuda, K. & Terlaky, T. Criss-cross methods: A fresh view on
pivot algorithms. Mathematical Programming 79, 369-395 (1997).
Expand Down
10 changes: 0 additions & 10 deletions tests/test_for_support/test_for_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,6 @@ def test_number_independent_conservation_relations(model, num):
assert matrix.number_independent_conservation_relations(model) == num


@pytest.mark.parametrize("model, num", [
("three_components_closed", 0),
("three_components_open", 1),
("x2_cycle_closed", 0),
("x2_cycle_open", 1),
], indirect=["model"])
def test_number_steady_state_flux_solutions(model, num):
assert matrix.number_steady_state_flux_solutions(model) == num


@pytest.mark.parametrize("model, num", [
("three_components_closed", 2),
("three_components_open", 3),
Expand Down

0 comments on commit 1511f96

Please sign in to comment.