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

Update maudtools to work with latest version of Maud (now with nicer sbml) #20

Merged
merged 17 commits into from Apr 4, 2023

Conversation

teddygroves
Copy link
Member

This change updates maudtools to keep up with the latest Maud (0.4.0.2).

It also improves the sbml export a lot, so that a) it only depends on the official libsbml library and b) the sbml file contains a lot more information.

Since Maud now includes example data in its package it was possible to delete a lot of duplicate test data.

@carrascomj carrascomj self-requested a review March 1, 2023 14:12
Copy link
Member

@carrascomj carrascomj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read part of the PR but the fetching dG CLI is failing. I'll review more of it once I have a sampled model with the new configuration to test.

maudtools/fetching_dgf_priors.py Show resolved Hide resolved
import os

import pandas as pd
import importlib_resources
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a future PR, we may want to add integration testing with the click testing capabilities so that we verify that cli.py is still working.

from maud.data_model.maud_input import MaudInput


def generate_inits(
idata: az.InferenceData, mi: MaudInput, chain: int, draw: int, warmup: int
) -> pd.DataFrame:
) -> dict:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dict as a qualified keyword will make anything python <=3.8 fail, but I saw that the minimum version was bumped up to 3.9 so I guess it's fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realise this but I think that is good - better to fail as much as possible in the bad python case

@@ -3,8 +3,8 @@
import arviz as az
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have yet to test this functionality. I am sampling a model with the new format, so I'll give a check once it finishes (same with the generate_sbml part).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UPDATE: still works fine. The problem now is that retrieving yconc and fluxes is more complicated since it is not shaped into a experiment, metabolites array, but that's an issue with Maud itself (using maud-metabolic-models==0.4.0.2).

# prepare scatter intervals
if non_negative:
df_priors.location = np.exp(df_priors.location)
df_priors.scale = np.exp(df_priors.scale)
df_priors["y_max"] = df_priors.location / df_priors.scale ** 2
df_priors["y_min"] = df_priors.location * df_priors.scale ** 2
df_priors["y_max"] = df_priors.location / df_priors.scale**2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

black prefers the spaces here, I don't mind too much.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my black actually did this - looks like a relatively recent change psf/black#2726

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright then!

@@ -3,8 +3,21 @@
This function takes in an InferenceData, MaudInput, chain, draw and experiment
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am getting the following error (maudtools generate-sbml output_dir):

Traceback (most recent call last):
  File "/home/georg/.virtualenvs/maud-local/bin/maudtools", line 8, in <module>
    sys.exit(cli())
  File "/home/georg/.virtualenvs/maud-local/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/georg/.virtualenvs/maud-local/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/georg/.virtualenvs/maud-local/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/georg/.virtualenvs/maud-local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/georg/.virtualenvs/maud-local/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/georg/.virtualenvs/maud-local/lib/python3.9/site-packages/maudtools/cli.py", line 112, in generate_sbml_command
    experiment.id for experiment in mi.measurements.experiments
AttributeError: 'MaudInput' object has no attribute 'measurements'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the sbml now works on my computer

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only balanced metabolites are reported as Species when I run it, generating in the end empty reactions (empty meaning without metabolites, although they have kinetic laws). Is that intended?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is intended - the unbalanced metabolites appear in Maud's Stan model as a parameter array called conc_unbalanced so I thought they should be represented in sbml in the same way as other parameters.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I see.

Another way to do it is to add unbalanced metabolites as any other Species with the attribute boundary_condition set to "true". This way the model can be parsed and inspected in a normal way, but it may be ambiguous if the parsing is not careful (which is a concern, I believe).

If you think it is fine as it is I can approve the PR, I don't have any more comments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd quite like to get this change merged soon but I've made an issue to look into the best way to do this separately.

Copy link
Member

@carrascomj carrascomj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge it!

@teddygroves teddygroves merged commit 06dca6c into master Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants