Skip to content

add genomics filter #23

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

Merged
merged 30 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
30 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
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
21173ac
fix import error
gcroci2 Aug 12, 2024
573ef52
add last suggestions
gcroci2 Aug 12, 2024
a77bea2
remove gm_text_input_ids_placeholder var
gcroci2 Aug 13, 2024
0644ed1
remove sys.path.append
gcroci2 Aug 13, 2024
d811c0d
fix tests
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
189 changes: 3 additions & 186 deletions app/app.py
Original file line number Diff line number Diff line change
@@ -1,191 +1,8 @@
import os
import pickle
import tempfile
import uuid
import dash_bootstrap_components as dbc
import dash_uploader as du
from dash import Dash
from dash import Input
from dash import Output
from dash import clientside_callback
from dash import dcc
from dash import html
from callbacks import app
from layouts import create_layout


dbc_css = "https://cdn.jsdelivr.net/gh/AnnMarieW/dash-bootstrap-templates/dbc.min.css"
app = Dash(__name__, external_stylesheets=[dbc.themes.UNITED, dbc_css, dbc.icons.FONT_AWESOME])

# ------------------ Nav Bar ------------------ #
color_mode_switch = html.Span(
[
dbc.Label(className="fa fa-moon", html_for="color-mode-switch"),
dbc.Switch(
id="color-mode-switch",
value=False,
className="d-inline-block ms-1",
persistence=True,
),
dbc.Label(className="fa fa-sun", html_for="color-mode-switch"),
],
className="p-2",
)

# Define the navigation bar
navbar = dbc.Row(
dbc.Col(
dbc.NavbarSimple(
children=[
dbc.NavItem(dbc.NavLink("Doc", href="https://nplinker.github.io/nplinker/latest/")),
dbc.NavItem(
dbc.NavLink("About", href="https://github.com/NPLinker/nplinker-webapp"),
),
dbc.NavItem(
color_mode_switch,
className="mt-1 p-1",
),
],
brand="NPLinker Webapp",
color="primary",
className="p-3 mb-2",
dark=True,
),
),
)

# ------------------ Uploader ------------------ #
# Configure the upload folder
TEMP_DIR = tempfile.mkdtemp()
du.configure_upload(app, TEMP_DIR)

uploader = html.Div(
[
dbc.Row(
dbc.Col(
du.Upload(
id="dash-uploader",
text="Import Data",
text_completed="Uploaded: ",
filetypes=["pkl", "pickle"],
upload_id=uuid.uuid1(), # Unique session id
cancel_button=True,
max_files=1,
),
)
),
dbc.Row(
dbc.Col(
html.Div(children="No file uploaded", id="dash-uploader-output", className="p-4"),
className="d-flex justify-content-center",
)
),
dcc.Store(id="file-store"), # Store to keep the file contents
],
className="p-5 ml-5 mr-5",
)

# ------------------ Tabs ------------------ #
# gm tab content
gm_content = dbc.Row(
dbc.Col(
dbc.Card(
dbc.CardBody([html.Div(id="file-content-gm")]),
)
)
)
# mg tab content
mg_content = dbc.Row(
dbc.Col(
dbc.Card(
dbc.CardBody([html.Div(id="file-content-mg")]),
)
),
)
# tabs
tabs = dbc.Row(
dbc.Col(
dbc.Tabs(
[
dbc.Tab(
gm_content,
label="Genomics -> Metabolomics",
activeTabClassName="fw-bold",
disabled=True,
id="gm-tab",
className="disabled-tab",
),
dbc.Tab(
mg_content,
label="Metabolomics -> Genomics",
activeTabClassName="fw-bold",
disabled=True,
id="mg-tab",
className="disabled-tab",
),
],
),
),
className="p-5",
)

# ------------------ App Layout ------------------ #
app.layout = dbc.Container([navbar, uploader, tabs], fluid=True, className="p-0")

# ------------------ Callbacks------------------ #
clientside_callback(
"""
(switchOn) => {
document.documentElement.setAttribute('data-bs-theme', switchOn ? 'light' : 'dark');
return window.dash_clientside.no_update
}
""",
Output("color-mode-switch", "id"),
Input("color-mode-switch", "value"),
)


@du.callback(
id="dash-uploader",
output=[Output("dash-uploader-output", "children"), Output("file-store", "data")],
)
def upload_data(status: du.UploadStatus): # noqa: D103
if status.is_completed:
latest_file = status.latest_file
with open(status.latest_file, "rb") as f:
pickle.load(f)
return (
f"Successfully uploaded: {os.path.basename(latest_file)} [{round(status.uploaded_size_mb, 2)} MB]",
str(latest_file),
)
return "No file uploaded", None


@app.callback(
[Output("gm-tab", "disabled"), Output("mg-tab", "disabled")],
[Input("file-store", "data")],
prevent_initial_call=True,
)
def disable_tabs(file_name): # noqa: D103
if file_name is None:
# Disable the tabs
return True, True
# Enable the tabs
return False, False


# Define another callback to access the stored file path and read the file
@app.callback(
[Output("file-content-gm", "children"), Output("file-content-mg", "children")],
[Input("file-store", "data")],
)
def display_file_contents(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, content # Display same content in both tabs
return "No data available", "No data available"

app.layout = create_layout()

if __name__ == "__main__":
app.run_server(debug=True)
25 changes: 25 additions & 0 deletions app/assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,29 @@

.nav-tabs .nav-item .nav-link.disabled {
color: #888888 !important; /* Set your desired color here */
}

.btn-primary {
/* Use theme color or styles explicitly */
background-color: #FF6E42 !important; /* Primary color in the UNITED theme */
border-color: #f19e85 !important;
}

.btn-primary:hover {
background-color: #e0400f !important; /* Hover color */
border-color: #f19e85 !important;
}

.btn-primary:active {
background-color: #e0400f !important;
border-color: #f19e85 !important;
}

.btn-primary:focus {
box-shadow: 0 0 0 0.2rem #e0400f !important; /* Focus outline color */
border-color: #f19e85 !important; /* Focus border color */
}

.custom-textinput .mantine-TextInput-input:focus {
border-color: #FF6E42 !important; /* Customize border color */
}
Loading
Loading