5de752e3fa6fd4941978107956e2a87b4c5b46ee kate Thu Jul 16 12:04:16 2015 -0700 Add support for GTEX tissue color scheme. refs #15645 diff --git src/hg/lib/gtexTissue.c src/hg/lib/gtexTissue.c index 91b671e..a05ed0b 100644 --- src/hg/lib/gtexTissue.c +++ src/hg/lib/gtexTissue.c @@ -12,30 +12,66 @@ char *gtexTissueCommaSepFieldNames = "id,name,description,organ,color"; void gtexTissueStaticLoad(char **row, struct gtexTissue *ret) /* Load a row from gtexTissue table into ret. The contents of ret will * be replaced at the next call to this function. */ { ret->id = sqlUnsigned(row[0]); ret->name = row[1]; ret->description = row[2]; ret->organ = row[3]; ret->color = sqlUnsigned(row[4]); } +struct gtexTissue *gtexTissueLoadByQuery(struct sqlConnection *conn, char *query) +/* Load all gtexTissue from table that satisfy the query given. + * Where query is of the form 'select * from example where something=something' + * or 'select example.* from example, anotherTable where example.something = + * anotherTable.something'. + * Dispose of this with gtexTissueFreeList(). */ +{ +struct gtexTissue *list = NULL, *el; +struct sqlResult *sr; +char **row; + +sr = sqlGetResult(conn, query); +while ((row = sqlNextRow(sr)) != NULL) + { + el = gtexTissueLoad(row); + slAddHead(&list, el); + } +slReverse(&list); +sqlFreeResult(&sr); +return list; +} + +void gtexTissueSaveToDb(struct sqlConnection *conn, struct gtexTissue *el, char *tableName, int updateSize) +/* Save gtexTissue as a row to the table specified by tableName. + * As blob fields may be arbitrary size updateSize specifies the approx size + * of a string that would contain the entire query. Arrays of native types are + * converted to comma separated strings and loaded as such, User defined types are + * inserted as NULL. This function automatically escapes quoted strings for mysql. */ +{ +struct dyString *update = newDyString(updateSize); +sqlDyStringPrintf(update, "insert into %s values ( %u,'%s','%s','%s',%u)", + tableName, el->id, el->name, el->description, el->organ, el->color); +sqlUpdate(conn, update->string); +freeDyString(&update); +} + struct gtexTissue *gtexTissueLoad(char **row) /* Load a gtexTissue from row fetched with select * from gtexTissue * from database. Dispose of this with gtexTissueFree(). */ { struct gtexTissue *ret; AllocVar(ret); ret->id = sqlUnsigned(row[0]); ret->name = cloneString(row[1]); ret->description = cloneString(row[2]); ret->organ = cloneString(row[3]); ret->color = sqlUnsigned(row[4]); return ret; }