Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows exporting to kappa when rules refer to only one compartment #461

Open
glucksfall opened this issue Sep 12, 2019 · 1 comment
Open

Comments

@glucksfall
Copy link

Hello everyone,

I did a workaround for models with one compartment or many but with rules only referring to one compartment. For instance, I took the model MODEL1608100000 from Biomodels. It has two compartments, but the 4 rules refer to only one. The export to kappa isn't allowed because of the model.compartments is non-empty.

The model has no expressions, so I copy the attribute (model.compartments = model.expressions, and because deletion isn't allowed by the exporter). The resulting model in kappa language has @compartment and @compartment: statements, but removing them makes the model executable by KaSim (and also repairing an agent mismatch in rule R3).

It would be useful for the user to declare an option allowing the conversion.

Thanks for your time and best regards.

@alubbock
Copy link
Member

Thanks for the report. It's possible to manually strip out compartments from a model, see the example code below, which you could use like this: new_model = remove_compartments(model).

Not sure how useful this would be as a helper function in PySB, since it will break model functionality in general. Perhaps @jmuhlich or @lh64 have thoughts on whether something along these lines is worth adding to PySB?

from pysb.core import ComponentSet
import copy


def _remove_compartment_complex_pattern(cp):
    cp.compartment = None
    for mp in cp.monomer_patterns:
        mp.compartment = None


def remove_compartments(model):
    """ Return a new copy of the model with compartments removed """
    model = copy.deepcopy(model)

    for rule in model.rules:
        for cp in rule.reactant_pattern.complex_patterns:
            _remove_compartment_complex_pattern(cp)
        for cp in rule.product_pattern.complex_patterns:
            _remove_compartment_complex_pattern(cp)

    for obs in model.observables:
        for cp in obs.reaction_pattern:
            _remove_compartment_complex_pattern(cp)

    model.compartments = ComponentSet()

    return model

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants