be4f99627b03673652489ddaf9254782ab5c8b3e
braney
  Fri Aug 14 09:07:33 2026 -0700
hgc: read chain query sequence from the two bit file when the query assembly has no database, refs #37974

htcChainAli chose the query sequence with the otherDb branch ahead of the
otherTwoBitUrl branch, and otherDb is the second word of the track's type
line, so it is never NULL. The two bit branch has been unreachable since
a1cfd4eb6e2.

That only shows up now because a quickLift chain names its source assembly in
the type line. When the source is a GenArk accession there is no database to
connect to, so clicking an alignment link on the Alignment Differences page
aborted with "Couldn't connect to database 'GCA_002844635.1'". The track
already carries the right file in otherTwoBitUrl; nothing read it.

Move the two bit branch first and gate it on the database not existing, so a
native chain track still takes the database branch.

diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c
index 6ea351a2428..af977e9af58 100644
--- src/hg/hgc/hgc.c
+++ src/hg/hgc/hgc.c
@@ -8945,40 +8945,43 @@
     return;
     }
 fatPsl = chainToPsl(chain);
 
 chainFree(&chain);
 
 psl = pslTrimToTargetRange(fatPsl, winStart, winEnd);
 pslFree(&fatPsl);
 
 struct twoBitFile *otherTbf = getOtherTwoBitUrl(tdb);
 if (sameWord(otherDb, "seq"))
     {
     qSeq = hExtSeqPart(database, psl->qName, psl->qStart, psl->qEnd);
     safef(name, sizeof name, "%s", psl->qName);
     }
+else if (otherTbf != NULL && !sqlDatabaseExists(otherDb))
+    {
+    // the query assembly has no database of its own (an assembly hub or a GenArk
+    // accession, as when a quickLift chain comes from one), so read the sequence
+    // out of the two bit file the track points at.
+    qSeq = twoBitReadSeqFragLower(otherTbf, psl->qName, psl->qStart, psl->qEnd);
+    safef(name, sizeof name, "%s", psl->qName);
+    }
 else if (otherDb != NULL)
     {
     qSeq = loadGenomePart(otherDb, psl->qName, psl->qStart, psl->qEnd);
     safef(name, sizeof name, "%s.%s", otherOrg, psl->qName);
     }
-else if (otherTbf != NULL)
-    {
-    qSeq = twoBitReadSeqFragLower(otherTbf, psl->qName, psl->qStart, psl->qEnd);
-    safef(name, sizeof name, "%s", psl->qName);
-    }
 if (qSeq == NULL)
     {
     errAbort("Can't find query sequence in htcChainAli");
     }
 char title[1024];
 safef(title, sizeof title, "%s %s vs %s %s ",
        (otherOrg == NULL ? "" : otherOrg), psl->qName, org, psl->tName );
 alnModernStart(title);
 showSomeAlignment(psl, qSeq, gftDnaX, psl->qStart, psl->qEnd, name, 0, 0);
 }
 
 void htcChainTransAli(char *item)
 /* Draw detailed alignment representation of a chain with translated protein */
 {
 struct chain *chain;