587c0ae924cde64738db226abbf1b0ef4ba86ff9
hiram
  Wed Sep 28 11:12:52 2022 -0700
fixups for hs1 to database assemblies refs #29819

diff --git src/hg/utils/automation/doBlastzChainNet.pl src/hg/utils/automation/doBlastzChainNet.pl
index 82467cc..d46225e 100755
--- src/hg/utils/automation/doBlastzChainNet.pl
+++ src/hg/utils/automation/doBlastzChainNet.pl
@@ -1077,54 +1077,55 @@
 rm -f $tDb.$qDb.net.txt $tDb.$qDb.net.summary.tab \\
         $tDb.$qDb.net.summary.bed
 _EOF_
       );
   }
 
   $bossScript->execute();
 }	#	sub netChains {}
 
 
 sub loadUp {
   # Load chains; add repeat/gap stats to net; load nets.
   my $runDir = "$buildDir/axtChain";
   my $QDbLink = "chain$QDb" . "Link";
   # First, make sure we're starting clean.
-  if (-e "$runDir/$tDb.$qDb.net" || -e "$runDir/$tDb.$qDb.net.gz") {
+  if (! $opt_debug && (-e "$runDir/$tDb.$qDb.net" || -e "$runDir/$tDb.$qDb.net.gz") ) {
     die "loadUp: looks like this was run successfully already " .
       "($tDb.$qDb.net[.gz] exists).  Either run with -continue download, " .
 	"or move aside/remove $runDir/$tDb.$qDb.net[.gz] and run again.\n";
   }
   # Make sure previous stage was successful.  Depends upon what was done:
   my $otherCheck = "$buildDir/mafNet";
   if ($opt_trackHub) {
      $otherCheck = "$buildDir/bigMaf";
      &HgAutomate::nfsNoodge("$otherCheck/$tDb.$qDb.net.maf");
   }
   my $successDir = $isSelf ? "$runDir/$tDb.$qDb.all.chain.gz" :
                              "$otherCheck";
   if (! -e $successDir && ! $opt_debug) {
     die "loadUp: looks like previous stage was not successful " .
       "(can't find $successDir).\n";
   }
   my $whatItDoes =
 "It loads the chain tables into $tDb, adds gap/repeat stats to the .net file,
 and loads the net table.";
   my $bossScript = new HgRemoteScript("$runDir/loadUp.csh", $dbHost,
 				      $runDir, $whatItDoes, $DEF);
   $bossScript->add(<<_EOF_
 # Load chains:
+set buildDir = "$buildDir"
 _EOF_
     );
   if ($opt_loadChainSplit && $splitRef) {
 ### XXX to be done: fixup this loop to make the bigBed files for the chain
 ####### instead of this database loading table (split table code could be
 ####### eliminated . . . )
     $bossScript->add(<<_EOF_
 cd $runDir/chain
 foreach c (`awk '{print \$1;}' $defVars{SEQ1_LEN}`)
     set f = \$c.chain
     if (! -e \$f) then
       echo no chains for \$c
       set f = /dev/null
     endif
     hgLoadChain $tDb \${c}_chain$QDb \$f
@@ -1178,45 +1179,66 @@
   | hgLoadNet -verbose=0 $tDb net$QDb stdin
 _EOF_
       );
       } else {
       $bossScript->add(<<_EOF_
 cp -p noClass.net $tDb.$qDb.net
 netFilter -minGap=10 noClass.net \\
   | hgLoadNet -test -noBin -warn -verbose=0 $tDb net$QDb stdin
 mv align.tab net$QDb.tab
 _EOF_
       );
       }
 
       $bossScript->add(<<_EOF_
 
-cd $buildDir
+cd \$buildDir
 featureBits $tDb $QDbLink >&fb.$tDb.$QDbLink.txt
 cat fb.$tDb.$QDbLink.txt
 _EOF_
       );
-    } else {
+    } else {	# not a database assembly
       $bossScript->add(<<_EOF_
 cp -p noClass.net $tDb.$qDb.net
 netFilter -minGap=10 noClass.net \\
   | hgLoadNet -test -noBin -warn -verbose=0 $tDb net$QDb stdin
 mv align.tab net$QDb.tab
 _EOF_
       );
+      # target may be database assembly, special set of gbdb symLinks
+      if ($dbExists && $tChromInfoExists) {
+      $bossScript->add(<<_EOF_
+mkdir -p /gbdb/$tDb/chainNet
+foreach T (chain chainRBest chainSyn)
+  if ( -s "\$buildDir/axtChain/\${T}${QDb}.bb" ) then
+    rm -f "/gbdb/$tDb/chainNet/$tDb.\${T}$QDb.bb" "/gbdb/$tDb/chainNet/$tDb.\${T}.${QDb}Link.bb"
+    ln -s "\$buildDir/axtChain/\${T}${QDb}.bb" "/gbdb/$tDb/chainNet/$tDb.\${T}$QDb.bb"
+    ln -s "\$buildDir/axtChain/\${T}${QDb}Link.bb" "/gbdb/$tDb/chainNet/$tDb.\${T}.${QDb}Link.bb"
+  endif
+end
+foreach T (net rbestNet synNet)
+  if ( -s "\$buildDir/bigMaf/$tDb.$qDb.\${T}.bb" ) then
+    rm -f "/gbdb/$tDb/chainNet/$tDb.$qDb.\${T}.bb" "/gbdb/$tDb/chainNet/$tDb.$qDb.\${T}.summary.bb"
+    ln -s "\$buildDir/bigMaf/$tDb.$qDb.\${T}.bb" "/gbdb/$tDb/chainNet/$tDb.$qDb.\${T}.bb"
+    ln -s "\$buildDir/bigMaf/$tDb.$qDb.\${T}.summary.bb" "/gbdb/$tDb/chainNet/$tDb.$qDb.\${T}.summary.bb"
+  endif
+end
+_EOF_
+      );
       }
     }
+  }	#	if (! $isSelf)
   $bossScript->execute();
 # maybe also peek in trackDb and see if entries need to be added for chain/net
 }	#	sub loadUp {}
 
 
 sub makeDownloads {
   # Compress the netClassed .net for download (other files should have been
   # compressed already).
   my $runDir = "$buildDir/axtChain";
   if (-s "$runDir/$tDb.$qDb.net") {
     &HgAutomate::run("$HgAutomate::runSSH $fileServer nice " .
 	 "gzip $runDir/$tDb.$qDb.net");
   }
   return if ($opt_skipDownload);
   # Make an md5sum.txt file.