15c2acbbf16454d91d9079216f21427fdd33a609 hiram Tue Apr 16 13:45:20 2019 -0700 beginning to allow the array output time to function refs #18869 diff --git src/hg/hubApi/hubApi.c src/hg/hubApi/hubApi.c index 5b3ef86..f6db268 100644 --- src/hg/hubApi/hubApi.c +++ src/hg/hubApi/hubApi.c @@ -18,30 +18,32 @@ */ /* Global Variables for all modules */ int maxItemsOutput = 1000; /* can be set in URL maxItemsOutput=N */ static int maxItemLimit = 1000000; /* maximum of 1,000,000 items returned */ /* for debugging purpose, current bot delay value */ int botDelay = 0; boolean debug = FALSE; /* can be set in URL debug=1, to turn off: debug=0 */ #define delayFraction 0.03 /* default is to list all trackDb entries, composite containers too. * This option will limit to only the actual track entries with data */ boolean trackLeavesOnly = FALSE; /* set by CGI parameter 'trackLeavesOnly' */ +/* this selects output type 'arrays', where the default type is: objects */ +boolean jsonOutputArrays = FALSE; /* set by CGI parameter 'jsonOutputArrays' */ /* Global only to this one source file */ static struct cart *cart; /* CGI and other variables */ static struct hash *oldVars = NULL; static struct hash *trackCounter = NULL; static long totalTracks = 0; static boolean measureTiming = FALSE; /* set by CGI parameters */ static boolean allTrackSettings = FALSE; /* checkbox setting */ static char **shortLabels = NULL; /* public hub short labels in array */ static int publicHubCount = 0; static char *defaultHub = "Plants"; static char *defaultDb = "ce11"; static long enteredMainTime = 0; /* will become = clock1000() on entry */ /* to allow calculation of when to bail out, taking too long */ static long timeOutSeconds = 100; @@ -212,102 +214,117 @@ if (isNotEmpty(errorString)) { safef(errorPrint, sizeof(errorPrint), " ERROR: %s", errorString); } boolean superChild = tdbIsSuperTrackChild(tdb); unsigned start = chromSize / 4; unsigned end = start + 10000; if (end > chromSize) end = chromSize; char *genome = NULL; if (hub) genome = hub->genomeList->name; +struct dyString *extraDyFlags = newDyString(128); +if (debug) + dyStringAppend(extraDyFlags, ";debug=1"); +if (jsonOutputArrays) + dyStringAppend(extraDyFlags, ";jsonOutputArrays=1"); +char *extraFlags = dyStringCannibalize(&extraDyFlags); + if (db) { if (hub) { char urlReference[2048]; - safef(urlReference, sizeof(urlReference), " (sample data)%s\n", urlPrefix, hub->url, genome, tdb->track, chrom, start, end, errorPrint); + safef(urlReference, sizeof(urlReference), " (sample data)%s\n", urlPrefix, hub->url, genome, tdb->track, chrom, start, end, extraFlags, errorPrint); if (tdb->parent) hPrintf("
  • %s: %s subtrack of parent: %s%s
  • \n", tdb->track, tdb->type, tdb->parent->track, urlReference); else hPrintf("
  • %s: %s%s
  • \n", tdb->track, tdb->type, urlReference); } else { char urlReference[2048]; - safef(urlReference, sizeof(urlReference), " (sample data)%s\n", urlPrefix, db, chrom, tdb->track, start, end, errorPrint); + safef(urlReference, sizeof(urlReference), " (sample data)%s\n", urlPrefix, db, chrom, tdb->track, start, end, extraFlags, errorPrint); if (superChild) hPrintf("
  • %s: %s superTrack child of parent: %s%s
  • \n", tdb->track, tdb->type, tdb->parent->track, urlReference); else if (tdb->parent) hPrintf("
  • %s: %s subtrack of parent: %s%s
  • \n", tdb->track, tdb->type, tdb->parent->track, urlReference); else hPrintf("
  • %s: %s%s
  • \n", tdb->track, tdb->type, urlReference ); } } else if (hub) { char urlReference[2048]; - safef(urlReference, sizeof(urlReference), " (sample data)%s\n", urlPrefix, hub->url, genome, tdb->track, chrom, start, end, errorPrint); + safef(urlReference, sizeof(urlReference), " (sample data)%s\n", urlPrefix, hub->url, genome, tdb->track, chrom, start, end, extraFlags, errorPrint); if (tdb->parent) hPrintf("
  • %s: %s subtrack of parent: %s%s
  • \n", tdb->track, tdb->type, tdb->parent->track, urlReference); else hPrintf("
  • %s: %s%s
  • \n", tdb->track, tdb->type, urlReference); } else hPrintf("
  • %s : %s not db hub track ?
  • \n", tdb->track, tdb->type); } static void hubSampleUrl(struct trackHub *hub, struct trackDb *tdb, long chromCount, long itemCount, char *chromName, unsigned chromSize, char *genome, char *errorString) { unsigned start = chromSize / 4; unsigned end = start + 10000; if (end > chromSize) end = chromSize; + +struct dyString *extraDyFlags = newDyString(128); +if (debug) + dyStringAppend(extraDyFlags, ";debug=1"); +if (jsonOutputArrays) + dyStringAppend(extraDyFlags, ";jsonOutputArrays=1"); +char *extraFlags = dyStringCannibalize(&extraDyFlags); + char errorPrint[2048]; errorPrint[0] = 0; if (isNotEmpty(errorString)) { safef(errorPrint, sizeof(errorPrint), " : ERROR: %s", errorString); } char countsMessage[512]; countsMessage[0] = 0; if (chromCount > 0 || itemCount > 0) { if (allowedBigBedType(tdb->type)) safef(countsMessage, sizeof(countsMessage), " : %ld chroms : %ld item count ", chromCount, itemCount); else if (startsWithWord("bigWig", tdb->type)) safef(countsMessage, sizeof(countsMessage), " : %ld chroms : %ld bases covered ", chromCount, itemCount); else safef(countsMessage, sizeof(countsMessage), " : %ld chroms : %ld count ", chromCount, itemCount); } if (isSupportedType(tdb->type)) { char urlReference[2048]; - safef(urlReference, sizeof(urlReference), "(sample data)%s\n", urlPrefix, hub->url, genome, tdb->track, chromName, start, end, errorPrint); + safef(urlReference, sizeof(urlReference), "(sample data)%s\n", urlPrefix, hub->url, genome, tdb->track, chromName, start, end, extraFlags, errorPrint); if (allowedBigBedType(tdb->type)) hPrintf("
  • %s: %s%s%s
  • \n", tdb->track, tdb->type, countsMessage, urlReference); else if (startsWithWord("bigWig", tdb->type)) hPrintf("
  • %s: %s%s%s
  • \n", tdb->track, tdb->type, countsMessage, urlReference); else hPrintf("
  • %s: %s%s%s
  • \n", tdb->track, tdb->type, countsMessage, urlReference); } else { if (allowedBigBedType(tdb->type)) hPrintf("
  • %s: %s%s
  • \n", tdb->track, tdb->type, countsMessage); else if (startsWithWord("bigWig", tdb->type)) hPrintf("
  • %s: %s%s
  • \n", tdb->track, tdb->type, countsMessage); else @@ -1094,31 +1111,31 @@ char *hogHost = getenv("REMOTE_ADDR"); char *pathInfo = getenv("PATH_INFO"); /* nothing on incoming path, then display the WEB page instead */ if (sameOk("/",pathInfo)) pathInfo = NULL; if (isNotEmpty(pathInfo)) { sendJsonHogMessage(hogHost); } else { sendHogMessage(hogHost); } } /* static void hogExit() */ -/* name of button group */ +/* name of radio button group */ #define RADIO_GROUP "selectRadio" /* button functions */ #define RADIO_PUBHUB "pubHub" #define RADIO_OTHERHUB "otherHub" #define RADIO_UCSCDB "ucscDb" static void selectionForm() /* setup the selection pull-downs for source */ { char *hubDropDown = cartUsualString(cart, "publicHubs", defaultHub); char *urlDropDown = urlFromShortLabel(hubDropDown); char *otherHubUrl = cartUsualString(cart, "urlHub", ""); char *ucscDb = cartUsualString(cart, "ucscGenome", defaultDb); if (isEmpty(otherHubUrl)) @@ -1183,37 +1200,42 @@ hWrites(""); maxDbNameWidth *= 9; // 9 should be font width here char widthPx[SMALLBUF]; safef(widthPx, sizeof(widthPx), "width: %dpx", maxDbNameWidth); cgiMakeDropListClassWithIdStyleAndJavascript("ucscGenome", "ucscGenome", ucscDbList, ucscDataBaseCount, ucscDb, NULL, widthPx, events); jsOnEventById("change", "ucscGenome", "document.getElementById('"RADIO_GROUP"_"RADIO_UCSCDB"').checked=true;"); hWrites("\n"); allTrackSettings = cartUsualBoolean(cart, "allTrackSettings", FALSE); hWrites(" display control:"); hCheckBox("allTrackSettings", allTrackSettings); hWrites(" display all track settings for each track"); hWrites("\n"); - trackLeavesOnly = cartUsualBoolean(cart, "trackLeavesOnly", trackLeavesOnly); hWrites(" JSON list output:"); hCheckBox("trackLeavesOnly", trackLeavesOnly); hWrites(" show only data tracks, do not show composite container information"); hWrites("\n"); +jsonOutputArrays = cartUsualBoolean(cart, "jsonOutputArrays", jsonOutputArrays); +hWrites(" JSON output type:"); +hCheckBox("jsonOutputArrays", jsonOutputArrays); +hWrites(" more array data than objects (default: mostly object output)"); +hWrites("\n"); + /* go button at the bottom of the table */ hWrites(" "); hButton("sourceSelected", "go"); hWrites("press 'go' after selections made\n"); hPrintf("\n"); hPrintf("(example JSON list output: Public hubs, and UCSC database genomes)\n"); hPrintf("\n"); hPrintf("\n"); /* how does debug carry forward ? */ // if (debug) // cgiMakeHiddenVar("debug", "1"); @@ -1224,30 +1246,31 @@ { cart = theCart; measureTiming = hPrintStatus() && isNotEmpty(cartOptionalString(cart, "measureTiming")); measureTiming = TRUE; char *database = NULL; char *genome = NULL; cgiVarSet("ignoreCookie", "1"); getDbAndGenome(cart, &database, &genome, oldVars); initGenbankTableNames(database); initSupportedTypes(); initUrlPrefix(); trackLeavesOnly = cartUsualBoolean(cart, "trackLeavesOnly", trackLeavesOnly); +jsonOutputArrays = cartUsualBoolean(cart, "jsonOutputArrays", jsonOutputArrays); /* global variable for all workers to honor this limit */ maxItemsOutput = cartUsualInt(cart, "maxItemsOutput", maxItemsOutput); if (maxItemsOutput < 0) /* can use -1 to indicate as much as allowed */ maxItemsOutput = maxItemLimit; /* maxItemsOutput of 0 might be useful, to be seen, let it go through */ // if (maxItemsOutput < 1) /* safety check */ // maxItemsOutput = 1; if (maxItemsOutput > maxItemLimit) /* safety check */ maxItemsOutput = maxItemLimit; debug = cartUsualBoolean(cart, "debug", debug); int timeout = cartUsualInt(cart, "udcTimeout", 300);