#!/bin/sh

syst=`uname -s`
arch=`uname -m`
name=`uname -n`

if [ "$arch" = "x86_64" ] ; then
  arch="amd64"
fi
if [ "$arch" = "Power Macintosh" ] ; then
  arch="ppc"
fi

bin="/usr/local/bioinformatics/canu-1.6/$syst-$arch/bin"

if [ ! -d "$bin" ] ; then
  bin="/usr/local/bioinformatics/canu-1.6"
fi


#  Store must exist: unitigging/20171018_oly_pacbio.gkpStore

#  Purge any previous intermediate result.  Possibly not needed, but safer.

rm -f ./20171018_oly_pacbio.ms22.WORKING*

$bin/meryl \
  -B -C -L 2 -v -m 22 -threads 24 -memory 58163 \
  -s ../20171018_oly_pacbio.gkpStore \
  -o ./20171018_oly_pacbio.ms22.WORKING \
&& \
mv ./20171018_oly_pacbio.ms22.WORKING.mcdat ./20171018_oly_pacbio.ms22.mcdat \
&& \
mv ./20171018_oly_pacbio.ms22.WORKING.mcidx ./20171018_oly_pacbio.ms22.mcidx

#  File is important: 20171018_oly_pacbio.ms22.mcdat

#  File is important: 20171018_oly_pacbio.ms22.mcidx


#  Dump a histogram

$bin/meryl \
  -Dh -s ./20171018_oly_pacbio.ms22 \
>  ./20171018_oly_pacbio.ms22.histogram.WORKING \
2> ./20171018_oly_pacbio.ms22.histogram.info \
&& \
mv -f ./20171018_oly_pacbio.ms22.histogram.WORKING ./20171018_oly_pacbio.ms22.histogram

#  File is important: 20171018_oly_pacbio.ms22.histogram

#  File is important: 20171018_oly_pacbio.ms22.histogram.info


#  Compute a nice kmer threshold.

$bin/estimate-mer-threshold \
  -h ./20171018_oly_pacbio.ms22.histogram \
  -c 1 \
>  ./20171018_oly_pacbio.ms22.estMerThresh.out.WORKING \
2> ./20171018_oly_pacbio.ms22.estMerThresh.err \
&& \
mv ./20171018_oly_pacbio.ms22.estMerThresh.out.WORKING ./20171018_oly_pacbio.ms22.estMerThresh.out

#  File is important: 20171018_oly_pacbio.ms22.estMerThresh.out

#  File is important: 20171018_oly_pacbio.ms22.estMerThresh.err


exit 0
