Giter Club home page Giter Club logo

biomass's Introduction


PyPI version Actions Status Documentation Status License Downloads PyPI pyversions pre-commit.ci status Code style: black Imports: isort Paper

BioMASS is a computational framework for modeling and analysis of biological signaling systems in Python.

It provides useful tools for numerical simulation, parameter estimation, network analysis, and result visualization.

Installation

The BioMASS library is available at the Python Package Index (PyPI).

$ pip install biomass

BioMASS supports Python 3.8 or newer.

References

  • Imoto, H., Zhang, S. & Okada, M. A Computational Framework for Prediction and Analysis of Cancer Signaling Dynamics from RNA Sequencing Data—Application to the ErbB Receptor Signaling Pathway. Cancers 12, 2878 (2020). https://doi.org/10.3390/cancers12102878

  • Imoto, H., Yamashiro, S. & Okada, M. A text-based computational framework for patient -specific modeling for classification of cancers. iScience 25, 103944 (2022). https://doi.org/10.1016/j.isci.2022.103944

  • Arakane, K., Imoto, H., Ormersbach, F. & Okada, M. Extending BioMASS to construct mathematical models from external knowledge. Bioinformatics Advances 4, vbae042 (2024). https://doi.org/10.1093/bioadv/vbae042

Author

Hiroaki Imoto

License

Apache License 2.0

biomass's People

Contributors

formersbach avatar himoto avatar johannesnicolaus avatar lgtm-com[bot] avatar pre-commit-ci[bot] avatar shmaki avatar ulrmu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

biomass's Issues

Using BioMASS without Graphviz

Discussed in #158

Originally posted by himoto July 23, 2022
BioMass requires users to manually install Graphviz for graph visualization but some packages derived from biomass, e.g., pasmpy, do not need it. Currently if we run import biomass without Graphviz, it will raise an ImportError.
I would like to make this optional so that biomass-derived packages can be run without error even if Graphviz is not installed.

Ideas:

  • Move pygraphviz and pyvis from requirements.txt to extras_require in setup.py
  • Modify graph.py as follows:
def to_graph(self):
    try:
        import pygraphviz as pgv
    except ImportError:
        print("pygraphviz is required to run this function.")
    ...

def dynamic_plot(self, ...):
    try:
        from pyvis.network import Network
    except ImportError:
        print("pyvis is required to run this function.")

@formersbach
I would be grateful if you could give me comments on this. I have a branch working on this and if it's ok, I will send a PR.

Unexpected behavior in reaction_rules

Description:

Equation where 1 reactant reacts to 2 products is not covered by state_transition function but rather raises ValueError in _bind_and_dissociate.
I was trying to create a transcription event with mass action kinetics. I'm not sure whether this is "right" or "wrong", maybe you have an idea @himoto !

Reproduce:

Text file containing:

nNfk --> nNfk + mIkb

Convert to model:

from biomass import Text2Model, create_model
model = Text2Model("test.txt")
model.convert(overwrite=True)

Observed behavior

Raises :

ValueError
line1: nNfk <- Use a different name.

Desired behavior

ODE:

dmIkb/dt = kf1 * nNfk
dnNfk/dt = 0

Plotting options

As implemented now, the simulated model time (duration and implicit unit) must be entered in observable.py, however, to truly adapt simulation time, also the plot script needs to be modified. Just as a suggestion, maybe this can be circumvented by adding some time variable to observable.py which is then passed to the plot script? Potentially, this could also include other plotting parameters such as axes limits etc. Some plotting parameters are currently hard coded, maybe there would be a way to dynamically adapt the plot range, potentially circumventing problems when working on several models in parallel.

Kinetic Information to BioMass

Currently kinetic information and the stoichiometric matrix is only available in the Text2Model object.
This is somewhat impractical since it is only accessible during initial generation of the Model. In my opinion transferring the information to the actual biomass model will be more sustainable for the future, since both the stoichiometric matrix and the kinetic information are vital parts for the downstream analysis of the system.
I'd propose adding the stoichiometric matrix information in ode.py and the kinetic information to reaction_network.py.

Error message for `run_similation()` not user friendly

When running

run_simulation(model, viz_type="experiment")

and len(x) != len(y), this will raise the following error message:

ValueError: 'x' and 'y' must have the same size

But it's difficult to identify the cause of the error from this.

'c' argument looks like a single numeric RGB or RGBA sequence

