#!/bin/bash
# =============================================================================
# CIBERSORTx Fractions -- SINGULARITY version
# Build signature matrix from single-cell reference + estimate cell fractions.
# =============================================================================
set -euo pipefail

# ---- USER CONFIG -----------------------------------------------------------
EMAIL="jin.yan1@wustl.edu"
TOKEN="$(cat "$HOME/.cibersortx_token")"

BASE="$HOME/TaRGET_II/cibersortx"
SIF="${BASE}/sif/cibersortx_fractions.sif"
INDIR="${BASE}/input"
OUTDIR="${BASE}/output_fractions"

REFSAMPLE="cibersortx_ref_main_4.txt"
MIXTURE="raw_bulk_counts.csv"
# ----------------------------------------------------------------------------

mkdir -p "$OUTDIR"

# --bind maps host dir -> container dir (same as docker -v)
# --containall keeps the container isolated from your host $HOME
singularity exec \
  --containall \
  --bind "${INDIR}:/src/data" \
  --bind "${OUTDIR}:/src/outdir" \
  "$SIF" \
  /src/CIBERSORTxFractions \
  --username "$EMAIL" \
  --token "$TOKEN" \
  --single_cell TRUE \
  --refsample "$REFSAMPLE" \
  --mixture "$MIXTURE" \
  --fraction 0 \
  --rmbatchSmode TRUE \
  --QN FALSE \
  --outdir /src/outdir \
  --verbose TRUE

echo "[DONE] Fractions output -> $OUTDIR"
