Skip to content

Commit

Permalink
Update hover information on 2D and 3D figures
Browse files Browse the repository at this point in the history
Close #7 and close #25
  • Loading branch information
Thibault-Poinsignon committed Sep 10, 2021
1 parent c122bb0 commit fef6140
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
24 changes: 19 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@
[
dbc.Col(
[
dcc.Graph(id="3D_representation_chrom"),
dcc.Loading(children=[dcc.Graph(id="3D_representation_chrom")]),
])
])
],
Expand Down Expand Up @@ -550,8 +550,23 @@ def update_3D_graph_chrom_tab1(n_clicks):

selected_loci_segments = vis3D.get_color_discreet_3D(selected_loci_segments, "Chromosome", list(range(1, 17)), colors)

return vis3D.genome_drawing(selected_loci_segments)
fig = go.Figure(data=[go.Scatter3d(x = selected_loci_segments.x,
y = selected_loci_segments.y,
z = selected_loci_segments.z,
mode = "lines",
name = "",
line = {"color": selected_loci_segments["legend"],
"width": 12},
customdata = selected_loci_segments["Chromosome"],
hovertemplate = ("<b>Chromosome :</b> %{customdata} <br>"),
hoverlabel = dict(bgcolor = "white", font_size = 16))])

fig.update_layout(scene=dict(xaxis = dict(showgrid = False, backgroundcolor = "white"),
yaxis = dict(showgrid = False, backgroundcolor = "white"),
zaxis = dict(showgrid = False, backgroundcolor = "white")))
fig.update_layout(height=800)

return fig
############TAB2_UPLOAD############
@app.callback(Output("output_data_upload_tab2", "children"),
Input("upload_data_tab2", "contents"),
Expand Down Expand Up @@ -609,9 +624,8 @@ def update_3D_graphs_tab2(n_clicks, input1, input2, input3):
"colorscale": input3,
"showscale": True,
"width": 12},
customdata=whole_genome_segments.Primary_SGDID,
hovertemplate=("<b>SGDID :</b> %{customdata} <br>"
"<b>x :</b> %{x} <br>"),
customdata=whole_genome_segments.Feature_name,
hovertemplate=("<b>YORF :</b> %{customdata} <br>"),
hoverlabel=dict(bgcolor="white", font_size=16))])

fig.update_layout(scene=dict(xaxis=dict(showgrid=False, backgroundcolor="white"),
Expand Down
8 changes: 4 additions & 4 deletions lib/visualization_2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def genome_drawing(genome_data, parameter, values = "null", values_colors = "nul
fig = px.line(genome_data,
x = "x",
y = "y",
color = "colors",
color = "legend",
color_discrete_map = {"Other": "darkgrey", "Background": "lightgrey", **color_discrete_map},
hover_name = "Feature_name")

Expand Down Expand Up @@ -227,11 +227,11 @@ def get_color_discreet(genome_data, parameter, values):
-------
Pandas dataframe
"""
genome_data.loc[genome_data[parameter] != values[0], "colors"] = "Other"
genome_data.loc[genome_data[parameter] != values[0], "legend"] = "Other"

for v in values :
genome_data.loc[genome_data[parameter] == v, "colors"] = v
genome_data.loc[genome_data[parameter] == v, "legend"] = v

genome_data.loc[genome_data["Chromosome"] == 0, "colors"] = "Background"
genome_data.loc[genome_data["Chromosome"] == 0, "legend"] = "Background"

return genome_data
8 changes: 4 additions & 4 deletions lib/visualization_3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def genome_drawing(whole_genome_segments):
z = whole_genome_segments.z,
mode = "lines",
name = "",
line = {"color": whole_genome_segments["colors"],
line = {"color": whole_genome_segments["legend"],
"width": 12},
customdata = whole_genome_segments["Feature_name"],
hovertemplate = ("<b>YORF :</b> %{customdata} <br>"),
Expand Down Expand Up @@ -54,11 +54,11 @@ def get_color_discreet_3D(genome_data, parameter, values, values_colors):
Pandas dataframe
"""

genome_data.loc[genome_data[parameter] != values[0], "colors"] = "darkgrey"
genome_data.loc[genome_data[parameter] != values[0], "legend"] = "darkgrey"

for v, c in zip(values, values_colors):
genome_data.loc[genome_data[parameter] == v, "colors"] = c
genome_data.loc[genome_data[parameter] == v, "legend"] = c

genome_data.loc[genome_data["Primary_SGDID"].isna() == True, "colors"] = "whitesmoke"
genome_data.loc[genome_data["Primary_SGDID"].isna() == True, "legend"] = "whitesmoke"

return genome_data

0 comments on commit fef6140

Please sign in to comment.