Esempio n. 1
0
def test_stoichiometric_consistency(read_only_model):
    """
    Expect that the stoichiometry is consistent.

    Stoichiometric inconsistency violates universal constraints:
    1. Molecular masses are always positive, and
    2. On each side of a reaction the mass is conserved.
    A single incorrectly defined reaction can lead to stoichiometric
    inconsistency in the model, and consequently to unconserved metabolites.
    Similar to insufficient constraints, this may give rise to cycles which
    either produce mass from nothing or consume mass from the model.

    This test uses an implementation of the algorithm presented by
    Gevorgyan, A., M. G Poolman, and D. A Fell.
    "Detection of Stoichiometric Inconsistencies in Biomolecular Models."
    Bioinformatics 24, no. 19 (2008): 2245.
    doi: 10.1093/bioinformatics/btn425
    """
    ann = test_stoichiometric_consistency.annotation
    is_consistent = consistency.check_stoichiometric_consistency(
        read_only_model)
    ann["data"] = [] if is_consistent else get_ids(
        consistency.find_unconserved_metabolites(read_only_model))
    ann["metric"] = len(ann["data"]) / len(read_only_model.metabolites)
    ann["message"] = wrapper.fill(
        """This model contains {} ({:.2%}) unconserved
        metabolites: {}""".format(
            len(ann["data"]), ann["metric"], truncate(ann["data"])))
    assert is_consistent, ann["message"]
Esempio n. 2
0
def test_stoichiometric_consistency(model):
    """
    Expect that the stoichiometry is consistent.

    Stoichiometric inconsistency violates universal constraints:
    1. Molecular masses are always positive, and
    2. On each side of a reaction the mass is conserved.
    A single incorrectly defined reaction can lead to stoichiometric
    inconsistency in the model, and consequently to unconserved metabolites.
    Similar to insufficient constraints, this may give rise to cycles which
    either produce mass from nothing or consume mass from the model.

    Implementation:
    This test first uses an implementation of the algorithm presented in
    section 3.1 by Gevorgyan, A., M. G Poolman, and D. A Fell.
    "Detection of Stoichiometric Inconsistencies in Biomolecular Models."
    Bioinformatics 24, no. 19 (2008): 2245.
    doi: 10.1093/bioinformatics/btn425
    Should the model be inconsistent, then the list of unconserved metabolites
    is computed using the algorithm described in section 3.2 of the same
    publication.

    """
    ann = test_stoichiometric_consistency.annotation
    is_consistent = consistency.check_stoichiometric_consistency(
        model)
    ann["data"] = [] if is_consistent else get_ids(
        consistency.find_unconserved_metabolites(model))
    ann["metric"] = len(ann["data"]) / len(model.metabolites)
    ann["message"] = wrapper.fill(
        """This model contains {} ({:.2%}) unconserved
        metabolites: {}""".format(
            len(ann["data"]), ann["metric"], truncate(ann["data"])))
    assert is_consistent, ann["message"]
Esempio n. 3
0
def test_stoichiometric_consistency(read_only_model, store):
    """Expect that the stoichiometry is mass-balanced."""
    is_consistent = consistency.check_stoichiometric_consistency(
        read_only_model)
    store["is_consistent"] = is_consistent
    unconserved = [] if is_consistent else [
        met.id
        for met in consistency.find_unconserved_metabolites(read_only_model)
    ]
    store["unconserved_metabolites"] = unconserved
    assert is_consistent,\
        "The following metabolites are involved in inconsistent reactions:"\
        " {}".format(", ".join(unconserved))
Esempio n. 4
0
def test_stoichiometric_consistency(model):
    """
    Expect that the stoichiometry is consistent.

    Stoichiometric inconsistency violates universal constraints:
    1. Molecular masses are always positive, and
    2. On each side of a reaction the mass is conserved.
    A single incorrectly defined reaction can lead to stoichiometric
    inconsistency in the model, and consequently to unconserved metabolites.
    Similar to insufficient constraints, this may give rise to cycles which
    either produce mass from nothing or consume mass from the model.

    Implementation:
    This test first uses an implementation of the algorithm presented in
    section 3.1 by Gevorgyan, A., M. G Poolman, and D. A Fell.
    "Detection of Stoichiometric Inconsistencies in Biomolecular Models."
    Bioinformatics 24, no. 19 (2008): 2245.
    doi: 10.1093/bioinformatics/btn425
    Should the model be inconsistent, then the list of unconserved metabolites
    is computed using the algorithm described in section 3.2 of the same
    publication. In addition, the list of min unconservable sets is computed
    using the algorithm described in section 3.3.

    """
    ann = test_stoichiometric_consistency.annotation
    is_consistent = consistency.check_stoichiometric_consistency(model)
    ann["data"] = {
        "unconserved_metabolites": [] if is_consistent else get_ids(
            consistency.find_unconserved_metabolites(model)),
        "minimal_unconservable_sets": [] if is_consistent else [
            get_ids(mets)
            for mets in consistency.find_inconsistent_min_stoichiometry(model)
        ],
    }
    ann["metric"] = len(ann["data"]["unconserved_metabolites"]) / len(
        model.metabolites)
    ann["message"] = wrapper.fill(
        """This model contains {} ({:.2%}) unconserved
        metabolites: {}; and {} minimal unconservable sets: {}""".format(
            len(ann["data"]["unconserved_metabolites"]),
            ann["metric"],
            truncate(ann["data"]["unconserved_metabolites"]),
            len(ann["data"]["minimal_unconservable_sets"]),
            truncate(ann["data"]["minimal_unconservable_sets"]),
        ))
    assert is_consistent, ann["message"]
Esempio n. 5
0
def test_find_unconserved_metabolites(model, inconsistent):
    unconserved_mets = consistency.find_unconserved_metabolites(model)
    assert set([met.id for met in unconserved_mets]) == set(inconsistent)
Esempio n. 6
0
def test_find_unconserved_metabolites(model, inconsistent):
    unconserved_mets = consistency.find_unconserved_metabolites(model)
    assert set([met.id for met in unconserved_mets]) == set(inconsistent)