060c9d0ae2bf7b3333d76c15ee3b114c3278f519 braney Sat Oct 8 14:29:09 2011 -0700 check trackDb.txt files and hub.txt files more closely in hgHubConnect so errors can be discovered ASAP. #4679 and others. diff --git src/hg/lib/trackHub.c src/hg/lib/trackHub.c index f367847..aeeb345 100644 --- src/hg/lib/trackHub.c +++ src/hg/lib/trackHub.c @@ -17,30 +17,31 @@ #include "common.h" #include "linefile.h" #include "hash.h" #include "options.h" #include "udc.h" #include "ra.h" #include "filePath.h" #include "htmlPage.h" #include "trackDb.h" #include "trackHub.h" #include "errCatch.h" #include "hgBam.h" #include "bigWig.h" #include "bigBed.h" +#include "hdb.h" static boolean hasProtocol(char *urlOrPath) /* Return TRUE if it looks like it has http://, ftp:// etc. */ { return stringIn("://", urlOrPath) != NULL; } char *trackHubRelativeUrl(char *hubUrl, char *path) /* Return full path (in URL form if it's a remote hub) given * path possibly relative to hubUrl. Do a freeMem of result * when done. */ { /* If path itself is a URL then just return a copy of it. */ if (hasProtocol(path)) return cloneString(path); @@ -118,30 +119,32 @@ struct lineFile *lf = udcWrapShortLineFile(url, NULL, 256*1024); struct hash *hubRa = raNextRecord(lf); if (hubRa == NULL) errAbort("empty %s in trackHubOpen", url); if (raNextRecord(lf) != NULL) errAbort("multiple records in %s", url); /* Allocate hub and fill in settings field and url. */ struct trackHub *hub; AllocVar(hub); hub->url = cloneString(url); hub->name = cloneString(hubName); hub->settings = hubRa; /* Fill in required fields from settings. */ +trackHubRequiredSetting(hub, "hub"); +trackHubRequiredSetting(hub, "email"); hub->shortLabel = trackHubRequiredSetting(hub, "shortLabel"); hub->longLabel = trackHubRequiredSetting(hub, "longLabel"); hub->genomesFile = trackHubRequiredSetting(hub, "genomesFile"); lineFileClose(&lf); char *genomesUrl = trackHubRelativeUrl(hub->url, hub->genomesFile); hub->genomeHash = hashNew(8); hub->genomeList = trackHubGenomeReadRa(genomesUrl, hub->genomeHash); freez(&genomesUrl); return hub; } void trackHubClose(struct trackHub **pHub) @@ -493,15 +496,41 @@ if (hub == NULL) return 1; verbose(2, "hub %s\nshortLabel %s\nlongLabel %s\n", hubUrl, hub->shortLabel, hub->longLabel); verbose(2, "%s has %d elements\n", hub->genomesFile, slCount(hub->genomeList)); struct trackHubGenome *genome; for (genome = hub->genomeList; genome != NULL; genome = genome->next) { retVal |= hubCheckGenome(hub, genome, errors); } trackHubClose(&hub); return retVal; } + +struct trackDb *trackHubAddTracks(int id, char *hubUrl, char *database, + struct trackHub **pHubList) +/* Load up stuff from data hub and append to list. The hubUrl points to + * a trackDb.ra format file. */ +{ +/* Load trackDb.ra file and make it into proper trackDb tree */ +char hubName[64]; +struct trackDb *tdbList = NULL; +safef(hubName, sizeof(hubName), "hub_%d",id); +struct trackHub *hub = trackHubOpen(hubUrl, hubName); +if (hub != NULL) + { + struct trackHubGenome *hubGenome = trackHubFindGenome(hub, database); + if (hubGenome != NULL) + { + tdbList = trackHubTracksForGenome(hub, hubGenome); + tdbList = trackDbLinkUpGenerations(tdbList); + tdbList = trackDbPolishAfterLinkup(tdbList, database); + trackDbPrioritizeContainerItems(tdbList); + if (tdbList != NULL) + slAddHead(pHubList, hub); + } + } +return tdbList; +}