Skip to content

Commit 392eef8

Browse files
committed
fixing building apptainer
1 parent ed08585 commit 392eef8

3 files changed

Lines changed: 48 additions & 17 deletions

File tree

.env_example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ DOCKER_VERSION=1.1.0
55
# Optional variables
66
QTL_DATA_DIR=
77
SNAKEMAKE_PROFILE=snakemake/profiles/local/
8-
APPTAINER_MODULE=apptainer/1.3.1-ksax
8+
APPTAINER_MODULE=
99
SLURM_PARTITION=
1010
SLURM_ACCOUNT=

README.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ There are **six** Snakemake pipelines (grouped as two tables of three). Each pip
4242
### 1. Clone the repository into your personal space on BlueCrystal 4
4343
`git clone git@github.com:MRCIEU/GeneHackman.git && cd GeneHackman`
4444

45-
### 2. Ensure you [have conda installed and initialised before activating](https://www.acrc.bris.ac.uk/protected/hpc-docs/software/python_conda.html)
45+
### 2. Ensure you [have conda installed and initialised before activating](https://www.anaconda.com/docs/getting-started/miniconda/install/overview)
4646

4747
```conda env create --file environment.yml```
4848

@@ -84,11 +84,41 @@ Alternatives if you don’t set **`QTL_DATA_DIR`** directly: keep the same direc
8484

8585
### 4. Populate `.env` and `input.yaml` files
8686

87-
`cp .env_example .env`
88-
* Set **`PROJECT_DIR`** to the root folder for this analysis; the pipeline uses **`PROJECT_DIR/data/`** for inputs (GWAS, clumps, …) and **`PROJECT_DIR/results/`** for outputs (finemap, coloc, plots, …).
89-
* Set **`PIPELINE_DATA_DIR`** to the path where you unpacked **`genehackman`** (see §3).
90-
* Set **`QTL_DATA_DIR`** to the path where you unpacked **`genehackman-qtl`** if you run **`qtl_mr`** (can be left empty otherwise; see [.env_example](.env_example)).
91-
* **Container cache:** If there is no pre-built `genehackman_<version>.sif` under `PIPELINE_DATA_DIR`, Snakemake pulls the `docker://` image and caches the SIF under `.snakemake/singularity` by default. Set **`GENEHACKMAN_SINGULARITY_PREFIX`** in `.env` to use another directory (e.g. scratch). Running `snakemake` without `./run_pipeline.sh`? Pass `--singularity-prefix /path` or add `singularity-prefix:` under **`snakemake/profiles/`** in **`config.yaml`** for the profile you use (paths are relative to the repo root).
87+
Copy the template and edit paths for your machine:
88+
89+
```bash
90+
cp .env_example .env
91+
```
92+
93+
Variables match [.env_example](.env_example):
94+
95+
**Mandatory**
96+
97+
| Variable | Purpose |
98+
|----------|---------|
99+
| **`PROJECT_DIR`** | Root folder for this analysis. The pipeline uses **`PROJECT_DIR/data/`** for inputs (GWAS, clumps, …) and **`PROJECT_DIR/results/`** for outputs (finemap, coloc, plots, …). |
100+
| **`PIPELINE_DATA_DIR`** | Path where you unpacked the shared **`genehackman`** reference data (see §3). Also used for the Apptainer image: **`PIPELINE_DATA_DIR/genomic_data/pipeline/genehackman_<DOCKER_VERSION>.sif`**. If that SIF is missing and the directory is writable, `run_pipeline.sh` builds it from `docker://mrcieu/genehackman:<DOCKER_VERSION>`. |
101+
| **`DOCKER_VERSION`** | Docker/Apptainer image tag (e.g. `1.1.0` or `develop`). Must match the SIF filename and the image you intend to run. |
102+
103+
**Optional**
104+
105+
| Variable | Purpose |
106+
|----------|---------|
107+
| **`QTL_DATA_DIR`** | Path to **`genehackman-qtl`** data if you run **`qtl_mr`**. Leave empty for other pipelines. You can instead place QTL data under **`PIPELINE_DATA_DIR/qtl_datasets/`** (see [PLATFORM_SETUP.md](PLATFORM_SETUP.md)). |
108+
| **`SNAKEMAKE_PROFILE`** | Snakemake profile directory. Default in `.env_example`: **`snakemake/profiles/local/`** (local Apptainer). On HPC use e.g. **`snakemake/profiles/slurm/`**. |
109+
| **`APPTAINER_MODULE`** | Environment module name to load Apptainer/Singularity before running on HPC (only used when the profile is not `local`). |
110+
| **`SLURM_PARTITION`** | Slurm partition for cluster jobs. If unset, `run_pipeline.sh` tries to detect one from `sinfo`, else uses **`compute`**. |
111+
| **`SLURM_ACCOUNT`** | Slurm account for cluster jobs. If unset, `run_pipeline.sh` tries to infer it from `sacctmgr`. |
112+
113+
Example `.env`:
114+
115+
```bash
116+
PROJECT_DIR=/path/to/my_project
117+
PIPELINE_DATA_DIR=/path/to/my_pipeline_data/
118+
DOCKER_VERSION=1.1.0
119+
QTL_DATA_DIR=/path/to/my_qtl_data/
120+
SNAKEMAKE_PROFILE=snakemake/profiles/local/
121+
```
92122

