74f7bf30603c7dfe869afcbe63adb6ddd74e9898 angie Wed Jan 10 12:58:38 2018 -0800 Link to NCBI's Genome Data Viewer (GDV) using GCA_ accessions from dbDb.sourceName instead of hardcoded GCF_ ids. refs #18671 diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c index 6b38607..a181aa1 100644 --- src/hg/lib/hdb.c +++ src/hg/lib/hdb.c @@ -32,30 +32,31 @@ #include "ra.h" #include "genbank.h" #include "chromInfo.h" #ifndef GBROWSE #include "axtInfo.h" #include "ctgPos.h" #include "hubConnect.h" #include "customTrack.h" #include "hgFind.h" #endif /* GBROWSE */ #include "hui.h" #include "trackHub.h" #include "net.h" #include "udc.h" #include "paraFetch.h" +#include "regexHelper.h" #include "filePath.h" #include "wikiLink.h" #include "cheapcgi.h" #ifdef LOWELAB #define DEFAULT_PROTEINS "proteins060115" #define DEFAULT_GENOME "Pyrobaculum aerophilum" #else #define DEFAULT_PROTEINS "proteins" #define DEFAULT_GENOME "Human" #endif static struct sqlConnCache *hdbCc = NULL; /* cache for primary database connection */ @@ -606,30 +607,52 @@ char *hNcbiGcfId(char *db) /* Return the NCBI RefSeq assembly+annotations ID (GCF_...) for db, or NULL if we don't know it. */ { char *gcf = NULL; int i; for (i = 0; dbToGcf[i].db != NULL; i++) if (sameString(db, dbToGcf[i].db)) { gcf = cloneString(dbToGcf[i].gcf); break; } return gcf; } +char *hNcbiGcaId(char *db) +/* Return the NCBI GenBank assembly id (GCA_...) for db, or NULL if we don't know it. */ +{ +char *gca = NULL; +if (! trackHubDatabase(db)) + { + struct sqlConnection *conn = hConnectCentral(); + char query[1024]; + sqlSafef(query, sizeof(query), "select sourceName from dbDb where name = '%s'", db); + char sourceName[2048]; + sqlQuickQuery(conn, query, sourceName, sizeof(sourceName)); + regmatch_t substrs[2]; + if (isNotEmpty(sourceName) && + regexMatchSubstr(sourceName, "GCA_[0-9]+\\.[0-9]+", substrs, ArraySize(substrs))) + { + gca = regexSubstringClone(sourceName, substrs[0]); + } + hDisconnectCentral(&conn); + } +return gca; +} + struct sqlConnection *hAllocConn(char *db) /* Get free connection if possible. If not allocate a new one. */ { if (hdbCc == NULL) hdbCc = sqlConnCacheNew(); return sqlConnCacheAlloc(hdbCc, db); } struct sqlConnection *hAllocConnMaybe(char *db) /* Get free connection if possible. If not allocate a new one. Return * NULL if db doesn't exist or can't be connected to. */ { if (hdbCc == NULL) hdbCc = sqlConnCacheNew(); return sqlConnCacheMayAlloc(hdbCc, db);