Suppressing warnings when loading model from file

326 views
Skip to first unread message

J P

unread,
Jun 30, 2019, 10:36:24 AM6/30/19
to cobra pie
Hello,

Is there a way to suppress "logger" warnings when reading an SBML model from file? Example, "Encoding OBJECTIVE_COEFFICIENT in KineticLaw is discouraged, use fbc:fluxObjective instead"-

Best regards,
Jarle P

Moritz Beber

unread,
Jun 30, 2019, 5:16:54 PM6/30/19
to cobr...@googlegroups.com
Hi,

A quick possibility is to raise the logging level to error. You can read more in the Python documentation (https://docs.python.org/3/library/logging.html?highlight=logging#module-logging).

import logging

logging.getLogger("cobra").setLevel(logging.ERROR)

Best,
Moritz
--
You received this message because you are subscribed to the Google Groups "cobra pie" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cobra-pie+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cobra-pie/92386e9e-4235-4afa-8c7d-51a57fff847f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matthias König

unread,
Jul 3, 2019, 3:28:35 AM7/3/19
to cobra pie
Hi J P, 

[1] another alternative is to use the validate_sbml_model function to read the model.
This is performing additional model validations (and catches all the warnings) in the error logs (this could take a bit longer to read due to the SBML validation, but for most model this does not matter too much, especially because you read the model only once.)

from cobra.io import validate_sbml_model
model, errors = validate_sbml_model(path)

[2] another is to convert the model to SBML3FBC, i.e. get rid of the warnings by encoding the model according to latest guidelines.
The cobrapy SBML exporter is doing this automatically. So you can do:

from cobra.io import read_sbml_model, write_sbml_model
model = read_sbml_model(path)
write_sbml_model(model, path_sbml3fbc) # stores as SBML3 + fbc
read_sbml_model(path_sbml_3fbc) # magic, no warnings

This has the big advantage that you got rid of all the legacy encoding which should in my opinion not be used any more.
Best Matthias

Best Matthias

On Sunday, June 30, 2019 at 11:16:54 PM UTC+2, Moritz Beber wrote:
Hi,

A quick possibility is to raise the logging level to error. You can read more in the Python documentation (https://docs.python.org/3/library/logging.html?highlight=logging#module-logging).

import logging

logging.getLogger("cobra").setLevel(logging.ERROR)

Best,
Moritz

On Sun, 2019-06-30 at 07:36 -0700, J P wrote:
Hello,

Is there a way to suppress "logger" warnings when reading an SBML model from file? Example, "Encoding OBJECTIVE_COEFFICIENT in KineticLaw is discouraged, use fbc:fluxObjective instead"-

Best regards,
Jarle P

--
You received this message because you are subscribed to the Google Groups "cobra pie" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cobr...@googlegroups.com.

J P

unread,
Oct 16, 2019, 5:31:16 PM10/16/19
to cobra pie
Hi,

Sorry for the late reply. Thanks to both of you for the tips. I didn't know about the function to convert the model!

Best regards,
Jarle Pahr
Reply all
Reply to author
Forward
0 new messages