Parameterize FreeSurfer license path and clean up README MIT-isms#5
Parameterize FreeSurfer license path and clean up README MIT-isms#5yibeichan wants to merge 3 commits into
Conversation
The FreeSurfer license path was hardcoded to
/orcd/scratch/bcs/001/yibei/prettymouth_babs/license.txt in
config_freesurfer-nidm.yaml, causing the BABS workflow to fail at job
runtime for any user outside that environment (the singularity bind
fails because the source path doesn't exist).
- Replace the hardcoded path with ${FS_LICENSE} in the YAML so the
existing babs_prepare_yaml_config substitution machinery handles it.
- Wire FS_LICENSE through freesurfer-nidm_babs_script.sh: validate it
is set and the file exists before submitting any jobs, then pass it
into the YAML substitution call.
- Document FS_LICENSE in the README .env block and add a Prerequisites
section covering BABS env, apptainer, .env contents, .sif files,
the FreeSurfer license, and DataLad inputs.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
# Conflicts: # README.md
The previous README told users what scripts existed but not what the
repo is for, and hardcoded MIT ORCD paths in Output Structure, Manual
BABS Commands, and Post-Processing examples — the same class of bug
that broke FS_LICENSE for non-MIT users.
Changes:
- Add an opening paragraph explaining what the wrapper scripts do
(container lookup, YAML prep, babs init + submit), and link out to
the three ReproNim BIDS App container repos so users know where
the .sif files come from.
- Point Prerequisites item 4 (container .sif files) at the same repos.
- Replace hardcoded /orcd/scratch/bcs/001/yibei/simple2/... in Output
Structure, Manual BABS Commands, and Post-Processing with
${SCRATCH_DIR} / ${SCRATCH_DIR_*} placeholders and
<dataset>/<site>/<RUN_DATE> tokens.
- Generalize the Git Safe Directories example to use ${DATALAD_SET_DIR}.
- Rewrite the .env explanatory paragraph in neutral docs voice.
- Restructure "Important Notes": fold SLURM partition and incremental
NIDM into Configuration Files (where they belong), drop the
duplicate FreeSurfer license note (now in Prerequisites), and keep
the git safe-directory caveat under a new "Caveats" heading.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request enhances the BABS wrapper scripts by improving documentation and parameterizing the FreeSurfer license path. The README.md was updated with detailed prerequisites and environment variable usage, while the FreeSurfer script now includes fail-fast validation for the license file. Review feedback recommends resolving the license path to an absolute path, explicitly binding it for Singularity containers, and ensuring the .env file is sourced in documentation examples.
| # Validate FreeSurfer license (fail fast before submitting jobs) | ||
| if [ -z "${FS_LICENSE:-}" ]; then | ||
| echo "ERROR: FS_LICENSE is not set. Add 'FS_LICENSE=/path/to/license.txt' to .env" >&2 | ||
| exit 1 | ||
| fi | ||
| if [ ! -f "$FS_LICENSE" ]; then | ||
| echo "ERROR: FreeSurfer license file not found at FS_LICENSE=$FS_LICENSE" >&2 | ||
| exit 1 | ||
| fi |
There was a problem hiding this comment.
It is recommended to resolve FS_LICENSE to an absolute path. This ensures the path remains valid if the script changes the current working directory (as seen on line 82) and provides a reliable path for container volume mounting. Using realpath is a standard way to achieve this in modern Linux environments.
| # Validate FreeSurfer license (fail fast before submitting jobs) | |
| if [ -z "${FS_LICENSE:-}" ]; then | |
| echo "ERROR: FS_LICENSE is not set. Add 'FS_LICENSE=/path/to/license.txt' to .env" >&2 | |
| exit 1 | |
| fi | |
| if [ ! -f "$FS_LICENSE" ]; then | |
| echo "ERROR: FreeSurfer license file not found at FS_LICENSE=$FS_LICENSE" >&2 | |
| exit 1 | |
| fi | |
| # Validate FreeSurfer license (fail fast before submitting jobs) | |
| if [ -z "${FS_LICENSE:-}" ]; then | |
| echo "ERROR: FS_LICENSE is not set. Add 'FS_LICENSE=/path/to/license.txt' to .env" >&2 | |
| exit 1 | |
| fi | |
| if [ ! -f "$FS_LICENSE" ]; then | |
| echo "ERROR: FreeSurfer license file not found at FS_LICENSE=$FS_LICENSE" >&2 | |
| exit 1 | |
| fi | |
| # Resolve to absolute path to ensure it remains valid after directory changes | |
| FS_LICENSE=$(realpath "$FS_LICENSE") |
| bids_app_args: | ||
| "$SUBJECT_SELECTION_FLAG": "--participant_label" | ||
| --fs-license-file: "/orcd/scratch/bcs/001/yibei/prettymouth_babs/license.txt" | ||
| --fs-license-file: "${FS_LICENSE}" |
There was a problem hiding this comment.
To ensure the FreeSurfer license file is accessible inside the container, especially when using --no-home (line 24), it should be explicitly bound. If the license is located outside of standard auto-bind paths (like /scratch), the pipeline will fail. Consider adding a bind point to the singularity_args section, for example: - -B ${FS_LICENSE}:${FS_LICENSE}:ro.
| # Navigate to the BABS project directory | ||
| cd "${SCRATCH_DIR_ANTS}/<dataset>_<RUN_DATE>/ants-nidm_bidsapp_<site>_<RUN_DATE>" |
There was a problem hiding this comment.
For these manual commands to work in a terminal session, the user must first source the environment variables so that variables like ${SCRATCH_DIR_ANTS} are defined. Adding a source .env line to the example makes it more complete and easier for users to follow.
| # Navigate to the BABS project directory | |
| cd "${SCRATCH_DIR_ANTS}/<dataset>_<RUN_DATE>/ants-nidm_bidsapp_<site>_<RUN_DATE>" | |
| # Navigate to the BABS project directory | |
| source .env | |
| cd "${SCRATCH_DIR_ANTS}/<dataset>_<RUN_DATE>/ants-nidm_bidsapp_<site>_<RUN_DATE>" |
Summary
config_freesurfer-nidm.yamlthat was causing the BABS workflow to fail at job runtime for any user outside MIT ORCD (the singularity bind to/orcd/scratch/bcs/001/yibei/prettymouth_babs/license.txtdoesn't resolve on other clusters — reported recently from a TSCC run).FS_LICENSEthrough the FreeSurfer wrapper script with fail-fast validation: the script now aborts at submission time with a clear error ifFS_LICENSEis unset or missing, rather than failing silently inside every SLURM job.What changed
Code
config_freesurfer-nidm.yaml:--fs-license-filenow uses the${FS_LICENSE}placeholder, picked up by the existingbabs_prepare_yaml_configsubstitution machinery.freesurfer-nidm_babs_script.sh: validatesFS_LICENSEis set and points at an existing file beforebabs init; passesFS_LICENSE=${FS_LICENSE}into the YAML substitution call.README
babs init→ submit), plus links to the three ReproNim BIDS App container repos so users know where the.siffiles come from..envsetup,.sifbuild, FreeSurfer license (with the registration link), and DataLad inputs..envtemplate:DATA_DIRvariable (confirmed unreferenced anywhere in the repo).SCRATCH_DIR-parent idea from Clarify.envcontract in README and align variable semantics with wrapper scripts #4, but in correct bash syntax — the merged form (SCRATCH_DIR = '...'with spaces, andSCRATCH_DIR_ANTS= SCRATCH_DIR + 'ants...'Python-style concat) would have silently mis-set the per-app paths when sourced. Now usesSCRATCH_DIR_ANTS=\"\${SCRATCH_DIR}/ants_bidsapp_babs\".FS_LICENSEwith a "FreeSurfer-NIDM pipeline only" comment./orcd/scratch/bcs/001/yibei/simple2/...paths in Output Structure, Manual BABS Commands, and Post-Processing with\${SCRATCH_DIR_*}placeholders and<dataset>/<site>/<RUN_DATE>tokens.\${DATALAD_SET_DIR}.Test plan
FS_LICENSEin.env, run./freesurfer-nidm_babs_script.sh <site> <study>, confirm no license-related errors.FS_LICENSEor point it at a missing file — script should abort before submitting jobs.🤖 Generated with Claude Code