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");
if (tdb->subtracks)
{
struct trackDb *tdbEl = NULL;
for (tdbEl = tdb->subtracks; tdbEl; tdbEl = tdbEl->next)
{
if (tdbIsCompositeView(tdbEl))
hPrintf("- %s : %s : composite view of parent: %s
\n", tdbEl->track, tdbEl->type, tdbEl->parent->track);
@@ -287,62 +269,90 @@
if (tdb->subtracks)
{
struct trackDb *tdbEl = NULL;
if (debug)
hPrintf(" - has %d subtrack(s)
\n", slCount(tdb->subtracks));
for (tdbEl = tdb->subtracks; tdbEl; tdbEl = tdbEl->next)
{
hPrintf("- subtrack: %s of parent: %s : type: '%s'
\n", tdbEl->track, tdbEl->parent->track, tdbEl->type);
hashCountTrack(tdbEl, countTracks);
trackSettings(tdbEl, countTracks);
}
}
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");
trackSettings(tdb, countTracks); /* show all settings */
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");
if (topTrackDb)
{
struct hash *countTracks = hashNew(0);
struct trackDb *tdb = NULL;
for ( tdb = topTrackDb; tdb; tdb = tdb->next )
{
char *bigDataIndex = NULL;
char *relIdxUrl = trackDbSetting(topTrackDb, "bigDataIndex");
if (relIdxUrl != NULL)
bigDataIndex = trackHubRelativeUrl(genome->trackDbFile, relIdxUrl);
- countOneTdb(NULL, tdb, bigDataIndex, countTracks, NULL, 0);
+ char *defaultGenome = NULL;
+ if (isNotEmpty(genome->name))
+ defaultGenome = genome->name;
+ countOneTdb(hub, NULL, tdb, bigDataIndex, countTracks, NULL, 0, defaultGenome);
if (timeOutReached())
break;
} /* for ( tdb = topTrackDb; tdb; tdb = tdb->next ) */
hPrintf(" - %d different track types
\n",countTracks->elCount - 1);
/* add this single genome count to the overall multi-genome counts */
if (countTracks->elCount)
{
hPrintf(" \n");
struct hashEl *hel, *helList = hashElListHash(countTracks);
slSort(&helList, hashElCmpIntValDesc);
for (hel = helList; hel; hel = hel->next)
{
if (sameOk("track count", hel->name))
continue;
int prevCount = ptToInt(hashFindVal(trackCounter, hel->name));
@@ -495,44 +533,44 @@
hashReplace(trackCounter, hel->name, intToPt(prevCount + ptToInt(hel->val)));
if (isSupportedType(hel->name))
hPrintf(" - %d - %s - supported
\n", ptToInt(hel->val), hel->name);
else
hPrintf(" - %d - %s
\n", ptToInt(hel->val), hel->name);
}
hPrintf("
\n");
}
}
else
hPrintf(" - no trackTopDb
\n");
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");
struct hashEl *hel;
struct hashCookie hc = hashFirst(genome->settingsHash);
while ((hel = hashNext(&hc)) != NULL)
{
hPrintf(" - %s : %s
\n", hel->name, (char *)hel->val);
if (sameWord("trackDb", hel->name)) /* examine the trackDb structure */
{
- hubTrackList(tdb, genome);
+ hubTrackList(hub, tdb, genome);
}
if (timeOutReached())
break;
}
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(" \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("\n");
-hPrintf("- %s:%lld
\n", chromName, chromSize);
+hPrintf("- %s:%u
\n", chromName, chromSize);
for (tdb = tdbList; tdb != NULL; tdb = tdb->next )
{
- countOneTdb(db, tdb, NULL, countTracks, chromName, chromSize);
+ countOneTdb(NULL, db, tdb, NULL, countTracks, chromName, chromSize, NULL);
if (timeOutReached())
break;
}
int trackCount = ptToInt(hashFindVal(countTracks, "track count"));
/* elCount - 1 since the 'track count' element isn't a track */
hPrintf(" - %d total tracks counted, %d different track types
\n", trackCount, countTracks->elCount - 1);
if (countTracks->elCount)
{
hPrintf(" \n");
struct hashEl *hel, *helList = hashElListHash(countTracks);
slSort(&helList, hashElCmpIntValDesc);
for (hel = helList; hel; hel = hel->next)
{
if (sameOk("track count", hel->name))
continue;
@@ -876,31 +914,31 @@
{
hPrintDisable();
puts("Content-Type:application/json");
puts("\n");
void (*apiFunction)(char **) = hel->val;
(*apiFunction)(words);
return;
}
else
commandError = TRUE;
}
puts("Content-Type:text/html");
puts("\n");
-(void) hubPublicLoadAll();
+(void) hubPublicDbLoadAll();
struct dbDb *dbList = ucscDbDb();
char **ucscDbList = NULL;
int listSize = slCount(dbList);
AllocArray(ucscDbList, listSize);
struct dbDb *el = dbList;
int ucscDataBaseCount = 0;
int maxDbNameWidth = 0;
for ( ; el != NULL; el = el->next )
{
ucscDbList[ucscDataBaseCount++] = el->name;
if (strlen(el->name) > maxDbNameWidth)
maxDbNameWidth = strlen(el->name);
}
maxDbNameWidth += 1;