476ebb957aebb1a7f20ea71301e894c5422bd57e
hiram
  Wed Apr 29 21:41:01 2026 -0700
subtle timing issue resolved and minor bugs fixed refs #31811

diff --git src/hg/utils/otto/userRequests/ottoRequestAlign.sh src/hg/utils/otto/userRequests/ottoRequestAlign.sh
index 39cb0ccc057..8867e80cf95 100755
--- src/hg/utils/otto/userRequests/ottoRequestAlign.sh
+++ src/hg/utils/otto/userRequests/ottoRequestAlign.sh
@@ -1,27 +1,28 @@
 #!/bin/bash
 
 # ottoRequestAlign.sh - look up an ottoRequest row by id and construct
 #   the kegAlignLastz.sh command line from genark metadata
 #
 # usage: ottoRequestAlign.sh <id>
 #
 # Queries hgcentraltest.ottoRequest for fromDb/toDb, then looks up
 # each accession in hgcentraltest.genark for asmName and clade.
 # Prints and executes the resulting kegAlignLastz.sh command.
 
 set -eEu -o pipefail
+set -x
 
 ############################################################################
 ### verify arguments
 ############################################################################
 if [ $# != 1 ]; then
   printf "usage: ottoRequestAlign.sh <id>\n" 1>&2
   printf "  where <id> is a row id from hgcentraltest.ottoRequest\n" 1>&2
   exit 255
 fi
 
 export requestId="$1"
 
 # validate id is a positive integer
 case "${requestId}" in
   ''|*[!0-9]*)
@@ -240,36 +241,38 @@
 export targetExists="/hive/data/genomes/${fromId}/bed"
 
 case ${fromId} in
   GC[AF]_*)
     gcX=$(printf "%s" "${fromId}" | cut -c1-3)
     d0=$(printf "%s" "${fromId}" | cut -c5-7)
     d1=$(printf "%s" "${fromId}" | cut -c8-10)
     d2=$(printf "%s" "${fromId}" | cut -c11-13)
     tGcPath="${gcX}/${d0}/${d1}/${d2}"
     buildDir="/hive/data/genomes/asmHubs/allBuild/${tGcPath}/${fromId}/trackData/lastz${Query}.${DS}"
     targetExists="/hive/data/genomes/asmHubs/allBuild/${tGcPath}/${fromId}/trackData"
     ;;
 esac
 
 # reuse existing build directory if one is already in progress
-working=$(ls -d ${targetExists}/lastz${Query}.* 2> /dev/null | wc -l)
+working=$(ls -d ${targetExists}/lastz${Query}.* 2> /dev/null | wc -l || true)
 if [ "${working}" -gt 0 ]; then
   buildDir=$(ls -d ${targetExists}/lastz${Query}.* | tail -1)
   printf "# existing buildDir: %s\n" "${buildDir}" 1>&2
 fi
 
+mkdir -p  "${buildDir}"
+
 printf "# buildDir: %s\n" "${buildDir}" 1>&2
 
 # store buildDir in ottoRequest table for workflowMonitor.sh
 hgsql -N -e \
   "UPDATE ottoRequest SET buildDir='${buildDir}', status=2 WHERE id=${requestId};" \
   hgcentraltest
 
 ############################################################################
 # step 5: map clades and build the kegAlignLastz.sh command
 ############################################################################
 export fromCladeArg=$(cladeMap "${fromClade}")
 export toCladeArg=$(cladeMap "${toClade}")
 
 export cmd="${HOME}/kent/src/hg/utils/automation/kegAlignLastz.sh ${fromId} ${toId} ${fromCladeArg} ${toCladeArg}"