Exemplo n.º 1
0
static void printActiveGenomes()
/* Print out JSON for an object mapping each genome that has at least one db with active=1
 * to its taxId.  */
{
struct jsonWrite *jw = jsonWriteNew();
jsonWriteObjectStart(jw, NULL);
struct sqlConnection *conn = hConnectCentral();
// Join with defaultDb because in rare cases, different taxIds (species vs. subspecies)
// may be used for different assemblies of the same species.  Using defaultDb means that
// we send a taxId consistent with the taxId of the assembly that we'll change to when
// the species is selected from the tree.
char *query = NOSQLINJ "select dbDb.genome, taxId, dbDb.name from dbDb, defaultDb "
    "where defaultDb.name = dbDb.name and active = 1 "
    "and taxId > 1;"; // filter out experimental hgwdev-only stuff with invalid taxIds
struct sqlResult *sr = sqlGetResult(conn, query);
char **row;
while ((row = sqlNextRow(sr)) != NULL)
    {
    char *genome = row[0], *db = row[2];
    int taxId = atoi(row[1]);
    if (hDbExists(db))
        jsonWriteNumber(jw, genome, taxId);
    }
hDisconnectCentral(&conn);
jsonWriteObjectEnd(jw);
puts(jw->dy->string);
jsonWriteFree(&jw);
}
Exemplo n.º 2
0
struct jsonWrite *jsonForSoftware(struct eapSoftware *sw)
/* Return JSON text for software.  This is something that looks
 * like:
	{
	"name" : "macs2",
	"title" : "macs2",
	"url" : "https://github.com/taoliu/MACS/"
	}
 */
{
struct jsonWrite *jw = jsonWriteNew(0);
jsonWriteObjectStart(jw);
jsonWriteString(jw, "name", sw->name);
jsonWriteString(jw, "title", sw->name);
jsonWriteString(jw, "url", sw->url);
jsonWriteObjectEnd(jw);
return jw;
}
Exemplo n.º 3
0
struct jsonWrite *jsonForSwVersion(struct sqlConnection *conn, struct eapSwVersion *ver)
/* Construct JSON string describing ver. */
{
char query[256];
sqlSafef(query, sizeof(query), "select * from eapSoftware where name='%s'", ver->software);
struct eapSoftware *sw = eapSoftwareLoadByQuery(conn, query);
if (sw == NULL || isEmpty(sw->metaUuid))
    {
    verbose(2, "Skipping %s %s because %s has not been registered with metadatabase\n", 
	ver->software, ver->version, ver->software);
    return NULL;
    }
uglyf("sw id %u, softare %s, metaUuid %s\n",  sw->id, sw->name, sw->metaUuid);
struct jsonWrite *jw = jsonWriteNew(0);
jsonWriteObjectStart(jw);
jsonWriteString(jw, "software", sw->metaUuid);
jsonWriteString(jw, "version", ver->version);
jsonWriteString(jw, "dcc_md5", ver->md5);
jsonWriteObjectEnd(jw);
return jw;
}
Exemplo n.º 4
0
struct cartJson *cartJsonNew(struct cart *cart)
/* Allocate and return a cartJson object with default handlers.
 * cart must have "db" set already. */
{
struct cartJson *cj;
AllocVar(cj);
cj->handlerHash = hashNew(0);
cj->jw = jsonWriteNew();
cj->cart = cart;
cartJsonRegisterHandler(cj, "getCladeOrgDbPos", getCladeOrgDbPos);
cartJsonRegisterHandler(cj, "changePosition", changePositionHandler);
cartJsonRegisterHandler(cj, "get", getVar);
cartJsonRegisterHandler(cj, "getGroupedTrackDb", cartJsonGetGroupedTrackDb);
cartJsonRegisterHandler(cj, "getAssemblyInfo", getAssemblyInfo);
cartJsonRegisterHandler(cj, "getGeneSuggestTrack", getGeneSuggestTrack);
cartJsonRegisterHandler(cj, "getHasCustomTracks", getHasCustomTracks);
cartJsonRegisterHandler(cj, "getIsSpecialHost", getIsSpecialHost);
cartJsonRegisterHandler(cj, "getHasHubTable", getHasHubTable);
cartJsonRegisterHandler(cj, "setIfUnset", setIfUnset);
cartJsonRegisterHandler(cj, "getStaticHtml", getStaticHtml);
return cj;
}
Exemplo n.º 5
0
static boolean writeGroupedTrack(struct jsonWrite *jw, char *name, char *label,
                                 struct hash *fieldHash, struct hash *excludeTypesHash,
                                 int maxDepth, struct slRef *tdbRefList)
