#!/bin/csh -f
#
# Find exact tandem repeats in specified file involving an
# exact duplicate of at least the specified length

set filename = $1
set matchlen = $2

set bindir = /opt/mambaforge/envs/bioconda/conda-bld/mummer_1723046587438/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho/opt/mummer-3.23
set scriptdir = /opt/mambaforge/envs/bioconda/conda-bld/mummer_1723046587438/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho/opt/mummer-3.23/scripts

if  ($filename == '' || $matchlen == '')  then
    echo "USAGE:  $0 <file> <min-match-len>"
    exit -1
endif

echo "Finding matches"
$bindir/repeat-match -t -n $matchlen $filename | tail +3 > $$.tmp.matches
if  ($status != 0)  exit -1

echo "Tandem repeats"
sort -k1n -k2n $$.tmp.matches | awk -f $scriptdir/tandem-repeat.awk
rm -f $$.tmp.matches
