123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- #!/bin/bash
- DEBUG=1
- EXTENSIONS=('nii.gz' 'nii' 'mgz')
- # Initialize variables with default values
- INPUT_DIR=""
- OUTPUT_DIR=""
- BIDS="yes"
- CONDOR="yes"
- RAW="yes"
- RUN_SINGULARITY_FILE=""
- SAVE="no"
- # Condor specific arguments
- CPUS='1'
- RAM='8G'
- DISK='1G'
- # Parse command-line arguments
- while [[ "$#" -gt 0 ]]; do
- case $1 in
- -input) INPUT_DIR="$2"; shift ;;
- -output) OUTPUT_DIR="$2"; shift ;;
- -BIDS) BIDS="$2"; shift ;;
- -CONDOR) CONDOR="$2"; shift ;;
- -RAW) RAW="$2"; shift ;;
- -RUN_FILE) RUN_SINGULARITY_FILE="$2"; shift ;;
- -SAVE_FILE) SAVE="$2"; shift ;;
- -CONTAINER_PATH) CONTAINER_PATH="$2"; shift ;;
- -help)
- echo "Usage: $0 -input <input_dir> -output <output_dir> -BIDS <yes/no> -CONDOR <yes/no> -RAW <yes/no> -RUN_FILE <path> -SAVE_FILE <yes/no> -CONTAINER_PATH <path>"
- exit 0
- ;;
- *) echo "Unknown parameter passed: $1"; exit 1 ;;
- esac
- shift
- done
- # Debugging or verbose mode can be added here if needed.
- if [ "$DEBUG" -eq 1 ]; then
- echo "Input directory: $INPUT_DIR" >&2
- echo "Output directory: $OUTPUT_DIR" >&2
- echo "BIDS: $BIDS" >&2
- echo "CONDOR: $CONDOR" >&2
- echo "RAW: $RAW" >&2
- echo "RUN_FILE: $RUN_SINGULARITY_FILE" >&2
- echo "SAVE_ALL: $SAVE" >&2
- echo "CONTAINER_PATH: $CONTAINER_PATH" >&2
- fi
- # Check if INPUT_DIR exists and is a directory (even if one file)
- if [ ! -d "$INPUT_DIR" ]; then
- echo "Error: $INPUT_DIR is not a directory or does not exist." >&2
- exit 1
- fi
- if [ -z "$( ls -A $INPUT_DIR )" ]; then
- echo "$INPUT_DIR Empty" >&2
- exit 1
- fi
- # Check if OUTPUT_DIR exists; if not, create it
- if [ ! -d "$OUTPUT_DIR" ]; then
- echo "Warning: $OUTPUT_DIR does not exist. Creating it now." >&2
- mkdir -p "$OUTPUT_DIR"
- fi
- if [ ! -z "$( ls -A $OUTPUT_DIR )" ]; then
- echo "Warning $OUTPUT_DIR is not Empty, files might be overwritten" >&2
- fi
- LOGS_DIR=${OUTPUT_DIR}/logs
- # create the logs dir if it doesn't exist
- if [ ! -d "${LOGS_DIR}" ]; then
- echo "Creating logs diretory ${LOGS_DIR}" >&2
- mkdir -p "${LOGS_DIR}"
- fi
- # # print the .submit header
- if [ "$CONDOR" == "yes" ]; then
- printf "# The environmentls
- universe = vanilla
- getenv = True
- request_cpus = ${CPUS}
- request_memory = ${RAM}
- request_disk = ${DISK}
- Requirements = HasSingularity
- # Execution
- executable = ${RUN_SINGULARITY_FILE}
- notification = Error
- \n"
- fi
- # Loop over subjects in INPUT_DIR no BIDS
- for type in "${EXTENSIONS[@]}"; do
- if [ "$BIDS" == "no" ]; then
- # no bids
- subj_list=($( find "$INPUT_DIR" -maxdepth 1 -name "*.${type}" \( -type f -o -type l \) ))
- else
- # bids
- subj_list=($( find "${INPUT_DIR}"/sub-*/ses-*/anat -maxdepth 1 -name "*T1*.${type}" \( -type f -o -type l \) ))
- fi
- for subj in "${subj_list[@]}"; do
- #printf "Processing subject: $subj \n" >&2
- if [ "$CONDOR" == "yes" ]; then
- sub=$(basename $subj)
- printf "arguments = $subj \ \n $OUTPUT_DIR \ \n $CONTAINER_PATH \ \n $SAVE $RAW \ \n"
- printf "log = ${LOGS_DIR}/\$(Cluster).\$(Process).${sub::-11}.log\n"
- printf "output = ${LOGS_DIR}/\$(Cluster).\$(Process).${sub::-11}.out\n"
- printf "error = ${LOGS_DIR}/\$(Cluster).\$(Process).${sub::-11}.err\n"
- printf "Queue\n\n"
- else
- printf "${RUN_SINGULARITY_FILE} $subj $OUTPUT_DIR $CONTAINER_PATH $SAVE $RAW \n"
- fi
- done
- done
|