3bbad1670f2e44ca41d06c657b8f8636abfce4fb hiram Wed Mar 27 14:47:11 2019 -0700 provide list chrom function for hubs refs #18869 diff --git src/hg/hubApi/apiUtils.c src/hg/hubApi/apiUtils.c index e304180..7b7936d 100644 --- src/hg/hubApi/apiUtils.c +++ src/hg/hubApi/apiUtils.c @@ -83,15 +83,68 @@ struct trackDb *obtainTdb(struct trackHubGenome *genome, char *db) /* return a full trackDb fiven the hub genome pointer, or ucsc database name */ { struct trackDb *tdb = NULL; if (db) tdb = hTrackDb(db); else { tdb = trackHubTracksForGenome(genome->trackHub, genome); tdb = trackDbLinkUpGenerations(tdb); tdb = trackDbPolishAfterLinkup(tdb, genome->name); slSort(&tdb, trackDbCmp); } return tdb; } + +struct trackDb *findTrackDb(char *track, struct trackDb *tdb) +/* search tdb structure for specific track, recursion on subtracks */ +{ +struct trackDb *trackFound = NULL; + +for (trackFound = tdb; trackFound; trackFound = trackFound->next) + { + if (trackFound->subtracks) + { + struct trackDb *subTrack = findTrackDb(track, trackFound->subtracks); + if (subTrack) + { + if (sameOk(subTrack->track, track)) + trackFound = subTrack; + } + } + if (sameOk(trackFound->track, track)) + break; + } +return trackFound; +} + +struct bbiFile *bigFileOpen(char *trackType, char *bigDataUrl) +/* open bigDataUrl for correct trackType and error catch if failure */ +{ +struct bbiFile *bbi = NULL; +struct errCatch *errCatch = errCatchNew(); +if (errCatchStart(errCatch)) + { +if (startsWith("bigBed", trackType)) + bbi = bigBedFileOpen(bigDataUrl); +else if (startsWith("bigWig", trackType)) + bbi = bigWigFileOpen(bigDataUrl); + } +errCatchEnd(errCatch); +if (errCatch->gotError) + { + apiErrAbort("error opening bigFile URL: '%s', '%s'", bigDataUrl, errCatch->message->string); + } +errCatchFree(&errCatch); +return bbi; +} + +int chromInfoCmp(const void *va, const void *vb) +/* Compare to sort based on size */ +{ +const struct chromInfo *a = *((struct chromInfo **)va); +const struct chromInfo *b = *((struct chromInfo **)vb); +int dif; +dif = (long) a->size - (long) b->size; +return dif; +}