# Last edited on 2026-06-02 20:43:59 by stolfi


temp_data_file="${temp}.dat"
echo "collecting plot data into ${temp_data_file} ..." 1>&2
for kc in $( count 2 ${kmax} ); do
  k=$(( ${kmax} - ${kc} + 2 ))
#
#, then the name {tx_name} of the orginal
# text file, where those repeated patterns should occur
# 
# The text file "res/${tx_name}.rex" must have and optional
# locus ID "<..>" and then words separated by spaces.
# The words of the repeat sequences must occur somewhere 
# in the same sequence.
tx_name="$1"; shift  # Name (sans folder and extension) of original source file.
echo "  tx_name = '${tx_name}' " 1>&2
tx_file="res/${tx_name}.txt"
echo "getting clean copy of text ..." 1>&2
temp_text_file="${temp}.txt"
cat ${tx_file} \
  | sed \
      -e 's:<[^<>]*>::g' \
      -e 's:^[ ][ ]*::g' \
      -e 's:[ ][ ]*$::g' \
      -e 's:[ ][ ][ ]*: :g' \
  > ${temp_text_file}

temp_reps_file="${temp}.rex"
  echo "extracting ${k}-repeats ..." 1>&2
  cat ${ex_file} \
    | gawk ' /^[@|]/{ for (i=6; i<=NF; i++) { printf " %s", $(i) } printf "\n" } ' \
    | sed \
        -e 's:^[ ][ ]*::g' \
        -e 's:[ ][ ]*$::g' \
        -e 's:[ ][ ][ ]*: :g' \
    | sort | uniq \
    > ${temp_reps_file}
 
  echo "locating the ${k}-repeats in the text file ..." 1>&2
  cat ${temp_text_file} \
    | fgrep -F -w -h -n -f ${temp_reps_file} \
    > .foo
  cat .foo \
    | sed \
        -e 's/:.*$//g' \
        -e 's:$: '${k}':g' \
    >> ${temp_data_file}
done
