#!/bin/bash
# Build the FP-control reference DB (module C) into <db_dir>/fpc/refset.
# Combines the IS-lineage positive pool (P|) and host-lineage negative pool (N|) into one mmseqs nt DB.
# Usage: build_fpc_db.sh <POS.fna> <NEG.fna> <db_dir>
set -e
POS=$1; NEG=$2; DBDIR=$3
MM=${MMSEQS:-mmseqs}
mkdir -p "$DBDIR/fpc"
tmpfa=$(mktemp)
awk '/^>/{print ">P|"substr($0,2);next}{print}' "$POS"  > "$tmpfa"
awk '/^>/{print ">N|"substr($0,2);next}{print}' "$NEG" >> "$tmpfa"
$MM createdb "$tmpfa" "$DBDIR/fpc/refset" --dbtype 2 >/dev/null
rm -f "$tmpfa"
echo "built $DBDIR/fpc/refset ($(grep -c '^>' "$POS") IS + $(grep -c '^>' "$NEG") host refs)"
