ff9f972ed500ac73b7d172766aa00b600438ad42 hiram Fri Apr 5 23:50:14 2019 -0700 fixup itemRgb column type for bigBed 9+ types refs #18869 diff --git src/hg/hubApi/getData.c src/hg/hubApi/getData.c index 6deddbb..933027c 100644 --- src/hg/hubApi/getData.c +++ src/hg/hubApi/getData.c @@ -33,31 +33,31 @@ static void jsonDatumOut(struct jsonWrite *jw, char *name, char *val, int jsonType) /* output a json item, determine type, appropriate output */ { 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 *table, char *chrom, unsigned start, unsigned end) -/* output the table data from the specified query string */ +/* output the SQL table data */ { char query[4096]; /* no chrom specified, return entire table */ if (isEmpty(chrom)) sqlSafef(query, sizeof(query), "select * from %s", table); else if (0 == (start + end)) /* have chrom, no start,end == full chr */ { /* need to extend the chrom column check to allow tName also */ if (! sqlColumnExists(conn, table, "chrom")) apiErrAbort("track '%s' is not a position track, request track without chrom specification, genome: '%s'", table, db); jsonWriteString(jw, "chrom", chrom); struct chromInfo *ci = hGetChromInfo(db, chrom); jsonWriteNumber(jw, "start", (long long)0); jsonWriteNumber(jw, "end", (long long)ci->size); sqlSafef(query, sizeof(query), "select * from %s where chrom='%s'", table, chrom); @@ -91,82 +91,90 @@ /* continuing, not a wiggle output */ char **columnNames = NULL; char **columnTypes = NULL; int *jsonTypes = NULL; int columnCount = tableColumns(conn, jw, table, &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); -// jsonWriteString(jw, columnNames[i], columnTypes[i]); } jsonWriteObjectEnd(jw); } jsonWriteListStart(jw, table); struct sqlResult *sr = sqlGetResult(conn, query); char **row = NULL; unsigned itemCount = 0; while (itemCount < maxItemsOutput && (row = sqlNextRow(sr)) != NULL) { jsonWriteObjectStart(jw, NULL); int i = 0; for (i = 0; i < columnCount; ++i) { jsonDatumOut(jw, columnNames[i], row[i], jsonTypes[i]); } jsonWriteObjectEnd(jw); ++itemCount; } sqlFreeResult(&sr); jsonWriteListEnd(jw); -} +} /* static void tableDataOutput(char *db, struct trackDb *tdb, ... ) */ static void bedDataOutput(struct jsonWrite *jw, struct bbiFile *bbi, - char *chrom, unsigned start, unsigned end, struct sqlFieldType *fiList) + char *chrom, unsigned start, unsigned end, struct sqlFieldType *fiList, + struct trackDb *tdb) /* output bed data for one chrom in the given bbi file */ { +char *itemRgb = trackDbSetting(tdb, "itemRgb"); int *jsonTypes = NULL; int columnCount = slCount(fiList); AllocArray(jsonTypes, columnCount); int i = 0; struct sqlFieldType *fi; for ( fi = fiList; fi; fi = fi->next) { + if (itemRgb) + { + if (8 == i && sameWord("on", itemRgb)) + jsonTypes[i++] = JSON_STRING; + else + jsonTypes[i++] = autoSqlToJsonType(fi->type); + } + else jsonTypes[i++] = autoSqlToJsonType(fi->type); } struct lm *bbLm = lmInit(0); struct bigBedInterval *iv, *ivList = NULL; ivList = bigBedIntervalQuery(bbi,chrom, start, end, 0, bbLm); char *row[bbi->fieldCount]; unsigned itemCount = 0; for (iv = ivList; itemCount < maxItemsOutput && iv; iv = iv->next) { char startBuf[16], endBuf[16]; bigBedIntervalToRow(iv, chrom, startBuf, endBuf, row, bbi->fieldCount); jsonWriteObjectStart(jw, NULL); int i; struct sqlFieldType *fi = fiList; for (i = 0; i < bbi->fieldCount; ++i) { jsonDatumOut(jw, fi->name, row[i], jsonTypes[i]); -// jsonWriteString(jw, fi->name, row[i]); fi = fi->next; } jsonWriteObjectEnd(jw); ++itemCount; } lmCleanup(&bbLm); } static void wigDataOutput(struct jsonWrite *jw, struct bbiFile *bwf, char *chrom, unsigned start, unsigned end) /* output wig data for one chrom in the given bwf file */ { struct lm *lm = lmInit(0); struct bbiInterval *iv, *ivList = bigWigIntervalQuery(bwf, chrom, start, end, lm); if (NULL == ivList) @@ -299,35 +307,35 @@ jsonWriteString(jw, "trackType", thisTrack->type); if (startsWith("bigBed", thisTrack->type)) { struct asObject *as = bigBedAsOrDefault(bbi); struct sqlFieldType *fiList = sqlFieldTypesFromAs(as); if (debug) bigColumnTypes(jw, fiList); jsonWriteListStart(jw, track); if (isEmpty(chrom)) { struct bbiChromInfo *bci; for (bci = chromList; bci; bci = bci->next) { - bedDataOutput(jw, bbi, bci->name, 0, bci->size, fiList); + bedDataOutput(jw, bbi, bci->name, 0, bci->size, fiList, thisTrack); } } else - bedDataOutput(jw, bbi, chrom, uStart, uEnd, fiList); + bedDataOutput(jw, bbi, chrom, uStart, uEnd, fiList, thisTrack); jsonWriteListEnd(jw); } else if (startsWith("bigWig", thisTrack->type)) { jsonWriteObjectStart(jw, track); wigData(jw, bbi, chrom, uStart, uEnd); jsonWriteObjectEnd(jw); } bbiFileClose(&bbi); jsonWriteObjectEnd(jw); fputs(jw->dy->string,stdout); } /* static void getHubTrackData(char *hubUrl) */ static void getTrackData() /* return data from a track, optionally just one chrom data, @@ -441,35 +449,35 @@ jsonWriteNumber(jw, "end", uEnd); } if (startsWith("bigBed", thisTrack->type)) { struct asObject *as = bigBedAsOrDefault(bbi); struct sqlFieldType *fiList = sqlFieldTypesFromAs(as); if (debug) bigColumnTypes(jw, fiList); jsonWriteListStart(jw, track); if (isEmpty(chrom)) { struct bbiChromInfo *bci; for (bci = chromList; bci; bci = bci->next) { - bedDataOutput(jw, bbi, bci->name, 0, bci->size, fiList); + bedDataOutput(jw, bbi, bci->name, 0, bci->size, fiList, thisTrack); } } else - bedDataOutput(jw, bbi, chrom, uStart, uEnd, fiList); + bedDataOutput(jw, bbi, chrom, uStart, uEnd, fiList, thisTrack); jsonWriteListEnd(jw); } else if (startsWith("bigWig", thisTrack->type)) { jsonWriteObjectStart(jw, track); wigData(jw, bbi, chrom, uStart, uEnd); jsonWriteObjectEnd(jw); bbiFileClose(&bbi); } else tableDataOutput(db, thisTrack, conn, jw, track, chrom, uStart, uEnd); jsonWriteObjectEnd(jw); /* closing the overall global object */ fputs(jw->dy->string,stdout); hFreeConn(&conn);