Example:

from biomass.models import insulin_signaling
from biomass import run_simulation

model = insulin_signaling.create()

run_simulation(model, viz_type="original")

*c* argument looks like a single numeric RGB or RGBA sequence, which should be avoided as value-mapping will have precedence in case its length matches with 'x' & 'y'. Please use a 2-D array with a single row if you really want to specify the same RGB or RGBA value for all points

Drop Python 3.7 support

As Python 3.8 has long been stable and many packages (e.g., numpy) dropped Python 3.7 support, it would make sense to follow..

Unexpected behavior for reversible reaction

Description:

Text2Model of reversible reaction with one reactant and one product fails.

Reproduce:

Text file containing:

A + C <--> B
A <--> B

Convert to model:

from biomass import Text2Model
model = Text2Model("test.txt")
model.convert(overwrite=True)

Raises:

DetectionError
Unregistered words in line2: A <--> B

Interactive graph

TODO:

  • Add pyvis to requirements.txt
  • Update graph.py (code, Examples section in docstring)

'overwrite' option in `optimize()` function

When parameter estimation is interrupted and re-run it, e.g.,

from biomass import create_model, optimize
model = create_model(...)
optimize(model, x_id=1)
# KeyboardInterrupt
optimize(model, x_id=1)

This will raise ValueError:

ValueError: out/1 already exists in {your_model_dir}. Use another parameter id.

It would be nice to have a parameter: overwrite in optimize function, by which we can skip this error when set to True.

Error in observable.py generation of text2model.py

Description:

If not explicitly declaring observables, Text2Model fails in generating a valid observables.py file.

Reproduce:

Text file containing:

A + C <--> B

Convert to model:

from biomass import Text2Model, create_model
model = Text2Model("test.txt")
model.convert(overwrite=True)
model = create_model(test)

Raises:

IndentationError:
expected an indented block after 'else' statement on line 75

Proposed changes:

Change line 530 in text2model.py of kinetics branch to:

lines[line_num + 3] = f"{4 * self.indentation}pass\n"

Proposal: rename files in BioMASS 0.7

Old New
set_model.py ode.py
set_search_param.py search_param.py
fitness.py problem.py

TODO:

  • Rename files in all example models
  • Fix _check_indices() in core.py
  • Update docs

Improve `ExternalOptimizer`

  1. Use get_obj_val for an objective function
  2. Convert gene (0-1) into param. values after optimization
>>> from scipy.optimize import differential_evolution
>>> from biomass import Model
>>> from biomass.estimation import ExternalOptimizer
>>> from biomass.models import Nakakuki_Cell_2010
>>> model = Model(Nakakuki_Cell_2010.__package__).create()
>>> optimizer = ExternalOptimizer(model, differential_evolution)
>>> def obj_fun(x):
...    '''Objective function to be minimized.'''
...    return optimizer.get_obj_val(x)
>>> res = optimizer.run(
...     obj_fun,
...     [(0, 1) for _ in range(len(model.problem.bounds))],
...     strategy="best2bin",
...     maxiter=50,
...     tol=1e-4,
...     mutation=0.1,
...     recombination=0.5,
...     disp=True,
...     polish=False,
...     workers=-1,
... )

differential_evolution step 1: f(x)= 5.19392
differential_evolution step 2: f(x)= 2.32477
differential_evolution step 3: f(x)= 1.93583
...
differential_evolution step 50: f(x)= 0.519774

>>> from biomass import run_simulation
>>> param_values = model.problem.gene2val(res.x)
>>> optimizer.import_solution(param_values, x_id=0)
>>> run_simulation(model, viz_type="0")

Error for the simulation example in the readme

The following error was produced when running the example in the readme

RuntimeWarning: invalid value encountered in double_scalars
  + (y[V.Fn] / x[C.KF31]) ** x[C.nF31]

The code:

from biomass import Model, optimize
from biomass.models import Nakakuki_Cell_2010

model = Model(Nakakuki_Cell_2010.__package__).create()
run_simulation(model, viz_type="average", stdev=True)

I think it is caused by an undefined parameter and thus, I propose changing the model used in the exampleto another model that does not require manual input of parameters, or to pre-input the default parameter for the model.

Please let me know if this is a misunderstanding.

Type of `show_controls` in the example code

Hi @formersbach,
I thinks the type of show_controls in the example code of dynamic_plot() should be boolean, not string:

