b7749ec648f88880da646bca0bba1a14f288639c hiram Wed Mar 20 18:13:15 2019 -0700 adding hubPublic.c and .h to library refs #18869 diff --git src/hg/hubApi/hubApi.c src/hg/hubApi/hubApi.c index c74b1f7..6897631 100644 --- src/hg/hubApi/hubApi.c +++ src/hg/hubApi/hubApi.c @@ -4,53 +4,52 @@ /* +------------------+------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------+------------------+------+-----+---------+-------+ | hubUrl | longblob | NO | PRI | NULL | | | shortLabel | varchar(255) | NO | | NULL | | | longLabel | varchar(255) | NO | | NULL | | | registrationTime | varchar(255) | NO | | NULL | | | dbCount | int(10) unsigned | NO | | NULL | | | dbList | blob | YES | | NULL | | | descriptionUrl | longblob | YES | | NULL | | +------------------+------------------+------+-----+---------+-------+ */ /* Global Variables */ -static boolean debug = FALSE; +static boolean debug = FALSE; /* can be set in URL debug=1 */ 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 */ // struct hubPublic *publicHubList = NULL; 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; static boolean timedOut = FALSE; static char *urlPrefix = ""; /* initalized to support self references */ static struct slName *supportedTypes = NULL; /* will be initialized to a known supported set */ static void initSupportedTypes() -/* initalize the list of supported track types, - */ +/* initalize the list of supported track types */ { struct slName *el = newSlName("bed"); slAddHead(&supportedTypes, el); el = newSlName("wig"); slAddHead(&supportedTypes, el); el = newSlName("broadPeak"); slAddHead(&supportedTypes, el); el = newSlName("narrowPeak"); slAddHead(&supportedTypes, el); el = newSlName("bigBed"); slAddHead(&supportedTypes, el); el = newSlName("bigWig"); slAddHead(&supportedTypes, el); el = newSlName("bigNarrowPeak"); slAddHead(&supportedTypes, el); @@ -61,76 +60,59 @@ el = newSlName("bigBarChart"); slAddHead(&supportedTypes, el); el = newSlName("bigInteract"); slAddHead(&supportedTypes, el); el = newSlName("bigMaf"); slAddHead(&supportedTypes, el); el = newSlName("bigChain"); slAddHead(&supportedTypes, el); slNameSort(&supportedTypes); } static boolean isSupportedType(char *type) /* is given type in the supportedTypes list ? */ { boolean ret = FALSE; -if (startsWith("wigMaf", type)) +if (startsWith("wigMaf", type)) /* not wigMaf at this time */ return ret; struct slName *el; for (el = supportedTypes; el; el = el->next) { if (startsWith(el->name, type)) { ret = TRUE; break; } } return ret; } static int publicHubCmpCase(const void *va, const void *vb) /* Compare two shortLabels, ignore case. */ { const struct hubPublic *a = *((struct hubPublic **)va); const struct hubPublic *b = *((struct hubPublic **)vb); return strcasecmp(a->shortLabel, b->shortLabel); } static void publicHubSortCase(struct hubPublic **pList) /* Sort slName list, ignore case. */ { slSort(pList, publicHubCmpCase); } -static struct hubPublic *hubPublicLoad(char **row) -/* Load a hubPublic from row fetched with select * from hubPublic - * from database. Dispose of this with hubPublicFree(). */ -{ -struct hubPublic *ret; - -AllocVar(ret); -ret->hubUrl = cloneString(row[0]); -ret->shortLabel = cloneString(row[1]); -ret->longLabel = cloneString(row[2]); -ret->registrationTime = cloneString(row[3]); -ret->dbCount = sqlUnsigned(row[4]); -ret->dbList = cloneString(row[5]); -ret->descriptionUrl = cloneString(row[6]); -return ret; -} - -struct hubPublic *hubPublicLoadAll() +struct hubPublic *hubPublicDbLoadAll() /* read entire hubPublic table in hgcentral and return resulting list */ { char query[1024]; struct hubPublic *list = NULL; struct sqlConnection *conn = hConnectCentral(); sqlSafef(query, sizeof(query), "select * from %s", hubPublicTableName()); struct sqlResult *sr = sqlGetResult(conn, query); char **row; while ((row = sqlNextRow(sr)) != NULL) { struct hubPublic *el = hubPublicLoad(row); slAddHead(&list, el); } sqlFreeResult(&sr); hDisconnectCentral(&conn); @@ -209,41 +191,41 @@ } else if (isEmpty(tdb->type)) hashIncInt(countTracks, "no type specified"); else { hashIncInt(countTracks, stripType); hashIncInt(countTracks, "track count"); } freeMem(stripType); // showCounts(countTracks); } static void sampleUrl(char *db, struct trackDb *tdb, char *chrom, long long chromSize) /* print out a sample getData URL */ { -long long start = chromSize / 4; -long long end = start + 10000; +unsigned start = chromSize / 4; +unsigned end = start + 10000; if (end > chromSize) end = chromSize; if (db) { if (tdb->parent) - hPrintf("
  • %s : %s subtrack of parent: %s (sample getData)
  • \n", tdb->track, tdb->type, tdb->parent->track, urlPrefix, db, chrom, tdb->track, start, end ); + hPrintf("
  • %s : %s subtrack of parent: %s (sample getData)
  • \n", tdb->track, tdb->type, tdb->parent->track, urlPrefix, db, chrom, tdb->track, start, end ); else - hPrintf("
  • %s : %s (sample getData)
  • \n", tdb->track, tdb->type, urlPrefix, db, chrom, tdb->track, start, end ); + hPrintf("
  • %s : %s (sample getData)
  • \n", tdb->track, tdb->type, urlPrefix, db, chrom, tdb->track, start, end ); } } static void showSubTracks(char *db, struct trackDb *tdb, struct hash *countTracks, char *chromName, long long chromSize) /* tdb has subtracks, show only subTracks, no details */ { hPrintf("
  • \n"); } -static int bbiBriefMeasure(char *type, char *bigDataUrl, char *bigDataIndex, long *chromCount, long *itemCount, struct dyString *errors) -/* check a bigDataUrl to find chrom count and item count */ +static void bbiBiggestChrom(struct bbiChromInfo *chromList, char **chromName, + unsigned *chromSize) +/* find largest chromosome name and size in the chromList */ +{ +if (chromName && chromSize) + { + *chromSize = 0; + char *returnName = NULL; + struct bbiChromInfo *el; + for (el = chromList; el; el = el->next) + { + if (el->size > *chromSize) + { + *chromSize = el->size; + returnName = el->name; + } + } + if (chromSize > 0) + *chromName = cloneString(returnName); + } +} + +static int bbiBriefMeasure(char *type, char *bigDataUrl, char *bigDataIndex, long *chromCount, long *itemCount, struct dyString *errors, char **chromName, unsigned *chromSize) +/* check a bigDataUrl to find chrom count and item count, return + * name of largest chrom and its size + */ { int retVal = 0; *chromCount = 0; *itemCount = 0; struct errCatch *errCatch = errCatchNew(); if (errCatchStart(errCatch)) { if (startsWithWord("bigNarrowPeak", type) || startsWithWord("bigBed", type) || startsWithWord("bigGenePred", type) || startsWithWord("bigPsl", type) || startsWithWord("bigChain", type) || startsWithWord("bigMaf", type) || startsWithWord("bigBarChart", type) || startsWithWord("bigInteract", type)) { struct bbiFile *bbi = NULL; bbi = bigBedFileOpen(bigDataUrl); struct bbiChromInfo *chromList = bbiChromList(bbi); *chromCount = slCount(chromList); *itemCount = bigBedItemCount(bbi); + bbiBiggestChrom(chromList, chromName, chromSize); + bbiChromInfoFreeList(&chromList); bbiFileClose(&bbi); } else if (startsWithWord("bigWig", type)) { struct bbiFile *bwf = bigWigFileOpen(bigDataUrl); struct bbiChromInfo *chromList = bbiChromList(bwf); struct bbiSummaryElement sum = bbiTotalSummary(bwf); *chromCount = slCount(chromList); *itemCount = sum.validCount; + bbiBiggestChrom(chromList, chromName, chromSize); + bbiChromInfoFreeList(&chromList); bbiFileClose(&bwf); } else if (startsWithWord("vcfTabix", type)) { struct vcfFile *vcf = vcfTabixFileAndIndexMayOpen(bigDataUrl, bigDataIndex, NULL, 0, 0, 1, 1); if (vcf == NULL) { dyStringPrintf(errors, "Could not open %s and/or its tabix index (.tbi) file. See http://genome.ucsc.edu/goldenPath/help/vcf.html", bigDataUrl); retVal = 1; } else vcfFileFree(&vcf); } else if (startsWithWord("bam", type)) { @@ -382,61 +392,86 @@ retVal = 1; } } errCatchEnd(errCatch); if (errCatch->gotError) { retVal = 1; dyStringPrintf(errors, "%s", errCatch->message->string); } errCatchFree(&errCatch); return retVal; } /* static int bbiBriefMeasure() */ -static void countOneTdb(char *db, struct trackDb *tdb, char *bigDataIndex, - struct hash *countTracks, char *chromName, long long chromSize) +static void hubSampleUrl(struct trackHub *hub, struct trackDb *tdb, + long chromCount, long itemCount, char *chromName, unsigned chromSize, + char *genome) +{ +unsigned start = chromSize / 4; +unsigned end = start + 10000; +if (end > chromSize) + end = chromSize; + +if (isSupportedType(tdb->type)) + { + if (startsWithWord("bigBed", tdb->type)) + hPrintf("
  • %s : %s : %ld chroms : %ld item count (sample getData)
  • \n", tdb->track, tdb->type, chromCount, itemCount, urlPrefix, hub->url, genome, tdb->track, chromName, start, end); + else if (startsWithWord("bigWig", tdb->type)) + hPrintf("
  • %s : %s : %ld chroms : %ld bases covered (sample getData)
  • \n", tdb->track, tdb->type, chromCount, itemCount, urlPrefix, hub->url, genome, tdb->track, chromName, start, end); + else + hPrintf("
  • %s : %s : %ld chroms : %ld count <(sample getData)
  • \n", tdb->track, tdb->type, chromCount, itemCount, urlPrefix, hub->url, genome, tdb->track, chromName, start, end); + } +else + { + if (startsWithWord("bigBed", tdb->type)) + hPrintf("
  • %s : %s : %ld chroms : %ld item count
  • \n", tdb->track, tdb->type, chromCount, itemCount); + else if (startsWithWord("bigWig", tdb->type)) + hPrintf("
  • %s : %s : %ld chroms : %ld bases covered
  • \n", tdb->track, tdb->type, chromCount, itemCount); + else + hPrintf("
  • %s : %s : %ld chroms : %ld count
  • \n", tdb->track, tdb->type, chromCount, itemCount); + } +} + +static void countOneTdb(struct trackHub *hub, char *db, struct trackDb *tdb, + char *bigDataIndex, struct hash *countTracks, char *chromName, + unsigned chromSize, char *genome) { char *bigDataUrl = trackDbSetting(tdb, "bigDataUrl"); // char *compositeTrack = trackDbSetting(tdb, "compositeTrack"); boolean compositeContainer = tdbIsComposite(tdb); boolean compositeView = tdbIsCompositeView(tdb); // char *superTrack = trackDbSetting(tdb, "superTrack"); boolean superChild = tdbIsSuperTrackChild(tdb); boolean depthSearch = cartUsualBoolean(cart, "depthSearch", FALSE); hashCountTrack(tdb, countTracks); if (depthSearch && bigDataUrl) { + char *longName = NULL; + unsigned longSize = 0; long chromCount = 0; long itemCount = 0; struct dyString *errors = newDyString(1024); - int retVal = bbiBriefMeasure(tdb->type, bigDataUrl, bigDataIndex, &chromCount, &itemCount, errors); + int retVal = bbiBriefMeasure(tdb->type, bigDataUrl, bigDataIndex, &chromCount, &itemCount, errors, &longName, &longSize); if (retVal) { hPrintf("
  • %s : %s : ERROR: %s
  • \n", tdb->track, tdb->type, errors->string); } else - { - if (startsWithWord("bigBed", tdb->type)) - hPrintf("
  • %s : %s : %ld chroms : %ld item count
  • \n", tdb->track, tdb->type, chromCount, itemCount); - else if (startsWithWord("bigWig", tdb->type)) - hPrintf("
  • %s : %s : %ld chroms : %ld bases covered
  • \n", tdb->track, tdb->type, chromCount, itemCount); - else - hPrintf("
  • %s : %s : %ld chroms : %ld count
  • \n", tdb->track, tdb->type, chromCount, itemCount); - } + hubSampleUrl(hub, tdb, chromCount, itemCount, longName, longSize, genome); } else { if (compositeContainer) hPrintf("
  • %s : %s : composite track container has %d subtracks
  • \n", tdb->track, tdb->type, slCount(tdb->subtracks)); else if (compositeView) hPrintf("
  • %s : %s : composite view of parent: %s
  • \n", tdb->track, tdb->type, tdb->parent->track); else if (superChild) hPrintf("
  • %s : %s : superTrack child of parent: %s
  • \n", tdb->track, tdb->type, tdb->parent->track); else if (! depthSearch && bigDataUrl) hPrintf("
  • %s : %s : %s
  • \n", tdb->track, tdb->type, bigDataUrl); else { if (isSupportedType(tdb->type)) sampleUrl(db, tdb, chromName, chromSize); @@ -448,45 +483,48 @@ { hPrintf("
  • \n"); } else if (tdb->subtracks) { showSubTracks(db, tdb, countTracks, chromName, chromSize); } return; } /* static void countOneTdb(char *db, struct trackDb *tdb, * char *bigDataIndex, struct hash *countTracks, * char *chromName, long long chromSize) */ -static void hubTrackList(struct trackDb *topTrackDb, struct trackHubGenome *genome) +static void hubTrackList(struct trackHub *hub, struct trackDb *topTrackDb, struct trackHubGenome *genome) /* process the track list in a hub to show all tracks */ { hPrintf("
  • \n"); } /* static struct trackDb *hubTrackList() */ -static struct trackDb *assemblySettings(struct trackHubGenome *genome) +static struct trackDb *assemblySettings(struct trackHub *hub, struct trackHubGenome *genome) /* display all the assembly 'settingsHash' */ { struct trackDb *tdb = obtainTdb(genome, NULL); hPrintf("
  • \n"); return tdb; } struct slName *genomeList(struct trackHub *hubTop, struct trackDb **dbTrackList, char *selectGenome) /* follow the pointers from the trackHub to trackHubGenome and around * in a circle from one to the other to find all hub resources * return slName list of the genomes in this track hub * optionally, return the trackList from this hub for the specified genome */ { @@ -550,31 +588,31 @@ { if ( differentStringNullOk(selectGenome, genome->name) ) continue; } ++totalAssemblyCount; struct slName *el = slNameNew(genome->name); slAddHead(&retList, el); if (genome->organism) { hPrintf("
  • %s - %s - %s
  • \n", genome->organism, genome->name, genome->description); } else { /* can there be a description when organism is empty ? */ hPrintf("
  • %s
  • \n", genome->name); } - struct trackDb *tdb = assemblySettings(genome); + struct trackDb *tdb = assemblySettings(hubTop, genome); if (dbTrackList) *dbTrackList = tdb; if (measureTiming) { long thisTime = clock1000(); hPrintf("
  • processing time %s: %ld millis
  • \n", genome->name, thisTime - lastTime); } if (timeOutReached()) break; } if (trackCounter->elCount) { hPrintf("
  • total genome assembly count: %ld
  • \n", totalAssemblyCount); hPrintf("
  • %ld total tracks counted, %d different track types:
  • \n", totalTracks, trackCounter->elCount); hPrintf("
    1. \n"); @@ -654,66 +692,66 @@ * parse that and return a function pointer and the parsed words * Returns NULL if not recognized */ { char *tmp = cloneString(pathInfo); /* skip the first leading slash to simplify chopByChar parsing */ tmp += 1; int wordCount = chopByChar(tmp, '/', words, MAX_PATH_INFO); if (wordCount < 1) return NULL; struct hashEl *hel = hashLookup(apiFunctionHash, words[0]); return hel; } -static long long largestChrom(char *db, char **nameReturn) +static unsigned largestChrom(char *db, char **nameReturn) /* return the length and get the chrom name for the largest chrom * from chromInfo table. For use is sample getData URLs */ { char query[1024]; struct sqlConnection *conn = hAllocConn(db); // Build a query to select the hubUrl for the given shortLabel sqlSafef(query, sizeof(query), "select chrom,size from chromInfo order by size desc limit 1"); struct sqlResult *sr = sqlGetResult(conn, query); char **row = sqlNextRow(sr); -long long length = 0; +unsigned length = 0; if (row) { *nameReturn = cloneString(row[0]); length = sqlLongLong(row[1]); } sqlFreeResult(&sr); hFreeConn(&conn); return length; } static void tracksForUcscDb(char *db) /* scan the specified database for all tracks */ { struct hash *countTracks = hashNew(0); char *chromName = NULL; -long long chromSize = largestChrom(db, &chromName); -hPrintf("

      Tracks in UCSC genome: '%s', longest chrom: %s:%lld

      \n", db, chromName, chromSize); +unsigned chromSize = largestChrom(db, &chromName); +hPrintf("

      Tracks in UCSC genome: '%s', longest chrom: %s:%u

      \n", db, chromName, chromSize); struct trackDb *tdbList = obtainTdb(NULL, db); struct trackDb *tdb; hPrintf("