0222476b54fcfb70acb694f9819c9fbcbbeea7f8 hiram Tue Apr 9 08:31:05 2019 -0700 adding supported type rmsk refs #18869 diff --git src/hg/hubApi/getData.c src/hg/hubApi/getData.c index 363e1c0..ed2aee8 100644 --- src/hg/hubApi/getData.c +++ src/hg/hubApi/getData.c @@ -36,98 +36,111 @@ { if (JSON_DOUBLE == jsonType) jsonWriteDouble(jw, name, sqlDouble(val)); else if (JSON_NUMBER == jsonType) jsonWriteNumber(jw, name, sqlLongLong(val)); else jsonWriteString(jw, name, val); } static void tableDataOutput(char *db, struct trackDb *tdb, struct sqlConnection *conn, struct jsonWrite *jw, char *track, char *chrom, unsigned start, unsigned end) /* output the SQL table data for given track */ { char query[4096]; + +/* for MySQL select statements, name for 'chrom' 'start' 'end' to use + * for a table which has different names than that + */ +char chromName[256]; +char startName[256]; +char endName[256]; + +/* defaults, normal stuff */ +safef(chromName, sizeof(chromName), "chrom"); +safef(startName, sizeof(startName), "chromStart"); +safef(endName, sizeof(endName), "chromEnd"); + /* might have a specific table defined instead of the track name */ char *sqlTable = cloneString(track); char *tableName = trackDbSetting(tdb, "table"); if (isNotEmpty(tableName)) { freeMem(sqlTable); sqlTable = cloneString(tableName); jsonWriteString(jw, "sqlTable", sqlTable); } +/* determine name for 'chrom' in table select */ +if (! sqlColumnExists(conn, sqlTable, "chrom")) + { + if (sqlColumnExists(conn, sqlTable, "tName")) // track type psl + { + safef(chromName, sizeof(chromName), "tName"); + safef(startName, sizeof(startName), "tStart"); + safef(endName, sizeof(endName), "tEnd"); + } + else if (sqlColumnExists(conn, sqlTable, "genoName"))// track type rmsk + { + safef(chromName, sizeof(chromName), "genoName"); + safef(startName, sizeof(startName), "genoStart"); + safef(endName, sizeof(endName), "genoEnd"); + } + } + +if (sqlColumnExists(conn, sqlTable, "txStart")) // track type genePred + { + safef(startName, sizeof(startName), "txStart"); + safef(endName, sizeof(endName), "txEnd"); + } + /* no chrom specified, return entire table */ if (isEmpty(chrom)) sqlSafef(query, sizeof(query), "select * from %s", sqlTable); else if (0 == (start + end)) /* have chrom, no start,end == full chr */ { - boolean useTname = FALSE; +// boolean useTname = FALSE; /* need to extend the chrom column check to allow tName also */ - if (! sqlColumnExists(conn, sqlTable, "chrom")) - { - if (sqlColumnExists(conn, sqlTable, "tName")) // track type psl - useTname = TRUE; - else + if (! sqlColumnExists(conn, sqlTable, chromName)) apiErrAbort("track '%s' is not a position track, request track without chrom specification, genome: '%s'", track, db); - } + jsonWriteString(jw, "chrom", chrom); struct chromInfo *ci = hGetChromInfo(db, chrom); jsonWriteNumber(jw, "start", (long long)0); jsonWriteNumber(jw, "end", (long long)ci->size); - if (useTname) - sqlSafef(query, sizeof(query), "select * from %s where tName='%s'", sqlTable, chrom); - else - sqlSafef(query, sizeof(query), "select * from %s where chrom='%s'", sqlTable, chrom); + sqlSafef(query, sizeof(query), "select * from %s where %s='%s'", sqlTable, chromName, chrom); } else /* fully specified chrom:start-end */ { - boolean useTxStartEnd = FALSE; - boolean useTnameStartEnd = FALSE; - if (! sqlColumnExists(conn, sqlTable, "chrom")) - { - if (sqlColumnExists(conn, sqlTable, "tName")) // track type psl - useTnameStartEnd = TRUE; - else - apiErrAbort("track '%s' is not a position track, request track without chrom specification, genome: '%s'", track, db); - } - if (useTnameStartEnd || ! sqlColumnExists(conn, sqlTable, "chromStart")) - { - if (sqlColumnExists(conn, sqlTable, "txStart")) // track type genePred - useTxStartEnd = TRUE; - } jsonWriteString(jw, "chrom", chrom); jsonWriteNumber(jw, "start", (long long)start); jsonWriteNumber(jw, "end", (long long)end); if (startsWith("wig", tdb->type)) { wigTableDataOutput(jw, db, sqlTable, chrom, start, end); return; /* DONE */ } else { - if (useTnameStartEnd) - sqlSafef(query, sizeof(query), "select * from %s where tName='%s' AND tEnd > %u AND tEnd < %u", sqlTable, chrom, start, end); - else if (useTxStartEnd) - sqlSafef(query, sizeof(query), "select * from %s where chrom='%s' AND txEnd > %u AND txStart < %u", sqlTable, chrom, start, end); - else - sqlSafef(query, sizeof(query), "select * from %s where chrom='%s' AND chromEnd > %u AND chromStart < %u", sqlTable, chrom, start, end); + sqlSafef(query, sizeof(query), "select * from %s where %s='%s' AND %s > %u AND %s < %u", sqlTable, chromName, chrom, endName, start, startName, end); } } +if (debug) + jsonWriteString(jw, "select", query); + /* continuing, not a wiggle output */ char **columnNames = NULL; char **columnTypes = NULL; int *jsonTypes = NULL; int columnCount = tableColumns(conn, jw, sqlTable, &columnNames, &columnTypes, &jsonTypes); if (debug) { jsonWriteObjectStart(jw, "columnTypes"); int i = 0; for (i = 0; i < columnCount; ++i) { char bothTypes[1024]; safef(bothTypes, sizeof(bothTypes), "%s - %s", columnTypes[i], jsonTypeStrings[jsonTypes[i]]); jsonWriteString(jw, columnNames[i], bothTypes); }