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

"Metrics are only available for models build using a model database" when using custom SBML files #31

Closed mmp3 closed 3 years ago

mmp3 commented 3 years ago

I have a custom set of SBML files for the organisms in my samples.

The input DataFrame looks like this:

> df.head()
    sample_id   id  abundance                          file
0  sample1  taxa1   0.364398  /data/model.taxa1.xml.gz
1  sample1  taxa2   0.029670  /data/model.taxa2.xml.gz
2  sample1  taxa3   0.016877  /data/model.taxa3.xml.gz
...

Following the micom documentation for building community models, I execute build as follows:

from micom.workflows import build
manifest = build( taxonomy = df , model_db = None , out_folder = '/data/out', cutoff = 1e-2 , threads = 8 , solver = 'cplex')

Note that model_db argument is None because there is a file column in the input DataFrame, as instructed by the documentation for build.

However, the above build command generates the following error:

Running ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━   0% -:--:--
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/usr/local/lib/python3.8/dist-packages/micom/workflows/build.py", line 28, in build_and_save
    metrics = com.build_metrics.to_frame().T
  File "/usr/local/lib/python3.8/dist-packages/micom/community.py", line 652, in build_metrics
    raise ValueError(
ValueError: Metrics are only available for models build using a model database :(
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ubuntu/work/20210423_micom/src/test.py", line 13, in <module>
    manifest = build( taxonomy = indf , model_db = None , out_folder = outdir , cutoff = 1e-2 , threads = 8 , solver = 'cplex')
  File "/usr/local/lib/python3.8/dist-packages/micom/workflows/build.py", line 87, in build
    res = workflow(build_and_save, args, threads)
  File "/usr/local/lib/python3.8/dist-packages/micom/workflows/core.py", line 41, in workflow
    results = list(it)
  File "/usr/local/lib/python3.8/dist-packages/rich/progress.py", line 148, in track
    yield from progress.track(
  File "/usr/local/lib/python3.8/dist-packages/rich/progress.py", line 669, in track
    for value in sequence:
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 868, in next
    raise value
ValueError: Metrics are only available for models build using a model database :(

Here is some system information:

$ python3  -c "import micom; micom.show_versions()"

System Information
==================
OS                  Linux
OS-release 5.4.0-1030-aws
Python              3.8.5

Package Versions
================
cobra        0.21.0
jinja2       2.10.1
micom        0.22.5
pip          20.0.2
scikit-learn 0.24.1
scipy         1.6.1
setuptools   45.2.0
symengine     0.7.2
wheel        0.34.2
cdiener commented 3 years ago

My bad, build is only tested with a model database. I'll get to fixing that. For larger data sets I would still recommend building a model database as this will speed up the build step by quite a bit.

mmp3 commented 3 years ago

No worries, thank you for looking into this so quickly! Yes, the workaround you suggested is working...

cdiener commented 3 years ago

Now fixed in version 0.22.6: pip install "micom>=0.22.6"