0544059f3df004f2d54e8978809ddfcbdee23645 braney Mon Feb 25 14:36:53 2013 -0800 modify twoBit library to auto-recognize whether it's dealing with a URL or local file (per code review #10237) diff --git src/hg/lib/trackHub.c src/hg/lib/trackHub.c index 9201664..d106160 100644 --- src/hg/lib/trackHub.c +++ src/hg/lib/trackHub.c @@ -28,36 +28,30 @@ #include "errCatch.h" #include "hgBam.h" #include "bigWig.h" #include "bigBed.h" #include "hdb.h" #include "chromInfo.h" #include "grp.h" #include "twoBit.h" #include "dbDb.h" static struct hash *hubCladeHash; // mapping of clade name to hub pointer static struct hash *hubAssemblyHash; // mapping of assembly name to genome struct static struct hash *hubOrgHash; // mapping from organism name to hub pointer struct trackHub *globalAssemblyHubList; // list of trackHubs in the user's cart -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); /* If it's a remote hub, let html path expander handle it. */ if (hasProtocol(hubUrl)) return htmlExpandUrl(hubUrl, path); /* If we got to here hub is local, and so is path. Do standard * path parsing. */ @@ -187,60 +181,60 @@ } } } return dbList; } int trackHubChromCount(char *database) /* Return number of chromosomes in a assembly data hub. */ { struct hashEl *hel = hashLookup(hubAssemblyHash, database); if (hel == NULL) return 0; struct trackHubGenome *genome = hel->val; -struct slName *chromList = twoBitSeqNamesExt(genome->twoBitPath, TRUE); +struct slName *chromList = twoBitSeqNames(genome->twoBitPath); int num = slCount(chromList); slFreeList(&chromList); return num; } struct slName *trackHubAllChromNames(char *database) /* Return a list of all the chrom names in this assembly hub database. */ /* Free with slFreeList. */ { struct hashEl *hel = hashLookup(hubAssemblyHash, database); if (hel == NULL) return 0; struct trackHubGenome *genome = hel->val; -struct slName *chromList = twoBitSeqNamesExt(genome->twoBitPath, TRUE); +struct slName *chromList = twoBitSeqNames(genome->twoBitPath); return chromList; } char *trackHubDefaultChrom(char *database) /* Return the default chromosome for this track hub assembly. */ { struct hashEl *hel = hashLookup(hubAssemblyHash, database); if (hel == NULL) return NULL; struct trackHubGenome *genome = hel->val; -struct slName *chromList = twoBitSeqNamesExt(genome->twoBitPath, TRUE); +struct slName *chromList = twoBitSeqNames(genome->twoBitPath); char *defaultName = cloneString( chromList->name); slFreeList(&chromList); return defaultName; } struct chromInfo *trackHubChromInfo(char *database, char *chrom) /* Return a chromInfo structure for just this chrom in this database. */ { if (hubAssemblyHash == NULL) return NULL; struct hashEl *hel = hashLookup(hubAssemblyHash, database); @@ -256,31 +250,31 @@ ci->size = twoBitSeqSize(genome->tbf, chrom); return ci; } struct chromInfo *trackHubAllChromInfo(char *db) /* Return a chromInfo structure for all the chroms in this database. */ { struct hashEl *hel = hashLookup(hubAssemblyHash, db); if (hel == NULL) return NULL; struct trackHubGenome *genome = hel->val; struct chromInfo *ci, *ciList = NULL; -struct slName *chromList = twoBitSeqNamesExt(genome->twoBitPath, TRUE); +struct slName *chromList = twoBitSeqNames(genome->twoBitPath); for(; chromList; chromList = chromList->next) { AllocVar(ci); ci->chrom = cloneString(chromList->name); ci->fileName = genome->twoBitPath; ci->size = twoBitSeqSize(genome->tbf, chromList->name); slAddHead(&ciList, ci); } slFreeList(&chromList); return ciList; } static char *getRequiredGrpSetting(struct hash *hash, char *name, struct lineFile *lf) /* Grab a group setting out of the group hash. errAbort if not found. */ @@ -432,31 +426,31 @@ AllocVar(el); el->name = cloneString(genome); el->trackDbFile = trackHubRelativeUrl(url, trackDb); el->trackHub = hub; hashAdd(hash, el->name, el); slAddHead(&list, el); char *groups = hashFindVal(ra, "groups"); if (twoBitPath != NULL) { //printf("reading genome %s twoBitPath %s\n", genome, el->twoBitPath); el->description = hashFindVal(ra, "description"); el->organism = addHubName(hashFindVal(ra, "organism"), hub->name); hashReplace(ra, "organism", el->organism); el->defaultPos = hashFindVal(ra, "defaultPos"); el->twoBitPath = trackHubRelativeUrl(url, twoBitPath); - el->tbf = twoBitOpenExt(el->twoBitPath, TRUE); + el->tbf = twoBitOpen(el->twoBitPath); hashReplace(ra, "htmlPath",trackHubRelativeUrl(url, hashFindVal(ra, "htmlPath"))); if (groups != NULL) el->groups = trackHubRelativeUrl(url, groups); addAssembly(genome, el, hub); } el->settingsHash = ra; hashAdd(ra, "hubName", hub->shortLabel); } /* Clean up and go home. */ lineFileClose(&lf); slReverse(&list); return list; }