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

[BUG] Gene.functional attribute not saved in SBML model #1422

Open
1 task done
wshao1 opened this issue Jan 8, 2025 · 5 comments
Open
1 task done

[BUG] Gene.functional attribute not saved in SBML model #1422

wshao1 opened this issue Jan 8, 2025 · 5 comments
Labels

Comments

@wshao1
Copy link

wshao1 commented Jan 8, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Problem description

When I knockout a gene, the gene.functional attribute is set to False. But when the model is saved/reloaded using write_sbml_model/read_sbml_model, the gene.functional attribute is reset to the default of True. I want the gene.functional attribute to be saved with each model.

A jerry-rigged solution is to save the attribute using _sbase_notes_dict in cobrapy/src/cobra/io/sbml.py:

_sbase_notes_dict(gp, {"functional": cobra_gene.functional}) --> after line 1344 in def _model_to_sbml

notes = _parse_notes_dict(gp)
if "functional" in notes:
    cobra_gene.functional = (notes["functional"] == "True")

--> after line 746 in def _sbml_to_model

I'm sure there's a better way to do this that aligns with SBML standards, so wondering if anyone who is familiar with SBML can fix this in a more elegant way.

Code sample

Code run:

# load textbook model and try KO'ing a gene
txtbook_model = load_model("textbook")
txtbook_model.genes.b0118.knock_out()
print(txtbook_model.genes.b0118.functional)

# save and reload textbook model
write_sbml_model(txtbook_model, 'txtbook_model.xml')
saved_txtbook_model = read_sbml_model('txtbook_model.xml')

# check if gene is still KO'ed (functional = False)
print(saved_txtbook_model.genes.b0118.functional)

Environment

### Package Information
Package Version
cobra 0.29.1

Dependency Information

Package Version
appdirs~ missing
black missing
bumpversion missing
depinfo~ missing
diskcache~ missing
future 1.0.0
httpx~ missing
importlib-resources 6.5.2
isort missing
numpy 2.2.1
optlang~ missing
pandas 2.2.3
pydantic 2.10.4
python-libsbml~ missing
rich 13.9.4
ruamel.yaml~ missing
scipy missing
swiglpk 5.0.12
tox missing

Build Tools Information

Package Version
pip 24.2
setuptools 75.1.0
wheel 0.44.0

Platform Information

Darwin 24.2.0-arm64
CPython 3.12.8

Anything else?

No response

@wshao1 wshao1 added the bug label Jan 8, 2025
@cdiener
Copy link
Member

cdiener commented Jan 10, 2025

Agreed it would be cool to have this, but this is currently not supported by SBML AFAICT. The only allowed attributes for genes are the id and name essentially and nothing else. You can save functionality in the notes, but we would probably not do this here because the SBML standard is pretty strict about not storing parseable information in the notes. There were some discussions of new key-value annotations but I don't think this is available yet.

@wshao1
Copy link
Author

wshao1 commented Jan 10, 2025

OK thanks Christian! I'll stick with my workaround solution for now, and will keep an eye out for any SBML updates.

@Midnighter
Copy link
Member

You might look at OMEX files which are essentially archives that include models and data files (like constraints or expression values).

@Midnighter
Copy link
Member

Key values are in SBML FBC level 3, I think.

@wshao1
Copy link
Author

wshao1 commented Jan 10, 2025

Thanks for the suggestions Midnighter!

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

No branches or pull requests

3 participants