ae4d6b0988cc34e674209890007aa8b46381603e hiram Thu May 16 14:31:45 2019 -0700 now returning itemsReturned count for any getData track function refs #18869 diff --git src/hg/hubApi/getData.c src/hg/hubApi/getData.c index 90d3c72..74eefe1 100644 --- src/hg/hubApi/getData.c +++ src/hg/hubApi/getData.c @@ -109,31 +109,31 @@ jsonWriteListEnd(jw); } else { jsonWriteObjectStart(jw, NULL); for (i = 0; i < columnCount; ++i) jsonDatumOut(jw, columnNames[i], row[i], jsonTypes[i]); jsonWriteObjectEnd(jw); } ++itemCount; } sqlFreeResult(&sr); if ((itemCount + itemsDone) >= maxItemsOutput) reachedMaxItems = TRUE; return itemCount; -} +} /* static unsigned sqlQueryJsonOutput(...) */ 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 */ { /* 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"); @@ -227,50 +227,48 @@ } else if (0 == (start + end)) /* have chrom, no start,end == full chr */ { if (! sqlColumnExists(conn, splitSqlTable, chromName)) apiErrAbort(err400, err400Msg, "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 (startsWith("wig", tdb->type)) { if (jsonOutputArrays || debug) wigColumnTypes(jw); jsonWriteListStart(jw, chrom); - wigTableDataOutput(jw, db, splitSqlTable, chrom, 0, ci->size, 0); + itemsReturned += wigTableDataOutput(jw, db, splitSqlTable, chrom, 0, ci->size, 0); jsonWriteListEnd(jw); return; /* DONE */ } else { sqlDyStringPrintf(query, "select * from %s where %s='%s'", splitSqlTable, chromName, chrom); } } else /* fully specified chrom:start-end */ { jsonWriteString(jw, "chrom", chrom); -// jsonWriteNumber(jw, "start", (long long)start); already printed out -// jsonWriteNumber(jw, "end", (long long)end); already printed out if (startsWith("wig", tdb->type)) { if (jsonOutputArrays || debug) wigColumnTypes(jw); jsonWriteListStart(jw, chrom); - wigTableDataOutput(jw, db, splitSqlTable, chrom, start, end, 0); + itemsReturned += 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, could be wiggle output with no chrom specified */ @@ -339,37 +337,39 @@ sqlDyStringPrintf(query, "select * from %s", fullTableName); } else sqlDyStringPrintf(query, "select * from %s", splitSqlTable); if (startsWith("wig", tdb->type)) itemsDone += wigTableDataOutput(jw, db, splitSqlTable, chrom, start, end, itemsDone); else itemsDone += sqlQueryJsonOutput(conn, jw, query->string, columnCount, columnNames, jsonTypes, itemsDone); jsonWriteListEnd(jw); /* chrom data output list end */ } if (itemsDone >= maxItemsOutput) reachedMaxItems = TRUE; jsonWriteObjectEnd(jw); /* end track data output */ + itemsReturned += itemsDone; } else { /* a single chrom has been requested, run it */ jsonWriteListStart(jw, track); /* data output list starting */ itemsDone += sqlQueryJsonOutput(conn, jw, query->string, columnCount, columnNames, jsonTypes, itemsDone); jsonWriteListEnd(jw); /* data output list end */ + itemsReturned += itemsDone; } freeDyString(&query); } /* static void tableDataOutput(char *db, struct trackDb *tdb, ... ) */ static unsigned bbiDataOutput(struct jsonWrite *jw, struct bbiFile *bbi, char *chrom, unsigned start, unsigned end, struct sqlFieldType *fiList, struct trackDb *tdb, unsigned itemsDone) /* output bed data for one chrom in the given bbi file */ { char *itemRgb = trackDbSetting(tdb, "itemRgb"); if (bbi->definedFieldCount > 8) itemRgb = "on"; int *jsonTypes = NULL; int columnCount = slCount(fiList); AllocArray(jsonTypes, columnCount); @@ -446,51 +446,53 @@ } 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); if (itemCount >= maxItemsOutput) reachedMaxItems = TRUE; return itemCount; -} +} /* static unsigned wigDataOutput(...) */ 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; +unsigned itemsDone = 0; if (isEmpty(chrom)) { chromList = bbiChromList(bwf); struct bbiChromInfo *bci; - unsigned itemsDone = 0; for (bci = chromList; bci && (itemsDone < maxItemsOutput); bci = bci->next) { itemsDone += wigDataOutput(jw, bwf, bci->name, 0, bci->size); } if (itemsDone >= maxItemsOutput) reachedMaxItems = TRUE; } else - (void) wigDataOutput(jw, bwf, chrom, start, end); + itemsDone += wigDataOutput(jw, bwf, chrom, start, end); + +itemsReturned += itemsDone; } 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); @@ -530,36 +532,34 @@ apiErrAbort(err400, err400Msg, "failed to find a track hub definition in genome=%s for endpoint '/getData/track' given hubUrl='%s'", genome, hubUrl); struct trackDb *thisTrack = findTrackDb(track, tdb); if (NULL == thisTrack) apiErrAbort(err400, err400Msg, "failed to find specified track=%s in genome=%s for endpoint '/getData/track' given hubUrl='%s'", track, genome, hubUrl); char *bigDataUrl = trackDbSetting(thisTrack, "bigDataUrl"); struct bbiFile *bbi = bigFileOpen(thisTrack->type, bigDataUrl); if (NULL == bbi) apiErrAbort(err400, err400Msg, "track type %s management not implemented yet TBD track=%s in genome=%s for endpoint '/getData/track' given hubUrl='%s'", thisTrack->type, track, genome, hubUrl); struct jsonWrite *jw = apiStartOutput(); jsonWriteString(jw, "hubUrl", hubUrl); jsonWriteString(jw, "genome", genome); -// jsonWriteString(jw, "track", track); unsigned chromSize = 0; struct bbiChromInfo *chromList = NULL; if (isNotEmpty(chrom)) { -// jsonWriteString(jw, "chrom", chrom); chromSize = bbiChromSize(bbi, chrom); if (0 == chromSize) apiErrAbort(err400, err400Msg, "can not find specified chrom=%s in bigBed file URL %s", chrom, bigDataUrl); jsonWriteNumber(jw, "chromSize", (long long)chromSize); } else { chromList = bbiChromList(bbi); jsonWriteNumber(jw, "chromCount", (long long)slCount(chromList)); } unsigned uStart = 0; unsigned uEnd = chromSize; if ( ! (isEmpty(start) || isEmpty(end)) ) { @@ -583,30 +583,31 @@ unsigned itemsDone = 0; if (isEmpty(chrom)) { struct bbiChromInfo *bci; for (bci = chromList; bci && (itemsDone < maxItemsOutput); bci = bci->next) { itemsDone += bbiDataOutput(jw, bbi, bci->name, 0, bci->size, fiList, thisTrack, itemsDone); } if (itemsDone >= maxItemsOutput) reachedMaxItems = TRUE; } else itemsDone += bbiDataOutput(jw, bbi, chrom, uStart, uEnd, fiList, thisTrack, itemsDone); + itemsReturned += itemsDone; jsonWriteListEnd(jw); } else if (startsWith("bigWig", thisTrack->type)) { if (jsonOutputArrays || debug) wigColumnTypes(jw); jsonWriteObjectStart(jw, track); wigData(jw, bbi, chrom, uStart, uEnd); jsonWriteObjectEnd(jw); } bbiFileClose(&bbi); apiFinishOutput(0, NULL, jw); } /* static void getHubTrackData(char *hubUrl) */ static void getTrackData() @@ -773,30 +774,31 @@ unsigned itemsDone = 0; if (isEmpty(chrom)) { struct bbiChromInfo *bci; for (bci = chromList; bci && (itemsDone < maxItemsOutput); bci = bci->next) { itemsDone += bbiDataOutput(jw, bbi, bci->name, 0, bci->size, fiList, thisTrack, itemsDone); } if (itemsDone >= maxItemsOutput) reachedMaxItems = TRUE; } else itemsDone += bbiDataOutput(jw, bbi, chrom, uStart, uEnd, fiList, thisTrack, itemsDone); + itemsReturned += itemsDone; jsonWriteListEnd(jw); } else if (startsWith("bigWig", thisTrack->type)) { if (jsonOutputArrays || debug) wigColumnTypes(jw); jsonWriteObjectStart(jw, track); wigData(jw, bbi, chrom, uStart, uEnd); jsonWriteObjectEnd(jw); bbiFileClose(&bbi); } else tableDataOutput(db, thisTrack, conn, jw, track, chrom, uStart, uEnd);