c3786681696b93476299dfbfb832b355035861b1
hiram
  Sat Jun 29 15:13:45 2024 -0700
ready for an upgrade to the genark table to add columns currently maintain compatible behavior with previous genark table refs #32596;

diff --git src/hg/lib/genark.c src/hg/lib/genark.c
index db8ce1c..0a660b7 100644
--- src/hg/lib/genark.c
+++ src/hg/lib/genark.c
@@ -1,43 +1,48 @@
 /* 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";
+char *genarkCommaSepFieldNames = "gcAccession,hubUrl,asmName,scientificName,commonName,taxId,priority,clade";
 
 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. */
 {
+int colCount = genArkColumnCount();
 
 ret->gcAccession = row[0];
 ret->hubUrl = row[1];
 ret->asmName = row[2];
 ret->scientificName = row[3];
 ret->commonName = row[4];
 ret->taxId = sqlSigned(row[5]);
+ret->priority = 0;
+if (colCount > 6) { ret->priority = sqlSigned(row[6]); }
+if (colCount > 7)
+    ret->clade = row[7];
+else
+    ret->clade = cloneString("n/a");
 }
 
 struct genark *genarkLoadByQuery(struct sqlConnection *conn, char *query)
 /* Load all genark from table that satisfy the query given.
  * Where query is of the form 'select * from example where something=something'
  * or 'select example.* from example, anotherTable where example.something =
  * anotherTable.something'.
  * Dispose of this with genarkFreeList(). */
 {
 struct genark *list = NULL, *el;
 struct sqlResult *sr;
 char **row;
 
 sr = sqlGetResult(conn, query);
 while ((row = sqlNextRow(sr)) != NULL)
@@ -46,119 +51,129 @@
     slAddHead(&list, el);
     }
 slReverse(&list);
 sqlFreeResult(&sr);
 return list;
 }
 
 void genarkSaveToDb(struct sqlConnection *conn, struct genark *el, char *tableName, int updateSize)
 /* Save genark as a row to the table specified by tableName.
  * As blob fields may be arbitrary size updateSize specifies the approx size
  * of a string that would contain the entire query. Arrays of native types are
  * converted to comma separated strings and loaded as such, User defined types are
  * inserted as NULL. This function automatically escapes quoted strings for mysql. */
 {
 struct dyString *update = dyStringNew(updateSize);
-sqlDyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s',%d)", 
-	tableName,  el->gcAccession,  el->hubUrl,  el->asmName,  el->scientificName,  el->commonName,  el->taxId);
+sqlDyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s',%d,%d,'%s')",
+	tableName,  el->gcAccession,  el->hubUrl,  el->asmName,  el->scientificName,  el->commonName,  el->taxId,  el->priority,  el->clade);
 sqlUpdate(conn, update->string);
 dyStringFree(&update);
 }
 
 struct genark *genarkLoad(char **row)
 /* Load a genark from row fetched with select * from genark
  * from database.  Dispose of this with genarkFree(). */
 {
+int colCount = genArkColumnCount();
 struct genark *ret;
 
 AllocVar(ret);
 ret->gcAccession = cloneString(row[0]);
 ret->hubUrl = cloneString(row[1]);
 ret->asmName = cloneString(row[2]);
 ret->scientificName = cloneString(row[3]);
 ret->commonName = cloneString(row[4]);
 ret->taxId = sqlSigned(row[5]);
+ret->priority = 0;
+if (colCount > 6) { ret->priority = sqlSigned(row[6]); }
+if (colCount > 7)
+    ret->clade = row[7];
+else
+    ret->clade = cloneString("n/a");
 return ret;
 }
 
 struct genark *genarkLoadAll(char *fileName)
 /* Load all genark from a whitespace-separated file.
  * Dispose of this with genarkFreeList(). */
 {
 struct genark *list = NULL, *el;
 struct lineFile *lf = lineFileOpen(fileName, TRUE);
-char *row[6];
+char *row[8];
 
 while (lineFileRow(lf, row))
     {
     el = genarkLoad(row);
     slAddHead(&list, el);
     }
 lineFileClose(&lf);
 slReverse(&list);
 return list;
 }
 
 struct genark *genarkLoadAllByChar(char *fileName, char chopper)
 /* Load all genark from a chopper separated file.
  * Dispose of this with genarkFreeList(). */
 {
 struct genark *list = NULL, *el;
 struct lineFile *lf = lineFileOpen(fileName, TRUE);
-char *row[6];
+char *row[8];
 
 while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
     {
     el = genarkLoad(row);
     slAddHead(&list, el);
     }
 lineFileClose(&lf);
 slReverse(&list);
 return list;
 }
 
 struct genark *genarkCommaIn(char **pS, struct genark *ret)
 /* Create a genark out of a comma separated string.
  * This will fill in ret if non-null, otherwise will
  * return a new genark */
 {
 char *s = *pS;
 
 if (ret == NULL)
     AllocVar(ret);
 ret->gcAccession = sqlStringComma(&s);
 ret->hubUrl = sqlStringComma(&s);
 ret->asmName = sqlStringComma(&s);
 ret->scientificName = sqlStringComma(&s);
 ret->commonName = sqlStringComma(&s);
 ret->taxId = sqlSignedComma(&s);
+ret->priority = sqlSignedComma(&s);
+ret->clade = sqlStringComma(&s);
 *pS = s;
 return ret;
 }
 
 void genarkFree(struct genark **pEl)
 /* Free a single dynamically allocated genark such as created
  * with genarkLoad(). */
 {
 struct genark *el;
 
 if ((el = *pEl) == NULL) return;
 freeMem(el->gcAccession);
 freeMem(el->hubUrl);
 freeMem(el->asmName);
 freeMem(el->scientificName);
 freeMem(el->commonName);
+freeMem(el->clade);
 freez(pEl);
 }
 
 void genarkFreeList(struct genark **pList)
 /* Free a list of dynamically allocated genark's */
 {
 struct genark *el, *next;
 
 for (el = *pList; el != NULL; el = next)
     {
     next = el->next;
     genarkFree(&el);
     }
 *pList = NULL;
 }
