0564395ec363631f2ff8d295da6f6b50f873fda4 braney Mon Jan 24 17:01:53 2022 -0800 more chromAlias work: some name changes and support for the new genark chromAlias format diff --git src/hg/lib/trackHub.c src/hg/lib/trackHub.c index b19ab51..279d04f 100644 --- src/hg/lib/trackHub.c +++ src/hg/lib/trackHub.c @@ -370,101 +370,30 @@ return ci; } struct chromInfo *trackHubChromInfo(char *database, char *chrom) /* Return a chromInfo structure for just this chrom in this database. * errAbort if chrom doesn't exist. */ { struct chromInfo *ci = trackHubMaybeChromInfo(database, chrom); if (ci == NULL) errAbort("%s is not in %s", chrom, database); return ci; } -static struct hash *readAliasFile(char *url) -/* given the URL (might be a file) read and process into chromAlias hash - * file structure: lines of white space separated words - * first word is the sequence name in the assembly, words following are - * alias names for that sequences name. Same format as use by IGV - * returned hash is key: sequence chrom name, hash value struct chromAlias * - */ -{ -struct hash *aliasHash = NULL; -struct dyString *ds = NULL; - -/* adding error trapping because various net.c functions can errAbort */ -struct errCatch *errCatch = errCatchNew(); -if (errCatchStart(errCatch)) - { - int sd = netUrlOpen(url); - if (sd >= 0) - { - char *newUrl = NULL; - int newSd = 0; - if (netSkipHttpHeaderLinesHandlingRedirect(sd, url, &newSd, &newUrl)) - { - if (newUrl) /* redirect can modify the url */ - { - freeMem(newUrl); - sd = newSd; - } - ds = netSlurpFile(sd); - close(sd); - } - } - } -errCatchEnd(errCatch); -if (errCatch->gotError) - warn("%s", errCatch->message->string); -errCatchFree(&errCatch); -/* if the read worked, process it */ -if (ds) - { - char *words[1024]; /* process lines, no more than 1,024 words on a line */ - char *line; - int size; - aliasHash = hashNew(0); - struct lineFile *lf = lineFileOnString("chromAlias", TRUE, - dyStringCannibalize(&ds)); - while (lineFileNext(lf, &line, &size)) - { - int wordCount = chopByWhite(line, words, ArraySize(words)); - if (wordCount > 1) - { - int i = 1; - for ( ; i < wordCount; ++i ) - { - if (isNotEmpty(words[i])) - { - struct chromAlias *ali; - AllocVar(ali); - ali->alias = cloneString(words[i]); - ali->chrom = cloneString(words[0]); - ali->source = cloneString("asmHub"); - hashAdd(aliasHash, words[0], ali); - } - } - } - } - lineFileClose(&lf); /* frees cannibalized ds string */ - } - -return aliasHash; -} /* static struct hash *readAliasFile(char *url) */ - static char *assemblyHubGenomeSetting(char *database, char *tagName) /* see if this assembly hub has specified tagName, return url if present * returns NULL when not present */ { struct trackHubGenome *genome = trackHubGetGenome(database); if (genome == NULL) return NULL; char *fileName = hashFindVal(genome->settingsHash, tagName); char *absFileName = NULL; if (fileName) absFileName = trackHubRelativeUrl((genome->trackHub)->url, fileName); if (absFileName) { hashReplace(genome->settingsHash, tagName, absFileName); @@ -477,40 +406,30 @@ /* see if this assembly hub has a chrom.sizes file, return url if present * returns NULL when not present */ { return assemblyHubGenomeSetting(database, "chromSizes"); } char *trackHubAliasFile(char *database) /* see if this assembly hub has an alias file, return url if present * returns NULL when not present */ { return assemblyHubGenomeSetting(database, "chromAlias"); } -struct hash *trackHubAllChromAlias(char *database) -/* Return a hash of chroms with alias names from alias file if present */ -{ -char *aliasFile = trackHubAliasFile(database); -if (aliasFile == NULL) - return NULL; - -return readAliasFile(aliasFile); -} /* struct hash *trackHubAllChromAlias(char *database) */ - struct chromInfo *trackHubAllChromInfo(char *database) /* Return a chromInfo structure for all the chroms in this database. */ { struct trackHubGenome *genome = trackHubGetGenome(database); if (genome == NULL) return NULL; if (genome->tbf == NULL) genome->tbf = twoBitOpen(genome->twoBitPath); struct chromInfo *ci, *ciList = NULL; struct slName *chromList = twoBitSeqNames(genome->twoBitPath); for(; chromList; chromList = chromList->next) { AllocVar(ci);