Skip to content
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

[Feature] Verbosity Option in read_sbml_model or similar. #1405

Open
1 task done
ggmirandac opened this issue Sep 9, 2024 · 1 comment
Open
1 task done

[Feature] Verbosity Option in read_sbml_model or similar. #1405

ggmirandac opened this issue Sep 9, 2024 · 1 comment

Comments

@ggmirandac
Copy link

Checklist

Problem

I been trying to work on some metagenome analysis with cobrapy. And to analyze some of the features in the metabolic network Cobrapy is often recommended. I store all my models in a sbml file and therefore I must read them. The issue is that when I am reading them there is A LOT of outputs in the terminal that at the end reduce the speed of the overall code (per my knowledge).

So, what I would think is that the read_sbml_model could have a verbose option which enables to ignore outputs that are not Errors

Solution

One solution that I would think of is condition the logs to the terminal by defining, for example:
if verbose == 1:
LOGGER.warning # for example

to ignore logger warnings, that often doesn't affect the overall run if the user knows before hand the model.

Alternatives

I considered using os.devnull
with open(os.devnull, 'w') as devnull, open(log_file, 'a') as log_f:
with redirect_stdout(devnull), redirect_stderr(devnull):
But I think would be more elegant if the solution was in the COBRApy.

Anything else?

No response

@cdiener
Copy link
Member

cdiener commented Sep 9, 2024

There was a discussion of adding a default verbosity to the Configuration also for progress bars that may become a feature in the future.

There is no need to redirect standard output though, since we use normal Python logging.

So a simple:

import logging

logging.basicConfig(level=logging.ERROR)

In the beginning of your script should be enough.

On a side note, SBML parsing will not raise warnings until there are issues with the file. So, unless you need to use some legacy models that you know will be parsed correctly, seeing a lot of warnings will usually indicate potential issues down the line or will require manual fixes to the models.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants