Skip to content

Commit 08d6a08

Browse files
authored
Merge pull request #63 from KumarLabJax/task/fix-submission-errors
Updating README and submission scripts
2 parents c1691c4 + 2833232 commit 08d6a08

File tree

5 files changed

+252
-10
lines changed

5 files changed

+252
-10
lines changed

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,37 @@ See [model docs](docs/models.md) for information about available models.
2121

2222
Pipelines are run using nextflow. For a list of all available parameters, see [nextflow parameters](nextflow.config). Not all parameters will affect all pipeline workflows.
2323

24-
If you are running the pipeline on the HPC, you should submit the workflow as a job. You can use the example test as a starting template: [test-nextflow.sh](test-nextflow.sh).
24+
You will need a batch file that lists the input files to process.
2525

26-
Input files should include the full path. An easy way to generate the list of inputs for `input_batch` is to run `find $(pwd) -name '*.avi' > video_batch.txt`.
26+
An easy way to generate the list of inputs for `input_batch` is to run
27+
`find $(pwd) -name '*.avi' > video_batch.txt`.
28+
29+
## Running on Sumner2 HPC (Slurm)
30+
31+
When running on the HPC (Sumner2),you should submit the workflow as a job. To make this
32+
simple, we've provided a submission script that you can use to configure and submit
33+
pipeline run.
34+
35+
The script is provided in the kumar-lab scripts module. To load the module, run:
36+
```
37+
module use --append /projects/kumar-lab/meta/modules
38+
module load scripts
39+
```
40+
41+
To see all available options, run:
42+
```
43+
submit-nextflow.sh --help
44+
```
45+
46+
An example submission command is:
47+
```
48+
submit-nextflow.sh -i my_batch.txt -w single-mouse -o /path/to/output_folder --resume
49+
```
50+
51+
To test a submission without actually submitting, you can use the `--dry-run` flag:
52+
```
53+
submit-nextflow.sh --dry-run -i my_batch.txt -w single-mouse -o /path/to/output_folder --resume
54+
```
2755

2856
## Single Mouse Pipelines
2957

