Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
62 changes: 54 additions & 8 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,9 @@
],
className="mb-3",
),
dbc.InputGroup(
[
dbc.InputGroupAddon("Dataset Password (if private MSV) - Beta Feature", addon_type="prepend"),
dbc.Input(id='dataset_password', placeholder="Enter Dataset Password", type="password", value=""),
],
className="mb-3",
),
dbc.Button("Enter Credentials", block=False, size="sm", id="credentials_modal_button"),
html.Br(),
html.Hr(),
dbc.Row([
dbc.Col(
dbc.FormGroup(
Expand Down Expand Up @@ -226,13 +221,53 @@
)
]

PRIVATE_CREDENTIALS_MODAL = [
dbc.Modal(
[
dbc.ModalHeader("Credentials (Beta)"),
dbc.ModalBody([
dbc.InputGroup(
[
dbc.InputGroupAddon("Dataset Password (if private MSV)", addon_type="prepend"),
dbc.Input(id='dataset_password', placeholder="Enter Dataset Password", type="password", value=""),
],
className="mb-3",
),
html.Hr(),
dbc.InputGroup(
[
dbc.InputGroupAddon("JGI Username", addon_type="prepend"),
dbc.Input(id='jgi_username', placeholder="Enter Username Password", value=""),
],
className="mb-3",
),
dbc.InputGroup(
[
dbc.InputGroupAddon("JGI Password", addon_type="prepend"),
dbc.Input(id='jgi_password', placeholder="Enter Dataset Password", type="password", value=""),
],
className="mb-3",
),
]),
dbc.ModalFooter(
dbc.Button("Close", id="credentials_modal_close", className="ml-auto")
),
],
id="credentials_modal",
size="xl",
),
]

BODY = dbc.Container(
[
dbc.Row([
dbc.Col(
dbc.Card(DASHBOARD)
),
], style={"marginTop": 30}),
dbc.Row(
PRIVATE_CREDENTIALS_MODAL
)
],
className="mt-12",
)
Expand Down Expand Up @@ -447,7 +482,7 @@ def create_link(accession, dataset_password, file_table_data, selected_table_dat
download_button = dbc.Button("Download First Selected File", color="primary", className="mr-1")
download_link = dcc.Link(download_button, href=download_url, target="_blank")
else:
download_link = html.Br()
download_link = html.Br()
else:
download_link = html.Br()

Expand Down Expand Up @@ -563,6 +598,17 @@ def dataset_information(accession, dataset_password):
def set_page_size(page_size):
return [int(page_size), int(page_size)]

# Helping to toggle the modals
def toggle_modal(n1, n2, is_open):
if n1 or n2:
return not is_open
return is_open

app.callback(
Output("credentials_modal", "is_open"),
[Input("credentials_modal_button", "n_clicks"), Input("credentials_modal_close", "n_clicks")],
[State("credentials_modal", "is_open")],
)(toggle_modal)


if __name__ == "__main__":
Expand Down
37 changes: 37 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ def get_dataset_files(accession, metadata_source, dataset_password="", metadata_
elif "ST" in accession:
files_df, dataset_accession = _get_metabolomicsworkbench_files(accession)

elif "JGI:" in accession:
all_files = _get_jgi_files(accession)
temp_df = pd.DataFrame(all_files)
files_df = pd.DataFrame()
files_df["filename"] = temp_df["filename"]

elif len(accession) == 32:
# We're likely looking at a uuid from GNPS, lets hit the API
all_files = _get_gnps_task_files(accession)
Expand Down Expand Up @@ -238,6 +244,37 @@ def _get_metabolomicsworkbench_dataset_information(dataset_accession):
return metabolomics_workbench_data["study_title"], metabolomics_workbench_data["study_summary"]


def _get_jgi_files(dataset_accession):
url = "https://genome.jgi.doe.gov/portal/ext-api/downloads/get-directory?organism={}&organizedByFileType=false".format(dataset_accession.replace("JGI:", ""))
session = requests.Session()
r = session.post('https://signon.jgi.doe.gov/signon/create', params={"login": "", "password": ''})
cookies = session.cookies.get_dict()

r = session.get(url, cookies=cookies)

acceptable_extensions = [".raw", ".mzML", ".mzXML", ".CDF", ".RAW", "cdf"]

output_list = []

import xmltodict as xtd
import json
dataset_list = xtd.parse(r.text)
all_folders = dataset_list["organismDownloads"]["folder"]["folder"][0]["folder"][0]["folder"]

for folder in all_folders:
file_url = "https://genome.jgi.doe.gov{}".format(folder["file"]["@url"])
filename = folder["file"]["@filename"]

_, extension = os.path.splitext(filename)

if extension in acceptable_extensions:
output_dict = {}
output_dict["filename"] = filename
output_dict["remote_link"] = file_url
output_list.append(output_dict)

return output_list


def _get_pxd_files(dataset_accession):
url = "http://proteomecentral.proteomexchange.org/cgi/GetDataset?ID={}&outputMode=json&test=no".format(dataset_accession)
Expand Down