Skip to content
Merged
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
11 changes: 9 additions & 2 deletions pages/run_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def reset_button_state():
run_pipeline_clicked = ss_values["run_pipeline_clicked"]
button_clicked = ss_values["button_clicked"]
custom_sample_list = ss_values["custom_sample_list"] # only availanle if custom sample is selected

BED_FILE = ss_values["BED_FILE"]
samples = ["all", "demo", "customised"] # , "test"]

# Create the selectbox and update session state
Expand Down Expand Up @@ -73,7 +73,12 @@ def reset_button_state():

st.write("Your custom samples:", custom_sample_list)
ss_set("custom_sample_list", custom_sample_list)

# Optional BED file path
BED_FILE = st.text_input(
"Optional BED file path",
value="",
help="Provide a full path to a BED file on Alma server, or leave empty to skip and use full genome",
)
WORK_DIR = st.text_input("Working directory", value=WORK_DIR or SCRATCH)
OUTPUT_DIR = st.text_input("Output directory", value=OUTPUT_DIR or SCRATCH)

Expand All @@ -88,6 +93,7 @@ def reset_button_state():
work_dir=WORK_DIR,
output_dir=OUTPUT_DIR,
custom_sample_list=custom_sample_list,
bed_file=BED_FILE
)
save_in_ss(
{
Expand All @@ -109,6 +115,7 @@ def reset_button_state():
"run_pipeline_clicked": run_pipeline_clicked,
"button_clicked": button_clicked,
"custom_sample_list": custom_sample_list,
"BED_FILE":BED_FILE,
}
)
else:
Expand Down
55 changes: 34 additions & 21 deletions shared/command_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,52 @@ def pipe_cmd(
work_dir="work",
output_dir="output",
custom_sample_list=[],
bed_file=""
):
def get_pipeline_command():
"""Generate the pipeline execution command based on the sample selection."""
path_to_script = get_path_to_script(selected_pipeline, selected_project, selected_samples)

cmd_pipeline = f"""
mkdir -p {work_dir}/logs
cd {work_dir}
"""
# not sure if this is the best thing-using job id for filenamne
log_out = f"{work_dir}/logs/%j.out"
log_err = f"{work_dir}/logs/%j.err"

args = []
base_cmd = f"sbatch -o {log_out} -e {log_err}"

if selected_samples == "demo":
cmd_pipeline += f"sbatch -o {log_out} -e {log_err} {path_to_script} {work_dir} {output_dir}"
elif selected_samples == "all": # this has no more sense since we have to specify the sample name index
cmd_pipeline += f"sbatch -o {log_out} -e {log_err} {path_to_script} --work-dir {work_dir} --outdir {output_dir}"
##./your_script.sh --env "/my/custom/env" --work-dir "my_work" --outdir "my_output" --config "my_config" --params "parans.json"
# Usage:
# bash launch_batch_analysis.sh \
# --work-dir "workdir" \
# --outdir "output" \
# --env "/data/rds/DIT/SCICOM/SCRSE/shared/conda/nextflow_env" \
# --params "/data/params/parameters.json" \
# --config "custom_config.config"
elif selected_samples == "customised":
if not len(custom_sample_list):
print("custom_sample_list cannot be empty")
args = [path_to_script, work_dir, output_dir]

tab_separated_string = "\t".join(custom_sample_list)
cmd_pipeline += f"sbatch -o {log_out} -e {log_err} {path_to_script} --work-dir {work_dir} --outdir {output_dir} --samples {tab_separated_string}"
# elif selected_samples == "test":
elif selected_samples == "all":
#./your_script.sh --env "/my/custom/env" --work-dir "my_work" --outdir "my_output" --config "my_config" --params "parans.json" --bed file.bed
args = [
path_to_script,
"--work-dir", work_dir,
"--outdir", output_dir,
]
if bed_file:
args += ["--bed", bed_file]

elif selected_samples == "customised":
if not custom_sample_list:
raise ValueError("custom_sample_list cannot be empty")
args = [
path_to_script,
"--work-dir", work_dir,
"--outdir", output_dir,
"--samples", "\t".join(custom_sample_list),
]
if bed_file:
args += ["--bed", bed_file]
# elif selected_samples == "test": #this will become dry-run, but I should develop it for all scripts
# cmd_pipeline += f"sbatch -o {log_out} -e {log_err} /data/scratch/DCO/DIGOPS/SCIENCOM/msarkis/NF-project-configurations/test.sh --work-dir {work_dir} --outdir {output_dir}"

preamble = f"""
mkdir -p {work_dir}/logs
cd {work_dir}
"""
# Combine all into the final shell command
cmd_pipeline = preamble + f"{base_cmd} {' '.join(args)}"
return cmd_pipeline.strip()

# Command mappings
Expand Down
1 change: 1 addition & 0 deletions shared/ss_defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ keys_defaults:
WORK_DIR: None
OUTPUT_DIR: None
custom_sample_list: []
BED_FILE: ""
2 changes: 2 additions & 0 deletions tabs/tab_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def tab(
work_dir="work",
output_dir="output",
custom_sample_list=[],
bed_file=""
):
# --- Initialize session state ---
st.session_state.setdefault("username", username)
Expand Down Expand Up @@ -46,6 +47,7 @@ def run_nextflow():
output_dir=output_dir,
work_dir=work_dir,
custom_sample_list=custom_sample_list,
bed_file=bed_file
)
st.code(cmd_pipeline)
result = MY_SSH.run_cmd(cmd_pipeline)
Expand Down