#!/usr/bin/env bash
# Build the R1 MEME sweep manifest: one row per host×gene. NA uses the reframed .inframe.fasta.
# Cols: gene,host,alignment,out_json,out_csv   (header + 18 data rows)
set -euo pipefail
cd "$(dirname "$0")/.."   # -> REPRODUCTION/
DATA="$PWD/data"; RES="$PWD/results"
M="$PWD/scripts/manifest_r1.csv"
echo "gene,host,alignment,out_json,out_csv" > "$M"
for gene in ha na pb1; do
  for host in na_avian eurasian_avian swine human equine canine; do
    # HA and NA both carry a 2-col frame-2 offset -> use reframed .inframe.fasta. PB1 is frame-0 clean.
    if [ "$gene" = "pb1" ]; then aln="$DATA/pb1/$host.fasta"; else aln="$DATA/$gene/$host.inframe.fasta"; fi
    [ -f "$aln" ] || { echo "MISSING: $aln" >&2; exit 1; }
    echo "$gene,$host,$aln,$RES/meme_${gene}_${host}.json,$RES/meme_${gene}_${host}.csv" >> "$M"
  done
done
echo "wrote $M with $(( $(wc -l < "$M") - 1 )) data rows"
column -t -s, "$M"
