#!/bin/bash

while getopts i:f:o: option
do
    case "${option}" 
        in
        i) input=${OPTARG};;
        o) output=${OPTARG};;
    esac
done


# 1 - Create Dictionary
SCRIPT_DIR=/opt/mambaforge/envs/bioconda/conda-bld/earlgrey_1708512744301/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/share/earlgrey-4.1.0-0/scripts/

grep ">" $input | awk '{printf("ctg_%01d %s\n", NR, $0)}'  | sed 's/ /\t/g; s/>//g' | awk '{OFS="\t"}{print $2, $1}' > ${input}.dict
tr -d $'\r' < ${input}.dict > ${input}.dict.1 && mv ${input}.dict{.1,}

# 2 - Replace Fasta Headers

${SCRIPT_DIR}/faswap.py ${input}.dict $input > $output
