3ccd2b6675cc1955d74aec568ef2fdc852bd3fd7
hiram
  Fri Jun 14 12:12:57 2024 -0700
adding a /list/genarkGenomes endpoint refs #23589

diff --git src/hg/hubApi/list.c src/hg/hubApi/list.c
index 7bb33aa..cfe6829 100644
--- src/hg/hubApi/list.c
+++ src/hg/hubApi/list.c
@@ -43,30 +43,48 @@
 char **columnNames = NULL;
 char **columnTypes = NULL;
 int *jsonTypes = NULL;
 int columnCount = tableColumns(conn, hubPublicTableName(), &columnNames,
     &columnTypes, &jsonTypes);
 jsonWriteListStart(jw, "publicHubs");
 for ( ; el != NULL; el = el->next )
     {
     hubPublicJsonData(jw, el, columnCount, columnNames);
     }
 jsonWriteListEnd(jw);
 apiFinishOutput(0, NULL, jw);
 hDisconnectCentral(&conn);
 }
 
+static void genArkJsonData(struct jsonWrite *jw, struct genark *el,
+    int columnCount, char **columnNames)
+/* Print out genark table element in JSON format.
+ * must be same as was stated in the columnName header element
+ */
+{
+int i = 0;
+jsonWriteObjectStart(jw, el->gcAccession);
+i++;
+// redundant: jsonWriteString(jw, NULL, el->gcAccession);
+jsonWriteString(jw, columnNames[i++], el->hubUrl);
+jsonWriteString(jw, columnNames[i++], el->asmName);
+jsonWriteString(jw, columnNames[i++], el->scientificName);
+jsonWriteString(jw, columnNames[i++], el->commonName);
+jsonWriteNumber(jw, columnNames[i++], (long long)el->taxId);
+jsonWriteObjectEnd(jw);
+}
+
 static void dbDbJsonData(struct jsonWrite *jw, struct dbDb *el,
     int columnCount, char **columnNames)
 /* Print out dbDb table element in JSON format.
  * must be same as was stated in the columnName header element
  * This code should be over in hg/lib/dbDb.c
  */
 {
 int i = 0;
 jsonWriteObjectStart(jw, el->name);
 i++;
 // redundant: jsonWriteString(jw, NULL, el->name);
 jsonWriteString(jw, columnNames[i++], el->description);
 jsonWriteString(jw, columnNames[i++], el->nibPath);
 jsonWriteString(jw, columnNames[i++], el->organism);
 jsonWriteString(jw, columnNames[i++], el->defaultPos);
@@ -102,30 +120,74 @@
 char **columnNames = NULL;
 char **columnTypes = NULL;
 int *jsonTypes = NULL;
 int columnCount = tableColumns(conn, "dbDb", &columnNames, &columnTypes,
     &jsonTypes);
 jsonWriteObjectStart(jw, "ucscGenomes");
 for ( el=dbList; el != NULL; el = el->next )
     {
     dbDbJsonData(jw, el, columnCount, columnNames);
     }
 jsonWriteObjectEnd(jw);
 apiFinishOutput(0, NULL, jw);
 hDisconnectCentral(&conn);
 }
 
+static void jsonGenArk()
+/* output the genark.hgcentral SQL table */
+{
+char *extraArgs = verifyLegalArgs(argListGenarkGenomes); /* no extras allowed */
+if (extraArgs)
+    apiErrAbort(err400, err400Msg, "extraneous arguments found for function /list/genark '%s'", extraArgs);
+
+struct sqlConnection *conn = hConnectCentral();
+char *genArkTable = genarkTableName();
+char *dataTime = sqlTableUpdate(conn, genArkTable);
+time_t dataTimeStamp = sqlDateToUnixTime(dataTime);
+replaceChar(dataTime, ' ', 'T');	/* ISO 8601 */
+long long genArkCount = genArkSize();
+char *genome = cgiOptionalString("genome");
+struct genark *list = genArkList(genome);
+struct jsonWrite *jw = apiStartOutput();
+if (genome && slCount(list) < 1)
+    apiErrAbort(err404, err404Msg, "genome '%s' not found", genome);
+jsonWriteString(jw, "dataTime", dataTime);
+jsonWriteNumber(jw, "dataTimeStamp", (long long)dataTimeStamp);
+char *hubPrefix = cfgOption("genarkHubPrefix");
+jsonWriteString(jw, "hubUrlPrefix", hubPrefix);
+freeMem(dataTime);
+char **columnNames = NULL;
+char **columnTypes = NULL;
+int *jsonTypes = NULL;
+int columnCount = tableColumns(conn, genArkTable, &columnNames, &columnTypes,
+    &jsonTypes);
+jsonWriteObjectStart(jw, "genarkGenomes");
+struct genark *el;
+for ( el=list; el != NULL; el = el->next )
+    {
+    genArkJsonData(jw, el, columnCount, columnNames);
+    }
+jsonWriteObjectEnd(jw);
+long long itemCount = slCount(list);
+jsonWriteNumber(jw, "totalAssemblies", genArkCount);
+jsonWriteNumber(jw, "itemsReturned", itemCount);
+if (!genome && (genArkCount > itemCount))
+    jsonWriteBoolean(jw, "maxItemsLimit", TRUE);
+apiFinishOutput(0, NULL, jw);
+hDisconnectCentral(&conn);
+}
+
 static void bigFileChromInfoOutput(struct jsonWrite *jw,
     struct trackDb *thisTrack, char *bigDataUrl)
 /* output the chromosome list for the bigDataUrl file */
 {
 struct bbiFile *bbi = bigFileOpen(thisTrack->type, bigDataUrl);
 struct bbiChromInfo *chrList = bbiChromList(bbi);
 slSort(chrList, chromInfoCmp);
 struct bbiChromInfo *el = chrList;
 jsonWriteNumber(jw, "chromCount", (long long)slCount(chrList));
 jsonWriteObjectStart(jw, "chromosomes");
 for ( ; el; el = el->next )
     {
     jsonWriteNumber(jw, el->name, (long long)el->size);
     }
 jsonWriteObjectEnd(jw);	/* chromosomes */
@@ -988,30 +1050,32 @@
 for (el = tdbList; el != NULL; el = el->next )
     {
     recursiveTrackList(jw, el, db);
     }
 jsonWriteObjectEnd(jw);
 apiFinishOutput(0, NULL, jw);
 }	/*	static void trackDbJsonOutput(char *db, FILE *f)	*/
 
 void apiList(char *words[MAX_PATH_INFO])
 /* 'list' function words[1] is the subCommand */
 {
 if (sameWord("publicHubs", words[1]))
     jsonPublicHubs();
 else if (sameWord("ucscGenomes", words[1]))
     jsonDbDb();
+else if (sameWord("genarkGenomes", words[1]))
+    jsonGenArk();
 else if (sameWord("hubGenomes", words[1]))
     {
     char *extraArgs = verifyLegalArgs(argListHubGenomes); /* only one allowed */
     if (extraArgs)
 	apiErrAbort(err400, err400Msg, "extraneous arguments found for function /list/hubGenomes '%s'", extraArgs);
 
     char *hubUrl = cgiOptionalString("hubUrl");
     if (isEmpty(hubUrl))
 	apiErrAbort(err400, err400Msg, "must supply hubUrl='http:...' some URL to a hub for /list/hubGenomes");
 
     struct trackHub *hub = errCatchTrackHubOpen(hubUrl);
     if (hub->genomeList)
 	{
 	slNameSort((struct slName **)&hub->genomeList);
         struct jsonWrite *jw = apiStartOutput();