-
Notifications
You must be signed in to change notification settings - Fork 3
/
step08_first_level_analysis.sh
executable file
·81 lines (68 loc) · 2.52 KB
/
step08_first_level_analysis.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
#-----------------------------------------------------------
# The script will run the first_level_script.py script for each subject.
#
# You will need a conda environment that contains the required packages.
#
# Usage:
# Configure the variables below and run the script: ./step08_first_level_analysis.sh
#-----------------------------------------------------------
# ------------------------------------------------------------
#
# !FILL IN THE VARIABLES BELOW!
#
# ------------------------------------------------------------
# Your project's root directory
PROJECT_PATH='/imaging/correia/da05/workshops/2024-CBU'
# Location of the first-level python script
SCRIPT_PATH="$PROJECT_PATH"/code/first_level_script.py
# Path to the job logs
JOB_DIR="$PROJECT_PATH"/work/first-level_job_logs
# Which conda environment to use
CONDA_ENV=fmri
# ------------------------------------------------------------
#
# You don't have to change anything below this line!
#
# ------------------------------------------------------------
# ----------------------------------------------------------
# Get the subject list
# ----------------------------------------------------------
SUBJECT_DIRS=("$PROJECT_PATH"/data/sub-*)
SUBJECT_LIST=("${SUBJECT_DIRS[@]##*/}")
# ----------------------------------------------------------
# CD to the job logs directory
mkdir -p "$JOB_DIR"
cd "$JOB_DIR" || exit
# ----------------------------------------------------------
# Do some checks before submitting the job
# ----------------------------------------------------------
echo "Checking if the project directory exists..."
if [ ! -d "$PROJECT_PATH" ]; then
echo "Project directory does not exist: $PROJECT_PATH"
exit 1
fi
echo "Checking if the first-level python script exists..."
# Check if the script exists
if [ ! -f "$SCRIPT_PATH" ]; then
echo "The script $SCRIPT_PATH does not exist"
exit
fi
echo "Checking if the conda environment exists..."
if ! conda env list | grep -q "$CONDA_ENV"; then
echo "The conda environment $CONDA_ENV does not exist"
exit
fi
#-----------------------------------------------------------
# Activate the environment and submit job for each subject
#-----------------------------------------------------------
conda activate "$CONDA_ENV"
# Couldn't use task array because passing a list as an argument is tricky.
# For loop is fine too.
for sub in "${SUBJECT_LIST[@]}"; do
sbatch \
--job-name=first_level \
--cpus-per-task=16 \
"$SCRIPT_PATH" "${PROJECT_PATH}" "${sub}"
done
conda deactivate