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

# Edit these values before running the script.
PRSCSX_DIR="/path/to/PRScsx"
REF_DIR="/path/to/reference"
TARGET_PREFIX="/path/to/target/target_genotypes"
EUR_SUMSTATS="/path/to/gwas/eur_sumstats.txt"
EAS_SUMSTATS="/path/to/gwas/eas_sumstats.txt"
EUR_N="200000"
EAS_N="100000"
OUTPUT_DIR="/path/to/results"
OUTPUT_NAME="prscsx_test"

# Test chromosome 22 first. After it succeeds, use: CHROMOSOMES=({1..22})
CHROMOSOMES=(22)

mkdir -p "${OUTPUT_DIR}"

export MKL_NUM_THREADS=1
export NUMEXPR_NUM_THREADS=1
export OMP_NUM_THREADS=1

for CHR in "${CHROMOSOMES[@]}"; do
  python "${PRSCSX_DIR}/PRScsx.py" \
    --ref_dir="${REF_DIR}" \
    --bim_prefix="${TARGET_PREFIX}" \
    --sst_file="${EUR_SUMSTATS},${EAS_SUMSTATS}" \
    --n_gwas="${EUR_N},${EAS_N}" \
    --pop=EUR,EAS \
    --chrom="${CHR}" \
    --meta=True \
    --out_dir="${OUTPUT_DIR}" \
    --out_name="${OUTPUT_NAME}"
done

echo "Generated posterior-effect files:"
find "${OUTPUT_DIR}" -maxdepth 1 -name "${OUTPUT_NAME}*chr*.txt" -print

echo
echo "Select one matched population-specific or meta-analyzed series before concatenating and scoring."
echo "Do not combine the population-specific and meta-analyzed files together."
