Metadata-Version: 2.1
Name: gene-rule-parser
Version: 0.1.4
Summary: Basic language to parse genetic rules to a structure
Author: pineiden
Author-email: dpineda@uchile.cl
Requires-Python: >=3.11,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: cobra (>=0.29.0,<0.30.0)
Requires-Dist: ipython (>=8.26.0,<9.0.0)
Requires-Dist: ply (>=3.11,<4.0)
Requires-Dist: polars (>=1.7.1,<2.0.0)
Requires-Dist: pydantic (>=2.8.2,<3.0.0)
Requires-Dist: rich (>=13.7.1,<14.0.0)
Requires-Dist: typer (>=0.12.3,<0.13.0)
Requires-Dist: ujson (>=5.10.0,<6.0.0)
Description-Content-Type: text/markdown

# Gene Parser AST

A rule expression in genetics can be found like this relation of
AND+OR:

``` python
rule = '(9045_AT1 and (B0783 and B0088)) or (3705_AT1 or (91012_AT1 and 55304_AT1))'
```

This module enables a a parser that convert an string expression that
relates the genes in a object structure like this:

``` python
Or(
    left=And(left=Gene(name='9045_AT1'), right=And(left=Gene(name='B0783'), right=Gene(name='B0088'))),
    right=Or(
        left=Gene(name='3705_AT1'),
        right=And(left=Gene(name='91012_AT1'), right=Gene(name='55304_AT1'))
    )
)
```

To process this and obtain the representative value first is necessary
use the **parser** method and then call **tree_analysis**. This last
function reads recursively all the tree and obtain, given this rules,
the final value:

- or : sum([a,b])
- and : min([a,b])

And, for UNKNOWN value:

- Expression(UNKNOWN) :: mean([Expression(G_i)])

With this is possible to have the representative value for the gene
rule expression.

Take a look on the examples on the **tests** directory.


# How install this.

Call **poetry**

``` shell
poetry install
```

Run the tests:

Basic example:

``` shell
poetry run python tests/test_basic.py 
```

General Example:

``` shell
poetry run python tests/test_parser_general.py 
```

# Check then the parser.

Once installed you can check the for gene rule expressions using the
command **rule_parser**. 

``` shell
rule_parser "1321A and 123123B and (123123B or 32312C)"
```

