#!/usr/bin/env bash

[[ $# -eq 4 ]] || { echo "usage $0 <srcdir> <trgdir> <genes file> <taxid>"; exit 0; }

SRCDIR="$1"
TRGDIR="$2"
FGENES="$3"
TAXID="$4"

FSRC=$SRCDIR/${TAXID}.fs_selected

[[ -d $SRCDIR ]] || { echo "error: missing source dir at $SRCDIR"; exit 255; }
[[ -d $TRGDIR ]] || { echo "error: missing target dir at $TRGDIR"; exit 255; }
[[ -f $FGENES ]] || { echo "error: missing genes file at $SRCDIR"; exit 255; }
[[ -f $FSRC   ]] || { echo "error: missing source fasta file at $FSRC"; exit 255; }
FLBL=$(basename $FGENES .txt)
fout=${TRGDIR}/${FLBL}.fs_selected
echo "$fout"
[[ -f $fout ]] && exit 0


grep -f $FGENES --no-group-separator -A 1 $FSRC > $fout
