f72d8b57a77755e64ef594ae2d4395a12c19712d hiram Tue Mar 19 21:46:37 2019 -0700 now showing a sample getData URL for supported tracks refs #18869 diff --git src/hg/hubApi/hubApi.c src/hg/hubApi/hubApi.c index f9a2b0c..a58944f 100644 --- src/hg/hubApi/hubApi.c +++ src/hg/hubApi/hubApi.c @@ -20,33 +20,87 @@ 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; +static char *urlPrefix = ""; /* initalized to support self references */ +static struct slName *supportedTypes = NULL; + /* will be initialized to a known supported set */ + +static void initSupportedTypes() +/* initalize the list of supported track types, + */ +{ +struct slName *el = newSlName("bed"); +slAddHead(&supportedTypes, el); +el = newSlName("wig"); +slAddHead(&supportedTypes, el); +el = newSlName("broadPeak"); +slAddHead(&supportedTypes, el); +el = newSlName("narrowPeak"); +slAddHead(&supportedTypes, el); +el = newSlName("bigBed"); +slAddHead(&supportedTypes, el); +el = newSlName("bigWig"); +slAddHead(&supportedTypes, el); +el = newSlName("bigNarrowPeak"); +slAddHead(&supportedTypes, el); +el = newSlName("bigGenePred"); +slAddHead(&supportedTypes, el); +el = newSlName("bigPsl"); +slAddHead(&supportedTypes, el); +el = newSlName("bigBarChart"); +slAddHead(&supportedTypes, el); +el = newSlName("bigInteract"); +slAddHead(&supportedTypes, el); +el = newSlName("bigMaf"); +slAddHead(&supportedTypes, el); +el = newSlName("bigChain"); +slAddHead(&supportedTypes, el); +slNameSort(&supportedTypes); +} + +static boolean isSupportedType(char *type) +/* is given type in the supportedTypes list ? */ +{ +boolean ret = FALSE; +if (startsWith("wigMaf", type)) + return ret; +struct slName *el; +for (el = supportedTypes; el; el = el->next) + { + if (startsWith(el->name, type)) + { + ret = TRUE; + break; + } + } +return ret; +} static int publicHubCmpCase(const void *va, const void *vb) -/* Compare two slNames, ignore case. */ +/* Compare two shortLabels, 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) /* Load a hubPublic from row fetched with select * from hubPublic * from database. Dispose of this with hubPublicFree(). */ @@ -152,46 +206,72 @@ hashIncInt(countTracks, "superTrack child"); hashIncInt(countTracks, stripType); hashIncInt(countTracks, "track count"); } else if (isEmpty(tdb->type)) hashIncInt(countTracks, "no type specified"); else { hashIncInt(countTracks, stripType); hashIncInt(countTracks, "track count"); } freeMem(stripType); // showCounts(countTracks); } -static void showSubTracks(struct trackDb *tdb, struct hash *countTracks) +static void sampleUrl(char *db, struct trackDb *tdb, char *chrom, long long chromSize) +/* print out a sample getData URL */ +{ +long long start = chromSize / 4; +long long end = start + 10000; +if (end > chromSize) + end = chromSize; + +if (db) + { + if (tdb->parent) + hPrintf("
  • %s : %s subtrack of parent: %s (sample getData)
  • \n", tdb->track, tdb->type, tdb->parent->track, urlPrefix, db, chrom, tdb->track, start, end ); + else + hPrintf("
  • %s : %s (sample getData)
  • \n", tdb->track, tdb->type, urlPrefix, db, chrom, tdb->track, start, end ); + } +} + +static void showSubTracks(char *db, struct trackDb *tdb, struct hash *countTracks, + char *chromName, long long chromSize) /* tdb has subtracks, show only subTracks, no details */ { hPrintf("
  • \n"); } static void trackSettings(struct trackDb *tdb, struct hash *countTracks) /* process the settingsHash for a trackDb, recursive when subtracks */ { hPrintf("
  • \n"); hPrintf("

    Parameters to endpoint functions:

    \n"); hPrintf("\n"); +hPrintf("

    Supported track types, at this time, for getData functions:

    \n"); +hPrintf("\n"); } -static void showExamples(char *url, struct trackHubGenome *hubGenome, char *ucscDb) +static void initUrlPrefix() +/* set up urlPrefix for self referenes */ { -char *urlPrefix = ""; char *httpHost = getenv("HTTP_HOST"); -if (! startsWith("hgwdev-api", httpHost)) { +if (! startsWith("hgwdev-api", httpHost)) + { if (startsWith("hgwdev",httpHost) || startsWith("genome-test", httpHost)) { urlPrefix = "../cgi-bin/hubApi"; } } +} +static void showExamples(char *url, struct trackHubGenome *hubGenome, char *ucscDb) +{ hPrintf("

    Example URLs to return json data structures:

    \n"); hPrintf("

    listing functions

    \n"); hPrintf("
      \n"); hPrintf("
    1. list public hubs %s/list/publicHubs
    2. \n", urlPrefix, urlPrefix); hPrintf("
    3. list database genomes %s/list/ucscGenomes
    4. \n", urlPrefix, urlPrefix); hPrintf("
    5. list genomes from specified hub %s/list/hubGenomes?hubUrl=%s
    6. \n", urlPrefix, url, urlPrefix, url); hPrintf("
    7. list tracks from specified hub and genome %s/list/tracks?hubUrl=%s&genome=%s
    8. \n", urlPrefix, url, hubGenome->name, urlPrefix, url, hubGenome->name); hPrintf("
    9. list tracks from specified UCSC database %s/list/tracks?db=%s
    10. \n", urlPrefix, ucscDb, urlPrefix, ucscDb); hPrintf("
    11. list chromosomes from specified UCSC database %s/list/chromosomes?db=%s
    12. \n", urlPrefix, ucscDb, urlPrefix, ucscDb); hPrintf("
    13. list chromosomes from specified track from UCSC databaset %s/list/chromosomes?db=%s&track=gap
    14. \n", urlPrefix, ucscDb, urlPrefix, ucscDb); hPrintf("
    \n"); hPrintf("

    getData functions

    \n"); hPrintf("
      \n"); @@ -736,30 +836,32 @@ } 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; cgiVarSet("ignoreCookie", "1"); getDbAndGenome(cart, &database, &genome, oldVars); initGenbankTableNames(database); +initSupportedTypes(); +initUrlPrefix(); char *docRoot = cfgOptionDefault("browser.documentRoot", DOCUMENT_ROOT); int timeout = cartUsualInt(cart, "udcTimeout", 300); if (udcCacheTimeout() < timeout) udcSetCacheTimeout(timeout); knetUdcInstall(); char *pathInfo = getenv("PATH_INFO"); /* nothing on incoming path, then display the WEB page instead */ if (sameOk("/",pathInfo)) pathInfo = NULL; boolean commandError = FALSE; /*expect no more than MAX_PATH_INFO number of words*/