/* If tdbRefList is empty after excluding tracks/views/subtracks whose types are
 * in excludeTypesHash, then return FALSE and write nothing.  Otherwise write a group
 * and its tracks/views/subtracks and return TRUE. */
{
// Make a new jsonWrite object in case this group turns out to have no children after filtering.
struct jsonWrite *jwNew = jsonWriteNew();
jsonWriteObjectStart(jwNew, NULL);
jsonWriteString(jwNew, "name", name);
jsonWriteString(jwNew, "label", label);
jsonWriteListStart(jwNew, "tracks");
boolean gotSomething = FALSE;
struct slRef *tdbRef;
for (tdbRef = tdbRefList;  tdbRef != NULL;  tdbRef = tdbRef->next)
    {
    struct trackDb *tdb = tdbRef->val;
    // First see if there are any tracks to show for this group:
    struct jsonWrite *jwTrack = rTdbToJw(tdb, fieldHash, excludeTypesHash, 1, maxDepth);
    if (jwTrack)
        {
        gotSomething = TRUE;
        jsonWriteAppend(jwNew, NULL, jwTrack);
        jsonWriteFree(&jwTrack);
        }
    }
if (gotSomething)
    {
    // Group has at least one track, so append it to jw.
    jsonWriteListEnd(jwNew);
    jsonWriteObjectEnd(jwNew);
    jsonWriteAppend(jw, NULL, jwNew);
    }
jsonWriteFree(&jwNew);
return gotSomething;
}
Exemplo n.º 6
0
void suggestAltOrPatch(char *database, char *term)
/* Print out a Javascript list of objects describing alternate haplotype or fix patch sequences
 * from database that match term. */
{
struct jsonWrite *jw = jsonWriteNew();
jsonWriteListStart(jw, NULL);
struct sqlConnection *conn = hAllocConn(database);
// First, search for prefix matches
struct slName *fixMatches = queryAltFixNames(conn, "fixLocations", term, "alt", TRUE);
struct slName *altMatches = queryAltFixNames(conn, "altLocations", term, "fix", TRUE);
// Add category labels only if we get both types of matches.
writeAltFixMatches(jw, fixMatches, altMatches ? "Fix Patches" : "");
writeAltFixMatches(jw, altMatches, fixMatches ? "Alt Patches" : "");
// If there are no prefix matches, look for partial matches
if (fixMatches == NULL && altMatches == NULL)
    {
    fixMatches = queryAltFixNames(conn, "fixLocations", term, "alt", FALSE);
    altMatches = queryAltFixNames(conn, "altLocations", term, "fix", FALSE);
    writeAltFixMatches(jw, fixMatches, altMatches ? "Fix Patches" : "");
    writeAltFixMatches(jw, altMatches, fixMatches ? "Alt Patches" : "");
    }
// If there are still no matches, try chromAlias.
if (fixMatches == NULL && altMatches == NULL)
    {
    struct slPair *aliasMatches = queryChromAlias(conn, term, TRUE);
    writeValLabelMatches(jw, aliasMatches, "");
    if (aliasMatches == NULL)
        {
        struct slPair *aliasMatches = queryChromAlias(conn, term, FALSE);
        writeValLabelMatches(jw, aliasMatches, "");
        }
    }
hFreeConn(&conn);
jsonWriteListEnd(jw);
puts(jw->dy->string);
jsonWriteFree(&jw);
}
Exemplo n.º 7
0
static void lookupTerm()
/* Look for matches to term in hgcentral and print as JSON for autocomplete if found. */
{
char *term = getSearchTermUpperCase();

// Write JSON response with list of matches
puts("Content-Type:text/javascript\n");

struct dbDb *dbDbList = hDbDbList();
struct dbDbMatch *matchList = searchDbDb(dbDbList, term);
struct aHubMatch *aHubMatchList = searchPublicHubs(dbDbList, term);
struct jsonWrite *jw = jsonWriteNew();
jsonWriteListStart(jw, NULL);
// Write out JSON for dbDb matches, if any; add category if we found assembly hub matches too.
char *category = aHubMatchList ? "UCSC databases" : NULL;
struct dbDbMatch *match;
for (match = matchList;  match != NULL;  match = match->next)
    writeDbDbMatch(jw, match, term, category);
// Write out assembly hub matches, if any.
writeAssemblyHubMatches(jw, aHubMatchList);
jsonWriteListEnd(jw);
puts(jw->dy->string);
jsonWriteFree(&jw);
}
Exemplo n.º 8
0
static struct jsonWrite *rTdbToJw(struct trackDb *tdb, struct hash *fieldHash,
                                  struct hash *excludeTypesHash, int depth, int maxDepth)
