From 4ef9c60efda0bed14f3a90b08146b8ab155deda0 Mon Sep 17 00:00:00 2001 From: "Terlouw, Barbara" <barbara.terlouw@wur.nl> Date: Wed, 5 Jan 2022 11:56:32 +0100 Subject: [PATCH] Added button for loading .zip folder --- .../2029240f6d1128be89ddc32729463129 | Bin 0 -> 8 bytes setup.py | 2 +- turterra/app_callbacks.py | 38 +++++++++++++++++- turterra/app_layout.py | 31 ++++++++++++++ 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 file_system_store/2029240f6d1128be89ddc32729463129 diff --git a/file_system_store/2029240f6d1128be89ddc32729463129 b/file_system_store/2029240f6d1128be89ddc32729463129 new file mode 100644 index 0000000000000000000000000000000000000000..7e3b954501c59fc5c9ccdfb32cc63f4365e4cce7 GIT binary patch literal 8 PcmeZf&}(4zX3zrw2NwZ& literal 0 HcmV?d00001 diff --git a/setup.py b/setup.py index b66052e..f0a9f33 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ setup( "dash", "dash-bio==0.5.*", "dash-daq", - "dash-bio-utils", + "dash-bio-utils==0.0.6", "cryptography", "dash-cytoscape==0.2.0", "dash-extensions", diff --git a/turterra/app_callbacks.py b/turterra/app_callbacks.py index c32b608..127c4e9 100644 --- a/turterra/app_callbacks.py +++ b/turterra/app_callbacks.py @@ -6,6 +6,7 @@ from dash_extensions.enrich import Trigger, ServersideOutput, Output, Input, Sta import os from zipfile import ZipFile, ZIP_DEFLATED import zlib +import io from dash_extensions.snippets import send_file from turterra.app_layout import BUTTON_STYLE from turterra.turterra import TurterraData @@ -70,8 +71,8 @@ def register_callbacks(app): "nodes": turterra_data.tree.nodes, "edges": turterra_data.tree.edges, } - return turterra_data, tree_elements - return None, [] + return [turterra_data, tree_elements] + return [None, []] # Filter accessions @app.callback( @@ -888,6 +889,39 @@ def register_callbacks(app): for file_name in os.listdir("uploaded_data/structures")] return None + @app.callback( + [ + ServersideOutput("input-turterra-data", "data"), + Output("phylogeny-tree-viewer", "elements"), + ], + [ + Input("load-zip", "filename"), + Input("load-zip", "contents"), + ], + ) + def upload_zipped_data(file_name, zip_contents): + if file_name and zip_contents: + if file_name.endswith('.zip'): + content_type, content_string = zip_contents.split(',') + decoded = base64.b64decode(content_string) + zip_str = io.BytesIO(decoded) + folder = '.'.join(file_name.split('.')[:-1]) + + with ZipFile(zip_str) as z: + z.extractall("data") + + directory = os.path.join("data", folder) + turterra_data = TurterraData.from_folder(directory) + + if turterra_data: + tree_elements = { + "nodes": turterra_data.tree.nodes, + "edges": turterra_data.tree.edges, + } + return [turterra_data, tree_elements] + + return [None, []] + def get_sequence_viewer_information(accession: str, turterra_data: TurterraData): return html.Div( diff --git a/turterra/app_layout.py b/turterra/app_layout.py index d9033bc..cfc0c09 100644 --- a/turterra/app_layout.py +++ b/turterra/app_layout.py @@ -20,6 +20,7 @@ def get_layout(): return html.Div( children=[ get_introduction_panel(), + get_loading_panel(), html.Div( className="pure-g", children=[get_input_panel(), get_tree_panel(), ] ), @@ -406,6 +407,36 @@ def get_compound_panel(): ) +def get_loading_panel(): + return html.Div( + id="loading-panel", + children=[ + html.Div( + html.P( + """Upload a .zip folder generated by turterra-build or manually constructed according to + guidelines described in the wiki.""" + ), + ), + html.Div( + [ + dcc.Upload( + id="load-zip", + children=html.Button( + "Load data", + id="load-zip-button", + className="pure-button pure-button-primary", + style=BUTTON_STYLE, + ), + ), + ], + ), + + ], + className="pure-u-1 pure-u-md-1-2", + style=BOX_STYLE, + ) + + def get_upload_panel(): return html.Div( id="upload-panel", -- GitLab