b6ea7e02e7c946b1cb700d3cab07decce272d4c7 hiram Tue Feb 26 16:00:40 2019 -0800 better counting of legitimate tracks refs #18869 diff --git src/hg/hubApi/hubApi.c src/hg/hubApi/hubApi.c index dd0eddd..45a44b1 100644 --- src/hg/hubApi/hubApi.c +++ src/hg/hubApi/hubApi.c @@ -1,774 +1,789 @@ /* hubApi - access mechanism to hub data resources. */ #include "dataApi.h" /* +------------------+------------------+------+-----+---------+-------+ | 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 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 int publicHubCmpCase(const void *va, const void *vb) /* Compare two slNames, 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]); -// if (row[6]) ret->descriptionUrl = cloneString(row[6]); -// else -// ret->descriptionUrl = cloneString(""); return ret; } struct hubPublic *hubPublicLoadAll() +/* 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); publicHubSortCase(&list); int listSize = slCount(list); AllocArray(shortLabels, listSize); struct hubPublic *el = list; int i = 0; for ( ; el != NULL; el = el->next ) { shortLabels[i++] = el->shortLabel; ++publicHubCount; } return list; } static boolean timeOutReached() +/* see if the timeout has been reached to determine if an exit + * is appropriate at this time + */ { long nowTime = clock1000(); timedOut = FALSE; if ((nowTime - enteredMainTime) > (1000 * timeOutSeconds)) timedOut= TRUE; return timedOut; } -static void trackSettings(struct trackDb *tdb) -/* process the settingsHash for a trackDb, recursive if subtracks */ +#ifdef NOT +static void showCounts(struct hash *countTracks) +{ +if (countTracks->elCount) + { + hPrintf(" \n"); + } +} +#endif + +static void hashCountTrack(struct trackDb *tdb, struct hash *countTracks) +/* this is counting up track types into the hash countTracks */ +{ +char *stripType = cloneString(tdb->type); +if (startsWith("chain ", tdb->type)) + stripType = cloneString("chain"); +else if (startsWith("netAlign ", tdb->type)) + stripType = cloneString("netAlign"); +else if (startsWith("genePred ", tdb->type)) + stripType = cloneString("genePred"); +else if (startsWith("bigWig ", tdb->type)) + stripType = cloneString("bigWig"); +else if (startsWith("wigMaf ", tdb->type)) + stripType = cloneString("wigMaf"); +else if (startsWith("wig ", tdb->type)) + stripType = cloneString("wig"); +else + stripType = cloneString(tdb->type); +// char *compositeTrack = trackDbLocalSetting(tdb, "compositeTrack"); +boolean compositeContainer = tdbIsComposite(tdb); +boolean compositeView = tdbIsCompositeView(tdb); +// char *superTrack = trackDbLocalSetting(tdb, "superTrack"); +boolean superChild = tdbIsSuperTrackChild(tdb); +if (compositeContainer) + hashIncInt(countTracks, "composite container"); +else if (compositeView) + hashIncInt(countTracks, "composite view"); +else if (superChild) + { + hashIncInt(countTracks, "superTrack child"); + hashIncInt(countTracks, stripType); + hashIncInt(countTracks, "track count"); + } +else if (isEmpty(tdb->type)) + hashIncInt(countTracks, "no type specified"); +else + { + hashIncInt(countTracks, stripType); + hashIncInt(countTracks, "track count"); + } +freeMem(stripType); +// showCounts(countTracks); +} + +static void trackSettings(struct trackDb *tdb, struct hash *countTracks) +/* process the settingsHash for a trackDb, recursive when subtracks */ { 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 */ { 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); 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; 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)) { bamFileAndIndexMustExist(bigDataUrl, bigDataIndex); } else if (startsWithWord("longTabix", type)) { struct bedTabixFile *btf = bedTabixFileMayOpen(bigDataUrl, NULL, 0, 0); if (btf == NULL) { dyStringPrintf(errors, "Couldn't open %s and/or its tabix index (.tbi) file.", bigDataUrl); retVal = 1; } else bedTabixFileClose(&btf); } #ifdef USE_HAL else if (startsWithWord("halSnake", type)) { char *errString; int handle = halOpenLOD(bigDataUrl, &errString); if (handle < 0) { dyStringPrintf(errors, "HAL open error: %s", errString); retVal = 1; } if (halClose(handle, &errString) < 0) { dyStringPrintf(errors, "HAL close error: %s", errString); retVal = 1; } } #endif else { dyStringPrintf(errors, "unrecognized type %s", type); retVal = 1; } } errCatchEnd(errCatch); if (errCatch->gotError) { retVal = 1; dyStringPrintf(errors, "%s", errCatch->message->string); } errCatchFree(&errCatch); return retVal; } /* static int bbiBriefMeasure() */ -static void hubTrackList(struct trackDb *topTrackDb, struct trackHubGenome *genome) -/* process the track list to show all tracks, return trackDb list */ -{ -if (topTrackDb) - { - struct hash *countTracks = hashNew(0); - hPrintf("