9f527929694c8bada3e0f6ab0145aada1a0973e5 hiram Wed Feb 13 14:23:42 2019 -0800 remove code that moved out refs #18869 diff --git src/hg/hubApi/hubApi.c src/hg/hubApi/hubApi.c index 850fb5f..9435577 100644 --- src/hg/hubApi/hubApi.c +++ src/hg/hubApi/hubApi.c @@ -3,99 +3,47 @@ /* +------------------+------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------+------------------+------+-----+---------+-------+ | hubUrl | longblob | NO | PRI | NULL | | | shortLabel | varchar(255) | NO | | NULL | | | longLabel | varchar(255) | NO | | NULL | | | registrationTime | varchar(255) | NO | | NULL | | | dbCount | int(10) unsigned | NO | | NULL | | | dbList | blob | YES | | NULL | | | descriptionUrl | longblob | YES | | NULL | | +------------------+------------------+------+-----+---------+-------+ */ -#ifdef NOT -/*this definition should be over in hg/inc/hubPublic.h but that does not exist*/ -struct hubPublic -/* Table of public track data hub connections. */ - { - struct hubPublic *next; /* Next in singly linked list. */ - char *hubUrl; /* URL to hub.ra file */ - char *shortLabel; /* Hub short label. */ - char *longLabel; /* Hub long label. */ - char *registrationTime; /* Time first registered */ - unsigned dbCount; /* Number of databases hub has data for. */ - char *dbList; /* Comma separated list of databases. */ - char *descriptionUrl; /* URL to description HTML */ - }; -#endif - /* Global Variables */ static struct cart *cart; /* CGI and other variables */ static struct hash *oldVars = NULL; static struct hash *trackCounter = NULL; static long totalTracks = 0; static boolean measureTiming = FALSE; /* set by CGI parameters */ static boolean allTrackSettings = FALSE; /* checkbox setting */ static char **shortLabels = NULL; /* public hub short labels in array */ // struct hubPublic *publicHubList = NULL; static int publicHubCount = 0; static char *defaultHub = "Plants"; static char *defaultDb = "ce11"; static long enteredMainTime = 0; /* will become = clock1000() on entry */ /* to allow calculation of when to bail out, taking too long */ static long timeOutSeconds = 100; static boolean timedOut = FALSE; -#ifdef NOT -static void hubPublicJsonData(struct jsonWrite *jw, struct hubPublic *el) -/* Print array data for one row from hubPublic table, order here - * must be same as was stated in the columnName header element - * TODO: need to figure out how to use the order of the columns as - * they are in the 'desc' request - */ -{ -jsonWriteListStart(jw, NULL); -jsonWriteString(jw, NULL, el->hubUrl); -jsonWriteString(jw, NULL, el->shortLabel); -jsonWriteString(jw, NULL, el->longLabel); -jsonWriteString(jw, NULL, el->registrationTime); -jsonWriteNumber(jw, NULL, (long long)el->dbCount); -jsonWriteString(jw, NULL, el->dbList); -jsonWriteString(jw, NULL, el->descriptionUrl); -jsonWriteListEnd(jw); -} - -static int trackDbTrackCmp(const void *va, const void *vb) -/* Compare to sort based on 'track' name; use shortLabel as secondary sort key. - * Note: parallel code to hgTracks.c:tgCmpPriority */ -{ -const struct trackDb *a = *((struct trackDb **)va); -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; -} - -#endif - static int publicHubCmpCase(const void *va, const void *vb) /* Compare two slNames, ignore case. */ { const struct hubPublic *a = *((struct hubPublic **)va); const struct hubPublic *b = *((struct hubPublic **)vb); return strcasecmp(a->shortLabel, b->shortLabel); } static void publicHubSortCase(struct hubPublic **pList) /* Sort slName list, ignore case. */ { slSort(pList, publicHubCmpCase); } static struct hubPublic *hubPublicLoad(char **row) @@ -466,373 +414,58 @@ * and then get the shortLabel */ { char hubUrl[1024]; char query[1024]; struct sqlConnection *conn = hConnectCentral(); // Build a query to select the hubUrl for the given shortLabel sqlSafef(query, sizeof(query), "select hubUrl from %s where shortLabel='%s'", hubPublicTableName(), shortLabel); if (! sqlQuickQuery(conn, query, hubUrl, sizeof(hubUrl))) hubUrl[0] = 0; hDisconnectCentral(&conn); return cloneString(hubUrl); } -#ifdef NOT -static void dbDbJsonData(struct jsonWrite *jw, struct dbDb *el) -/* Print out dbDb table element in JSON format. - * must be same as was stated in the columnName header element - * TODO: need to figure out how to use the order of the columns as - * they are in the 'desc' request - */ -{ -jsonWriteListStart(jw, NULL); -jsonWriteString(jw, NULL, el->name); -jsonWriteString(jw, NULL, el->description); -jsonWriteString(jw, NULL, el->nibPath); -jsonWriteString(jw, NULL, el->organism); -jsonWriteString(jw, NULL, el->defaultPos); -jsonWriteNumber(jw, NULL, (long long)el->active); -jsonWriteNumber(jw, NULL, (long long)el->orderKey); -jsonWriteString(jw, NULL, el->genome); -jsonWriteString(jw, NULL, el->scientificName); -jsonWriteString(jw, NULL, el->htmlPath); -jsonWriteNumber(jw, NULL, (long long)el->hgNearOk); -jsonWriteNumber(jw, NULL, (long long)el->hgPbOk); -jsonWriteString(jw, NULL, el->sourceName); -jsonWriteNumber(jw, NULL, (long long)el->taxId); -jsonWriteListEnd(jw); -} - - -static boolean tableColumns(struct jsonWrite *jw, char *table) -/* output the column names for the given table - * return: TRUE on error, FALSE on success - */ -{ -jsonWriteListStart(jw, "columnNames"); -char query[1024]; -struct sqlConnection *conn = hConnectCentral(); -sqlSafef(query, sizeof(query), "desc %s", table); -struct sqlResult *sr = sqlGetResult(conn, query); -char **row; -row = sqlNextRow(sr); -if (NULL == row) - { - jsonErrAbort("ERROR: can not 'desc' table '%s'", table); - return TRUE; - } -while ((row = sqlNextRow(sr)) != NULL) - jsonWriteString(jw, NULL, row[0]); -sqlFreeResult(&sr); -hDisconnectCentral(&conn); -jsonWriteListEnd(jw); -return FALSE; -} - -static void jsonPublicHubs() -/* output the hubPublic SQL table */ -{ -struct sqlConnection *conn = hConnectCentral(); -char *dataTime = sqlTableUpdate(conn, hubPublicTableName()); -hDisconnectCentral(&conn); -time_t dataTimeStamp = sqlDateToUnixTime(dataTime); -replaceChar(dataTime, ' ', 'T'); -struct hubPublic *el = hubPublicLoadAll(); -struct jsonWrite *jw = jsonStartOutput(); -jsonWriteString(jw, "dataTime", dataTime); -jsonWriteNumber(jw, "dataTimeStamp", (long long)dataTimeStamp); -freeMem(dataTime); -jsonWriteString(jw, "tableName", hubPublicTableName()); -tableColumns(jw, hubPublicTableName()); -jsonWriteListStart(jw, "publicHubData"); -for ( ; el != NULL; el = el->next ) - { - hubPublicJsonData(jw, el); - } -jsonWriteListEnd(jw); -jsonWriteObjectEnd(jw); -fputs(jw->dy->string,stdout); -} -#endif - static int dbDbCmpName(const void *va, const void *vb) /* Compare two dbDb elements: name, ignore case. */ { const struct dbDb *a = *((struct dbDb **)va); const struct dbDb *b = *((struct dbDb **)vb); return strcasecmp(a->name, b->name); } struct dbDb *ucscDbDb() /* return the dbDb table as an slList */ { char query[1024]; struct sqlConnection *conn = hConnectCentral(); sqlSafef(query, sizeof(query), "select * from dbDb"); struct dbDb *dbList = NULL, *el = NULL; struct sqlResult *sr = sqlGetResult(conn, query); char **row; while ((row = sqlNextRow(sr)) != NULL) { el = dbDbLoad(row); slAddHead(&dbList, el); } sqlFreeResult(&sr); hDisconnectCentral(&conn); slSort(&dbList, dbDbCmpName); return dbList; } -#ifdef NOT -static void jsonDbDb() -/* output the dbDb SQL table */ -{ -struct sqlConnection *conn = hConnectCentral(); -char *dataTime = sqlTableUpdate(conn, "dbDb"); -hDisconnectCentral(&conn); -time_t dataTimeStamp = sqlDateToUnixTime(dataTime); -replaceChar(dataTime, ' ', 'T'); -struct dbDb *dbList = ucscDbDb(); -struct dbDb *el; -struct jsonWrite *jw = jsonStartOutput(); -jsonWriteString(jw, "dataTime", dataTime); -jsonWriteNumber(jw, "dataTimeStamp", (long long)dataTimeStamp); -freeMem(dataTime); -jsonWriteString(jw, "tableName", "dbDb"); -tableColumns(jw, "dbDb"); -jsonWriteListStart(jw, "ucscGenomes"); -for ( el=dbList; el != NULL; el = el->next ) - { - dbDbJsonData(jw, el); - } -jsonWriteListEnd(jw); -jsonWriteObjectEnd(jw); -fputs(jw->dy->string,stdout); -} - -static void chromInfoJsonOutput(FILE *f, char *db) -/* for given db, if there is a track, list the chromosomes in that track, - * for no track, simply list the chromosomes in the sequence - */ -{ -char *table = cgiOptionalString("track"); -struct sqlConnection *conn = hAllocConn(db); -/* in trackDb language: track == table */ -if (table) - { - if (! sqlTableExists(conn, table)) - jsonErrAbort("ERROR: endpoint: /list/chromosomes?db=%&table=%s ERROR table does not exist", db, table); - if (sqlColumnExists(conn, table, "chrom")) - { - char *dataTime = sqlTableUpdate(conn, table); - time_t dataTimeStamp = sqlDateToUnixTime(dataTime); - replaceChar(dataTime, ' ', 'T'); - struct jsonWrite *jw = jsonStartOutput(); - jsonWriteString(jw, "genome", db); - jsonWriteString(jw, "track", table); - jsonWriteString(jw, "dataTime", dataTime); - jsonWriteNumber(jw, "dataTimeStamp", (long long)dataTimeStamp); - freeMem(dataTime); - struct slPair *list = NULL; - char query[2048]; - sqlSafef(query, sizeof(query), "select distinct chrom from %s", table); - struct sqlResult *sr = sqlGetResult(conn, query); - char **row; - while ((row = sqlNextRow(sr)) != NULL) - { - int size = hChromSize(db, row[0]); - slAddHead(&list, slPairNew(row[0], intToPt(size))); - } - sqlFreeResult(&sr); - slPairIntSort(&list); - slReverse(&list); - jsonWriteNumber(jw, "chromCount", (long long)slCount(list)); - jsonWriteObjectStart(jw, "chromosomes"); - struct slPair *el = list; - for ( ; el != NULL; el = el->next ) - jsonWriteNumber(jw, el->name, (long long)ptToInt(el->val)); - jsonWriteObjectEnd(jw); /* chromosomes */ - jsonWriteObjectEnd(jw); /* top level */ - fputs(jw->dy->string,stdout); - } - else - { - jsonErrAbort("ERROR: table '%s' is not a position table, no chromosomes for genome: '%s'", table, db); - } - } -else - { - char *dataTime = sqlTableUpdate(conn, "chromInfo"); - time_t dataTimeStamp = sqlDateToUnixTime(dataTime); - replaceChar(dataTime, ' ', 'T'); - struct chromInfo *ciList = createChromInfoList(NULL, db); - struct chromInfo *el = ciList; - struct jsonWrite *jw = jsonStartOutput(); - jsonWriteString(jw, "genome", db); - jsonWriteString(jw, "dataTime", dataTime); - jsonWriteNumber(jw, "dataTimeStamp", (long long)dataTimeStamp); - freeMem(dataTime); - jsonWriteNumber(jw, "chromCount", (long long)slCount(ciList)); - jsonWriteObjectStart(jw, "chromosomes"); - for ( ; el != NULL; el = el->next ) - { - jsonWriteNumber(jw, el->chrom, (long long)el->size); - } - jsonWriteObjectEnd(jw); /* chromosomes */ - jsonWriteObjectEnd(jw); /* top level */ - fputs(jw->dy->string,stdout); - } -hFreeConn(&conn); -} - -static void recursiveTrackList(struct jsonWrite *jw, struct trackDb *tdb, char *type) -{ -jsonWriteListStart(jw, type); -struct trackDb *el; -for (el = tdb; el != NULL; el = el->next ) - { - jsonWriteObjectStart(jw, NULL); - jsonWriteString(jw, "track", el->track); - jsonWriteString(jw, "shortLabel", el->shortLabel); - jsonWriteString(jw, "type", el->type); - jsonWriteString(jw, "longLabel", el->longLabel); - if (tdbIsComposite(el)) - { - recursiveTrackList(jw, el->subtracks, "subtracks"); - } - if (tdb->parent && tdbIsSuperTrackChild(el)) - jsonWriteString(jw, "superTrack", "TRUE"); - jsonWriteObjectEnd(jw); - } -jsonWriteListEnd(jw); -} - -static void trackDbJsonOutput(char *db, FILE *f) -/* return track list from specified UCSC database name */ -{ -struct sqlConnection *conn = hAllocConn(db); -char *dataTime = sqlTableUpdate(conn, "trackDb"); -time_t dataTimeStamp = sqlDateToUnixTime(dataTime); -replaceChar(dataTime, ' ', 'T'); -hFreeConn(&conn); -struct trackDb *tdbList = hTrackDb(db); -struct jsonWrite *jw = jsonStartOutput(); -jsonWriteString(jw, "db", db); -jsonWriteString(jw, "dataTime", dataTime); -jsonWriteNumber(jw, "dataTimeStamp", (long long)dataTimeStamp); -freeMem(dataTime); -recursiveTrackList(jw, tdbList, "tracks"); -jsonWriteObjectEnd(jw); -fputs(jw->dy->string,stdout); -} /* static void trackDbJsonOutput(char *db, FILE *f) */ - -static void apiList(char *words[MAX_PATH_INFO]) -/* 'list' function words[1] is the subCommand */ -{ -if (sameWord("publicHubs", words[1])) - jsonPublicHubs(); -else if (sameWord("ucscGenomes", words[1])) - jsonDbDb(); -else if (sameWord("hubGenomes", words[1])) - { - char *hubUrl = cgiOptionalString("hubUrl"); - if (isEmpty(hubUrl)) - jsonErrAbort("must supply hubUrl='http:...' some URL to a hub for /list/hubGenomes"); - - struct trackHub *hub = NULL; - struct errCatch *errCatch = errCatchNew(); - if (errCatchStart(errCatch)) - { - hub = trackHubOpen(hubUrl, ""); - } - errCatchEnd(errCatch); - if (errCatch->gotError) - { - jsonErrAbort("error opening hubUrl: '%s', '%s'", hubUrl, errCatch->message->string); - } - errCatchFree(&errCatch); - if (hub->genomeList) - { - struct jsonWrite *jw = jsonStartOutput(); - jsonWriteString(jw, "hubUrl", hubUrl); - jsonWriteListStart(jw, "genomes"); - struct slName *theList = genomeList(hub, NULL, NULL); - slNameSort(&theList); - struct slName *el = theList; - for ( ; el ; el = el->next ) - { - jsonWriteString(jw, NULL, el->name); - } - jsonWriteListEnd(jw); - jsonWriteObjectEnd(jw); - fputs(jw->dy->string,stdout); - } - } -else if (sameWord("tracks", words[1])) - { - char *hubUrl = cgiOptionalString("hubUrl"); - char *genome = cgiOptionalString("genome"); - char *db = cgiOptionalString("db"); - if (isEmpty(hubUrl) && isEmpty(db)) - jsonErrAbort("ERROR: must supply hubUrl or db name to return track list"); - 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)) - warn("# must supply genome='someName' the name of a genome in a hub for /list/tracks\n"); - if (isEmpty(hubUrl)) - jsonErrAbort("ERROR: must supply hubUrl='http:...' some URL to a hub for /list/genomes"); - } - struct trackHub *hub = trackHubOpen(hubUrl, ""); - if (hub->genomeList) - { - struct trackDb *dbTrackList = NULL; - (void) genomeList(hub, &dbTrackList, genome); - slSort(dbTrackList, trackDbTrackCmp); - struct jsonWrite *jw = jsonStartOutput(); - jsonWriteString(jw, "hubUrl", hubUrl); - jsonWriteString(jw, "genome", genome); - recursiveTrackList(jw, dbTrackList, "tracks"); - jsonWriteObjectEnd(jw); - fputs(jw->dy->string,stdout); - } - } -else if (sameWord("chromosomes", words[1])) - { - char *hubUrl = cgiOptionalString("hubUrl"); -// char *genome = cgiOptionalString("genome"); - char *db = cgiOptionalString("db"); - if (isEmpty(hubUrl) && isEmpty(db)) - jsonErrAbort("ERROR: must supply hubUrl or db name to return chromosome list"); - - if (isEmpty(hubUrl)) // missing hubUrl implies UCSC database - { - chromInfoJsonOutput(stdout, db); - return; - } - } -else - jsonErrAbort("do not recognize endpoint function: '/%s/%s'", words[0], words[1]); -} -#endif - static struct hash *apiFunctionHash = NULL; static void setupFunctionHash() /* initialize the apiFunctionHash */ { if (apiFunctionHash) return; /* already done */ apiFunctionHash = hashNew(0); hashAdd(apiFunctionHash, "list", &apiList); hashAdd(apiFunctionHash, "getData", &apiGetData); } static void apiFunctionSwitch(char *pathInfo) /* given a pathInfo string: /command/subCommand/etc... @@ -880,38 +513,40 @@ hPrintf("
\n"); cartDump(cart); hPrintf("\n"); } +#endif static void doMiddle(struct cart *theCart) /* Set up globals and make web page */ { cart = theCart; measureTiming = hPrintStatus() && isNotEmpty(cartOptionalString(cart, "measureTiming")); measureTiming = TRUE; char *database = NULL; char *genome = NULL; getDbAndGenome(cart, &database, &genome, oldVars); initGenbankTableNames(database); char *docRoot = cfgOptionDefault("browser.documentRoot", DOCUMENT_ROOT); @@ -961,37 +596,37 @@ char *hubDropDown = cartUsualString(cart, "publicHubs", defaultHub); char *urlDropDown = urlFromShortLabel(hubDropDown); char *ucscDb = cartUsualString(cart, "ucscGenomes", defaultDb); char *urlInput = urlDropDown; /* assume public hub */ if (sameWord("go", goOtherHub)) /* requested other hub URL */ urlInput = otherHubUrl; long lastTime = clock1000(); struct trackHub *hub = trackHubOpen(urlInput, ""); if (measureTiming) { long thisTime = clock1000(); hPrintf("hub open time: %ld millis