Skip to content

Commit

Permalink
fix: require that finding of transp rxns relies on compartments. (#531)
Browse files Browse the repository at this point in the history
* fix: require that finding of transp rxns relies on compartments.

* fix: make all test cases include compartments.

* fix: ye olde flake8

* fix: remove duplicated lines

* test: extend transport rxn test cases by the test model from #528

* chore: update History.rst
  • Loading branch information
ChristianLieven committed Jan 22, 2019
1 parent 03ecd8b commit 7191633
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 6 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ History

Next Release
------------
* Fix bug which involved find_transport_reactions to ignore compartments.
* Internal change to use model context rather than copy.
* Internal changes to JSON structure.
* Remove tests for metabolite inconsistency with closed bounds. The results
Expand Down
3 changes: 3 additions & 0 deletions memote/support/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ def find_transport_reactions(model):
transport_reactions = []
transport_rxn_candidates = set(model.reactions) - set(model.boundary) \
- set(find_biomass_reaction(model))
transport_rxn_candidates = set(
[rxn for rxn in transport_rxn_candidates if len(rxn.compartments) >= 2]
)
# Add all labeled transport reactions
sbo_matches = set([rxn for rxn in transport_rxn_candidates if
rxn.annotation is not None and
Expand Down
72 changes: 66 additions & 6 deletions tests/test_for_support/test_for_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ def energy_transfer_annotations(base):
@register_with(MODEL_REGISTRY)
def labeled_reaction(base):
"""Provide a model with a labeled transport reaction."""
a = cobra.Metabolite("a")
b = cobra.Metabolite("b")
a = cobra.Metabolite("a", compartment="c")
b = cobra.Metabolite("b", compartment="p")
rxn = cobra.Reaction("rxn")
rxn.annotation["sbo"] = "SBO:0000655"
rxn.add_metabolites({a: -1, b: 1})
Expand All @@ -239,6 +239,59 @@ def unlabeled_reaction(base):
return base


@register_with(MODEL_REGISTRY)
def ndpk1_annotation(base):
"""Provide a model with a reportedly false positive."""
a = cobra.Metabolite("atp_c", compartment="c")
b = cobra.Metabolite("adp_c", compartment="c")
c = cobra.Metabolite("gtp_c", compartment="c")
d = cobra.Metabolite("gdp_c", compartment="c")
b.charge = -3
b.formula = "C10H12N5O10P2"
b.annotation = {
"chebi": "45626",
"kegg.compound": "cpd00008",
"biocyc": "ADP",
"seed.compound": "cpd00008",
"pubchem": "6022",
"fc_source": "MetaCyc"
}
a.charge = -4
a.formula = "C10H12N5O13P3"
a.annotation = {
"chebi": "30616",
"kegg.compound": "C00002",
"biocyc": "ATP",
"seed.compound": "cpd00002",
"pubchem": "5957",
"fc_source": "MetaCyc"
}
c.charge = -4
c.formula = "C10H12N5O14P3"
c.annotation = {
"chebi": "57600",
"kegg.compound": "C00044",
"biocyc": "GTP",
"seed.compound": "cpd00038",
"pubchem": "6830",
"fc_source": "MetaCyc"
}
d.charge = -3
d.formula = "C10H12N5O11P2"
d.annotation = {
"chebi": "58189",
"kegg.compound": "C00035",
"biocyc": "GDP",
"seed.compound": "cpd00031",
"pubchem": "8977",
"fc_source": "MetaCyc"
}
rxn = cobra.Reaction("NDPK1")
rxn.add_metabolites({a: -1, d: -1, b: 1, c: 1})
base.add_reactions([rxn])
return base


@register_with(MODEL_REGISTRY)
def converting_reactions(base):
"""Provide a model with a couple of converting reaction."""
Expand Down Expand Up @@ -290,11 +343,11 @@ def find_met_id(base):
g = cobra.Metabolite("cpd00010", compartment='c')
# ADP - Cryptic ID - MNX ID in the annotation
h = cobra.Metabolite("OVER9000_c0", compartment='c')
h.annotation = {"metanetx.chemical":"MNXM7"}
h.annotation = {"metanetx.chemical": "MNXM7"}
# Proton - Cryptic ID - Chebi array in the annotation
i = cobra.Metabolite("x12", compartment='c')
i.annotation = {"chebi":["15378", "10744", "13357", "5584",
"24636", "29233", "29234"]}
i.annotation = {"chebi": ["15378", "10744", "13357", "5584",
"24636", "29233", "29234"]}
base.add_metabolites([a, b, c, d, e, f, g, h, i])
return base

Expand Down Expand Up @@ -416,6 +469,7 @@ def biomass_metabolite(base):
base.add_reactions([rxn1, rxn2])
return base


@register_with(REACTION_REGISTRY)
def transport_reaction_true():
"""Provide a transport reaction identifiable through met annotations"""
Expand All @@ -427,6 +481,7 @@ def transport_reaction_true():
r.add_metabolites({a: -1, b: 1})
return r


@register_with(REACTION_REGISTRY)
def transport_reaction_missing_annotation():
"""Provide a transport reaction identifiable through met annotations"""
Expand All @@ -436,6 +491,7 @@ def transport_reaction_missing_annotation():
r.add_metabolites({a: -1, b: 1})
return r


@register_with(REACTION_REGISTRY)
def transport_reaction_missing_values():
"""Provide a transport reaction identifiable through met annotations"""
Expand All @@ -447,6 +503,7 @@ def transport_reaction_missing_values():
r.add_metabolites({a: -1, b: 1})
return r


@register_with(REACTION_REGISTRY)
def transport_reaction_false():
"""Provide a fake transport reaction that uses SBO terms"""
Expand All @@ -462,6 +519,7 @@ def transport_reaction_false():
r.add_metabolites({a: -1, b: 1, c: -1, d: 1})
return r


@pytest.mark.parametrize("model, num", [
("uni_anti_symport_formulae", 3),
("uni_anti_symport_annotations", 3),
Expand All @@ -474,7 +532,8 @@ def transport_reaction_false():
("phosphotransferase_system_formulae", 1),
("phosphotransferase_system_annotations", 0),
("labeled_reaction", 1),
("unlabeled_reaction", 0)
("unlabeled_reaction", 0),
("ndpk1_annotation", 0)
], indirect=["model"])
def test_find_transport_reactions(model, num):
"""Expect amount of transporters to be identified correctly."""
Expand Down Expand Up @@ -601,6 +660,7 @@ def test_find_biomass_reaction(model, expected):
"""
assert len(helpers.find_biomass_reaction(model)) == expected


@pytest.mark.parametrize("reaction, boolean", [
("transport_reaction_true", True),
("transport_reaction_false", None),
Expand Down

0 comments on commit 7191633

Please sign in to comment.