679b48855a32f8ea1e1ea8ca3c095a0c2c7f6c7a max Tue Sep 8 10:08:41 2026 -0700 detailsScript: add a scatterPlot plot type, and use it for pcLAI Clicking a pcLAI window now shows where that window sits in the ancestry space it was placed in: a scatterplot of the 1000 Genomes reference haplotypes with the window's own PCA coordinate and its segment's coordinate marked on it. The numbers were already on the details page and told a reader almost nothing. New plot type scatterPlot (hg/js/hgc.scatterPlot.js), driven the same way as histogram. Background points come from a JSON or TSV file named by dataUrl and may carry a category, which colors them and builds a legend, and a label, which is shown on mouseover. The cloud is drawn on a canvas, since these files hold thousands of points and that many elements make the page crawl; axes and the highlighted points stay SVG on top. Point lookup for the mouseover goes through a cell index so a large file stays smooth. Two additions serve every plot type, not just this one: - exportFields, a config key listing further bigBed fields whose values are passed to the module as a fieldValues object. Without it a plot needing two coordinates would need them packed into one field, and pcLAI keeps them in pca and pcaSegment. Only fields that exist in the bigBed are exported, at most 32, and the JSON types are checked rather than asserted because jsonListVal and jsonStringVal errAbort and this JSON is written by a hub. - a config key ending in Url is treated as a file, by the convention trackSettingIsFile() already uses, and a relative one is resolved against the track's own bigDataUrl. The module does not fetch it directly; it asks hgTrackUi for it, the route facetedComposite uses for its metadata. That checks the canonicalized path against the hubs on the cart and reads it with udc, so a hub-relative path works even for a hub loaded from a local path (the GenArk /gbdb hubs), no CORS header is needed, and a file outside a connected hub cannot be read. Verified that /etc/passwd, file://, a dot-dot escape, an unattached hub and an unrelated host are all refused with 400. When the session has file caching off, hgc now exports udcTimeout the way hgTrackUi does and the module POSTs, so the browser cannot answer from cache. Fixes a crash reachable from any hub: "detailsScript.. null" segfaulted hgc, because jsonObjectVal returns NULL for a JSON null and the hash routines dereference it. This hit the shipped histogram type too. trackDbSettingsGen.py stopped reading a setting's description at the first "Example:" paragraph and never read
    at all, so it dropped everything after the first example and every list item. That silently truncated 226 of the 264 descriptions, including spectrum's minGrayLevel/scoreMin/scoreMax bullets, and would have dropped this whole scatterPlot section. It now skips the Example label instead of stopping, and folds list items in. No setting loses a word and none gains or loses an example. pcLAI wiring: the background file is the authors' published reference panel (github.com/AI-sandbox/hprc-pclai reference_pca_metadata.tsv), converted by hprc2annotMakePclaiRefPanel.py -- 3122 haplotypes, 21 populations, 94 KB, one file for the collection since it is the reference space rather than per-assembly data. The four values pcaSegment takes across all 460 assemblies turn out to be the four continental cluster centres, so the highlighted segment dot always lands on one of them. genark: addContrib now rewrites a "...Url" inside a detailsScript value the same way it rewrites bigDataUrl, and symlinks the collection's shared root-level data files next to the docs, so contrib// resolves in the deeper GenArk layout. It writes the alpha tier only, leaving the assembly's default hub alone, and clears any unmarked copy of the collection's stanzas that the assembly build baked in, which would otherwise leave the hub declaring each track twice. refs #35415 diff --git src/hg/hgc/bigBedClick.c src/hg/hgc/bigBedClick.c index 3a5bd821609..fdac6c12423 100644 --- src/hg/hgc/bigBedClick.c +++ src/hg/hgc/bigBedClick.c @@ -8,30 +8,32 @@ #include "cart.h" #include "hgc.h" #include "hubConnect.h" #include "hCommon.h" #include "hgColors.h" #include "bigBed.h" #include "hui.h" #include "subText.h" #include "web.h" #include "chromAlias.h" #include "quickLift.h" #include "hgConfig.h" #include "jsHelper.h" #include "jsonParse.h" #include "jsonWrite.h" +#include "net.h" +#include "trackHub.h" static void bigGenePredLinks(char *track, char *item) /* output links to genePred driven sequence dumps */ { printf("

    Links to sequence:

    \n"); printf("
      \n"); puts("
    • \n"); hgcAnchorSomewhere("htcTranslatedPredMRna", item, "translate", seqName); printf("Translated Protein from genomic DNA\n"); puts("
    • \n"); puts("
    • \n"); hgcAnchorSomewhere("htcGeneMrna", item, track, seqName); printf("Predicted mRNA \n"); puts("
    • \n"); @@ -599,61 +601,132 @@ motifHitSection(seq, motif); } // detailsScript.*: load JS visualization scripts and export field data as JSON // see also hgc.c detailsScriptFieldNames() which parses the same settings to skip fields struct hash *plotTypeHash = detailsScriptGroupByPlotType(tdb); if (plotTypeHash) { // Build the bedDetails JSON object using jsonWrite struct jsonWrite *jw = jsonWriteNew(); jsonWriteObjectStart(jw, NULL); jsonWriteString(jw, "track", tdb->track); jsonWriteString(jw, "chrom", chrom); jsonWriteNumber(jw, "start", bed->chromStart); jsonWriteNumber(jw, "end", bed->chromEnd); + // Caching turned off for this session (the hgHubConnect file-caching button). + // A module that fetches a file has to say so, because a GET the browser has + // already cached would defeat it; the same flag hgTrackUi hands its own JS. + if (isNotEmpty(cartOptionalString(cart, "udcTimeout"))) + jsonWriteBoolean(jw, "udcTimeout", TRUE); jsonWriteObjectStart(jw, "scripts"); struct hashEl *hel, *helList = hashElListHash(plotTypeHash); for (hel = helList; hel != NULL; hel = hel->next) { struct slPair *fieldList = hel->val; jsonWriteListStart(jw, hel->name); struct slPair *fp; for (fp = fieldList; fp != NULL; fp = fp->next) { jsonWriteObjectStart(jw, NULL); jsonWriteString(jw, "field", fp->name); // Look up field value from bigBed extra fields char *fv = ""; if (extraFieldPairs) { char *found = slPairFindVal(extraFieldPairs, fp->name); if (found) fv = found; } jsonWriteString(jw, "value", fv); // Parse trackDb JSON config and merge its keys into this object char *jsonConfig = fp->val; if (isNotEmpty(jsonConfig)) { struct jsonElement *configEl = jsonParse(jsonConfig); + // jsonObjectVal hands back NULL for a JSON null, and the hash + // routines below dereference their argument, so a hub writing + // "detailsScript.. null" would crash us. struct hash *configHash = jsonObjectVal(configEl, "detailsScript config"); + if (configHash == NULL) + { + jsonWriteObjectEnd(jw); + continue; + } struct hashEl *cel, *celList = hashElListHash(configHash); for (cel = celList; cel != NULL; cel = cel->next) - jsonWriteJsonElement(jw, cel->name, cel->val); + { + // A config key ending in "Url" names a file, by the same convention + // trackSettingIsFile() uses. The JS does not fetch it directly: it + // asks hgTrackUi for it, which checks the path against the hubs on + // this cart and reads it with udc. So resolve a relative path here + // against the track's own bigDataUrl, which works whether the hub + // was loaded over http or from a local path. A path the author + // already made absolute is left alone. + struct jsonElement *cval = cel->val; + if (endsWith(cel->name, "Url") && cval != NULL + && cval->type == jsonString && isNotEmpty(cval->val.jeString) + && !hasProtocol(cval->val.jeString) + && cval->val.jeString[0] != '/') + { + char *base = trackDbSetting(tdb, "bigDataUrl"); + if (isNotEmpty(base)) + { + char *abs = trackHubRelativeUrl(base, cval->val.jeString); + if (abs != NULL) + { + jsonWriteString(jw, cel->name, abs); + freeMem(abs); + continue; + } + } + } + jsonWriteJsonElement(jw, cel->name, cval); + } hashElFreeList(&celList); + + // exportFields names other bigBed fields whose values are exported too, + // so one setting can drive a plot that needs several fields. Only fields + // that exist in this bigBed are exported, so a hub cannot name anything + // else, and the type is checked rather than asserted because jsonListVal + // and jsonStringVal errAbort on a mismatch and this JSON is hub-authored. + struct jsonElement *efEl = hashFindVal(configHash, + DETAILS_SCRIPT_EXPORT_FIELDS); + if (efEl != NULL && efEl->type == jsonList) + { + jsonWriteObjectStart(jw, "fieldValues"); + struct slRef *ref; + int efCount = 0; + for (ref = efEl->val.jeList; + ref != NULL && efCount < DETAILS_SCRIPT_MAX_EXPORT; + ref = ref->next) + { + struct jsonElement *nameEl = ref->val; + if (nameEl == NULL || nameEl->type != jsonString) + continue; + char *efName = nameEl->val.jeString; + if (isEmpty(efName) || extraFieldPairs == NULL) + continue; + char *efVal = slPairFindVal(extraFieldPairs, efName); + if (efVal == NULL) + continue; + jsonWriteString(jw, efName, efVal); + efCount++; + } + jsonWriteObjectEnd(jw); + } } jsonWriteObjectEnd(jw); } jsonWriteListEnd(jw); } jsonWriteObjectEnd(jw); // scripts jsonWriteObjectEnd(jw); // root // Emit as inline JavaScript struct dyString *ds = dyStringNew(1024); dyStringPrintf(ds, "var bedDetails = %s;\n", jw->dy->string); // Dynamically import and call each plot type's module for (hel = helList; hel != NULL; hel = hel->next)