opencobra / cobrapy

COBRApy is a package for constraint-based modeling of metabolic networks.
http://opencobra.github.io/cobrapy/
GNU General Public License v2.0
455 stars 211 forks source link

AttributeError: 'list' object has no attribute 'items' #1354

Closed QixingWei closed 1 month ago

QixingWei commented 10 months ago

Checklist


AttributeError Traceback (most recent call last)

in ----> 1 cobra.io.write_sbml_model(ptest, "Sep12th2023.xml") ~\.conda\envs\Cobra013\lib\site-packages\cobra\io\sbml3.py in write_sbml_model(cobra_model, filename, use_fbc_package, **kwargs) 715 return 716 # create xml --> 717 xml = model_to_xml(cobra_model, **kwargs) 718 write_args = {"encoding": "UTF-8", "xml_declaration": True} 719 if _with_lxml: ~\.conda\envs\Cobra013\lib\site-packages\cobra\io\sbml3.py in model_to_xml(cobra_model, units) 482 hasOnlySubstanceUnits="false") 483 set_attrib(species, "name", met.name) --> 484 annotate_sbml_from_cobra(species, met) 485 set_attrib(species, "compartment", met.compartment) 486 set_attrib(species, "fbc:charge", met.charge) ~\.conda\envs\Cobra013\lib\site-packages\cobra\io\sbml3.py in annotate_sbml_from_cobra(sbml_element, cobra_element) 242 bag = SubElement(SubElement(rdf_desc, ns("bqbiol:is")), 243 ns("rdf:Bag")) --> 244 for provider, identifiers in sorted(iteritems(cobra_element.annotation)): 245 if provider == "SBO": 246 set_attrib(sbml_element, "sboTerm", identifiers) ~\.conda\envs\Cobra013\lib\site-packages\six.py in iteritems(d, **kw) 603 604 def iteritems(d, **kw): --> 605 return iter(d.items(**kw)) 606 607 def iterlists(d, **kw): AttributeError: 'list' object has no attribute 'items' ![Screenshot 2023-09-12 133510](https://github.com/opencobra/cobrapy/assets/105372439/e46ef935-4050-412e-95af-7cfdfdc52cf4) ### Question This command works if I use "e_coli_core.json". But if I use my own model it doesn't work.
Midnighter commented 10 months ago

Please provide the cobrapy version information.

QixingWei commented 10 months ago

I tried cobra 0.13.3 and 0.17.0, they show the same results.

Midnighter commented 10 months ago

At some point annotations were lists but now they are dicts and have been for quite a while. Is it possible for you to install the latest cobrapy version and load that model from SBML again? Or do you need to load the old JSON?

QixingWei commented 10 months ago

I loaded an old version .json model. The model cannot be read by new version cobrapy, it can olny be read at 0.17.1 or 0.13.3.

Midnighter commented 10 months ago

I understand. I'm asking if that model stored in JSON is somehow special and only available that way or if an SBML version of that model exists that you can load in the latest cobrapy version?

QixingWei commented 10 months ago

I got the file from my previous co-worker. The situation is I can read and save e_coli_core(json or xml) in any version. But for this file, I can only read it(json format) in 0.13.3 or 0.17.1 and I cannot save it in xml format.

cdiener commented 10 months ago

This is related to https://github.com/opencobra/cobrapy/issues/1012. You would need to go through your JSON and fix the annotations. There is an example notebook here that fixes the BIGG universal model but it would depend a bit on how your annotations actually look like. Do you have an example for some [reaction,metabolite].annotation outputs?

cdiener commented 1 month ago

Closing due to lack of activity.