/* Recursively build and return a new jsonWrite object with JSON for tdb and its children,
 * or NULL if tdb or all children have been filtered out by excludeTypesHash.
 * If excludeTypesHash is non-NULL, omit any tracks/views/subtracks with type in excludeTypesHash.
 * If fieldHash is non-NULL, include only the field names indexed in fieldHash. */
{
if (maxDepth >= 0 && depth > maxDepth)
    return NULL;
boolean doSubtracks = (tdb->subtracks && fieldOk("subtracks", fieldHash));
// If excludeTypesHash is given and tdb is a leaf track/subtrack, look up the first word
// of tdb->type in excludeTypesHash; if found, return NULL.
if (excludeTypesHash && !doSubtracks)
    {
    char typeCopy[PATH_LEN];
    safecpy(typeCopy, sizeof(typeCopy), tdb->type);
    if (hashLookup(excludeTypesHash, firstWordInLine(typeCopy)))
        return NULL;
    }
boolean gotSomething = !doSubtracks;
struct jsonWrite *jwNew = jsonWriteNew();
jsonWriteObjectStart(jwNew, NULL);
writeTdbSimple(jwNew, tdb, fieldHash);
if (tdb->parent && fieldOk("parent", fieldHash))
    {
    // We can't link to an object in JSON and better not recurse here or else infinite loop.
    if (tdbIsSuperTrackChild(tdb))
        {
        // Supertracks have been omitted from fullTrackList, so add the supertrack object's
        // non-parent/child info here.
        jsonWriteObjectStart(jwNew, "parent");
        writeTdbSimple(jwNew, tdb->parent, fieldHash);
        jsonWriteObjectEnd(jwNew);
        }
    else
        // Just the name so we don't have infinite loops.
        jsonWriteString(jwNew, "parent", tdb->parent->track);
    }
if (doSubtracks)
    {
    jsonWriteListStart(jwNew, "subtracks");
    slSort(&tdb->subtracks, trackDbViewCmp);
    struct trackDb *subTdb;
    for (subTdb = tdb->subtracks;  subTdb != NULL;  subTdb = subTdb->next)
        {
        struct jsonWrite *jwSub = rTdbToJw(subTdb, fieldHash, excludeTypesHash, depth+1, maxDepth);
        if (jwSub)
            {
            gotSomething = TRUE;
            jsonWriteAppend(jwNew, NULL, jwSub);
            jsonWriteFree(&jwSub);
            }
        }
    jsonWriteListEnd(jwNew);
    }
jsonWriteObjectEnd(jwNew);
if (! gotSomething)
    // All children were excluded; clean up and null out jwNew.
    jsonWriteFree(&jwNew);
return jwNew;
}
Exemplo n.º 9
0
struct jsonWrite *jsonForStep(struct sqlConnection *conn, struct eapStep *step)
/* Convert an eapStep to json. See step.json in same directory as the .c file. 
 * for an example. */
{
struct jsonWrite *jw = jsonWriteNew();
jsonWriteObjectStart(jw);

/* Write name and description. */
jsonWriteString(jw, "name", step->name);
jsonWriteString(jw, "description", step->description);

/* Write version */
struct eapStepVersion *ver = eapStepVersionLatest(conn, step->name);
jsonWriteNumber(jw, "version", ver->version);

/* Write software */
jsonWriteListStart(jw, "software");
char query[512];
sqlSafef(query, sizeof(query), "select * from eapStepSoftware where step='%s'", step->name);
struct eapStepSoftware *ss, *ssList = eapStepSoftwareLoadByQuery(conn, query);
boolean isFirst = TRUE;
struct dyString *dy = jw->dy;
for (ss = ssList; ss != NULL; ss = ss->next)
    {
    struct eapSoftware *software = eapSoftwareLoadByName(conn, ss->software);
    assert(software != NULL);
    if (software->metaUuid)
        {
	if (!isFirst)
	    {
	    dyStringAppendC(dy, ',');
	    dyStringAppendC(dy, '\n');
	    }
	isFirst = FALSE;
	dyStringAppendC(dy, '"');
	dyStringPrintf(dy, "/software/%s/", software->metaUuid);
	dyStringAppendC(dy, '"');
	}
    }
if (!isFirst)
    dyStringAppendC(dy, '\n');
jsonWriteListEnd(jw);
/* Done with writing software list */


/* Write input list */
jsonWriteListStart(jw, "inputs");
int i;
for (i=0; i<step->inCount; ++i)
    {
    jsonWriteObjectStart(jw);
    jsonWriteString(jw, "format", step->inputFormats[i]);
    jsonWriteString(jw, "name", step->inputTypes[i]);
    jsonWriteString(jw, "description", step->inputDescriptions[i]);
    jsonWriteObjectEnd(jw);
    }
jsonWriteListEnd(jw);

/* Write output list */
jsonWriteListStart(jw, "outputs");
for (i=0; i<step->outCount; ++i)
    {
    jsonWriteObjectStart(jw);
    jsonWriteString(jw, "format", step->outputFormats[i]);
    jsonWriteString(jw, "name", step->outputTypes[i]);
    jsonWriteString(jw, "description", step->outputDescriptions[i]);
    jsonWriteObjectEnd(jw);
    }
jsonWriteListEnd(jw);

jsonWriteObjectEnd(jw);
return jw;
}