micom-dev / micom

Python package to study microbial communities using metabolic modeling.
https://micom-dev.github.io/micom
Apache License 2.0
89 stars 18 forks source link

Add a more permissible media completion #101

Closed cdiener closed 2 years ago

cdiener commented 2 years ago

The medium completion functions now have a flag that allows adding additional flux to components already in the candidate medium. The default is now changed to that new non-strict mode which makes it much easier and more efficient to complete media. In that case the max_added_import amount now specifies the maximum flux added on top the limit specified in the candidate medium.

In [1]: import micom as mm

In [2]: com = mm.Community(mm.data.test_taxonomy())
Building ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00

In [3]: med = mm.media.minimal_medium(com, 0.85, 0.85)

In [4]: med
Out[4]: 
EX_glc__D_m    10.000000
EX_nh4_m        4.634880
EX_o2_m        20.757401
EX_pi_m         3.126895
dtype: float64

In [5]: co = mm.media.complete_medium(com, growth=0.95, min_growth=0.95, medium=med, strict=med.index)  # old
[18:43:53] WARNING  solver encountered an error infeasible                                                                                                                              solution.py:220
---------------------------------------------------------------------------
OptimizationError                         Traceback (most recent call last)
Input In [5], in <cell line: 1>()
----> 1 co = mm.media.complete_medium(com, growth=0.95, min_growth=0.95, medium=med, strict=med.index)

File ~/code/micom/micom/media.py:380, in complete_medium(model, medium, growth, min_growth, max_import, minimize_components, weights, strict)
    378             sol = None
    379 if sol is None:
--> 380     raise OptimizationError(
    381         "Could not find a solution that completes the medium :("
    382     )
    383 completed = pd.Series(dtype="float64")
    384 for rxn in model.exchanges:

OptimizationError: Could not find a solution that completes the medium :(

In [6]: co = mm.media.complete_medium(com, growth=0.95, min_growth=0.95, medium=med)  # new

In [7]: co
Out[7]: 
EX_fru_m        0.965127
EX_glc__D_m    11.000000
EX_gln__L_m     0.272640
EX_nh4_m        4.634880
EX_o2_m        20.757401
EX_pi_m         3.494765
dtype: float64

In [8]: co - med
Out[8]: 
EX_fru_m           NaN
EX_glc__D_m    1.00000
EX_gln__L_m        NaN
EX_nh4_m       0.00000
EX_o2_m        0.00000
EX_pi_m        0.36787
dtype: float64
codecov[bot] commented 2 years ago

Codecov Report

Base: 77.64% // Head: 79.19% // Increases project coverage by +1.54% :tada:

Coverage data is based on head (3db7e9e) compared to base (591c7a4). Patch coverage: 84.61% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #101 +/- ## ========================================== + Coverage 77.64% 79.19% +1.54% ========================================== Files 32 30 -2 Lines 1991 1831 -160 Branches 377 337 -40 ========================================== - Hits 1546 1450 -96 + Misses 319 264 -55 + Partials 126 117 -9 ``` | [Impacted Files](https://codecov.io/gh/micom-dev/micom/pull/101?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=micom-dev) | Coverage Δ | | |---|---|---| | [micom/workflows/db\_media.py](https://codecov.io/gh/micom-dev/micom/pull/101/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=micom-dev#diff-bWljb20vd29ya2Zsb3dzL2RiX21lZGlhLnB5) | `45.94% <83.33%> (+27.85%)` | :arrow_up: | | [micom/workflows/\_\_init\_\_.py](https://codecov.io/gh/micom-dev/micom/pull/101/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=micom-dev#diff-bWljb20vd29ya2Zsb3dzL19faW5pdF9fLnB5) | `100.00% <100.00%> (ø)` | | | [micom/media.py](https://codecov.io/gh/micom-dev/micom/pull/101/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=micom-dev#diff-bWljb20vbWVkaWEucHk=) | | | | [micom/\_\_init\_\_.py](https://codecov.io/gh/micom-dev/micom/pull/101/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=micom-dev#diff-bWljb20vX19pbml0X18ucHk=) | | | | [micom/solution.py](https://codecov.io/gh/micom-dev/micom/pull/101/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=micom-dev#diff-bWljb20vc29sdXRpb24ucHk=) | `75.49% <0.00%> (+1.32%)` | :arrow_up: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=micom-dev). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=micom-dev)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.