0781f49ccdacd52dd75b0f12dab183e4b4cd25fc hiram Tue Mar 21 15:04:48 2023 -0700 extend the chromAlias function to the getSequence operation refs #30544 diff --git src/hg/hubApi/getData.c src/hg/hubApi/getData.c index 7833096..9b1a325 100644 --- src/hg/hubApi/getData.c +++ src/hg/hubApi/getData.c @@ -433,53 +433,44 @@ reachedMaxItems = TRUE; } else itemsDone += wigDataOutput(jw, bwf, chrom, start, end); itemsReturned += itemsDone; } static void getHubTrackData(char *hubUrl) /* return data from a hub track, optionally just one chrom data, * optionally just one section of that chrom data */ { char *genome = cgiOptionalString("genome"); char *trackArg = cgiOptionalString("track"); -/* char *chrom = cgiOptionalString("chrom"); */ char *start = cgiOptionalString("start"); char *end = cgiOptionalString("end"); if (isEmpty(genome)) apiErrAbort(err400, err400Msg, "missing genome=<name> for endpoint '/getData/track' given hubUrl='%s'", hubUrl); if (isEmpty(trackArg)) apiErrAbort(err400, err400Msg, "missing track=<name> for endpoint '/getData/track' given hubUrl='%s'", hubUrl); struct trackHub *hub = errCatchTrackHubOpen(hubUrl); struct trackHubGenome *hubGenome = findHubGenome(hub, genome, "/getData/track", hubUrl); -if (hubGenome->settingsHash) - { - char *aliasFile = hashFindVal(hubGenome->settingsHash, "chromAliasBb"); - char *absFileName = NULL; - if (aliasFile) - absFileName = trackHubRelativeUrl((hubGenome->trackHub)->url, aliasFile); - if (absFileName) - { - chromAliasSetupBb(NULL, absFileName); - } - } + +hubAliasSetup(hubGenome); + char *chrom = chrOrAlias(genome, hubUrl); struct trackDb *tdb = obtainTdb(hubGenome, NULL); if (NULL == tdb) apiErrAbort(err400, err400Msg, "failed to find a track hub definition in genome=%s for endpoint '/getData/track' given hubUrl='%s'", genome, hubUrl); struct jsonWrite *jw = apiStartOutput(); jsonWriteString(jw, "hubUrl", hubUrl); jsonWriteString(jw, "genome", genome); // allow optional comma sep list of tracks char *tracks[100]; int numTracks = chopByChar(trackArg, ',', tracks, sizeof(tracks)); int i = 0; @@ -562,31 +553,30 @@ jsonWriteObjectStart(jw, track); bigWigData(jw, bbi, chrom, uStart, uEnd); jsonWriteObjectEnd(jw); } bbiFileClose(&bbi); } apiFinishOutput(0, NULL, jw); } /* static void getHubTrackData(char *hubUrl) */ static void getTrackData() /* return data from a track, optionally just one chrom data, * optionally just one section of that chrom data */ { char *db = cgiOptionalString("genome"); -/* char *chrom = cgiOptionalString("chrom"); */ char *chrom = chrOrAlias(db, NULL); char *start = cgiOptionalString("start"); char *end = cgiOptionalString("end"); /* 'track' name in trackDb often refers to a SQL 'table' */ char *trackArg = cgiOptionalString("track"); //char *sqlTable = cloneString(trackArg); /* might be something else */ /* depends upon 'table' setting in track db, or split table business */ unsigned chromSize = 0; /* maybe set later */ unsigned uStart = 0; unsigned uEnd = chromSize; /* maybe set later */ if ( ! (isEmpty(start) || isEmpty(end)) ) { uStart = sqlUnsigned(start); uEnd = sqlUnsigned(end); @@ -791,31 +781,31 @@ jsonWriteObjectEnd(jw); bbiFileClose(&bbi); } else tableDataOutput(db, thisTrack, conn, jw, track, chrom, uStart, uEnd); } apiFinishOutput(0, NULL, jw); hFreeConn(&conn); } /* static void getTrackData() */ static void getSequenceData(char *db, char *hubUrl) /* return DNA sequence, given at least a genome=name and chrom=chr, optionally start and end, might be a track hub for UCSC database */ { -char *chrom = cgiOptionalString("chrom"); +char *chrom = chrOrAlias(db, hubUrl); char *start = cgiOptionalString("start"); char *end = cgiOptionalString("end"); long timeStart = clock1000(); if (isEmpty(chrom)) apiErrAbort(err400, err400Msg, "missing URL chrom=<name> for endpoint '/getData/sequence?genome=%s'", db); if (chromSeqFileExists(db, chrom)) { struct chromInfo *ci = hGetChromInfo(db, chrom); unsigned chromSize = ci->size; struct dnaSeq *seq = NULL; if (isEmpty(start) || isEmpty(end)) if (chromSize > MAX_DNA_LENGTH) @@ -860,49 +850,52 @@ et = endTime - timeStart; if (measureTiming) jsonWriteNumber(jw, "dnaJsonWriteTimeMs", et); apiFinishOutput(0, NULL, jw); freeDnaSeq(&seq); } else apiErrAbort(err400, err400Msg, "can not find specified chrom=%s in sequence for endpoint '/getData/sequence?genome=%s;chrom=%s", chrom, db, chrom); } /* static void getSequenceData(char *db, char *hubUrl) */ static void getHubSequenceData(char *hubUrl) /* return DNA sequence, given at least a genome=name and chrom=chr, optionally start and end */ { char *genome = cgiOptionalString("genome"); -char *chrom = cgiOptionalString("chrom"); char *start = cgiOptionalString("start"); char *end = cgiOptionalString("end"); if (isEmpty(genome)) apiErrAbort(err400, err400Msg, "missing genome=<name> for endpoint '/getData/sequence' given hubUrl='%s'", hubUrl); -if (isEmpty(chrom)) - apiErrAbort(err400, err400Msg, "missing chrom=<name> for endpoint '/getData/sequence?genome=%s' given hubUrl='%s'", genome, hubUrl); struct trackHub *hub = errCatchTrackHubOpen(hubUrl); struct trackHubGenome *hubGenome = NULL; for (hubGenome = hub->genomeList; hubGenome; hubGenome = hubGenome->next) { if (sameString(genome, hubGenome->name)) break; } if (NULL == hubGenome) apiErrAbort(err400, err400Msg, "failed to find specified genome=%s for endpoint '/getData/sequence' given hubUrl '%s'", genome, hubUrl); +hubAliasSetup(hubGenome); + +char *chrom = chrOrAlias(genome, hubUrl); +if (isEmpty(chrom)) + apiErrAbort(err400, err400Msg, "missing chrom=<name> for endpoint '/getData/sequence?genome=%s' given hubUrl='%s'", genome, hubUrl); + /* might be a UCSC database track hub, where hubGenome=name is the database */ if (isEmpty(hubGenome->twoBitPath)) { getSequenceData(hubGenome->name, hubUrl); return; } /* this MaybeChromInfo will open the twoBit file, if not already done */ struct chromInfo *ci = trackHubMaybeChromInfo(hubGenome->name, chrom); unsigned chromSize = ci->size; if (NULL == ci) apiErrAbort(err400, err400Msg, "can not find sequence for chrom=%s for endpoint '/getData/sequence?genome=%s;chrom=%s' given hubUrl='%s'", chrom, genome, chrom, hubUrl); struct jsonWrite *jw = apiStartOutput();