938f87d8ba8f5b68f03d807bec70521363de8a48
hiram
  Thu Sep 15 10:45:05 2016 -0700
allow chrom name lookup to use the new chromXref table refs #18027

diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c
index 953b850..f7c7c52 100644
--- src/hg/lib/hdb.c
+++ src/hg/lib/hdb.c
@@ -185,32 +185,47 @@
 return ci;
 }
 
 char *hgOfficialChromName(char *db, char *name)
 /* Returns "canonical" name of chromosome or NULL
  * if not a chromosome. (Case-insensitive search w/sameWord()) */
 {
 struct chromInfo *ci = NULL;
 char buf[HDB_MAX_CHROM_STRING];
 strncpy(buf, name, HDB_MAX_CHROM_STRING);
 buf[HDB_MAX_CHROM_STRING-1] = 0;
 ci = hGetChromInfo(db, buf);
 if (ci != NULL)
     return cloneString(ci->chrom);
 else
+    {
+    if (hTableExists(db, "chromXref"))
+       {
+       struct sqlConnection *conn = hAllocConn(db);
+       char query[512];
+       char *chrName;
+       sqlSafef(query, sizeof(query),
+          "select ucsc from chromXref where refseq='%s' or genbank='%s' or ensembl='%s' limit 1",
+      name, name, name);
+       chrName = sqlQuickString(conn, query);
+       hFreeConn(&conn);
+       if (isNotEmpty(chrName))  // chrName is already a cloneString result
+         return chrName;
+       }
     return NULL;
     }
+}
 
 boolean hgIsOfficialChromName(char *db, char *name)
 /* Determine if name is exact (case-sensitive) match with
  * a chromosome in the given assembly */
 {
 char *chrom;
 return ((chrom = hgOfficialChromName(db, name)) != NULL &&
 	sameString(name, chrom));
 }
 
 
 int hGetMinIndexLength(char *db)
 /* get the minimum index size for the given database that won't smoosh
  * together chromNames. */
 {