@@ -175,30 +190,36 @@
 if (sep == ',') fputc('"',f);
 fputc(sep,f);
 if (sep == ',') fputc('"',f);
 fprintf(f, "%s", el->asmName);
 if (sep == ',') fputc('"',f);
 fputc(sep,f);
 if (sep == ',') fputc('"',f);
 fprintf(f, "%s", el->scientificName);
 if (sep == ',') fputc('"',f);
 fputc(sep,f);
 if (sep == ',') fputc('"',f);
 fprintf(f, "%s", el->commonName);
 if (sep == ',') fputc('"',f);
 fputc(sep,f);
 fprintf(f, "%d", el->taxId);
+fputc(sep,f);
+fprintf(f, "%d", el->priority);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->clade);
+if (sep == ',') fputc('"',f);
 fputc(lastSep,f);
 }
 
 void genarkJsonOutput(struct genark *el, FILE *f)
 /* Print out genark in JSON format. */
 {
 fputc('{',f);
 fputc('"',f);
 fprintf(f,"gcAccession");
 fputc('"',f);
 fputc(':',f);
 fputc('"',f);
 fprintf(f, "%s", el->gcAccession);
 fputc('"',f);
 fputc(',',f);
@@ -227,30 +248,44 @@
 fputc('"',f);
 fputc(',',f);
 fputc('"',f);
 fprintf(f,"commonName");
 fputc('"',f);
 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);
+fputc('"',f);
+fprintf(f,"priority");
+fputc('"',f);
+fputc(':',f);
+fprintf(f, "%d", el->priority);
+fputc(',',f);
+fputc('"',f);
+fprintf(f,"clade");
+fputc('"',f);
+fputc(':',f);
+fputc('"',f);
+fprintf(f, "%s", el->clade);
+fputc('"',f);
 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;
 
@@ -296,15 +331,37 @@
 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;
 }
+
+/* temporary function while the genark table is in transistion with
+ * new coluns being added, July 2024.  Allows compatibility with existing
+ * genark table.
+ */
+int genArkColumnCount()
+/* return number of columns in genark table */
+{
+static int colCount = 0;
+if (colCount > 0)
+   return colCount;
+char *centralProfile = "central";
+char *centralDb = cfgOption2(centralProfile, "db");
+struct sqlConnection *conn = hConnectCentral();
+if (!sqlTableExists(conn, genarkTableName()))
+    return colCount;
+char query[4096];
+sqlSafef(query, sizeof query, "SELECT count(*) FROM information_schema.columns WHERE table_schema = '%s' AND table_name = '%s'", centralDb, genarkTableName());
+colCount = sqlQuickNum(conn, query);
+hDisconnectCentral(&conn);
+return colCount;
+}