527d5b5e1e77777e67a1f69d19e615e850258570 hiram Tue Apr 30 09:46:00 2019 -0700 fixup wiggle output itemCount refs #18869 diff --git src/hg/hubApi/getData.c src/hg/hubApi/getData.c index da59138..17aaad2 100644 --- src/hg/hubApi/getData.c +++ src/hg/hubApi/getData.c @@ -257,31 +257,31 @@ wigTableDataOutput(jw, db, splitSqlTable, chrom, start, end, 0); jsonWriteListEnd(jw); return; /* DONE */ } else { sqlDyStringPrintf(query, "select * from %s where ", splitSqlTable); hAddBinToQuery(start, end, query); sqlDyStringPrintf(query, "%s='%s' AND %s > %u AND %s < %u", chromName, chrom, endName, start, startName, end); } } if (debug) jsonWriteString(jw, "select", query->string); -/* continuing, not a wiggle output */ +/* continuing, could be wiggle output with no chrom specified */ char **columnNames = NULL; char **columnTypes = NULL; int *jsonTypes = NULL; struct asObject *as = asForTable(conn, splitSqlTable, tdb); struct asColumn *columnEl = as->columnList; int asColumnCount = slCount(columnEl); int columnCount = tableColumns(conn, jw, splitSqlTable, &columnNames, &columnTypes, &jsonTypes); if (jsonOutputArrays || debug) { if (startsWith("wig", tdb->type)) { wigColumnTypes(jw); } else { @@ -400,85 +400,85 @@ jsonWriteListEnd(jw); } else { jsonWriteObjectStart(jw, NULL); for (i = 0; i < bbi->fieldCount; ++i, fi = fi->next) jsonDatumOut(jw, fi->name, row[i], jsonTypes[i]); jsonWriteObjectEnd(jw); } ++itemCount; } lmCleanup(&bbLm); return itemCount; } /* static void bbiDataOutput(struct jsonWrite *jw, . . . ) */ -static void wigDataOutput(struct jsonWrite *jw, struct bbiFile *bwf, +static unsigned wigDataOutput(struct jsonWrite *jw, struct bbiFile *bwf, char *chrom, unsigned start, unsigned end) -/* output wig data for one chrom in the given bwf file */ +/* output wig data for one chrom in the given bwf file, return itemCount out */ { +unsigned itemCount = 0; struct lm *lm = lmInit(0); struct bbiInterval *iv, *ivList = bigWigIntervalQuery(bwf, chrom, start, end, lm); if (NULL == ivList) - return; - -unsigned itemCount = 0; + return itemCount; jsonWriteListStart(jw, chrom); for (iv = ivList; iv && itemCount < maxItemsOutput; iv = iv->next) { int s = max(iv->start, start); int e = min(iv->end, end); double val = iv->val; if (jsonOutputArrays) { jsonWriteListStart(jw, NULL); jsonWriteNumber(jw, NULL, (long long)s); jsonWriteNumber(jw, NULL, (long long)e); jsonWriteDouble(jw, NULL, val); jsonWriteListEnd(jw); } else { jsonWriteObjectStart(jw, NULL); jsonWriteNumber(jw, "start", (long long)s); jsonWriteNumber(jw, "end", (long long)e); jsonWriteDouble(jw, "value", val); jsonWriteObjectEnd(jw); } ++itemCount; } jsonWriteListEnd(jw); +return itemCount; } static void wigData(struct jsonWrite *jw, struct bbiFile *bwf, char *chrom, unsigned start, unsigned end) /* output the data for a bigWig bbi file */ { struct bbiChromInfo *chromList = NULL; -// struct bbiSummaryElement sum = bbiTotalSummary(bwf); if (isEmpty(chrom)) { chromList = bbiChromList(bwf); struct bbiChromInfo *bci; - for (bci = chromList; bci; bci = bci->next) + unsigned itemsDone = 0; + for (bci = chromList; bci && (itemsDone < maxItemsOutput); bci = bci->next) { - wigDataOutput(jw, bwf, bci->name, 0, bci->size); + itemsDone += wigDataOutput(jw, bwf, bci->name, 0, bci->size); } } else - wigDataOutput(jw, bwf, chrom, start, end); + (void) wigDataOutput(jw, bwf, chrom, start, end); } static void bigColumnTypes(struct jsonWrite *jw, struct sqlFieldType *fiList, struct asObject *as) /* show the column types from a big file autoSql definitions */ { struct asColumn *columnEl = as->columnList; jsonWriteListStart(jw, "columnTypes"); struct sqlFieldType *fi = fiList; for ( ; fi; fi = fi->next, columnEl = columnEl->next) { int jsonType = autoSqlToJsonType(fi->type); jsonWriteObjectStart(jw, NULL); jsonWriteString(jw, "name", fi->name); jsonWriteString(jw, "sqlType", fi->type);