Skip to content

Commit ca18780

Browse files
authored
Merge pull request #26 from ICR-RSE-Group/fix_issue_25
Fix_issue_25
2 parents 5c38dd5 + 89c52ed commit ca18780

File tree

3 files changed

+27
-23
lines changed

3 files changed

+27
-23
lines changed

pages/run_pipeline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ def reset_button_state():
3535
button_clicked = ss_values["button_clicked"]
3636
custom_sample_list = ss_values["custom_sample_list"] # only availanle if custom sample is selected
3737
BED_FILE = ss_values["BED_FILE"]
38-
samples = ["demo", "customised"] # , "test"]
38+
samples = ["demo", "customised"]
3939

4040
# Create the selectbox and update session state
4141
pipeline_options = ["select"] + list(map_pipeline_project.keys())
4242
index = pipeline_options.index(PIPELINE)
43-
PIPELINE = st.selectbox("Select a pipeline", options=pipeline_options, index=index) # , key="PIPELINE")
43+
PIPELINE = st.selectbox("Select a pipeline", options=pipeline_options, index=index)
44+
adapt_samples = False
4445
# adding "select" as the first and default choice
4546
if PIPELINE != "select":
4647
project_options = list(map_pipeline_project[PIPELINE].keys())
@@ -74,7 +75,6 @@ def reset_button_state():
7475
st.write("Your custom samples:", custom_sample_list)
7576
ss_set("custom_sample_list", custom_sample_list)
7677

77-
adapt_samples = False
7878
if(map_pipeline_project[PIPELINE][PROJECT]["adapt_samples"]):
7979
adapt_samples = st.checkbox("Adapt samples prior to running nextflow",
8080
value=False,

shared/command_helper.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from typing import Tuple, Optional
2+
import streamlit as st
33

44
def get_path_to_script(
55
selected_pipeline: str,
@@ -27,7 +27,7 @@ def pipe_cmd(
2727
selected_pipeline="",
2828
selected_project="",
2929
cmd_num=0,
30-
selected_samples="all",
30+
selected_samples="",
3131
work_dir="work",
3232
output_dir="output",
3333
custom_sample_list=[],
@@ -38,15 +38,13 @@ def pipe_cmd(
3838
def get_pipeline_command():
3939
"""Generate the pipeline execution command based on the sample selection."""
4040
path_to_script = get_path_to_script(selected_pipeline, selected_project, selected_samples)
41-
42-
# not sure if this is the best thing-using job id for filenamne
43-
log_out = f"{work_dir}/logs/%j.out"
44-
log_err = f"{work_dir}/logs/%j.err"
4541

4642
args = []
4743
base_cmd = f"bash {path_to_script}" #default
4844

4945
if selected_samples == "demo":
46+
log_out = f"{work_dir}/logs/log_demo.out"
47+
log_err = f"{work_dir}/logs/log_demo.err"
5048
base_cmd = f"sbatch -o {log_out} -e {log_err}"
5149
args += [path_to_script, work_dir, output_dir]
5250

@@ -64,7 +62,8 @@ def get_pipeline_command():
6462
args += ["--adapt-samples"]
6563
if bed_file:
6664
args += ["--bed", bed_file]
67-
65+
66+
# note: I use logs/log_{samplename} for sample logs
6867
preamble = f"""
6968
mkdir -p {work_dir}/logs
7069
cd {work_dir}
@@ -75,16 +74,16 @@ def get_pipeline_command():
7574

7675
# Command mappings
7776
command_map = {
78-
0: get_pipeline_command(),
79-
1: f"squeue -u {username}",
80-
2: (
77+
0: get_pipeline_command,
78+
1: lambda: f"squeue -u {username}",
79+
2: lambda: (
8180
f"sacct --user {username} "
8281
"--format UID,User,JobID,JobName,Submit,Elapsed,Partition,"
8382
"NNodes,NCPUS,TotalCPU,CPUTime,ReqMem,MaxRSS,WorkDir,State,"
8483
"Account,AllocTres -P"
8584
),
86-
3: "echo hello from nextflow-on-Alma app",
85+
3: lambda: "echo hello from nextflow-on-Alma app",
8786
}
8887

8988
# Return the corresponding command
90-
return command_map.get(cmd_num, "echo 'Invalid command number'")
89+
return command_map.get(cmd_num, lambda: "echo 'Invalid command number'")()

tabs/tab_command.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def tab(
1111
MY_SSH,
1212
selected_pipeline,
1313
selected_project,
14-
selected_samples="all",
14+
selected_samples="",
1515
work_dir="work",
1616
output_dir="output",
1717
custom_sample_list=[],
@@ -21,7 +21,7 @@ def tab(
2121
):
2222
# --- Initialize session state ---
2323
st.session_state.setdefault("username", username)
24-
st.session_state.setdefault("JOB_ID", "17379785")
24+
st.session_state.setdefault("JOB_ID", "")
2525
st.session_state.setdefault("run_pipeline_clicked", False)
2626

2727
# --- Display username input ---
@@ -77,17 +77,21 @@ def run_nextflow():
7777
if st.session_state["JOB_ID"]:
7878
st.success(f"Running Job ID: {st.session_state['JOB_ID']}")
7979

80+
get_sample_list = lambda selected_samples, custom_sample_list: [selected_samples] if selected_samples == 'demo' else custom_sample_list
81+
parsed_sample_list = get_sample_list(selected_samples, custom_sample_list)
8082
# --- Logs tab ---
8183
with tabL:
84+
# when checking logs, ask user to select one (drop-down list) of his samples at a time : demo or customised sample
8285
if st.button("Get Logs"):
83-
# st.write("📦 session_state:", dict(st.session_state))
84-
job_id = st.session_state.get("JOB_ID")
85-
st.write("📌 Accessed JOB_ID:", job_id) # DEBUG
86-
if not job_id:
86+
_sample_to_log = st.selectbox("Choose an option", parsed_sample_list)
87+
st.write("You selected:", _sample_to_log)
88+
#job_id = st.session_state.get("JOB_ID")
89+
#st.write("📌 Accessed JOB_ID:", job_id) # DEBUG
90+
if not _sample_to_log:
8791
st.error("No job was launched yet")
8892
else:
89-
log_out = f"{work_dir}/logs/{job_id}.out"
90-
log_err = f"{work_dir}/logs/{job_id}.err"
93+
log_out = f"{work_dir}/logs/log_{_sample_to_log}.out"
94+
log_err = f"{work_dir}/logs/log_{_sample_to_log}.err"
9195
tO, tE = st.tabs(["Output", "Error"])
9296
outputO, outputE = tO.empty(), tE.empty()
9397
with st.spinner("Fetching logs..."):
@@ -98,6 +102,7 @@ def run_nextflow():
98102
with tabQ:
99103
if st.button("Check slurm queues"):
100104
output = st.empty()
105+
st.write(cmd_hlp.pipe_cmd(st.session_state["username"], cmd_num=1))
101106
with st.spinner("Checking queue..."):
102107
with hlp.st_capture(output.code):
103108
cmd_pipeline = cmd_hlp.pipe_cmd(st.session_state["username"], cmd_num=1)

0 commit comments

Comments
 (0)