pstjohn / d3flux

D3.js based visualizations of cobrapy metabolic models
MIT License
41 stars 9 forks source link

Not possible to overlap reactions #14

Open petzel96 opened 2 years ago

petzel96 commented 2 years ago

Hi Peter,

I love using d3flux, but I encountered an issue compared to 0.2.6. In the past, I sometimes had reactions overlap and co-factors on top of each other. In 0.2.7 it seems that every time I save a model as json, the overlapping reaction is moved to a free space. Is there an option to disable this behavior? I am trying to show that the (cofactor) product of one reaction is the cofactor input of another reaction. I appended a section of a map made with 0.2.6. Unfortunately, I can't replicate it due to the issue with jupyter notebook and 0.2.6.

Sincerely,

Tim d3flux_issue

pstjohn commented 2 years ago

Hey Tim,

Glad you're finding the package useful! That's odd, I don't think anything changed between those two versions that would impact how the reaction position is saved: https://github.com/pstjohn/d3flux/compare/0.2.6...0.2.7

Are you 'showing reaction nodes' and dragging those reactions and cofactors into position before saving? that should fix their position in the resulting json. Can you double check if x,y positions for the cofactors are saved in the notes['map_info']['cofactors'] field of the json file you create?

petzel96 commented 2 years ago

I am showing reaction nodes and dragging the reactions and cofactors into position before saving. The position is also saved. But the different reactions are always separated. Meaning for example that the shape of H20 -> O2 + H+ can be saved, but it will never lay over the PSII point. So the saving and writing it into a new json works, but something prevents the overlap of reactions.

pstjohn commented 2 years ago

Ah ok, so you want the H2O -> O2 + H+ reaction to go through the psII point? what happens if you open the JSON as a text file manually set the map_info x,y coordinates for the H2O reaction and PSII metabolite to be the same value?

petzel96 commented 2 years ago

I tried changing the positions in the json itself. They still don't overlap. The reaction center is set far away from PSII even though the x,y coordinates are identical. I am not quite sure how to fix this issue.

I appended a minimum working example. I just test it by running

bio = cobra.io.load_json_model('./test.json') d3flux.flux_map(bio, figsize=(1020,1040) test.txt ) *I had to convert it to text due to github limitations.

pstjohn commented 2 years ago

Ah, ok, thanks for the minimal example. Looks like it's an issue when you have non-connected graphs; i'm not sure why it's moving the reaction when it's not connected to the larger model.

bio = cobra.io.load_json_model('./test.json')

rxn = cobra.Reaction(id='test')
bio.add_reaction(rxn)
rxn.reaction = 'PSII --> H2O'
rxn.notes['map_info'] = {'hidden': False}

bio.reactions.rec08.notes['map_info']['x'] = bio.metabolites.PSII.notes['map_info']['x']
bio.reactions.rec08.notes['map_info']['y'] = bio.metabolites.PSII.notes['map_info']['y']

d3flux.flux_map(bio, figsize=(1020,1040))

Screen Shot 2022-06-29 at 3 32 26 PM

I'm not sure exactly what you're trying to show here though, the other option is to use two cofactor nodes and just make sure they overlap