7e5840e03baf4a7b7c198016c393d0b86f7b72b6
braney
  Tue Nov 16 15:25:19 2021 -0800
allow hgc pages on chains to provide a link to the "other" browser if
the other assembly is an unattached genark assembly hub

diff --git src/hg/lib/genark.c src/hg/lib/genark.c
index eef5151..bd2707d 100644
--- src/hg/lib/genark.c
+++ src/hg/lib/genark.c
@@ -1,24 +1,26 @@
 /* genark.c was originally generated by the autoSql program, which also 
  * generated genark.h and genark.sql.  This module links the database and
  * the RAM representation of objects. */
 
 #include "common.h"
 #include "linefile.h"
 #include "dystring.h"
 #include "jksql.h"
 #include "genark.h"
+#include "hgConfig.h"
+#include "hdb.h"
 
 
 
 char *genarkCommaSepFieldNames = "gcAccession,hubUrl,asmName,scientificName,commonName,taxId";
 
 void genarkStaticLoad(char **row, struct genark *ret)
 /* Load a row from genark table into ret.  The contents of ret will
  * be replaced at the next call to this function. */
 {
 
 ret->gcAccession = row[0];
 ret->hubUrl = row[1];
 ret->asmName = row[2];
 ret->scientificName = row[3];
 ret->commonName = row[4];
@@ -229,15 +231,60 @@
 fputc(':',f);
 fputc('"',f);
 fprintf(f, "%s", el->commonName);
 fputc('"',f);
 fputc(',',f);
 fputc('"',f);
 fprintf(f,"taxId");
 fputc('"',f);
 fputc(':',f);
 fprintf(f, "%d", el->taxId);
 fputc('}',f);
 }
 
 /* -------------------------------- End autoSql Generated Code -------------------------------- */
 
+char *genarkUrl(char *accession)
+/* Return the URL to the genark assembly with this accession if present,
+ * otherwise return NULL
+ * */
+{
+char *genarkPrefix = cfgOption("genarkHubPrefix");
+
+if (genarkPrefix == NULL)
+    return NULL;
+
+struct sqlConnection *conn = hConnectCentral();
+if (!sqlTableExists(conn, genarkTableName()))
+    return NULL;
+
+char *url = NULL;
+char query[4096];
+char buffer[4096];
+sqlSafef(query, sizeof query, "select hubUrl from %s where gcAccession='%s'", genarkTableName(), accession);
+if (sqlQuickQuery(conn, query, buffer, sizeof buffer))
+    {
+    char buffer2[4096];
+    safef(buffer2, sizeof buffer2, "%s/%s", genarkPrefix, buffer);
+
+    url = cloneString(buffer2);
+    }
+
+hDisconnectCentral(&conn);
+
+return url;
+}
+
+static char *_genarkTableName = NULL;
+
+char *genarkTableName()
+/* return the genark table name from the environment, 
+ * or hg.conf, or use the default.  Cache the result */
+{
+if (_genarkTableName == NULL)
+    _genarkTableName = cfgOptionEnvDefault("HGDB_GENARK_STATUS_TABLE",
+	    genarkTableConfVariable, defaultGenarkTableName);
+
+return _genarkTableName;
+}
+
+