model.dynamic_plot(save_dir='example_dir', file_name='nfkb_dynamic.html' show_controls='True', which_controls=['physics', 'layout'])

If yes, I have a fix-doc branch and fix this.
Thank you!

Name of the directory in which the graph image will be stored

Hi @formersbach, thanks for implementing amazing features!
As we discussed before, I have tried to create all files related to a single model in the model folder so that a user will not forget where he/she saved a file.
Accordingly, I would like to save graph in the model folder as well, which can easily be achieved by adding self.path in the beginning of each path:

# Example, from
self.graph.draw(os.path.join(save_dir, file_name))
network.save_graph(os.path.join(save_dir, file_name))
# to
self.graph.draw(os.path.join(self.path, save_dir, file_name))
network.save_graph(os.path.join(self.path, save_dir, file_name))

If it is ok for you, I would like to set "graph" to save_dir as a default folder name.

Text2Model class

As pasmopy depends on biomass, it would be nice to host Text2Model source code as a biomass core library for enabling text-to-model conversion without installing pasmopy.

TODO:

  • Migrate construction/
  • Migrate tests regarding text-to-model conversion
  • Migrate module references in docs (don't move Model development section to biomass)
  • Update tutorial

Generalization of Mass action kinetics

Current implementation of Mass action kinetics is limited to 2 reactants or 2 products. Mass action rate law can however be generalized to n reactants and n products (see e.g. https://doi.org/10.1007/BF00251225 or https://doi.org/10.1371%2Fjournal.pcbi.1004012).
The easiest implementation I could find is the one as stated in the textbook "Systems Biology" Klipp et al. p.40 :

$$ v = v_+ - v_- = k_+\prod_{i=1}^{m_{i}} S_{i}^{n_{i}} - k_-\prod_{j=1}^{m_{j}} P_{j}^{n_{j}}$$

With $k_+$ and $k_-$ being the forward and backward rate constants respectively. $m_i$ Substrates with concentrations $S_i$ react to $m_j$ products with concentrations $P_j$. $n$ denotes the molecularities.
Species that appear on both sides of the equation could be treated as modulators.

KineticInfo of state_transition rule not working as intended

Description:

Rate of Kinetic Info is supposed to contain the pure rate equation with just parameters and species. state_transition method wrongly adds concentration identifiers such as y[species].

Reproduce:

Text file containing:

A --> B

Convert to model:

from biomass import Text2Model, create_model
model = Text2Model("test.txt")
model.convert(overwrite=True)
print(model.kinetics)

Expected:

model.kinetics.rate : kf1 * A

Observed:

model.kinetics.rate : kf1 * y[V.A]

Docs for graph visualization

TODO:

  • Edit graph_visualization.rst
  • Use one of biomass.models for showing usage examples
  • Add how to use dynamic/static_plot()

Note:
If you want embed images, please put the source in _static/img/ folder. You can call them via .. image:: _static/img/xxx in .rst files.

Update tutorial

As pasmopy 0.3.0 supports better text-to-model conversion method (pasmopy/pasmopy#78), we will need a tutorial that contains followings:

  • Model construction from text via pasmopy.Text2Model
  • Parameter estimation
  • Result visualization
  • Sensitivity analysis

Regarding options for run_sim.py

It might be easier to use if you forward arguments of run_sim.py to the script, so that there will be no need to edit the script. For example

run_sim.py average show_all stdev to produce:

simulate_all(viz_type='average',show_all=True,stdev=True)

Error in multiple_observables_options in `viz.py`

When enabling multiple_observables_options and execute run_simulation(..., viz_type="average"), all trajectories for each simulation condition are divided by their maximum values.

Thanks Hayate Takagishi for reporting this error.

Phosphorylation generates duplicate ODE

Description:

If "is phosphorylated" reaction rule is used with a unphosphorylated species that has been previously used, a second ODE is mistakenly generated.

Reproduce:

Text file containing:

TNFR phosphorylates Ikk --> pIkk   
Ikk is phosphorylated <--> pIkk
pIkk is phosphorylated <--> ppIkk

Convert to model:

from biomass import Text2Model, create_model
model = Text2Model("test.txt")
model.convert(overwrite=True)
model = create_model(test)

Proposed changes:

Add missing format string in line 1099:

elif "dydt[V.{phosphorylated_form}]" in eq:

to

elif f"dydt[V.{phosphorylated_form}]" in eq:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.