4ab22d829bff96467e64331dad271bcb0bc84de1
chmalee
  Tue Mar 24 15:22:00 2026 -0700
Force genark autocomplete results to send their genome identifier like GC[AF]_XXX as the db field to hgGateway back end, refs #37276

diff --git src/hg/js/hgGateway.js src/hg/js/hgGateway.js
index a1c5bd7c414..9e2b1134e12 100644
--- src/hg/js/hgGateway.js
+++ src/hg/js/hgGateway.js
@@ -1621,44 +1621,39 @@
 
 
     function setDbFromAutocomplete(item) {
         // The user has selected a result from the species-search autocomplete.
         // It might be a taxId and/or db from dbDb, or it might be a hub db,
         // or a taxon-only result (like "Human") that shows an assembly dropdown.
         var taxId = item.taxId || -1;
         var db = item.db;
         var org = item.org || item.value || item.label;
         var cmd;
         var genome = item.genome || '';
 
         // Check if db is a valid assembly name (not an organism name).
         // If db is the same as org, it's likely a taxon-only result, not an assembly.
         var isValidDb = db && db !== org;
-
-        // Detect GenArk: must have hubUrl, and either "UCSC Curated" category (GenArk hubs
-        // under /gbdb) or a GCA_/GCF_ genome pattern.  The hubUrl check distinguishes GenArk
-        // from native databases which also use "UCSC Curated" category.
-        // Recent genome items store the original category in originalCategory.
-        var cat = item.originalCategory || item.category;
-        var isGenArk = item.hubUrl &&
-                       ((typeof cat !== "undefined" && cat.startsWith("UCSC Curated")) ||
-                        (genome.startsWith('GCA_') || genome.startsWith('GCF_')));
+        let isGenArk = isGenarkItem(item);
 
         if (isGenArk) {
-            // For items from localStorage recents, db is the accession; for fresh autocomplete, genome is
-            db = item.db || item.genome;
-            setHubDb(item.hubUrl, taxId, db, "GenArk", item.scientificName || org, true);
+            // genark results should have item.db set to the genome name like GC[AF]_, however
+            // due to history some genark results come from the genark table and not the
+            // assemblyList table, and thus have item.db set to asmName and item.genome
+            // set to the actual identifier. Thus always force genark results to use item.genome
+            // (item.db is normalized to item.genome in autocompleteCat.js before saving to localStorage)
+            setHubDb(item.hubUrl, taxId, item.genome, "GenArk", item.scientificName || org, true);
         } else if (item.hubUrl && item.hubName) {
             // Public hub - the autocomplete sends the hub database from hubPublic.dbList,
             // without the hub prefix -- restore the prefix here.
             db = item.hubName + '_' + item.db;
             setHubDb(item.hubUrl, taxId, db, item.hubName, org, true);
         } else if (item.hubUrl) {
             // Connected hub from localStorage recents without hubName.
             // db is already the bare assembly name; server resolves via hubUrl.
             setHubDb(item.hubUrl, taxId, db, null, org, true);
         } else if (taxId > 0) {
             // Native db with valid taxId - pass db only if it's a valid assembly name
             setTaxId(taxId, isValidDb ? db : null, org, true, false);
         } else if (isValidDb) {
             // Native db without taxId - use setDb command directly
             cmd = { setDb: { db: db, position: "lastDbPos" } };