Skip to content
Snippets Groups Projects
Commit 4ef9c60e authored by Terlouw, Barbara's avatar Terlouw, Barbara
Browse files

Added button for loading .zip folder

parent 6aa50f87
Branches
No related tags found
No related merge requests found
File added
...@@ -22,7 +22,7 @@ setup( ...@@ -22,7 +22,7 @@ setup(
"dash", "dash",
"dash-bio==0.5.*", "dash-bio==0.5.*",
"dash-daq", "dash-daq",
"dash-bio-utils", "dash-bio-utils==0.0.6",
"cryptography", "cryptography",
"dash-cytoscape==0.2.0", "dash-cytoscape==0.2.0",
"dash-extensions", "dash-extensions",
......
...@@ -6,6 +6,7 @@ from dash_extensions.enrich import Trigger, ServersideOutput, Output, Input, Sta ...@@ -6,6 +6,7 @@ from dash_extensions.enrich import Trigger, ServersideOutput, Output, Input, Sta
import os import os
from zipfile import ZipFile, ZIP_DEFLATED from zipfile import ZipFile, ZIP_DEFLATED
import zlib import zlib
import io
from dash_extensions.snippets import send_file from dash_extensions.snippets import send_file
from turterra.app_layout import BUTTON_STYLE from turterra.app_layout import BUTTON_STYLE
from turterra.turterra import TurterraData from turterra.turterra import TurterraData
...@@ -70,8 +71,8 @@ def register_callbacks(app): ...@@ -70,8 +71,8 @@ def register_callbacks(app):
"nodes": turterra_data.tree.nodes, "nodes": turterra_data.tree.nodes,
"edges": turterra_data.tree.edges, "edges": turterra_data.tree.edges,
} }
return turterra_data, tree_elements return [turterra_data, tree_elements]
return None, [] return [None, []]
# Filter accessions # Filter accessions
@app.callback( @app.callback(
...@@ -888,6 +889,39 @@ def register_callbacks(app): ...@@ -888,6 +889,39 @@ def register_callbacks(app):
for file_name in os.listdir("uploaded_data/structures")] for file_name in os.listdir("uploaded_data/structures")]
return None 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): def get_sequence_viewer_information(accession: str, turterra_data: TurterraData):
return html.Div( return html.Div(
......
...@@ -20,6 +20,7 @@ def get_layout(): ...@@ -20,6 +20,7 @@ def get_layout():
return html.Div( return html.Div(
children=[ children=[
get_introduction_panel(), get_introduction_panel(),
get_loading_panel(),
html.Div( html.Div(
className="pure-g", children=[get_input_panel(), get_tree_panel(), ] className="pure-g", children=[get_input_panel(), get_tree_panel(), ]
), ),
...@@ -406,6 +407,36 @@ def get_compound_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(): def get_upload_panel():
return html.Div( return html.Div(
id="upload-panel", id="upload-panel",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment