You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 genetxtbook_model=load_model("textbook")
txtbook_model.genes.b0118.knock_out()
print(txtbook_model.genes.b0118.functional)
# save and reload textbook modelwrite_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
The text was updated successfully, but these errors were encountered:
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.
Is there an existing issue for this?
Problem description
When I knockout a gene, the
gene.functional
attribute is set toFalse
. But when the model is saved/reloaded usingwrite_sbml_model
/read_sbml_model
, thegene.functional
attribute is reset to the default ofTrue
. I want thegene.functional
attribute to be saved with each model.A jerry-rigged solution is to save the attribute using
_sbase_notes_dict
incobrapy/src/cobra/io/sbml.py
:_sbase_notes_dict(gp, {"functional": cobra_gene.functional})
--> after line 1344 indef _model_to_sbml
--> 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:
Environment
Dependency Information
Build Tools Information
Platform Information
Anything else?
No response
The text was updated successfully, but these errors were encountered: