d92ba8d3eb476aeeaaa7a52cf097bb8b3ba6ba46 hiram Wed Apr 24 14:30:00 2019 -0700 all errors checked in list function refs #18869 diff --git src/hg/hubApi/list.c src/hg/hubApi/list.c index 260e2fe..10d3a7a 100644 --- src/hg/hubApi/list.c +++ src/hg/hubApi/list.c @@ -142,63 +142,79 @@ char *track = cgiOptionalString("track"); if (isEmpty(genome)) apiErrAbort(err400, err400Msg, "must specify a 'genome=name' with hubUrl for endpoint: /list/chromosomes?hubUrl=%s;genome=", hubUrl); struct trackHubGenome *foundGenome = NULL; for (ge = hub->genomeList; ge; ge = ge->next) { if (sameOk(genome, ge->name)) { foundGenome = ge; continue; /* found genome */ } } + if (NULL == foundGenome) apiErrAbort(err400, err400Msg, "can not find specified 'genome=%s' for endpoint: /list/chromosomes?hubUrl=%s;genome=%s", genome, hubUrl, genome); struct jsonWrite *jw = apiStartOutput(); jsonWriteString(jw, "hubUrl", hubUrl); jsonWriteString(jw, "genome", genome); if (isNotEmpty(track)) { jsonWriteString(jw, "track", track); struct trackDb *tdb = obtainTdb(foundGenome, NULL); if (NULL == tdb) - apiErrAbort(err400, err400Msg, "failed to find a track hub definition in genome=%s for endpoint '/list/chromosomes' give hubUrl=%s'", genome, hubUrl); + apiErrAbort(err400, err400Msg, "failed to find a track hub definition in genome=%s for endpoint '/list/chromosomes' given hubUrl=%s'", genome, hubUrl); struct trackDb *thisTrack = findTrackDb(track, tdb); if (NULL == thisTrack) - apiErrAbort(err400, err400Msg, "failed to find specified track=%s in genome=%s for endpoint '/getdata/track' given hubUrl='%s'", track, genome, hubUrl); + apiErrAbort(err400, err400Msg, "failed to find specified track=%s in genome=%s for endpoint '/list/chromosomes' given hubUrl='%s'", track, genome, hubUrl); char *bigDataUrl = trackDbSetting(thisTrack, "bigDataUrl"); struct bbiFile *bbi = bigFileOpen(thisTrack->type, bigDataUrl); struct bbiChromInfo *chrList = bbiChromList(bbi); slSort(chrList, chromInfoCmp); struct bbiChromInfo *el = chrList; jsonWriteNumber(jw, "chromCount", (long long)slCount(chrList)); jsonWriteObjectStart(jw, "chromosomes"); for ( ; el; el = el->next ) { jsonWriteNumber(jw, el->name, (long long)el->size); } jsonWriteObjectEnd(jw); /* chromosomes */ } else { - struct chromInfo *ci = trackHubAllChromInfo(foundGenome->name); + struct chromInfo *ci = NULL; + /* might be a track hub on a UCSC database */ + if (isEmpty(foundGenome->twoBitPath)) + { + struct sqlConnection *conn = hAllocConnMaybe(foundGenome->trackHub->defaultDb); + if (NULL == conn) + apiErrAbort(err400, err400Msg, "can not find database 'genome=%s' for endpoint '/list/chromosomes", foundGenome->trackHub->defaultDb); + else + hFreeConn(&conn); + ci = createChromInfoList(NULL, foundGenome->trackHub->defaultDb); + } + else + { + ci = trackHubAllChromInfo(foundGenome->name); + } +fprintf(stderr, "# DBG: sorting ci length: %d\n", slCount(ci)); slSort(ci, chromInfoCmp); jsonWriteNumber(jw, "chromCount", (long long)slCount(ci)); jsonWriteObjectStart(jw, "chromosomes"); struct chromInfo *el = ci; for ( ; el != NULL; el = el->next ) { jsonWriteNumber(jw, el->chrom, (long long)el->size); } jsonWriteObjectEnd(jw); /* chromosomes */ } apiFinishOutput(0, NULL, jw); } static void chromInfoJsonOutput(FILE *f, char *db) /* for given db, if there is a track, list the chromosomes in that track, @@ -329,31 +345,31 @@ const struct trackDb *b = *((struct trackDb **)vb); int dif = strcmp(a->track, b->track); if (dif < 0) return -1; else if (dif == 0.0) return strcasecmp(a->shortLabel, b->shortLabel); else return 1; } static void trackDbJsonOutput(char *db, FILE *f) /* return track list from specified UCSC database name */ { struct sqlConnection *conn = hAllocConnMaybe(db); if (NULL == conn) - apiErrAbort(err400, err400Msg, "can not find database 'db=%s' for endpoint '/list/hubGenomes", db); + apiErrAbort(err400, err400Msg, "can not find database 'db=%s' for endpoint '/list/tracks", db); char *dataTime = sqlTableUpdate(conn, "trackDb"); time_t dataTimeStamp = sqlDateToUnixTime(dataTime); replaceChar(dataTime, ' ', 'T'); /* ISO 8601 */ hFreeConn(&conn); struct trackDb *tdbList = obtainTdb(NULL, db); struct jsonWrite *jw = apiStartOutput(); jsonWriteString(jw, "db", db); jsonWriteString(jw, "dataTime", dataTime); jsonWriteNumber(jw, "dataTimeStamp", (long long)dataTimeStamp); freeMem(dataTime); struct trackDb *el = NULL; for (el = tdbList; el != NULL; el = el->next ) { recursiveTrackList(jw, el); @@ -395,31 +411,31 @@ jsonWriteObjectEnd(jw); } jsonWriteObjectEnd(jw); apiFinishOutput(0, NULL, jw); } } else if (sameWord("tracks", words[1])) { char *hubUrl = cgiOptionalString("hubUrl"); char *genome = cgiOptionalString("genome"); char *db = cgiOptionalString("db"); if (isNotEmpty(db)) { struct sqlConnection *conn = hAllocConnMaybe(db); if (NULL == conn) - apiErrAbort(err400, err400Msg, "can not find database 'db=%s' for endpoint '/list/chromosomes", db); + apiErrAbort(err400, err400Msg, "can not find database 'db=%s' for endpoint '/list/tracks", db); else hFreeConn(&conn); } if (isEmpty(hubUrl) && isEmpty(db)) apiErrAbort(err400, err400Msg, "ERROR: missing hubUrl or db name for endpoint /list/tracks"); if (isEmpty(hubUrl)) // missing hubUrl implies UCSC database { trackDbJsonOutput(db, stdout); // only need db for this function return; } if (isEmpty(genome) || isEmpty(hubUrl)) { if (isEmpty(genome)) apiErrAbort(err400, err400Msg, "ERROR: must supply genome='someName' the name of a genome in a hub for /list/tracks\n"); if (isEmpty(hubUrl)) @@ -444,31 +460,31 @@ } else if (sameWord("chromosomes", words[1])) { char *hubUrl = cgiOptionalString("hubUrl"); char *genome = cgiOptionalString("genome"); char *db = cgiOptionalString("db"); if (isNotEmpty(db)) { struct sqlConnection *conn = hAllocConnMaybe(db); if (NULL == conn) apiErrAbort(err400, err400Msg, "can not find database 'db=%s' for endpoint '/list/chromosomes", db); else hFreeConn(&conn); } if (isEmpty(hubUrl) && isEmpty(db)) - apiErrAbort(err400, err400Msg, "ERROR: must '%s' '%s' supply hubUrl or db name to return chromosome list", hubUrl, db); + apiErrAbort(err400, err400Msg, "must supply hubUrl or db name for endpoint '/list/chromosomes", hubUrl, db); if (isEmpty(hubUrl)) // missing hubUrl implies UCSC database { chromInfoJsonOutput(stdout, db); return; } else { hubChromInfoJsonOutput(stdout, hubUrl, genome); return; } } else apiErrAbort(err400, err400Msg, "do not recognize endpoint function: '/%s/%s'", words[0], words[1]); } /* void apiList(char *words[MAX_PATH_INFO]) */