64df1dc542e3f7653a5d24cfef8d13d55a22aca2
angie
  Thu Jul 7 09:44:07 2016 -0700
Fixing a couple more places that assume that transcript status tables are in the same database as the gene track.  refs #17597

diff --git src/hg/hgVai/hgVai.c src/hg/hgVai/hgVai.c
index 34cf4e0..57ee9b0 100644
--- src/hg/hgVai/hgVai.c
+++ src/hg/hgVai/hgVai.c
@@ -2438,63 +2438,72 @@
     hTableExists(db, "knownCanonical"))
     {
     slAddHead(&txStatusExtras, joinerDtfNew(db, "knownCanonical", "transcript"));
     }
 if (cartUsualBoolean(cart, "hgva_txStatus_refSeqStatus", FALSE) &&
     sameString(track, "refGene") &&
     genbankTableExists(db, refSeqStatusTable))
     {
     char *genbankDb=NULL, *tableName=NULL;
     genbankGetDbTable(db, refSeqStatusTable, &genbankDb, &tableName);
     slAddHead(&txStatusExtras, joinerDtfNew(genbankDb, tableName, "status"));
     }
 return txStatusExtras;
 }
 
-static void configAddTableField(struct dyString *dy, char *table, char *field, boolean *pIsFirst)
-/* Add a JSON object with table and (list of one) field. */
-// (with "." prepended to table name
-// because that's the convention for related tables in same db as track):
+static void configAddDtf(struct dyString *dy, struct joinerDtf *dtf, boolean *pIsFirst)
+/* Add a JSON object with [db].table and (list of one) field. */
 {
 if (! *pIsFirst)
     dyStringAppend(dy, ", ");
-dyStringPrintf(dy, "{ \"table\": \".%s\", \"fields\": [\"%s\"] }", table, field);
+// The convention for related tables in same db as track is to prepend "." instead of "<db>.":
+char *db = (sameString(dtf->database, database) ? "" : dtf->database);
+dyStringPrintf(dy, "{ \"table\": \"%s.%s\", \"fields\": [\"%s\"] }", db, dtf->table, dtf->field);
 *pIsFirst = FALSE;
 }
 
+static void configAddTableField(struct dyString *dy, char *table, char *field, boolean *pIsFirst)
+/* Add a JSON object with current database, table and (list of one) field. */
+{
+struct joinerDtf dtf;
+dtf.database = database;
+dtf.table = table;
+dtf.field = field;
+configAddDtf(dy, &dtf, pIsFirst);
+}
 
 static struct jsonElement *configForStreamer(char *db, struct trackDb *tdb,
                                              struct joinerDtf *txStatusExtras)
 /* Add VAI-specific config options, if applicable. */
 {
 struct jsonElement *config = NULL;
 char *track = tdb->track;
 struct dyString *dyConfig = dyStringCreate("{ \"naForMissing\": false,"
                                            "  \"relatedTables\": [ ");
 boolean isFirst = TRUE;
 // If track is sql-based knownGene and we have kgXref, then add kgXref.geneSymbol after
 // the columns of knownGene.
 if (sameString(track, "knownGene") &&
     !isCustomTrack(track) && !isHubTrack(track) &&
     !trackDbSetting(tdb, "bigDataUrl") &&
     hTableExists(db, "kgXref"))
     {
     configAddTableField(dyConfig, "kgXref", "geneSymbol", &isFirst);
     }
 struct joinerDtf *txStatDtf;
 for (txStatDtf = txStatusExtras;  txStatDtf != NULL;  txStatDtf = txStatDtf->next)
-    configAddTableField(dyConfig, txStatDtf->table, txStatDtf->field, &isFirst);
+    configAddDtf(dyConfig, txStatDtf, &isFirst);
 
 // If any of the above apply, close the relatedTables list and config object
 // and parse into jsonElements.
 if (! isFirst)
     {
     dyStringAppend(dyConfig, " ] }");
     config = jsonParse(dyConfig->string);
     dyStringFree(&dyConfig);
     }
 return config;
 }
 
 static void adjustGpVarOverlapRule(struct annoGrator *gpVarGrator, boolean haveRegulatory)
 /* If we're able to detect regulatory elements, and want to keep those annotations, loosen up
  * gpVarGrator's overlap rule from the default (must overlap). */
@@ -2502,32 +2511,34 @@
 if (haveRegulatory && cartUsualBoolean(cart, "hgva_include_regulatory", TRUE))
     gpVarGrator->setOverlapRule(gpVarGrator, agoNoConstraint);
 }
 
 static void addTxStatusExtras(struct annoFormatter *vepOut, char *geneTrack,
                               struct annoGrator *gpVarGrator,
                               struct joinerDtf *txStatusExtras)
 /* Given a list of tables and fields that will be joined with geneTrack to provide transcript
  * status info, configure vepOut to put them in the EXTRAs column. */
 {
 struct joinerDtf *txStatDtf;
 for (txStatDtf = txStatusExtras;  txStatDtf != NULL;  txStatDtf = txStatDtf->next)
     {
     char *tag = NULL, *description = NULL;
     boolean isBoolean = FALSE;
-    if (differentString(txStatDtf->database, database))
-        errAbort("addTxStatusExtras: Expected db=%s in txStatDtf but got %s",
+    // Double-check that we're not joining in some table from a different assembly database:
+    if (differentString(txStatDtf->database, database) &&
+        differentString(txStatDtf->database, "hgFixed"))
+        errAbort("addTxStatusExtras: Expected db=%s or hgFixed in txStatDtf but got %s",
                  database, txStatDtf->database);
     if ((startsWith(GENCODE_PREFIX"Tag", txStatDtf->table) &&
          sameString(txStatDtf->field, "tag")) ||
         (sameString(txStatDtf->table, "knownToTag") &&
          sameString(txStatDtf->field, "value")))
         {
         tag = "GENCODE_TAG";
         description = "<A HREF=" GENCODE_TAG_DOC_URL " "
             "TARGET=_BLANK>GENCODE tags</A> for the transcript";
         }
     else if (sameString(txStatDtf->table, "knownCanonical") &&
              sameString(txStatDtf->field, "transcript"))
         {
         tag = "CANONICAL";
         description = "If present, the transcript is the 'canonical' transcript of the gene "