micom-dev / micom

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

UnboundLocalError when running minimal_media with `summarize=False` #178

Closed zoey-rw closed 6 months ago

zoey-rw commented 6 months ago

When using the second dataframe output from complete_db_medium and summing up the fluxes per metabolite as the medium file for grow, most communities couldn't grow (the flux values seemed too low)

I also tried getting the per-sample results using the minimal_media function with summarize=False, but I'm receiving this error after 100%:

from micom.workflows import minimal_media

minimal_media_persample = minimal_media(manual_amplicon_manifest, summarize=False,
                    model_folder="/projectnb/dietzelab/zrwerbin/N-cycle/data/MICOM/manual_amplicon/", 
                          min_growth=.01,threads=28)

Running ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:04:52

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
Cell In[5], line 3
      1 from micom.workflows import minimal_media
----> 3 minimal_media_persample = minimal_media(manual_amplicon_manifest, summarize=False,
      4                     model_folder="/projectnb/dietzelab/zrwerbin/N-cycle/data/MICOM/manual_amplicon/", 
      5                           min_growth=.01,threads=28)

File /projectnb/talbot-lab-data/zrwerbin/.conda/envs/micom/lib/python3.12/site-packages/micom/workflows/media.py:64, in minimal_media(manifest, model_folder, summarize, min_growth, threads)
     62 if summarize:
     63     medium = results.groupby("reaction").flux.max().reset_index()
---> 64 medium["metabolite"] = medium.reaction.str.replace("EX_", "")
     65 return medium

UnboundLocalError: cannot access local variable 'medium' where it is not associated with a value

Originally posted by @zoey-rw in https://github.com/micom-dev/micom/discussions/177#discussioncomment-9348162

cdiener commented 6 months ago

Yep, very clearly a bug. Will send in a fix.