c497641abbae591cc2dc13cf184c5e13fa58b6b1
hiram
  Mon Jun 17 12:51:42 2024 -0700
add genArkHubTxt() function to contruct the hub.txt URL from a GCx_ name no redmine

diff --git src/hg/lib/genark.c src/hg/lib/genark.c
index b475faf..db8ce1c 100644
--- src/hg/lib/genark.c
+++ src/hg/lib/genark.c
@@ -1,19 +1,20 @@
 /* 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 <limits.h>
 #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. */
@@ -262,29 +263,48 @@
 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;
 }
 
+char *genArkHubTxt(char *gcX)
+/* given a GC[AF]_012345678.9 name, return hub.txt URL */
+{
+char hubTxt[PATH_MAX + 1024];
+/* temporary construction of the path */
+char tPath[PATH_MAX + 1024];
+safencpy(tPath, 4, gcX, 3);
+safencpy(tPath+3, 2, "/", 1);
+safencpy(tPath+4, 4, gcX+4, 3);
+safencpy(tPath+7, 2, "/", 1);
+safencpy(tPath+8, 4, gcX+7, 3);
+safencpy(tPath+11, 2, "/", 1);
+safencpy(tPath+12, 4, gcX+10, 3);
+safencpy(tPath+15, 2, "/", 1);
+safecpy(tPath+16, PATH_MAX-16, gcX);
+/* start the result with the genArkHubPrefix, add in tPath and /hub.txt */
+safef(hubTxt, sizeof(hubTxt), "%s/%s/hub.txt", cfgOption("genarkHubPrefix"),
+   tPath);
+return cloneString(hubTxt);  // no need to free this
+}
+
 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;
 }
-
-