94ab45bc69a304d7f68851812e96de7af8943f6d angie Wed Mar 9 13:12:36 2016 -0800 Libified hgVai's code to find the latest snpNNN table so that other spots in the code could use it instead of hardcoding version numbers. Thx Matt for pointing out the hardcoding. refs #16777 diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c index 95e40d1..7cea64b 100644 --- src/hg/lib/hdb.c +++ src/hg/lib/hdb.c @@ -5326,15 +5326,57 @@ char *seqName) /* Return file name from bigDataUrl or little table that might have a seqName column. * If table does have a seqName column, return NULL if there is no file for seqName. */ { char *fileName = hReplaceGbdb(trackDbSetting(tdb, "bigDataUrl")); if (fileName == NULL) fileName = bbiNameFromTableChrom(conn, table, seqName); return fileName; } char *bbiNameFromSettingOrTable(struct trackDb *tdb, struct sqlConnection *conn, char *table) /* Return file name from bigDataUrl or little table. */ { return bbiNameFromSettingOrTableChrom(tdb, conn, table, NULL); } + +char *hFindLatestSnpTableConn(struct sqlConnection *conn, char *suffix) +/* Return the name of the 'snp1__<suffix>' table with the highest build number, if any. + * suffix may be NULL to get the 'All SNPs' table (as opposed to Common, Flagged, Mult). */ +{ +if (suffix == NULL) + suffix = ""; +char *tableName = NULL; +char likeExpr[64]; +safef(likeExpr, sizeof(likeExpr), "LIKE 'snp1__%s'", suffix); +struct slName *snpNNNTables = sqlListTablesLike(conn, likeExpr); +if (snpNNNTables) + { + // Skip to last in list -- highest number (show tables can't use rlike or 'order by'): + struct slName *table = snpNNNTables; + while (table->next != NULL && isdigit(table->next->name[4]) && isdigit(table->next->name[5])) + table = table->next; + if (table != NULL) + tableName = cloneString(table->name); + } +else if (isEmpty(suffix)) + { + // Before snpNNN* tables (e.g. hg16) there was a track with table 'snp', so check for that: + snpNNNTables = sqlListTablesLike(conn, "LIKE 'snp'"); + if (snpNNNTables != NULL) + tableName = cloneString(snpNNNTables->name); + } +slNameFreeList(&snpNNNTables); +return tableName; +} + +char *hFindLatestSnpTable(char *db, char *suffix) +/* Return the name of the 'snp1__<suffix>' table with the highest build number, if any. + * suffix may be NULL to get the 'All SNPs' table (as opposed to Common, Flagged, Mult). */ +{ +if (startsWith(hubTrackPrefix, db)) + return NULL; +struct sqlConnection *conn = hAllocConn(db); +char *tableName = hFindLatestSnpTableConn(conn, suffix); +hFreeConn(&conn); +return tableName; +}