AttributeError: 'list' object has no attribute 'items'
QixingWei opened this issue · 8 comments
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'
Question
This command works if I use "e_coli_core.json". But if I use my own model it doesn't work.
Please provide the cobrapy version information.
I tried cobra 0.13.3 and 0.17.0, they show the same results.
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?
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.
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?
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.
This is related to #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?
Closing due to lack of activity.