b94049706947c8eeaa56aa8593a74940fdfd544f kate Thu Feb 12 15:22:25 2015 -0800 Use controlledVocabulary setting for non-ENCODE (table-based) vocabularies (replace briefly used *MetaTables settings) diff --git src/hg/lib/hui.c src/hg/lib/hui.c index 8860f06..0b057b7 100644 --- src/hg/lib/hui.c +++ src/hg/lib/hui.c @@ -4185,55 +4185,66 @@ printf("</TD></TR></TFOOT>\n"); } } /********************/ /* Basic info for a controlled vocabulary term */ struct vocabBasic { struct vocabBasic *next; char *term; char *description; char *url; }; +boolean vocabSettingIsEncode(char *setting) +/* Distinguish ENCODE controlled vocab settings (first arg is cv.ra filename) from non-ENCODE + (table-based vocabs) +*/ +{ +if (setting && (strchr(cloneFirstWord(setting), '=') == NULL)) + return TRUE; +return FALSE; +} + char *vocabLink(struct hash *vocabFieldHash, char *term, char *title) /* Make an anchor with mouseover containing description and link if present */ { struct vocabBasic *vocab = hashFindVal(vocabFieldHash, term); if (vocab == NULL) return NULL; struct dyString *ds = dyStringNew(0); if (vocab->url == NULL || strlen(vocab->url) == 0) dyStringPrintf(ds, "<A title='%s' style='cursor: pointer;'>%s</A>", vocab->description, term); else dyStringPrintf(ds, "<A target='_blank' class='cv' title='%s' href='%s'>%s</A>\n", vocab->description, vocab->url, term); return dyStringCannibalize(&ds); } -struct hash *vocabBasicFromSetting(struct trackDb *parentTdb, struct cart *cart, char *setting) +struct hash *vocabBasicFromSetting(struct trackDb *parentTdb, struct cart *cart) /* Get description and URL for all vocabTables. Returns a hash of hashes */ { -if (differentString(setting, "subGroupMetaTables") && - differentString(setting, "inputFieldMetaTables")) - return NULL; -char *spec = trackDbSetting(parentTdb, setting); +char *spec = trackDbSetting(parentTdb, "controlledVocabulary"); if (!spec) return NULL; +// Not yet implemented for ENCODE-style CV +if (vocabSettingIsEncode(spec)) + return NULL; + struct slPair *vocabTables = slPairFromString(spec); struct slPair *vocabTable = NULL; struct hash *tableHash = hashNew(0); struct sqlResult *sr; char **row; char query[256]; char *database = cartString(cart, "db"); for (vocabTable = vocabTables; vocabTable != NULL; vocabTable = vocabTable->next) { char *db = database; char *tableSpec = (char *)vocabTable->val; char *tableName = chopPrefix(tableSpec); if (differentString(tableName, tableSpec)) { chopSuffix(tableSpec); @@ -4285,31 +4296,31 @@ { // preserves user's prev sort/drags preSorted = tdbRefSortPrioritiesFromCart(cart, &subtrackRefList); printf("<TBODY class='%saltColors'>\n", (sortOrder != NULL ? "sortable " : "") ); } else { slSort(&subtrackRefList, trackDbRefCmp); // straight from trackDb.ra preSorted = TRUE; puts("<TBODY>"); } // Finally the big "for loop" to list each subtrack as a table row. printf("\n<!-- ----- subtracks list ----- -->\n"); membersForAll_t* membersForAll = membersForAllSubGroupsGet(parentTdb,NULL); -struct hash *vocabHash = vocabBasicFromSetting(parentTdb, cart, "subGroupMetaTables"); +struct hash *vocabHash = vocabBasicFromSetting(parentTdb, cart); struct slRef *subtrackRef; /* Color handling ?? */ //char *colors[2] = { COLOR_BG_DEFAULT, // COLOR_BG_ALTDEFAULT }; char *colors[2] = { "bgLevel1", "bgLevel1" }; int colorIx = settings->bgColorIx; for (subtrackRef = subtrackRefList; subtrackRef != NULL; subtrackRef = subtrackRef->next) { struct trackDb *subtrack = subtrackRef->val; int ix; // Determine whether subtrack is checked, visible, configurable, has group membership, etc. @@ -6851,39 +6862,47 @@ } } } } puts("</TABLE>"); freeMem(matchedViewTracks); return TRUE; } char *compositeLabelWithVocabLink(char *db,struct trackDb *parentTdb, struct trackDb *childTdb, char *vocabType, char *label) // If the parentTdb has a controlledVocabulary setting and the vocabType is found, // then label will be wrapped with the link to display it. Return string is cloned. { char *vocab = trackDbSetting(parentTdb, "controlledVocabulary"); + +// WARNING: this is needed to cache metadata in trackDb object (accessed by metadataFindValue) +(void)metadataForTable(db,childTdb,NULL); + if (vocab == NULL) return cloneString(label); // No wrapping! -#define BUFSIZ 16 -char *words[BUFSIZ]; +// Currently implemented just for ENCODE style vocab +if (!vocabSettingIsEncode(vocab)) + return cloneString(label); + +char *words[SMALLBUF]; int count; -if ((count = chopByWhite(cloneString(vocab), words, BUFSIZ)) <= 1) +if ((count = chopByWhite(cloneString(vocab), words, SMALLBUF)) <= 1) return cloneString(label); + char *suffix = NULL; char *rootLabel = labelRoot(label, &suffix); boolean found = FALSE; int ix; for (ix=1;ix<count && !found;ix++) { if (sameString(vocabType,words[ix])) // controlledVocabulary setting matches tag { // so all labels are linked char *link = wgEncodeVocabLink(words[0],"term",words[ix],rootLabel,rootLabel,suffix); return link; } else if (countChars(words[ix],'=') == 1 && childTdb != NULL) // The name of a trackDb setting follows and will be the controlled vocab term {