|
| 1 | +"""Tests for ``yeastgem.curation`` against the real yeast-GEM model. |
| 2 | +
|
| 3 | +Unit-level coverage of the generic engine lives upstream in |
| 4 | +``raven_python/tests/test_curation.py``; here we just verify the |
| 5 | +yeast-GEM shim picks up the ``s_`` / ``r_`` prefixes and that real |
| 6 | +v8_*/v9_* TSVs apply cleanly. |
| 7 | +""" |
| 8 | +from __future__ import annotations |
| 9 | + |
| 10 | +import pandas as pd |
| 11 | + |
| 12 | +from yeastgem import curation |
| 13 | +from yeastgem.io import REPO_PATH |
| 14 | + |
| 15 | + |
| 16 | +def test_new_met_uses_s_prefix(model): |
| 17 | + mutated = model.copy() |
| 18 | + df = pd.DataFrame([ |
| 19 | + {"metNames": "test_metabolite_phase_6", "comps": "c", |
| 20 | + "formula": "C2H6O", "charge": 0, "inchi": "", "metNotes": ""}, |
| 21 | + ]) |
| 22 | + result = curation.curate_mets_rxns_genes(mutated, mets_df=df) |
| 23 | + assert len(result.added_metabolites) == 1 |
| 24 | + assert result.added_metabolites[0].startswith("s_") |
| 25 | + |
| 26 | + |
| 27 | +def test_new_rxn_uses_r_prefix(model): |
| 28 | + mutated = model.copy() |
| 29 | + # Use an existing yeast met (s_0794 = H+[c]) to avoid the |
| 30 | + # add-new-met machinery. |
| 31 | + atp = next(m for m in mutated.metabolites if m.name == "ATP" and m.compartment == "c") |
| 32 | + rxns_df = pd.DataFrame([ |
| 33 | + {"rxnNames": "phase6 test rxn", "grRules": "", "lb": 0, "ub": 1000, |
| 34 | + "rev": 0, "subSystems": "", "eccodes": "", "rxnNotes": "", |
| 35 | + "rxnReferences": "", "rxnConfidenceScores": ""}, |
| 36 | + ]) |
| 37 | + coeffs_df = pd.DataFrame([ |
| 38 | + {"rxnNames": "phase6 test rxn", "metNames": atp.name, "comps": "c", |
| 39 | + "coefficient": -1.0}, |
| 40 | + {"rxnNames": "phase6 test rxn", "metNames": "H+", "comps": "c", |
| 41 | + "coefficient": 1.0}, |
| 42 | + ]) |
| 43 | + result = curation.curate_mets_rxns_genes( |
| 44 | + mutated, rxns_df=rxns_df, rxns_coeffs_df=coeffs_df, |
| 45 | + ) |
| 46 | + assert len(result.added_reactions) == 1 |
| 47 | + assert result.added_reactions[0].startswith("r_") |
| 48 | + |
| 49 | + |
| 50 | +def test_real_curation_tsvs_v8_6_3_volpolyp(model): |
| 51 | + """Apply the v8_6_3 VolPolyP curation files end-to-end. Mostly a |
| 52 | + smoke test: confirm no exception, and that some entities were |
| 53 | + added/updated.""" |
| 54 | + mutated = model.copy() |
| 55 | + data_dir = REPO_PATH / "data" / "modelCuration" / "v8_6_3" |
| 56 | + |
| 57 | + result = curation.curate_mets_rxns_genes_from_tsv( |
| 58 | + mutated, |
| 59 | + mets_tsv=data_dir / "VolPolyPMets.tsv", |
| 60 | + genes_tsv=data_dir / "VolPolyPGenes.tsv", |
| 61 | + rxns_tsv=data_dir / "VolPolyPRxns.tsv", |
| 62 | + rxns_coeffs_tsv=data_dir / "VolPolyPRxnsCoeffs.tsv", |
| 63 | + ) |
| 64 | + # We applied a TSV pack — at minimum some entity should land. |
| 65 | + touched = ( |
| 66 | + len(result.added_metabolites) + len(result.updated_metabolites) |
| 67 | + + len(result.added_genes) + len(result.updated_genes) |
| 68 | + + len(result.added_reactions) + len(result.updated_reactions) |
| 69 | + ) |
| 70 | + assert touched > 0 |
| 71 | + |
| 72 | + |
| 73 | +def test_empty_call_no_op(model): |
| 74 | + mutated = model.copy() |
| 75 | + result = curation.curate_mets_rxns_genes(mutated) |
| 76 | + assert not result |
0 commit comments