Skip to content
Closed
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
5 changes: 5 additions & 0 deletions custom_files/pipeline_project_map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"epi2me-human-variation": ["nf-long-reads"],
"epi2me-somatic-variation": ["mopopgen-support"],
"nfcore-rnaseq": ["nf-tp53"]
}
7 changes: 7 additions & 0 deletions custom_files/user_whitelist.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
username group account-code
admin admin None
msarkis SCIENCOM None
ralcraft SCIENCOM None
sstephens OGENETIC None
jhouseham UNKNOWN None
ahyde1 MOPOPGEN None
4 changes: 2 additions & 2 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@


def main():
p1 = st.Page("pages/login.py")
p2 = st.Page("pages/run_pipeline.py")
p1 = st.Page("views/login.py")
p2 = st.Page("views/run_pipeline.py")
nav_pages = [p1, p2]
pages = {"p1": p1, "p2": p2}
st.session_state["pages"] = pages
Expand Down
45 changes: 0 additions & 45 deletions pages/login.py

This file was deleted.

11 changes: 11 additions & 0 deletions pipeline_project_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import json


def load_json_to_dict(file_path):
with open(file_path, "r") as file:
data = json.load(file)
return data


file_path = "custom_files/pipeline_project_map.json"
map_pipeline_project = load_json_to_dict(file_path)
18 changes: 16 additions & 2 deletions tabs/tab_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import pandas as pd
import streamlit as st

# from ping3 import ping
# Initialize session state variables
if "run_pipeline_clicked" not in st.session_state:
st.session_state.run_pipeline_clicked = False


@contextmanager
Expand Down Expand Up @@ -67,6 +69,9 @@ def tab(username, MY_SSH, selected_pipeline, selected_project, selected_samples=
)

def run_nextflow(): # username, MY_SSH, selected_pipeline, selected_project):
st.success("Button clicked!")
print("run_nextflow was called")
return True # temporary
cmd_pipeline = pipe_cmd(
username, selected_pipeline, selected_project, cmd_num=0, selected_samples="all"
) # develop this
Expand All @@ -90,5 +95,14 @@ def check_queue(): # username):
st.error(err_str)

left_column, right_column = st.columns(2)
left_column.button(f"Run the selected nextflow pipeline for {username}", on_click=run_nextflow)
# disable button once the user click a first time. by default it gets disabled after calling the callback
v = left_column.button(
f"Run the selected nextflow pipeline for {username}", disabled=st.session_state.run_pipeline_clicked
) # on_click=run_nextflow,
if v:
st.session_state.run_pipeline_clicked = True
run_nextflow()
print("session value:", st.session_state.run_pipeline_clicked)
# st.session_state.run_pipeline_clicked = True

right_column.button(f"Check queue for {username}", key="checkqueue", on_click=check_queue)
85 changes: 85 additions & 0 deletions views/login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import pandas as pd
import streamlit as st

import shared.sessionstate as ss
import tabs.tab_logon as tl

header = """
<span style="color:black;">
<img src="https://www.icr.ac.uk/assets/img/logo.png"
alt="icr" width="200px"></span><span style=
"color:darkred;font-size:40px;"> -🍃 </span><span style=
"color:green;font-size:40px;">RUN-NEXTFLOW</span><span style=
"color:darkred;font-size:40px;">🍃- </span>
"""
st.markdown(header, unsafe_allow_html=True)

st.write("--- ")

st.write("## Login")
st.write("Login to your alma account before running a nextflow pipeline.")

OK, MY_SSH, username = tl.tab()

ss.ss_set("LOGIN_OK", OK)
ss.ss_set("MY_SSH", MY_SSH)
ss.ss_set("user_name", username)


# I want to move between tabs automatically
# move between tabs
def display():
st.session_state["run_pipeline"] = True
if st.session_state.get("run_pipeline", False) and "login" in st.session_state:
if "pages" in st.session_state:
page = st.session_state["pages"].get("p2", None)
if page:
st.switch_page(page)


def display_restricted_access(username):
st.error(
f"⚠️ Access Restricted ⚠️\n\n"
f"Dear {username},\n\n"
"We apologize, but access to the nextflow-app is currently restricted. "
"For any requests or further information, please contact our support team.\n\n"
"**Contact Information:**\n"
"- **Name:** Mira Sarkis\n"
"- **Department:** Scientific Computing Helpdesk (SCHelpdesk)\n"
"- **Email:** [[email protected]](mailto:[email protected])\n\n"
"Thank you for your understanding."
)

st.info(
"ℹ️ **Note:** Please include your username and the reason for your request "
"when contacting the support team. This will help us process your request more efficiently."
)


def update_session_info(group, cost_account):
ss.ss_set("user_group", group)
ss.ss_set("user_cost_account", cost_account)


def check_whiteList(username):
whitelist = "custom_files/user_whitelist.tsv"
df = pd.read_csv(whitelist, delimiter="\t")
row = df.loc[df["username"] == username]
if row.empty: # user not on the white liste
return False

# update session info
update_session_info(row["group"], row["account-code"])
return True


if "login" not in st.session_state:
st.session_state["login"] = {}
if "run_pipeline" not in st.session_state:
st.session_state["run_pipeline"] = False

if OK:
if not check_whiteList(username):
display_restricted_access(username)
else:
display()
30 changes: 20 additions & 10 deletions pages/run_pipeline.py → views/run_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

import shared.sessionstate as ss
import tabs.tab_command as tt
from pipeline_project_map import map_pipeline_project

# Initialize session state variables
if "select1_value" not in st.session_state:
st.session_state.select1_value = None
if "select2_value" not in st.session_state:
st.session_state.select2_value = None


def reset_button_state():
st.session_state.button_clicked = False


header = """
<span style="color:black;">
Expand All @@ -22,23 +34,21 @@
MY_SSH = ss.ss_get("MY_SSH")
username = ss.ss_get("user_name")

pipelines = ["epi2me-human-variation", "epi2me-somatic-variation", "nfcore-rnaseq"]
projects = ["nf-long-reads", "nf-tp53", "mopopgen-support"]
samples = ["all", "demo"] # , "customised"]

map_pipeline_project = {
"epi2me-human-variation": ["nf-long-reads"],
"epi2me-somatic-variation": ["nf-tp53"],
"nfcore-rnaseq": ["mopopgen-support"],
}
selected_project = None
selected_samples = None

# adding "select" as the first and default choice
selected_pipeline = st.selectbox("Select a pipeline", options=["select"] + list(map_pipeline_project.keys()))
# display selectbox 2 if selected_pipeline is not "select"
if selected_pipeline != "select":
selected_project = st.selectbox("Select your project", options=map_pipeline_project[selected_pipeline])
selected_samples = st.selectbox("Select your samples", samples)
selected_project = st.selectbox(
"Select your project",
options=map_pipeline_project[selected_pipeline],
on_change=reset_button_state,
key="select_pipeline",
)
selected_samples = st.selectbox("Select your samples", samples, on_change=reset_button_state, key="selecct_samples")

# passing inputs between tabs
if LOGIN_OK:
Expand Down