-
Notifications
You must be signed in to change notification settings - Fork 218
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
read_sbml_model
does not substitute legacy SBML placeholders anymore
#1149
Comments
Maybe I'm overlooking something but that change seems like it wouldn't work. |
Yeah, sure. Each of the items in the _renames set is structured as [(symbol, esc_symbol)] so when the replace function tries to look for the first argument, what it tries to looks for in the id is the symbol instead. Try this short code snippet: _renames = (
(".", "_DOT_"),
("(", "_LPAREN_"),
(")", "_RPAREN_"))
id_to_fix = "EX_co2_LPAREN_e_RPAREN__BS"
def _escape_str_id_old(id_str):
"""make a single string id SBML compliant"""
for c in ("'", '"'):
if id_str.startswith(c) and id_str.endswith(c) \
and id_str.count(c) == 2:
id_str = id_str.strip(c)
for char, escaped_char in _renames:
id_str = id_str.replace(char, escaped_char)
return id_str
def _escape_str_id_new(id_str):
"""make a single string id SBML compliant"""
for c in ("'", '"'):
if id_str.startswith(c) and id_str.endswith(c) \
and id_str.count(c) == 2:
id_str = id_str.strip(c)
for char, escaped_char in _renames:
id_str = id_str.replace(escaped_char, char)
return id_str
print(escape_str_id_old(id_str))
print(escape_str_id_new(id_str)) The latter one should print correctly. |
Yeah but that is not what the function is supposed to do. As the docstring indicates it is supposed to transform a non-SBML compliant string to an SBML-compliant one.
|
Oh, okay. Haha. My apologies. Thought it was the other way around (The docstring being the non-compliant format). Thank you for the clarification. Seems I found a new use for this function -- it turns the SBML-compliant format to a more human-readable one. :) |
Sure, no problem. Yep, but that is also done by default in the SBMl reader. See the top of the file here. So |
Hmm. That's weird. It doesn't automatically change when I'm using read_sbml_file() though, which is why I looked for a parser with that specific function instead. Should I open another ticket for this instead? Thanks a lot. |
Nope, can leave it here. Can you provide a code example (and preferably the model) where it does not substitute the ID? |
Sure, no problem. Here's the model I've been using: Here's a short code snippet from my notebook: import cobra
ios2164 = cobra.io.read_sbml_model("../ios2164.xml")
for rxns in ios2164.exchanges:
print(rxns.id) |
Oh yeah sorry. It only substitutes IDs with the new pattern which is As a reference, here is the output of the code:
|
read_sbml_model
does not substitute legacy SBML placeholders anymore
No problem. Either way I've found what I needed. Haha. Thanks a lot. 👍 |
Hi. I'm trying to convert an SBML 2 model and I've encountered a bug in the model.manipulation.modify module. Apparently there's an error in one of the functions which prevents the parser from replacing the escaped strings.
Interchanging the char & escaped_char fixes the problem with the function as well as others that use it (like escape_ID()).
The text was updated successfully, but these errors were encountered: