Metadata-Version: 2.4
Name: emasp
Version: 1.0.0
Summary: Elementary modes of metabolic network (like EFM) using Clingo/ASP
Author-email: Emma Crisci <emma.crisci@inria.fr>, Francois Gindraud <francois.gindraud@inria.fr>
License-Expression: AGPL-3.0-or-later
Project-URL: Repository, https://gitlab.inria.fr/erable/emasp/
Keywords: metabolism,efm,asp,clingo
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: clingo-lpx>=1.3.0
Requires-Dist: python-libsbml>=5.21.1
Requires-Dist: typer>=0.26.7
Dynamic: license-file

# EMASP

Elementary Modes of metabolic networks using *Answer Set Programming* ([ASP](https://potassco.org/)) :
- Elementary Flux Modes ([EFM](https://en.wikipedia.org/wiki/Elementary_modes)) with `emasp efm enumerate ...`

## Install
EMASP is available in [pypi](https://pypi.org/project/emasp) :
```
pip install emasp
```

If you cannot use the pypi packages (OS support, or versions), you can also use the development version (see below).

## EFM enumeration
[EFM computation details](doc/efm.md)

```bash
# EFM illustrated by a Carlson 2004 example, available on the git :
cd example/

# EFM enumeration : 1658 EFM
emasp efm enumerate carlson_2004.xml
emasp efm enumerate carlson_2004.xml -o efms.jsonl # File output

# EFM with enzyme cost constraint. Try betas in the [1,10] range to see effect of threshold on EFM count
emasp efm enumerate carlson_2004.xml --enzymatic-cost 1 --kcat-csv apparent_kcat_carlson_2004.csv --csv-delimiter ';' --mass-value 100000 # ~134 EFM
emasp efm enumerate carlson_2004.xml --enzymatic-cost 10 --kcat-csv apparent_kcat_carlson_2004.csv --csv-delimiter ';' --mass-value 100000 # ~809 EFM

# EFM with thermodynamic constraint : ~1133 EFM
emasp efm enumerate carlson_2004.xml --csv-delimiter ';' --thermodynamic --concentration-csv concentration_carlson.csv --deltag0-csv deltaGo_carlson.csv

# EFM with both constraints : ~618 EFM
emasp efm enumerate carlson_2004.xml --enzymatic-cost 10 --kcat-csv apparent_kcat_carlson_2004.csv --csv-delimiter ';' --mass-value 100000 --thermodynamic --concentration-csv concentration_carlson.csv --deltag0-csv deltaGo_carlson.csv

# Advanced users mode for ASP-speaking-people : equivalent to above, but provides access to ASP code for inspection or tweaks.
emasp efm model-to-asp carlson_2004.xml -o model.clp # Encode SBML model to ASP
emasp efm enzymatic-cost-to-asp model.clp --beta 10 --kcat-csv apparent_kcat_carlson_2004.csv --csv-delimiter ';' --mass-value 100000 -o enzyme_cost.clp # Optional: generate enzyme cost constraints
emasp efm thermodynamics-to-asp model.clp --deltag0-csv deltaGo_carlson.csv --concentration-csv concentration_carlson.csv --csv-delimiter ';' -o thermo.clp # Optional: generate thermodynamic constraints
emasp efm clingolpx model.clp enzyme_cost.clp thermo.clp # Perform enumeration with explicit ASP files. 
```

![EFM workflow](doc/efm.svg)

[EFM output example](example/efms_10.jsonl) : the first 10 EFMs for the `carlson_2004.xml` example. Each EFM is a [JSON object on 1 line](https://en.wikipedia.org/wiki/JSONL).

[Example of Python code](example/read_efms.py) to read the set of EFMs as Python objects.

## References
- Emma Crisci, Maxime Mahout, Sabine Peres. Computing Thermodynamically Consistent Elementary Flux Modes with Answer Set Programming. CMSB 2024 - 22nd International Conference Computational Methods in Systems Biology, Sep 2024, Pise, Italy. pp.80-88, [hal-04707880](https://hal.archives-ouvertes.fr/hal-04707880)

## Useful tools
- ASP syntax highlighting extension : https://marketplace.visualstudio.com/items?itemName=abelcour.asp-syntax-highlight.
- `example/` contains a script used to retrieve DeltaG0 values for the thermodynamic cost constraint

## Development

### Run the development version from git
Clone the git and install the dependencies using the tool of your choice.

For example, with [uv](https://docs.astral.sh/uv/) :
```bash
git clone https://gitlab.inria.fr/erable/emasp.git
cd emasp
uv run emasp
```

### C++ module
EMASP includes a C++ compiled module for fast output formatting, as the pure Python formatter slows the enumeration speed by 2.
A C/C++ compiler must be installed on your system ([`apt install binutils`](https://packages.debian.org/binutils) on Debian / Ubuntu).
You can disable the C++ module during package build with the `EMASP_DISABLE_CPP` environment variable as a fallback :
```bash
# UV example
uv clean # clean package cache
EMASP_DISABLE_CPP=1 uv pip install . # force rebuild the package without C++
uv run emasp ... # will use a slower python fallback
```

### Roadmap / todo
Optional
- [ ] Extension CI tests ?
- [ ] thermodynamics constraints : retrieve deltaG0 from iQ (separate command). Currently, only present as an [example python script](example/equilibrator_fetch_deltaG0.py)
- [ ] mparser: Load model from other formats ?
- [ ] EFM enumeration CSV output ? (id, flux_reaction_0, ..., flux_reaction_n)
- [ ] Enzyme cost: get kcat / enzyme mass from SBML ? Some code left to read from sbml
- [ ] Remove C++ formatter if too brittle ? Formatting cost will be on small benchmarks

### Release process
Use [cibuildwheel](https://cibuildwheel.pypa.io/en/stable/) to generate wheels for many python versions.
Then upload to pypi manually ; less fragile than doing it through the CI.

Linux is easily covered by this.
Windows and MacOS : maybe use the free github runners by referencing this as an external project ? TODO

There is an option to generate a pure python package with the no CPP option.
