#!/usr/bin/env bash
set -euo pipefail

# Redirect all Nextflow caches & temps away from /mmfs1/home/$USER
BASE_SCRATCH=/mmfs1/gscratch/scrubbed/${USER}
export NXF_HOME="${BASE_SCRATCH}/.nextflow"           # Nextflow runtime & plugin cache
export NXF_TEMP="${BASE_SCRATCH}/tmp"                # General temp space
export APPTAINER_CACHEDIR="${BASE_SCRATCH}/singularity-cache"  # Image cache
export SINGULARITY_CACHEDIR="$APPTAINER_CACHEDIR"    # Backward compat
export NXF_SINGULARITY_CACHEDIR="$APPTAINER_CACHEDIR"

mkdir -p "$NXF_HOME" "$NXF_TEMP" "$APPTAINER_CACHEDIR"

nextflow run nf-core/methylseq \
	-c /mmfs1/gscratch/scrubbed/sr320/github/project-caligus-methylation/code/04.config \
	--input /mmfs1/gscratch/scrubbed/sr320/github/project-caligus-methylation/code/04.samplesheet.csv \
	--outdir /mmfs1/gscratch/scrubbed/sr320/github/project-caligus-methylation/output/04-nextflow-comb \
	--fasta /mmfs1/gscratch/scrubbed/sr320/github/project-caligus-methylation/data/GCA_013387185.1_ASM1338718v1_genomic.fa \
	-resume \
	--clip_r2 15 \
	-with-trace \
	-with-report nf_report.html \
	-with-timeline nf_timeline.html \
	--nomeseq

echo "Run complete. Caches located under $BASE_SCRATCH (NXF_HOME, tmp, singularity-cache)."