4f80b3af4cb02e10216ba047ea8de0378c4abe3d
angie
  Mon Mar 19 09:58:16 2018 -0700
hListGencodeTables' version comparison didn't account for the 'VM' mouse version strings; if there's a letter following the V, skip it.  Thanks Cath!  refs #21076

diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c
index 8cb5d24..32fd7db 100644
--- src/hg/lib/hdb.c
+++ src/hg/lib/hdb.c
@@ -5583,51 +5583,54 @@
     return NULL;
 struct sqlConnection *conn = hAllocConn(db);
 struct slName *snpNNNTables = hListSnpNNNTables(conn, suffix);
 // Return the first trackDb that we can find (sometimes there is a brand new lastest-version table
 // that does not yet have a trackDb)
 struct slName *table;
 for (table = snpNNNTables;  table != NULL;  table = table->next)
     {
     struct trackDb *tdb = tdbForTrack(db, table->name, pFullTrackList);
     if (tdb)
         return tdb;
     }
 return NULL;
 }
 
-static int getVVersion(const char *name)
-/* If name ends in V[0-9]+, return the number, else 0. */
+static int getGencodeVersion(const char *name)
+/* If name ends in VM?[0-9]+, return the number, else 0. */
 {
 int version = 0;
 char *p = strrchr(name, 'V');
 if (p)
     {
     char *versionStr = p + 1;
+    // GENCODE mouse versions begin with "VM", skip the M if present.
+    if (isalpha(*versionStr))
+        versionStr++;
     if (isAllDigits(versionStr))
         version = atoi(versionStr);
     }
 return version;
 }
 
 static int cmpVDesc(const void *va, const void *vb)
 /* Compare by version number, descending, e.g. tableV2 < tableV1. */
 {
 const struct slName *a = *((struct slName **)va);
 const struct slName *b = *((struct slName **)vb);
-int aVersion = getVVersion(a->name);
-int bVersion = getVVersion(b->name);
+int aVersion = getGencodeVersion(a->name);
+int bVersion = getGencodeVersion(b->name);
 int dif = bVersion - aVersion;
 if (dif == 0)
     dif = strcmp(b->name, a->name);
 return dif;
 }
 
 static struct slName *hListGencodeTables(struct sqlConnection *conn, char *suffix)
 /* Return a list of 'wgEncodeGencode<suffix>V<version>' tables, if any, highest version first.
  * If suffix is NULL, it defaults to Basic. */
 {
 char likeExpr[128];
 safef(likeExpr, sizeof(likeExpr), "wgEncodeGencode%sV%%", suffix ? suffix : "Basic");
 struct slName *gencodeTables = sqlListTablesLike(conn, likeExpr);
 slSort(&gencodeTables, cmpVDesc);
 return gencodeTables;