4b2e806a0d57f97bbadf9a762778965ccd36989d
angie
Fri Dec 21 13:57:15 2012 -0800
Bug #9860 (Table Browser paste identifiers button not working for 1000 genomes ph1 Accessible Regions):getExamples() was unaware of bigBed, so an illegal mysql query was constructed.
Fix: added randomBigBedIds(). While in there, enhanced ramdomVcfIds() to ignore
runs of identical IDs because those are placeholders, and might otherwise crowd
out a few meaningful IDs (#8886 note 28).
diff --git src/hg/hgTables/identifiers.c src/hg/hgTables/identifiers.c
index fedbe89..5c4ef05 100644
--- src/hg/hgTables/identifiers.c
+++ src/hg/hgTables/identifiers.c
@@ -48,116 +48,122 @@
idField = words[1];
aliasField = words[2];
if (!sqlTableExists(conn, xrefTable) ||
sqlFieldIndex(conn, xrefTable, idField) < 0 ||
sqlFieldIndex(conn, xrefTable, aliasField) < 0)
xrefTable = idField = aliasField = NULL;
}
if (retXrefTable != NULL)
*retXrefTable = xrefTable;
if (retIdField != NULL)
*retIdField = idField;
if (retAliasField != NULL)
*retAliasField = aliasField;
}
-static struct slName *getExamples(struct sqlConnection *conn,
+static struct slName *getExamples(char *db, struct sqlConnection *conn,
char *table, char *field, int count)
/* Return a list of several example values of table.field. */
{
if (isBamTable(table))
{
assert(sameString(field, "qName"));
return randomBamIds(table, conn, count);
}
-if (isVcfTable(table))
+else if (isBigBed(db, table, curTrack, ctLookupName))
+ {
+ assert(sameString(field, "name"));
+ return randomBigBedIds(table, conn, count);
+ }
+else if (isVcfTable(table))
{
assert(sameString(field, "id"));
return randomVcfIds(table, conn, count);
}
else
{
char fullTable[HDB_MAX_TABLE_STRING];
char *c = strchr(table, '.');
if (c || ! hFindSplitTable(database, NULL, table, fullTable, NULL))
safecpy(fullTable, sizeof(fullTable), table);
return sqlRandomSampleConn(conn, fullTable, field, count);
}
}
-static void explainIdentifiers(struct sqlConnection *conn, char *idField)
+static void explainIdentifiers(char *db, struct sqlConnection *conn, char *idField)
/* Tell the user what field(s) they may paste/upload values for, and give
* some examples. */
{
char *xrefTable = NULL, *xrefIdField = NULL, *aliasField = NULL;
getXrefInfo(conn, &xrefTable, &xrefIdField, &aliasField);
hPrintf("The items must be values of the %s field of the currently "
"selected table, %s",
idField, curTable);
if (aliasField != NULL)
{
if (sameString(curTable, xrefTable))
{
if (!sameString(idField, aliasField))
hPrintf(", or the %s field.\n", aliasField);
else
hPrintf(".\n");
}
else
hPrintf(", or the %s field of the alias table %s.\n",
aliasField, xrefTable);
}
else
hPrintf(".\n");
hPrintf("(The \"describe table schema\" button shows more information about "
"the table fields.)\n");
if (!isCustomTrack(curTable))
{
struct slName *exampleList = NULL, *ex;
hPrintf("Some example values:
\n");
- exampleList = getExamples(conn, curTable, idField, 3);
+ exampleList = getExamples(db, conn, curTable, idField,
+ aliasField != NULL ? 3 : 5);
for (ex = exampleList; ex != NULL; ex = ex->next)
{
char *tmp = htmlEncode(ex->name);
hPrintf("%s
\n", tmp);
freeMem(tmp);
}
if (aliasField != NULL)
{
char tmpTable[512];
char query[2048];
// do not use any db. prefix on curTable for name
char *plainCurTable = strrchr(curTable, '.');
if (plainCurTable)
plainCurTable++;
else
plainCurTable = curTable;
safef(tmpTable, sizeof(tmpTable), "hgTemp.tmp%s%s", plainCurTable, xrefTable);
if (differentString(xrefTable, curTable))
safef(query, sizeof(query),
"create temporary table %s select %s.%s as %s from %s,%s "
"where %s.%s = %s.%s and %s.%s != %s.%s limit 100000",
tmpTable, xrefTable, aliasField, aliasField, xrefTable, curTable,
xrefTable, xrefIdField, curTable, idField,
xrefTable, xrefIdField, xrefTable, aliasField);
else
safef(query, sizeof(query),
"create temporary table %s select %s from %s "
"where %s != %s limit 100000",
tmpTable, aliasField, xrefTable, aliasField, xrefIdField);
sqlUpdate(conn, query);
- exampleList = getExamples(conn, tmpTable, aliasField, 3);
+ exampleList = getExamples(db, conn, tmpTable, aliasField, 3);
for (ex = exampleList; ex != NULL; ex = ex->next)
hPrintf("%s
\n", ex->name);
}
hPrintf("\n");
}
}
void doPasteIdentifiers(struct sqlConnection *conn)
/* Respond to paste identifiers button. */
{
struct sqlConnection *alternateConn = conn;
char *actualDb = database;
if (sameWord(curTable, WIKI_TRACK_TABLE))
{
alternateConn = wikiConnect();
@@ -165,31 +171,31 @@
}
char *oldPasted = forCurTable() ?
cartUsualString(cart, hgtaPastedIdentifiers, "") : "";
struct hTableInfo *hti = maybeGetHti(actualDb, curTable, conn);
char *idField = getIdField(actualDb, curTrack, curTable, hti);
htmlOpen("Paste In Identifiers for %s", curTableLabel());
if (idField == NULL)
errAbort("Sorry, I can't tell which field of table %s to treat as the "
"identifier field.", curTable);
hPrintf("