#!/bin/bash

VERSION=0.1

gspread_lettering(){
echo -e "        ____                           _  ____                      "
echo -e "   __ _/ ___| _ __  _ __ ___  __ _  __| |/ ___|___  _ __ ___  _ __  "
echo -e "  / _\` \\___ \\| '_ \\| '__/ _ \\/ _\` |/ _\` | |   / _ \\| '_ \` _ \\| '_ \\ "
echo -e " | (_| |___) | |_) | | |  __/ (_| | (_| | |__| (_) | | | | | | |_) |"
echo -e "  \\__, |____/| .__/|_|  \\___|\\__,_|\\__,_|\\____\\___/|_| |_| |_| .__/ "
echo -e "  |___/      |_|                                             |_|    "
echo -e "Prokaryotic quantitative risk assessment, gene spread, and plasmid-mediated horizontal transmission to pathogens"
echo -e "\t\t\t\tVersion $VERSION\n\n"
}


help_message () {
        echo""
        echo "gspreadcomp v=$VERSION"
        echo "Usage: gspreadcomp [module] [module_options]"
        echo ""
		echo "  Modules:"
		echo ""
        echo "  taxonomy	Assign taxonomy to genomes using GTDBtk v2"
        echo "  quality	Estimate genome completeness and contamination using CheckM"
		echo "  args	Predicts the Antimicrobial Resistance Genes (ARGs) in a genome using DeepARG"
		echo "  plasmid	Predicts if a sequence within a fasta file is a chromosome, plasmid or undetermined using Plasflow"
		echo "  pathogens	Aligns provided genomes to Virulence Factors databases and format the output"
		echo "  gspread	Run the main gspreadcomp to compare spread, plasmid-mediated HGT, and calculate pathogenic risk"    
        echo ""
        echo "  --help | -h	show this help message"
        echo "  --version | -v	show gspreadcomp version"
        echo "  --show-config	show where the gspreadcomp configuration files are stored"
        echo "";}
  
gspread_lettering

config_path="$(which config)"
source $config_path
if [[ $? -ne 0 ]]; then #Tests the exit status of the last command
	echo "cannot find config file - something went wrong with the installation!"
	exit 1
fi


########################################################################################################
########################     LOADING IN THE PARAMETERS AND RUNNING MODULE       ########################
########################################################################################################

# config file should be in the bin folder from the gspreadcomp_env conda environment

if [ "$1" = taxonomy ]; then
	echo gspreadcomp taxonomy ${@:2}
	bash -i $mSPREAD_CONDA_ENVIRONMENT_PATH/bin/taxonomy.sh ${@:2}
elif [ "$1" = quality ]; then
	echo gspreadcomp quality ${@:2}
	bash -i $mSPREAD_CONDA_ENVIRONMENT_PATH/bin/quality.sh ${@:2}
elif [ "$1" = plasmid ]; then
	echo gspreadcomp plasmid ${@:2}
	bash -i $mSPREAD_CONDA_ENVIRONMENT_PATH/bin/plasmid.sh ${@:2}
elif [ "$1" = pathogens ]; then
	echo gspreadcomp pathogens ${@:2}
	bash -i $mSPREAD_CONDA_ENVIRONMENT_PATH/bin/pathogens.sh ${@:2}
elif [ "$1" = gspread ]; then
	echo gspreadcomp gspread ${@:2}
	time $mSPREAD_CONDA_ENVIRONMENT_PATH/bin/gspread.sh ${@:2}
elif [ "$1" = args ]; then
	echo gspreadcomp args ${@:2}
	bash -i $mSPREAD_CONDA_ENVIRONMENT_PATH/bin/args.sh ${@:2}
elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
	help_message
elif [ "$1" = "-v" ] || [ "$1" = "--version" ]; then
	echo ""
	echo "gSpreadcomp v=$VERSION"
	echo ""
elif [ "$1" = "--show-config" ]; then
	echo "gspreadcomp script found in $(which gspreadcomp) and config file was found in $(which config)."
	echo -e "\nHere are the contents of config:\n"
	cat $(which config)
else
        comm "Please select a proper module of gspreadcomp."
        help_message
        exit 1
fi