main.nf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (params.input_batch != null) {
2424

2525
// Validate each file in the batch
2626
batch_lines.each { file_path ->
27-
def (is_valid, error_message) = validateInputFile(file_path, params.pipeline)
27+
def (is_valid, error_message) = validateInputFile(file_path, params.workflow)
2828

2929
if (is_valid) {
3030
valid_files.add(file_path)

nextflow.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ params {
1515
*/
1616
input_batch = null
1717
ignore_invalid_inputs = false
18-
pipeline = 'single-mouse'
1918
profile = 'sumner2'
2019
corner_frame = 100
2120
batch_timestamp = new java.util.Date().format( 'yyyy-MM-dd_HH-mm-ss')

submit-nextflow.sh

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
#!/bin/bash
2+
3+
# Usage function
4+
usage() {
5+
local script_name=$(basename "$0")
6+
7+
cat << EOF
8+
Usage: $script_name [OPTIONS] [-- NEXTFLOW_ARGS...]
9+
10+
REQUIRED:
11+
-i, --input BATCH_FILE Input batch file
12+
-o, --output OUTPUT_DIR Output directory
13+
14+
OPTIONAL:
15+
-n, --pipeline PIPELINE Nextflow pipeline (default: KumarLabJax/mouse-tracking-runtime)
16+
-r, --revision REVISION Pipeline revision/branch/tag (default: none)
17+
-w, --workflow WORKFLOW Workflow type (default: single-mouse)
18+
-p, --profile PROFILE Nextflow profile (default: sumner2)
19+
-j, --job-name JOB_NAME SBATCH job name (default: KL_Tracking_Nextflow)
20+
-t, --time TIME Time limit (default: 14-00:00:00)
21+
-m, --memory MEMORY Memory allocation (default: 16G)
22+
--partition PARTITION SBATCH partition (default: compute)
23+
--qos QOS SBATCH QoS (default: long)
24+
--resume Resume Nextflow run
25+
--dry-run Show what would be submitted without submitting
26+
-h, --help Show this help message
27+
28+
ADDITIONAL NEXTFLOW ARGUMENTS:
29+
Any arguments after '--' will be passed directly to the nextflow command.
30+
You can also mix additional nextflow arguments without using '--'.
31+
32+
EXAMPLES:
33+
$script_name -i my_batch.txt -o results/
34+
$script_name -i data.txt -o output/ -w multi-mouse -t 7-00:00:00 -m 32G
35+
$script_name -i batch.txt -o results/ --resume --dry-run
36+
$script_name -n my-org/my-pipeline -i batch.txt -o results/
37+
$script_name -n KumarLabJax/mouse-tracking-runtime -r dev -i batch.txt -o results/
38+
$script_name -r v2.1.0 -i batch.txt -o results/
39+
$script_name -n ./local-pipeline -i corners_batch.txt -w single-mouse-corrected-corners -o test_output/ --sleap_file manual_correction.slp
40+
$script_name -i batch.txt -o results/ -- --some_other_param value -nextflow-flag
41+
42+
EOF
43+
}
44+
45+
# Default values
46+
PIPELINE="KumarLabJax/mouse-tracking-runtime"
47+
REVISION=""
48+
WORKFLOW="single-mouse"
49+
PROFILE="sumner2"
50+
JOB_NAME="KL_Tracking_Nextflow"
51+
TIME_LIMIT="14-00:00:00"
52+
MEMORY="16G"
53+
PARTITION="compute"
54+
QOS="long"
55+
RESUME=""
56+
DRY_RUN=false
57+
INPUT_BATCH=""
58+
OUTPUT_DIR=""
59+
ADDITIONAL_ARGS=()
60+
61+
# Parse command line arguments
62+
while [[ $# -gt 0 ]]; do
63+
case $1 in
64+
-n|--pipeline)
65+
PIPELINE="$2"
66+
shift 2
67+
;;
68+
-r|--revision)
69+
REVISION="$2"
70+
shift 2
71+
;;
72+
-i|--input)
73+
INPUT_BATCH="$2"
74+
shift 2
75+
;;
76+
-o|--output)
77+
OUTPUT_DIR="$2"
78+
shift 2
79+
;;
80+
-w|--workflow)
81+
WORKFLOW="$2"
82+
shift 2
83+
;;
84+
-p|--profile)
85+
PROFILE="$2"
86+
shift 2
87+
;;
88+
-j|--job-name)
89+
JOB_NAME="$2"
90+
shift 2
91+
;;
92+
-t|--time)
93+
TIME_LIMIT="$2"
94+
shift 2
95+
;;
96+
-m|--memory)
97+
MEMORY="$2"
98+
shift 2
99+
;;
100+
--partition)
101+
PARTITION="$2"
102+
shift 2
103+
;;
104+
--qos)
105+
QOS="$2"
106+
shift 2
107+
;;
108+
--resume)
109+
RESUME="-resume"
110+
shift
111+
;;
112+
--dry-run)
113+
DRY_RUN=true
114+
shift
115+
;;
116+
-h|--help)
117+
usage
118+
exit 0
119+
;;
120+
--)
121+
# Everything after -- goes to additional args
122+
shift
123+
ADDITIONAL_ARGS+=("$@")
124+
break
125+
;;
126+
--*)
127+
# Any other -- argument is likely a nextflow parameter
128+
ADDITIONAL_ARGS+=("$1")
129+
if [[ $# -gt 1 && ! "$2" =~ ^- ]]; then
130+
ADDITIONAL_ARGS+=("$2")
131+
shift 2
132+
else
133+
shift
134+
fi
135+
;;
136+
*)
137+
echo "Unknown option: $1"
138+
usage
139+
exit 1
140+
;;
141+
esac
142+
done
143+
144+
# Validate required arguments
145+
if [[ -z "$INPUT_BATCH" ]]; then
146+
echo "Error: Input batch file (-i/--input) is required"
147+
usage
148+
exit 1
149+
fi
150+
151+
if [[ -z "$OUTPUT_DIR" ]]; then
152+
echo "Error: Output directory (-o/--output) is required"
153+
usage
154+
exit 1
155+
fi
156+
157+
# Check if input file exists
158+
if [[ ! -f "$INPUT_BATCH" ]]; then
159+
echo "Error: Input batch file '$INPUT_BATCH' does not exist"
160+
exit 1
161+
fi
162+
163+
# Create output directory if it doesn't exist
164+
mkdir -p "$OUTPUT_DIR"
165+
166+
# Build the revision flag if specified
167+
REVISION_FLAG=""
168+
if [[ -n "$REVISION" ]]; then
169+
REVISION_FLAG="-r $REVISION"
170+
fi
171+
172+
# Generate the sbatch script content
173+
SBATCH_SCRIPT=$(cat << EOF
174+
#!/bin/bash
175+
176+
#SBATCH --job-name=$JOB_NAME
177+
#SBATCH -p $PARTITION
178+
#SBATCH -q $QOS
179+
#SBATCH -t $TIME_LIMIT
180+
#SBATCH --mem=$MEMORY
181+
#SBATCH --ntasks=1
182+
183+
# LOAD NEXTFLOW
184+
module use --append /projects/kumar-lab/meta/modules
185+
module load nextflow/stable
186+
187+
# RUN NEXTFLOW PIPELINE
188+
nextflow run $PIPELINE $REVISION_FLAG -profile $PROFILE --input_batch $INPUT_BATCH --workflow $WORKFLOW --pubdir $OUTPUT_DIR $RESUME $(printf " %s" "${ADDITIONAL_ARGS[@]}")
189+
EOF
190+
)
191+
192+
if [[ "$DRY_RUN" == true ]]; then
193+
echo "=== DRY RUN: Would submit the following sbatch script ==="
194+
echo "$SBATCH_SCRIPT"
195+
echo "=============================================="
196+
echo "Command that would be executed: sbatch <<< \"\$SBATCH_SCRIPT\""
197+
else
198+
# Submit the job
199+
echo "Submitting Nextflow pipeline with the following parameters:"
200+
echo " Pipeline: $PIPELINE"
201+
[[ -n "$REVISION" ]] && echo " Revision: $REVISION"
202+
echo " Input batch: $INPUT_BATCH"
203+
echo " Output directory: $OUTPUT_DIR"
204+
echo " Workflow: $WORKFLOW"
205+
echo " Profile: $PROFILE"
206+
echo " Job name: $JOB_NAME"
207+
echo " Time limit: $TIME_LIMIT"
208+
echo " Memory: $MEMORY"
209+
echo " Partition: $PARTITION"
210+
echo " QoS: $QOS"
211+
[[ -n "$RESUME" ]] && echo " Resume: enabled"
212+
[[ ${#ADDITIONAL_ARGS[@]} -gt 0 ]] && echo " Additional args: ${ADDITIONAL_ARGS[*]}"
213+
echo ""
214+
215+
# Submit using here-string to avoid temporary files
216+
sbatch <<< "$SBATCH_SCRIPT"
217+
fi

test-nextflow.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@
77
#SBATCH --mem=16G
88
#SBATCH --ntasks=1
99

10-
cd /projects/kumar-lab/multimouse-pipeline/nextflow-code/
11-
1210
# LOAD NEXTFLOW
1311
module use --append /projects/kumar-lab/meta/modules
1412
module load nextflow/stable
1513

1614
# RUN TEST PIPELINE
17-
nextflow run main.nf \
18-
-c nextflow.config \
19-
-c nextflow/configs/profiles/sumner2.config \
15+
nextflow run KumarLabJax/mouse-tracking-runtime \
16+
-profile sumner2 \
2017
--input_batch /projects/kumar-lab/multimouse-pipeline/nextflow-tests/test_batch.txt \
2118
--workflow single-mouse \
22-
--pubdir /projects/kumar-lab/multimouse-pipeline/nextflow-test-results/ \
19+
--pubdir /projects/kumar-lab/multimouse-pipeline/nextflow-test-results/
20+
ß

0 commit comments

Comments
 (0)