aba8125cb532df17beb7c7c9bc8467a43d09e3d6
braney
  Wed Feb 10 13:39:27 2016 -0800
changes to allow for GenBank metadata to be held in a common table.  #16809

diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c
index f466337..46111c4 100644
--- src/hg/lib/hdb.c
+++ src/hg/lib/hdb.c
@@ -1638,31 +1638,31 @@
 
 aaSeq *hPepSeqMustGet(char *db, char *acc, char *seqTbl, char *extFileTbl)
 /* Get a peptide sequence from the specified seq and extFile tables.  The
  * seqTbl/extFileTbl arguments may include the database, in which case they
  * override what is in db (which could even be NULL). Abort if
  * not found. */
 {
 return seqMustGet(db, acc, FALSE, seqTbl, extFileTbl);
 }
 
 static boolean querySeqInfo(struct sqlConnection *conn, char *acc, char *seqTbl, char *extFileFld,
                             HGID *retId, HGID *retExtId, size_t *retSize, off_t *retOffset)
 /* lookup information in the seq or gbSeq table */
 {
 boolean gotIt = FALSE;
-if (hTableExists(sqlGetDatabase(conn), seqTbl))
+if (sqlTableExists(conn, seqTbl))
     {
     char query[256];
     sqlSafef(query, sizeof(query),
        "select id, %s, file_offset, file_size from %s where acc = '%s'",
           extFileFld, seqTbl, acc);
     struct sqlResult *sr = sqlMustGetResult(conn, query);
     char **row = sqlNextRow(sr);
     if (row != NULL)
         {
         if (retId != NULL)
             *retId = sqlUnsigned(row[0]);
         if (retExtId != NULL)
             *retExtId = sqlUnsigned(row[1]);
         if (retOffset != NULL)
             *retOffset = sqlLongLong(row[2]);
@@ -1672,52 +1672,52 @@
         }
     sqlFreeResult(&sr);
     }
 return gotIt;
 }
 
 static char* getSeqAndId(struct sqlConnection *conn, char *acc, HGID *retId)
 /* Return sequence as a fasta record in a string and it's database ID, or
  * NULL if not found. Optionally get genbank modification date. */
 {
 HGID extId;
 size_t size;
 off_t offset;
 char *extTable = NULL;
 /* try gbExtFile table first, as it tends to be  more performance sensitive */
-if (querySeqInfo(conn, acc, "gbSeq", "gbExtFile", retId, &extId, &size, &offset))
-    extTable = "gbExtFile";
+if (querySeqInfo(conn, acc, gbSeqTable, "gbExtFile", retId, &extId, &size, &offset))
+    extTable = gbExtFileTable;
 else if (querySeqInfo(conn, acc, "seq", "extFile", retId, &extId, &size, &offset))
     extTable = "extFile";
 else
     return NULL;
 struct largeSeqFile *lsf = largeFileHandle(conn, extId, extTable);
 if (lsf == NULL)
     return NULL;
 
 char *buf = readOpenFileSection(lsf->fd, offset, size, lsf->path, acc);
 return buf;
 }
 
 static char* mustGetSeqAndId(struct sqlConnection *conn, char *acc,
                              HGID *retId)
 /* Return sequence as a fasta record in a string and it's database ID,
  * abort if not found */
 {
 char *buf= getSeqAndId(conn, acc, retId);
 if (buf == NULL)
-    errAbort("No sequence for %s in seq or gbSeq tables", acc);
+    errAbort("No sequence for %s in seq or %s tables", acc, gbSeqTable);
 return buf;
 }
 
 char* hGetSeqAndId(struct sqlConnection *conn, char *acc, HGID *retId)
 /* Return sequence as a fasta record in a string and it's database ID, or
  * NULL if not found. */
 {
 return getSeqAndId(conn, acc, retId);
 }
 
 int hRnaSeqAndIdx(char *acc, struct dnaSeq **retSeq, HGID *retId, struct sqlConnection *conn)
 /* Return sequence for RNA and it's database ID. Return -1 if not found. */
 {
 char *buf = getSeqAndId(conn, acc, retId);
 if (buf == NULL)
@@ -1793,32 +1793,32 @@
  * sequences in external files.  If compatTable is not NULL and the table
  * exists, it is used to obtain the sequence.  Otherwise the seq and gbSeq
  * tables are checked.
  */
 {
 struct sqlConnection *conn = hAllocConn(db);
 boolean haveSeq = FALSE;
 
 /* Check compatTable if we have it, otherwise check seq and gbSeq */
 if ((compatTable != NULL) && hTableExists(db, compatTable))
     {
     haveSeq = checkIfInTable(conn, acc, "name", compatTable);
     }
 else
     {
-    if (hTableExists(db, "gbSeq"))
-        haveSeq = checkIfInTable(conn, acc, "acc", "gbSeq");
+    if (sqlTableExists(conn, gbSeqTable))
+        haveSeq = checkIfInTable(conn, acc, "acc", gbSeqTable);
     if ((!haveSeq) && hTableExists(db, "seq"))
         haveSeq = checkIfInTable(conn, acc, "acc", "seq");
     }
 
 hFreeConn(&conn);
 return haveSeq;
 }
 
 static struct dnaSeq *loadSeqFromTable(struct sqlConnection *conn,
                                        char *acc, char *table)
 /* load a sequence from table. */
 {
 struct dnaSeq *seq = NULL;
 struct sqlResult *sr;
 char **row;
@@ -1926,39 +1926,39 @@
 
 char *hGenBankGetDesc(char *db, char *acc, boolean native)
 /* Get a description for a genbank or refseq mRNA. If native is TRUE, an
  * attempt is made to get a more compact description that doesn't include
  * species name. Acc may optionally include the version.  NULL is returned if
  * a description isn't available.  Free string when done. */
 {
 struct sqlConnection *conn = hAllocConn(db);
 char *desc =  NULL;
 char accId[GENBANK_ACC_BUFSZ], query[256];
 
 genbankDropVer(accId, acc);
 
 if (native && genbankIsRefSeqAcc(accId))
     {
-    sqlSafef(query, sizeof(query), "select product from refLink where mrnaAcc = \"%s\"", accId);
+    sqlSafef(query, sizeof(query), "select product from %s where mrnaAcc = \"%s\"", refLinkTable, accId);
     desc = sqlQuickString(conn, query);
     }
 
 if (desc == NULL)
     {
-    sqlSafef(query, sizeof(query), "select description.name from description,gbCdnaInfo "
-          "where gbCdnaInfo.acc = \"%s\" "
-          "and gbCdnaInfo.description = description.id", accId);
+    sqlSafef(query, sizeof(query), "select d.name from %s d, %s g "
+          "where g.acc = \"%s\" "
+          "and g.description = d.id", descriptionTable, gbCdnaInfoTable, accId);
     desc = sqlQuickString(conn, query);
     }
 hFreeConn(&conn);
 return desc;
 }
 
 struct bed *hGetCtBedRange(char *db, char *browserDb, char *table, char *chrom, int chromStart,
 			   int chromEnd, char *sqlConstraints)
 /* Return a bed list of all items (that match sqlConstraints, if nonNULL)
  * in the given range in table.  If chromEnd is 0, omit the range (whole chrom).
  * WARNING: this does not use the bin column and maybe slower than you would like. */
 {
 struct dyString *query = newDyString(512);
 struct sqlConnection *conn = hAllocConn(db);
 struct sqlResult *sr;
@@ -5198,31 +5198,31 @@
 return sqlQuickList(conn, query);
 }
 
 boolean isUnknownChrom(char *dataBase, char *chromName)
 /* Return true if chrom is one of our "unknown" chromomsomes (e.g. chrUn). */
 {
 return  endsWith(chromName, "_random") || startsWith("chrUn", chromName);
 }
 
 char *hGenbankModDate(char *acc, struct sqlConnection *conn)
 /* Get string for genbank last modification date, or NULL if not found..
  * Free resulting string. */
 {
 char query[128];
 sqlSafef(query, sizeof(query),
-      "select moddate from gbCdnaInfo where (acc = '%s')", acc);
+      "select moddate from %s where (acc = '%s')",gbCdnaInfoTable, acc);
 return sqlQuickString(conn, query);
 }
 
 struct trackDb *findTdbForTable(char *db,struct trackDb *parent,char *table, struct customTrack *(*ctLookupName)(char *table))
 /* Find or creates the tdb for this table.  Might return NULL! (e.g. all tables)
  * References an externally defined function ctLookupName() which looks up a
  * custom track by name
  * If this is a custom track, pass in function ctLookupName(table) which looks up a
  * custom track by name, otherwise pass NULL
  */
 {
 if(isEmpty(table))
     return parent;
 
 // hub tracks aren't in the trackDb hash, just use the parent tdb