93123
**`input.yaml`**
94124

run_pipeline.sh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fi
2424

2525
if [ -f .env ]
2626
then
27-
export $(cat .env | xargs)
27+
export $(grep -vE '^[[:space:]]*#' .env | xargs)
2828
else
2929
echo "Error: .env file missing"
3030
exit 1
@@ -50,10 +50,10 @@ if [[ -z "${SLURM_PARTITION:-}" ]]; then
5050
fi
5151
export SLURM_PARTITION
5252

53-
if [[ -z "${SLURM_ACCOUNT:-}" ]]; then
53+
if [[ -z "${SLURM_ACCOUNT:-}" ]] && command -v sacctmgr >/dev/null 2>&1; then
5454
export USER=$(whoami)
55-
export ACCOUNT_ID=$(sacctmgr show user withassoc format=account where user=$USER | grep '[0-9]' | head -n1)
56-
export SLURM_ACCOUNT="$ACCOUNT_ID"
55+
export ACCOUNT_ID=$(sacctmgr show user withassoc format=account where user="$USER" | grep '[0-9]' | head -n1)
56+
export SLURM_ACCOUNT="${ACCOUNT_ID:-}"
5757
fi
5858

5959
export GENEHACKMAN_EXTRA_SINGULARITY_BINDS=""
@@ -102,11 +102,13 @@ PIPELINE_GENOMIC_DIR="${PIPELINE_GENOMIC_DIR%/}"
102102
SIF_PATH="${PIPELINE_GENOMIC_DIR}/${SIF_NAME}"
103103

104104
echo "SIF_PATH: ${SIF_PATH}"
105-
if [[ -f "${SIF_PATH}" ]] || [[ -w "${PIPELINE_GENOMIC_DIR}" ]] ; then
106-
mkdir -p "${PIPELINE_GENOMIC_DIR}"
107-
else
108-
SIF_PATH=".snakemake/singularity/${SIF_NAME}"
109-
fi
105+
if [[ ! -f "${SIF_PATH}" ]]; then
106+
if ! mkdir -p "${PIPELINE_GENOMIC_DIR}" 2>/dev/null || [[ ! -w "${PIPELINE_GENOMIC_DIR}" ]]; then
107+
SIF_PATH=".snakemake/singularity/${SIF_NAME}"
108+
echo "Note: caching SIF under ${SIF_PATH} (${PIPELINE_GENOMIC_DIR} missing or not writable)"
109+
fi
110+
fi
111+
mkdir -p "$(dirname "${SIF_PATH}")"
110112

111113
SINGULARITY_DOCKER_REFERENCE="docker://mrcieu/genehackman:${GENEHACKMAN_VERSION}"
112114

@@ -123,7 +125,6 @@ fi
123125

124126
if [[ ! -f "${SIF_PATH}" ]]; then
125127
echo "SIF file not found: ${SIF_PATH}"
126-
mkdir -p "${PIPELINE_GENOMIC_DIR}"
127128
echo "Building container with singularity from: ${SINGULARITY_DOCKER_REFERENCE}"
128129
if [[ "${#SINGULARITY_BUILD_ARCH_ARGS[@]}" -gt 0 ]]; then
129130
echo "(host is ARM: using singularity build ${SINGULARITY_BUILD_ARCH_ARGS[*]} for amd64 image)"

0 commit comments

Comments
 (0)