stelmo / Escher.jl

Visualization of metabolic models in Makie.
MIT License
20 stars 1 forks source link

Reversible reaction arrows not showing #5

Closed jchitpin closed 2 years ago

jchitpin commented 2 years ago

Hi again,

It's been a while since I've used Escher.jl for visualizing networks and am having issues with reversible reactions only showing arrowheads in one direction. I updated to Escher.jl version v0.6.5 and was following your tutorial with the E. coli core model from Bigg/Escher. From what I remember, there was no issue the first time you implemented reaction directions, but I haven't done any regression testing.

using Escher, CairoMakie, ColorSchemes
rd = Dict(
    "PGM" => (Dict("3pg_c" => 1, "2pg_c" => -1), :r),
    "PYK" => (Dict("pep_c" => -1, "adp_c" => -1, "h_c" => -1.0, "atp_c" => 1.0, "pyr_c" => 1), :f)

f = Figure(resolution = (1200, 800));
ax = Axis(f[1, 1]);
escherplot!(
    ax,
    "/path/to/escher-map-file/e_coli_core.Core metabolism.json",
    reaction_directions = rd,
    reaction_arrow_size = 12,
    reaction_show_text = true,
)
hidexdecorations!(ax)
hideydecorations!(ax)

The resulting plot is identical to yours with only a single arrow head for the reversible PGM reaction.

stelmo commented 2 years ago

Ah, this is definitely something I broke! I'm just on holiday at the moment, I will fix it once I get back in about a week.

jchitpin commented 2 years ago

No worries! Enjoy your holiday and take your time.

stelmo commented 2 years ago

Hi there, can you check out branch #6 and see if it works? You can add directionality with :forward, :backward and :bidirectional as shown here:

rd = Dict(
    "PGM" => (Dict("3pg_c" => 1, "2pg_c" => -1), :backward),
    "PYK" => (Dict("pep_c" => -1, "adp_c" => -1, "h_c" => -1.0, "atp_c" => 1.0, "pyr_c" => 1), :forward),
    "ENO" => (Dict("2pg_c" => 1, "pep_c" => -1, "h2o_c" => -1), :bidirectional),
)

f = Figure(resolution = (1200, 800));
ax = Axis(f[1, 1]);
escherplot!(
    ax,
    joinpath(pkgdir(Escher), "data", "core-map.json");
    reaction_directions = rd,
    reaction_arrow_size = 12,
    reaction_show_text = true,
)
hidexdecorations!(ax)
hideydecorations!(ax)
f
jchitpin commented 2 years ago

Hi again. Can confirm that branch 6 works perfectly. I did the following to generate rd for an entire Bigg/Escher network. Many thanks :)

# rev is the reaction vector with 1=reversible reaction and 0 otherwise.
rev_dict = Dict(zip([0, 1], [:forward, :bidirectional]))

model = load_model("/bigg-models/e_coli_core.json")
rd = Dict(#
  String(model.rxns[k]["id"]) => (#
    Dict{String,Float64}(model.rxns[k]["metabolites"]),
    rev_dict[rev[k]]
  )
  for k in 1:length(model.rxns)
)