#$ -N merqury
#$ -o ../../logs/$JOB_NAME.$JOB_ID.log
#$ -e ../../logs/$JOB_NAME.$JOB_ID.err
#$ -cwd
#$ -pe smp 50
#$ -l h_vmem=4g
#$ -t 1:3
#$ -tc 3

#####################
GENOME_DIR=/mnt/data/arslan/Teas/01_Assembly/scaffolding

export MERQURY=/mnt/bin/merqury/merqury_v1.3/
export PATH=/mnt/bin/meryl/meryl-1.4/bin/:$PATH


echo -e "AJ\nZJ\nL618" >baseNames.txt
SEEDFILE="baseNames.txt"
SEED=$(awk "NR==$SGE_TASK_ID" $SEEDFILE)

# Calculate Kmer size
/mnt/bin/merqury/merqury_v1.3/best_k.sh 3000000000 # output is 20.7 so kmer is 21

mkdir -p 02_Assembly_QA/Merqury/${SEED}
cd 02_Assembly_QA/Merqury/${SEED}

# Creating Meryl database
/mnt/bin/meryl/meryl-1.4/bin/meryl k=21 count threads=50 memory=150 output ${SEED}.meryl /mnt/data/arslan/Teas/00_Reads/${SEED}.fastq.gz

# Merquery analysis
/mnt/bin/merqury/merqury_v1.3/merqury.sh ${SEED}.meryl ${GENOME_DIR}/${SEED}-scaffold/${SEED}_rename.scaffold.fasta ${SEED}_merqury

# Genomescope2 
/mnt/data/arslan/tool/genomescope2.0/genomescope.R -i ${SEED}.hist -o ${SEED}_genomescope -n ${SEED} -k 21
