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

create plot for inspecting the data #24

Merged
merged 31 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4b2ab88
update nplinker version
gcroci2 Jul 29, 2024
1f620f8
move callbacks to file
gcroci2 Jul 29, 2024
3771cd5
fix tests
gcroci2 Jul 29, 2024
8b90bfe
move layouts to specific file
gcroci2 Jul 29, 2024
b3088bb
remove unused init and comment
gcroci2 Jul 29, 2024
586205d
improve layout structure by removing the functions
gcroci2 Jul 29, 2024
ccf44c4
fix linting error
gcroci2 Jul 29, 2024
cbd1ab6
fix mypy issues
gcroci2 Jul 29, 2024
f344618
add gcfs filters to gm tab
gcroci2 Jul 30, 2024
7683c3a
add collapse functionality
gcroci2 Jul 30, 2024
67d8355
add tests for gm_filter
gcroci2 Jul 30, 2024
db55eea
add graph for gm tab
gcroci2 Jul 30, 2024
ef02754
use accordion instead of button
gcroci2 Aug 5, 2024
95d4457
use dmc grid for filter
gcroci2 Aug 5, 2024
76842a3
add the add filter functionality
gcroci2 Aug 5, 2024
1ef908d
start with one filter block and keep button only on the last ones
gcroci2 Aug 5, 2024
17b79ac
improve ids name, add default filter value, improve gcf ids hint
gcroci2 Aug 6, 2024
d0d3bef
use unique id for the first block
gcroci2 Aug 7, 2024
d87c0f7
keep previous dropdown and input text values when a new block is added
gcroci2 Aug 7, 2024
34fb975
change bigscape class to multivalue bgc class
gcroci2 Aug 7, 2024
5bcabfe
update tests
gcroci2 Aug 7, 2024
56d32a4
order BGC classes and add config
gcroci2 Aug 9, 2024
0e232f4
handle fake file upload
gcroci2 Aug 9, 2024
981817d
add type hints and doc stringas
gcroci2 Aug 9, 2024
c11da79
fix mypy error
gcroci2 Aug 9, 2024
18ebd60
fix tests
gcroci2 Aug 9, 2024
81c258c
narrow bars for fewer number of bars
gcroci2 Aug 9, 2024
7f34eea
simplify defaultdict
gcroci2 Aug 9, 2024
18d424a
add GCF IDs to hover texts
gcroci2 Aug 9, 2024
94d674d
merge with 18_genomics_filter_gcroci2
gcroci2 Aug 9, 2024
85b3394
merge with main
gcroci2 Aug 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 42 additions & 13 deletions app/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dash_bootstrap_components as dbc
import dash_mantine_components as dmc
import dash_uploader as du
import plotly.graph_objects as go
from config import GM_DROPDOWN_BGC_CLASS_OPTIONS
from config import GM_DROPDOWN_MENU_OPTIONS
from dash import ALL
Expand Down Expand Up @@ -106,27 +107,55 @@ def disable_tabs(file_name: str | None) -> tuple[bool, bool, bool]:
return False, False, False


# Define another callback to access the stored file path and read the file
@app.callback(
Output("gm-graph", "figure"),
Output("gm-graph", "style"),
Output("file-content-mg", "children"),
[Input("file-store", "data")],
)
def display_file_contents(file_path: str | None) -> str:
"""Read and display the contents of the uploaded file.

Args:
file_path: The path to the uploaded file.

Returns:
A string representation of the file contents.
"""
def gm_plot(file_path): # noqa: D103
if file_path is not None:
with open(file_path, "rb") as f:
data = pickle.load(f)
# Process and display the data as needed
content = f"File contents: {data[0][:2]}"
return content # Display same content in both tabs
return "No data available"
_, gcfs, _, _, _, _ = data
n_bgcs = {}
for gcf in gcfs:
n = len(gcf.bgcs)
if n not in n_bgcs:
n_bgcs[n] = [gcf.id]
else:
n_bgcs[n].append(gcf.id)
x_values = list(n_bgcs.keys())
x_values.sort()
y_values = [len(n_bgcs[x]) for x in x_values]
hover_texts = [f"GCF IDs: {', '.join(n_bgcs[x])}" for x in x_values]
# Adjust bar width based on number of data points
if len(x_values) <= 5:
bar_width = 0.4
else:
bar_width = None
# Create the bar plot
fig = go.Figure(
data=[
go.Bar(
x=x_values,
y=y_values,
text=hover_texts,
hoverinfo="text",
textposition="none",
width=bar_width, # Set the bar width
)
]
)
# Update layout
fig.update_layout(
xaxis_title="# BGCs",
yaxis_title="# GCFs",
xaxis=dict(type="category"),
)
return fig, {"display": "block"}, "uploaded!!"
return {}, {"display": "none"}, "No data available"


@app.callback(
Expand Down
9 changes: 8 additions & 1 deletion app/layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,15 @@
],
className="mt-5 mb-3",
)
# gm graph
gm_graph = dcc.Graph(id="gm-graph", className="mt-5 mb-3", style={"display": "none"})
# gm tab content
gm_content = dbc.Row(dbc.Col(gm_accordion, width=10, className="mx-auto"))
gm_content = dbc.Row(
[
dbc.Col(gm_accordion, width=10, className="mx-auto"),
dbc.Col(gm_graph, width=10, className="mx-auto"),
]
)
# mg tab content
mg_content = dbc.Row(
dbc.Col(
Expand Down
Loading