Skip to content

Commit

Permalink
hotfix growth #79
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-Hades committed Feb 14, 2024
1 parent b7a5de1 commit 607a348
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 16 deletions.
93 changes: 86 additions & 7 deletions dev/CB_under_construction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/brune/miniconda3/envs/sprg/lib/python3.10/site-packages/pydantic/_internal/_config.py:322: UserWarning: Valid config keys have changed in V2:\n",
"* 'underscore_attrs_are_private' has been removed\n",
" warnings.warn(message, UserWarning)\n"
]
}
],
"source": [
"# TESTING for Tobias - this stays for a bit \n",
"from refinegems.utility.io import load_model\n",
Expand All @@ -90,17 +100,86 @@
"test_model = load_model(test_model_path,'cobra')\n",
"\n",
"m = load_medium_from_db('LB')\n",
"l = load_medium_from_db('SNM3')\n",
"test = growth_analysis(test_model,[m,l], retrieve='plot')"
"l = load_medium_from_db('M9')\n",
"s = load_medium_from_db('SNM3')\n",
"test = growth_analysis(test_model,[m,l,s], retrieve='report', supplements='std')"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>model_name</th>\n",
" <th>medium_name</th>\n",
" <th>growth_value</th>\n",
" <th>doubling_time</th>\n",
" <th>additives</th>\n",
" <th>no_exchange</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Kp_std</td>\n",
" <td>LB</td>\n",
" <td>5.56527</td>\n",
" <td>7.472922</td>\n",
" <td>None</td>\n",
" <td>[EX_pydxn_e, EX_pydx_e, EX_lipt_e, EX_nh3_e, E...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Kp_std</td>\n",
" <td>M9</td>\n",
" <td>0.00000</td>\n",
" <td>0.000000</td>\n",
" <td>None</td>\n",
" <td>[EX_nh3_e, EX_glc__bD_e]</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" model_name medium_name growth_value doubling_time additives \\\n",
"0 Kp_std LB 5.56527 7.472922 None \n",
"1 Kp_std M9 0.00000 0.000000 None \n",
"\n",
" no_exchange \n",
"0 [EX_pydxn_e, EX_pydx_e, EX_lipt_e, EX_nh3_e, E... \n",
"1 [EX_nh3_e, EX_glc__bD_e] "
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"test.plot_growth()"
"# test.plot_growth(unit='h')\n",
"test.to_table()"
]
},
{
Expand Down
15 changes: 6 additions & 9 deletions src/refinegems/analysis/growth.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def get_uptake(model: cobraModel, type: str, exchange_regex:str='^EX') -> list[s
case 'minimal' | 'min':
with model:
minimal = cobra.medium.minimal_medium(model)
print(minimal)
# print(minimal)
return list(minimal.index)
# return standart, non-zero flux compounds
case 'standard' | 'std':
Expand Down Expand Up @@ -166,7 +166,7 @@ def find_growth_essential_exchanges(model: cobraModel, growth_medium: dict, stan
list[str]: The list of exchanges essential for growth.
"""
with model:
if not standard_uptake:
if standard_uptake:
# combine standard and second medium, set all fluxes to 10.0 for standard
standard_medium = {i: 10.0 for i in standard_uptake}
new_medium = {**growth_medium, **standard_medium}
Expand Down Expand Up @@ -212,15 +212,12 @@ def find_additives_to_enable_growth(model: cobraModel, growth_medium: dict, stan
Returns:
list[str] or dict: List of the exchange reaction IDs of the additives or the supplemented medium, if combine is set to True.
"""

# find essential exchange reactions
essential = find_growth_essential_exchanges(model, growth_medium, standard_uptake)

# find the essential compounds not in the growth medium
additives = []
for metab in essential:
if metab not in growth_medium.keys():
additives.append(metab)
additives = [_ for _ in essential if _ not in growth_medium.keys()]

# return ...
if combine:
Expand Down Expand Up @@ -285,7 +282,7 @@ def growth_sim_single(model: cobraModel, m: medium.Medium, namespace:Literal['Bi

# convert to a cobrapy medium
exported_m = medium.medium_to_model(medium=m, model=model,
namespace='BiGG',
namespace=namespace,
default_flux=10.0,
replace=False,
double_o2=False,
Expand Down Expand Up @@ -502,7 +499,7 @@ def read_media_config(yaml_path:str) -> tuple[list[medium.Medium],list[str,None]
def growth_analysis(models:cobra.Model|str|list[str]|list[cobra.Model],
media:medium.Medium|list[medium.Medium]|str,
namespace:Literal["BiGG"]='BiGG',
supplements:None|list[Literal[None,'std','min']]=None,
supplements:None|list[Literal[None,'std','min']]|Literal[None,'std','min']=None,
retrieve:Literal['report','plot','both']='plot') -> reports.GrowthSimulationReport|plt.Figure|tuple:

# read-in all models into list
Expand Down

0 comments on commit 607a348

Please sign in to comment.