Commit 4ef9c60e authored by Terlouw, Barbara's avatar Terlouw, Barbara
Browse files

Added button for loading .zip folder

parent 6aa50f87
......@@ -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",
......
......@@ -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(
......
......@@ -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",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment