C-CoMP-STC / GEM-mit1002

Creative Commons Attribution 4.0 International
0 stars 0 forks source link

Identify problematic reactions by adding dilution fluxes #32

Closed hgscott closed 11 months ago

hgscott commented 11 months ago

Connect with Devlin to use his tool to identify cycles that are generating ATP/etc.

hgscott commented 11 months ago

I pinged Devlin to get documentation or set up a time to meet.

hgscott commented 11 months ago

Devlin says that a more straightforward way to identify loops is to set both bounds on every exchange reaction to 0, do FVA, and see if any reactions have non-zero min or max fluxes (and that it turns out that's one of the tests in MEMOTE).

hgscott commented 11 months ago

This was in the memote report for the non-gapfilled MS2 model, is this what Devlin was referring to: Image

hgscott commented 11 months ago

I believe these IDs are metanet metabolite IDs for the different currency metabolites (i.e. ATP), and we want to run the algorithm on each metabolite. I don't know why they were all skipped in this model- it's not just because the model doesn't grow- they were all also skipped on the older version of the model, that had significant growth: Image

hgscott commented 11 months ago

I can get the code to run locally- not sure why it is being skipped in the report.

To run the code for just ATP, I ran the following in my "memote-test" conda environment:

>>> import cobra
>>> model = cobra.io.read_sbml_model("model.xml")
'' is not a valid SBML 'SId'.
Scaling...
 A: min|aij| =  1.000e+00  max|aij| =  1.000e+00  ratio =  1.000e+00
Problem data seem to be well scaled
>>> import memote.support.consistency as consistency
>>> consistency.detect_energy_generating_cycles(model, "MNXM3")
['rxn05595_c0', 'rxn05206_c0', 'rxn08173_c0']
hgscott commented 11 months ago

The tests are all being skipped because it is looking for a metabolite with an ID that matched the metanetx ID, which mine don't have, it's not enough to just have the metanetx ID as an annotation.

hgscott commented 11 months ago

I worked on my own fork of the MEMOTE repository, and I solved the problem.

Before the test was using the MetaNetX ID to look for the metabolite directly, i.e.:

    if met not in model.metabolites:
        pytest.skip(
            "This test has been skipped since metabolite {} could "
            "not be found in the model.".format(met)
        )

(From https://github.com/opencobra/memote/blob/4c08f46849628507ac8c4de56b5d6ec745feed0b/src/memote/suite/tests/test_consistency.py#L156)

But the function itself uses the helpers.find_met_in_model function to find the metabolite using the MetaNetX ID. So I used that function to check if the metabolite is in the model with:

    if helpers.find_met_in_model(model, met, main_comp)[0] is None:
        pytest.skip(
            "This test has been skipped since metabolite {} could "
            "not be found in the model.".format(met)
        )

And when I installed memote from my fork/branch, I got this report: Image

Even though the report looks good, I'm mildly concerned that the way I wrote the check won't be able to skip anything since I'm not sure the if statement could ever get caught, but for my purposes, this works.

hgscott commented 11 months ago

Now I have a giant list of reactions involved in making ATP, and I don't know what to do with it: Image

hgscott commented 11 months ago

I started with trying to manually draw a cycle, starting from the first reaction in the list.

I looked up one of the metabolites in that reaction, and saw that it was involved in just one other reaction in the list by running this code:

# Find all reactions that involve PRPP (what rxn00836 produces)
metabolite_id = "cpd00103_c0"
# Check if the metabolite exists in the model
if metabolite_id in model.metabolites:
    metabolite = model.metabolites.get_by_id(metabolite_id)
else:
    raise ValueError(f"Metabolite {metabolite_id} not found in the model.")

# Find all reactions containing the metabolite
reactions_with_metabolite = [reaction.id for reaction in model.reactions if metabolite in reaction.metabolites if reaction.id in cycle_rxns]

I then looked up that next reaction, and the metabolites involved in that reaction.

I ended up with this map, and gave up. I want to find an automated way to do this. Image

hgscott commented 11 months ago

I went back to how I changed the MEMOTE code to be a better fix.

The memote function helpers.find_met_in_model does not return nothing if the metabolite is missing from the model, it returns a runtime error. So instead of the if ... is None I did a try and except:

Here's the new code:

main_comp = helpers.find_compartment_id_in_model(model, "c")
    try:
        helpers.find_met_in_model(model, met, main_comp)[0]
    except:
        pytest.skip(
            "This test has been skipped since metabolite {} could "
            "not be found in the model.".format(met)
        )

Which gave me this report (now skipping metabolites instead of erroring): Image

But I don't know why the number of reaction decreased from 150 to 80.

hgscott commented 11 months ago

I added dilution fluxes using Devlin's tool: Image

And then ran FVA using COBRA with:

fva_res = cobra.flux_analysis.flux_variability_analysis(model, model.reactions)

I saved the results to excel and calculated the difference between the maximum flux and the minimum flux and sorted based on that difference: Image

Devlin said that all the reactions in a cycle would have the same flux, so I took all the reactions with a difference of 2000, and made/drew a NetworkX graph: Image

And now I don't know what to do.

hgscott commented 11 months ago

When I run MEMOTE locally, I only get 3 reactions for ATP. Image

Why do I keep getting different results with MEMOTE?

hgscott commented 11 months ago

I had the idea that different numbers (at least the 152 and the 84) could be coming from different flux solutions that are giving same amount of ATP. No idea where the 3 is coming from.

So I want to run MEMOTE a lot of times and see the distribution of values I get.

hgscott commented 11 months ago

No, I ran the GitHub action 4 times and got 84 each time. So now I have no idea where the 152 came from either.

hgscott commented 11 months ago

Rather than using MEMOTE, I tried to do the same thing myself-

I blocked all uptake: Image

Then I found my maintenance reaction, and set it as the objective: Image

And I optimized, but I got no ATP production: Image

hgscott commented 11 months ago

Based on what MEMOTE does, I added demand reactions for water, protons, and phosphate: Image

But that still didn't work.

hgscott commented 11 months ago

I added water to the media, but that didn't work.

hgscott commented 11 months ago

I did what MEMOTE actually does, and instead of adding boundaries for the three metabolites, I added one reaction where water is the reactant and proton and phosphate are the prodcuts: Image

And then when I optimized, I did not non-zero fluxes! Image

This small number is different than the 3 that MEMOTE was giving me locally- except for one reaction, rxn08173.

hgscott commented 11 months ago

This thread was getting very long/less well defined, so I divided this into subtasks: