read_sbml_model error. sbml.py xml in filename

40 views
Skip to first unread message

norm vinson

unread,
May 18, 2023, 4:49:57 PM5/18/23
to cobra pie
I get an error when trying to read a model. the file sbml.py seems to be expecting "xml" in the filename, but I don;t see why that would be.

setting data path

sal_dir = Path(".") / ".." / "models" / "salmonella"
sal_dir = sal_dir.resolve()
print(sal_dir)
C:\Users\vinsonn\Documents\COBRApy\models\salmonella *so far so good !dir ..\models\salmonella *jupyter notebookVolume in drive C has no label. Volume Serial Number is 4A56-B1B6 Directory of C:\Users\vinsonn\Documents\COBRApy\models\salmonella (...) 2023-05-18 03:33 PM 12,044,462 iYS1720.xml *there's my model file. (...)
The SBML.org validator says its valid.BUT...
read_sbml_model("iYS1720.xml")
--------------------------------------------------------------------------- OSError Traceback (most recent call last) Input In [29], in <cell line: 1>() ----> 1 read_sbml_model("iYS1720.xml") File ~\Anaconda3\lib\site-packages\cobra\io\sbml.py:252, in read_sbml_model(filename, number, f_replace, **kwargs) 250 return _sbml_to_model(doc, number=number, f_replace=f_replace, **kwargs) 251 except IOError as e: --> 252 raise e 254 except Exception as original_error: 255 cobra_error = CobraSBMLError( 256 "Something went wrong reading the SBML model. Most likely the SBML" 257 " model is not valid. Please check that your model is valid using " (...) 262 "at https://github.com/opencobra/cobrapy/issues ." 263 ) File ~\Anaconda3\lib\site-packages\cobra\io\sbml.py:249, in read_sbml_model(filename, number, f_replace, **kwargs) 201 """Reads SBML model from given filename. 202 203 If the given filename ends with the suffix ''.gz'' (for example, (...) 246 File handles to compressed files are not supported yet. 247 """ 248 try: --> 249 doc = _get_doc_from_filename(filename) 250 return _sbml_to_model(doc, number=number, f_replace=f_replace, **kwargs) 251 except IOError as e: File ~\Anaconda3\lib\site-packages\cobra\io\sbml.py:292, in _get_doc_from_filename(filename) 289 else: 290 # string representation 291 if "<sbml" not in filename: --> 292 raise IOError( 293 "The file with 'filename' does not exist, " 294 "or is not an SBML string. Provide the path to " 295 "an existing SBML file or a valid SBML string " 296 "representation: \n%s", 297 filename, 298 ) 300 doc = libsbml.readSBMLFromString( 301 filename 302 ) # noqa: E501 type: libsbml.SBMLDocument 304 elif hasattr(filename, "read"): 305 # file handle OSError: [Errno The file with 'filename' does not exist, or is not an SBML string. Provide the path to an existing SBML file or a valid SBML string representation: %s] iYS1720.xml

Matthias König

unread,
May 22, 2023, 7:50:21 AM5/22/23
to cobra pie
Please just use the absolute file path to the file for loading the SBML and make sure the path exists.
I.e.
```
model_path = Path(".." / "models" / "salmonella" / "iYS1720.xml")
if not model_path.exists():
    print(f"Path does not exist: {model_path}")
read_sbml_model(model_path)
```

norm vinson

unread,
May 25, 2023, 12:40:45 PM5/25/23
to cobra pie
That works! thanks.
Reply all
Reply to author
Forward
0 new messages