f0d09119e54af30308746dd1c5d4f0178f07af72
angie
  Thu Nov 21 10:45:56 2019 -0800
When displaying ncbiRefSeq alignments, use ncbiRefSeqCds not gbCdnaInfo which may have a different version.  refs #24554

diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c
index 9352a3e..34680d7 100644
--- src/hg/hgc/hgc.c
+++ src/hg/hgc/hgc.c
@@ -7230,50 +7230,56 @@
 	   bodyTn.forCgi);
 else
     puts("<FRAMESET COLS = \"13%,87% \" >");
 printf("  <FRAME SRC=\"%s\" NAME=\"index\">\n", indexTn.forCgi);
 printf("  <FRAME SRC=\"%s\" NAME=\"body\">\n", bodyTn.forCgi);
 puts("<NOFRAMES><BODY></BODY></NOFRAMES>");
 puts("</FRAMESET>");
 puts("</HTML>\n");
 exit(0);	/* Avoid cartHtmlEnd. */
 }
 
 static void getCdsStartAndStop(struct sqlConnection *conn, char *acc, char *trackTable,
 			       uint *retCdsStart, uint *retCdsEnd)
 /* Get cds start and stop, if available */
 {
-char query[256];
-if (sqlTableExists(conn, gbCdnaInfoTable))
-    {
-    sqlSafef(query, sizeof query, "select cds from %s where acc = '%s'", gbCdnaInfoTable, acc);
-    char *cdsId = sqlQuickString(conn, query);
-    if (isNotEmpty(cdsId))
+struct trackDb *tdb = hashMustFindVal(trackHash, trackTable);
+// Note: this variable was previously named cdsTable but unfortunately the
+// hg/(inc|lib)/genbank.[hc] code uses the global var cdsTable!
+char *tdbCdsTable = trackDbSetting(tdb, "cdsTable");
+if (isEmpty(tdbCdsTable) && startsWith("ncbiRefSeq", trackTable))
+    tdbCdsTable = "ncbiRefSeqCds";
+if (isNotEmpty(tdbCdsTable) && hTableExists(database, tdbCdsTable))
     {
-        sqlSafef(query, sizeof query, "select name from %s where id = '%s'", cdsTable, cdsId);
+    char query[256];
+    sqlSafef(query, sizeof(query), "select cds from %s where id = '%s'", tdbCdsTable, acc);
     char *cdsString = sqlQuickString(conn, query);
     if (isNotEmpty(cdsString))
         genbankParseCds(cdsString, retCdsStart, retCdsEnd);
     }
-    }
-else
+else if (sqlTableExists(conn, gbCdnaInfoTable))
     {
-    struct trackDb *tdb = hashMustFindVal(trackHash, trackTable);
-    char *cdsTable = trackDbSetting(tdb, "cdsTable");
-    if (isNotEmpty(cdsTable) && hTableExists(database, cdsTable))
+    char accChopped[512];
+    safecpy(accChopped, sizeof(accChopped), acc);
+    chopSuffix(accChopped);
+    char query[256];
+    sqlSafef(query, sizeof query, "select cds from %s where acc = '%s'",
+             gbCdnaInfoTable, accChopped);
+    char *cdsId = sqlQuickString(conn, query);
+    if (isNotEmpty(cdsId))
         {
-	sqlSafef(query, sizeof(query), "select cds from %s where id = '%s'", cdsTable, acc);
+        sqlSafef(query, sizeof query, "select name from %s where id = '%s'", cdsTable, cdsId);
         char *cdsString = sqlQuickString(conn, query);
         if (isNotEmpty(cdsString))
             genbankParseCds(cdsString, retCdsStart, retCdsEnd);
         }
     }
 }
 
 void htcBigPslAli(char *acc)
 /* Show alignment for accession in bigPsl file. */
 {
 struct psl *psl;
 char *aliTable;
 int start;
 unsigned int cdsStart = 0, cdsEnd = 0;
 
@@ -7426,39 +7432,40 @@
 char accTmp[64];
 struct sqlConnection *conn;
 struct sqlResult *sr;
 char **row;
 struct psl *psl;
 struct dnaSeq *rnaSeq;
 char *aliTable;
 int start;
 unsigned int cdsStart = 0, cdsEnd = 0;
 boolean hasBin;
 char accChopped[512] ;
 safef(accChopped, sizeof(accChopped), "%s",acc);
 chopSuffix(accChopped);
 
 aliTable = cartString(cart, "aliTable");
+char *accForTitle = startsWith("ncbiRefSeq", aliTable) ? acc : accChopped;
 char title[1024];
-safef(title, sizeof title, "%s vs Genomic [%s]", accChopped, aliTable);
+safef(title, sizeof title, "%s vs Genomic [%s]", accForTitle, aliTable);
 htmlFramesetStart(title);
 
 /* Get some environment vars. */
 start = cartInt(cart, "o");
 
 conn = hAllocConn(database);
-getCdsStartAndStop(conn, accChopped, aliTable, &cdsStart, &cdsEnd);
+getCdsStartAndStop(conn, acc, aliTable, &cdsStart, &cdsEnd);
 
 /* Look up alignments in database */
 if (!hFindSplitTable(database, seqName, aliTable, table, sizeof table, &hasBin))
     errAbort("Failed to find aliTable=%s", aliTable);
 sqlSafef(query, sizeof query, "select * from %s where qName like '%s%%' and tName=\"%s\" and tStart=%d",
 	table, acc, seqName, start);
 sr = sqlGetResult(conn, query);
 if ((row = sqlNextRow(sr)) == NULL)
     errAbort("Couldn't find alignment for %s at %d", acc, start);
 psl = pslLoad(row+hasBin);
 sqlFreeResult(&sr);
 
 /* get bz rna snapshot for blastz alignments */
 if (sameString("mrnaBlastz", aliTable) || sameString("pseudoMrna", aliTable))
     {
@@ -7516,36 +7523,37 @@
 char **row;
 struct psl *wholePsl, *partPsl;
 struct dnaSeq *rnaSeq;
 char *aliTable;
 int start;
 unsigned int cdsStart = 0, cdsEnd = 0;
 boolean hasBin;
 char accChopped[512] ;
 safef(accChopped, sizeof(accChopped), "%s",acc);
 chopSuffix(accChopped);
 
 /* Get some environment vars. */
 aliTable = cartString(cart, "aliTable");
 start = cartInt(cart, "o");
 
+char *accForTitle = startsWith("ncbiRefSeq", aliTable) ? acc : accChopped;
 char title[1024];
-safef(title, sizeof title, "%s vs Genomic [%s]", accChopped, aliTable);
+safef(title, sizeof title, "%s vs Genomic [%s]", accForTitle, aliTable);
 htmlFramesetStart(title);
 
 conn = hAllocConn(database);
-getCdsStartAndStop(conn, accChopped, aliTable, &cdsStart, &cdsEnd);
+getCdsStartAndStop(conn, acc, aliTable, &cdsStart, &cdsEnd);
 
 if (startsWith("user", aliTable))
     {
     char *pslName, *faName, *qName;
     struct lineFile *lf;
     bioSeq *oSeqList = NULL, *oSeq = NULL;
     struct psl *psl;
     int start;
     enum gfType tt, qt;
     boolean isProt;
     char *ss = cartOptionalString(cart, "ss");
 
     if ((ss != NULL) && !ssFilesExist(ss))
 	{
 	ss = NULL;