|
4 | 4 | import pytest |
5 | 5 | import sys |
6 | 6 | from pytfa.io.json import json_dumps_model, json_loads_model |
| 7 | +from pytfa.thermo.equilibrator import build_thermo_from_equilibrator |
| 8 | +from pytfa import ThermoModel |
| 9 | +from settings import small_model |
7 | 10 |
|
8 | 11 |
|
9 | 12 |
|
|
14 | 17 | def test_load_with_equi_thermo(request): |
15 | 18 | """Build thermo data structure with equilibrator.""" |
16 | 19 | t_model = request.config.cache.get('model', None) |
17 | | - from pytfa.thermo.equilibrator import build_thermo_from_equilibrator |
18 | | - from pytfa import ThermoModel |
19 | | - from settings import cobra_model |
20 | | - cmodel = cobra_model.copy() |
| 20 | + cmodel = small_model.copy() |
21 | 21 | for met in cmodel.metabolites: |
22 | 22 | # normalize but don't overwrite |
23 | | - met.annotation["seed.compound"] = met.annotation["seed_id"] |
| 23 | + if "seed_id" in met.annotation: |
| 24 | + met.annotation["seed.compound"] = met.annotation["seed_id"] |
24 | 25 | thermo_data = build_thermo_from_equilibrator(cmodel) |
25 | 26 | t_model = ThermoModel(thermo_data, cmodel) |
26 | 27 | t_model.solver = "optlang-glpk" |
@@ -50,6 +51,45 @@ def test_equilibrator_conversion(request): |
50 | 51 |
|
51 | 52 | @pytest.mark.dependency(depends=['test_equilibrator_conversion']) |
52 | 53 | @pytest.mark.skipif(sys.version_info < (3, 6), reason="requires >= python3.6") |
| 54 | +def test_equilibrator_deltag_loaded(request): |
| 55 | + """Test that deltaG values are actually loaded from equilibrator.""" |
| 56 | + # Get the original cobra model and rebuild thermo_data to check it directly |
| 57 | + |
| 58 | + cmodel = small_model.copy() |
| 59 | + for met in cmodel.metabolites: |
| 60 | + # normalize but don't overwrite |
| 61 | + if "seed_id" in met.annotation: |
| 62 | + met.annotation["seed.compound"] = met.annotation["seed_id"] |
| 63 | + |
| 64 | + # Build thermo data from equilibrator |
| 65 | + thermo_data = build_thermo_from_equilibrator(cmodel) |
| 66 | + |
| 67 | + print(f"Thermo data structure: {thermo_data['name']}") |
| 68 | + print(f"Units: {thermo_data['units']}") |
| 69 | + |
| 70 | + # Check metabolites in thermo_data |
| 71 | + metabolites_with_deltag = 0 |
| 72 | + sample_mets = [] |
| 73 | + |
| 74 | + for met_data in thermo_data['metabolites']: |
| 75 | + if 'DeltaGf_tr' in met_data: |
| 76 | + metabolites_with_deltag += 1 |
| 77 | + if len(sample_mets) < 5: # Collect some samples |
| 78 | + sample_mets.append((met_data['id'], met_data['DeltaGf_tr'])) |
| 79 | + |
| 80 | + print(f"Found {metabolites_with_deltag} metabolites with deltaG formation values from equilibrator") |
| 81 | + print("Sample metabolites with deltaG values:") |
| 82 | + for met_id, deltag in sample_mets: |
| 83 | + print(f" {met_id}: {deltag} {thermo_data['units']}") |
| 84 | + |
| 85 | + # There should be at least some metabolites with deltaG values |
| 86 | + assert metabolites_with_deltag > 0, f"No deltaG formation values found in thermo_data! Expected > 0, got {metabolites_with_deltag}" |
| 87 | + |
| 88 | + return metabolites_with_deltag |
| 89 | + |
| 90 | + |
| 91 | +@pytest.mark.dependency(depends=['test_equilibrator_deltag_loaded']) |
| 92 | +@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires >= python3.6") |
53 | 93 | def test_equilibrator_optim(request): |
54 | 94 | """LP optimization by the usual method in `ThermoModel`.""" |
55 | 95 | t_model = json_loads_model(request.config.cache.get('model',None)) |
|
0 commit comments