e408d52de2f812c4dc407b1865c97c45090dcf16 chmalee Mon Oct 11 16:40:46 2021 -0700 Renaming the trackDb settings extraDetailsTable and extraTableFields to the more descriptive and more accurate detailsStaticTable and detailsDynamicTable. Also rename detailsTabUrls to detailsUrls, luckily that setting has not been documented yet, so a simple rename is possible diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c index 621dbb5..3f157d9 100644 --- src/hg/hgc/hgc.c +++ src/hg/hgc/hgc.c @@ -1685,93 +1685,125 @@ char field[256]; safef(field, sizeof(field), "${%s}", col->name); if (stringIn(field, table)) { struct slName *replaceField = slNameNew(col->name); slAddHead(&foundFields, replaceField); } } dyStringPrintf(ds, "%s", table); if (foundFields) slReverse(foundFields); } return foundFields; } +#define TDB_DYNAMICTABLE_SETTING "detailsDynamicTable" +#define TDB_DYNAMICTABLE_SETTING_2 "extraTableFields" void getExtraTableFields(struct trackDb *tdb, struct slName **retFieldNames, struct embeddedTbl **retList, struct hash *embeddedTblHash) -/* Parse the trackDb field "extraTableFields" into the field names and titles specified, +/* Parse the trackDb field TDB_DYNAMICTABLE_FIELD into the field names and titles specified, * and fill out a hash keyed on the bigBed field name (which may be in an external file * and not in the bigBed itself) to a helper struct for storing user defined tables. */ { -struct slName *tmp, *embeddedTblSetting = slNameListFromComma(trackDbSetting(tdb, "extraTableFields")); +struct slName *tmp; *embeddedTblSetting = slNameListFromComma(trackDbSetting(tdb, TDB_DYNAMICTABLE_SETTING)); +struct slName *embeddedTblSetting2 = slNameListFromComma(trackDbSetting(tdb, TDB_DYNAMICTABLE_SETTING_2)); char *title = NULL, *fieldName = NULL; for (tmp = embeddedTblSetting; tmp != NULL; tmp = tmp->next) { fieldName = cloneString(tmp->name); if (strchr(tmp->name, '|')) { title = strchr(fieldName, '|'); *title++ = 0; } struct embeddedTbl *new; AllocVar(new); new->field = fieldName; new->title = title != NULL ? cloneString(title) : fieldName; slAddHead(retList, new); slNameAddHead(retFieldNames, fieldName); hashAdd(embeddedTblHash, fieldName, new); } +for (tmp = embeddedTblSetting2; tmp != NULL; tmp = tmp->next) + { + fieldName = cloneString(tmp->name); + if (strchr(tmp->name, '|')) + { + title = strchr(fieldName, '|'); + *title++ = 0; + } + struct embeddedTbl *new; + AllocVar(new); + new->field = fieldName; + new->title = title != NULL ? cloneString(title) : fieldName; + slAddHead(retList, new); + slNameAddHead(retFieldNames, fieldName); + hashAdd(embeddedTblHash, fieldName, new); + } } +#define TDB_STATICTABLE_SETTING "extraDetailsTable" +#define TDB_STATICTABLE_SETTING_2 "detailsStaticTable" int extraFieldsPrintAs(struct trackDb *tdb,struct sqlResult *sr,char **fields,int fieldCount, struct asObject *as) // Any extra bed or bigBed fields (defined in as and occurring after N in bed N + types. // sr may be null for bigBeds. // Returns number of extra fields actually printed. { // We are trying to print extra fields so we need to figure out how many fields to skip int start = extraFieldsStart(tdb, fieldCount, as); struct asColumn *col = as->columnList; char *urlsStr = trackDbSettingClosestToHomeOrDefault(tdb, "urls", NULL); struct hash* fieldToUrl = hashFromString(urlsStr); boolean skipEmptyFields = trackDbSettingOn(tdb, "skipEmptyFields"); // make list of fields to skip char *skipFieldsStr = trackDbSetting(tdb, "skipFields"); struct slName *skipIds = NULL; if (skipFieldsStr) skipIds = slNameListFromComma(skipFieldsStr); // make list of fields that are separated from other fields char *sepFieldsStr = trackDbSetting(tdb, "sepFields"); struct slName *sepFields = NULL; if (sepFieldsStr) sepFields = slNameListFromComma(sepFieldsStr); // make list of fields that we want to substitute // this setting has format description|URLorFilePath, with the stuff before the pipe optional -char *extraDetailsTableName = NULL, *extraDetails = cloneString(trackDbSetting(tdb, "extraDetailsTable")); +char *extraDetailsTableName = NULL, *extraDetails = cloneString(trackDbSetting(tdb, TDB_STATICTABLE_SETTING)); if (extraDetails && strchr(extraDetails,'|')) { extraDetailsTableName = extraDetails; extraDetails = strchr(extraDetails,'|'); *extraDetails++ = 0; } struct dyString *extraTblStr = dyStringNew(0); struct slName *detailsTableFields = NULL; if (extraDetails) detailsTableFields = findFieldsInExtraFile(extraDetails, col, extraTblStr); +char *extraDetails2TableName = NULL, *extraDetails2 = cloneString(trackDbSetting(tdb, TDB_STATICTABLE_SETTING_2)); +if (extraDetails2 && strchr(extraDetails2,'|')) + { + extraDetails2TableName = extraDetails2; + extraDetails2 = strchr(extraDetails2,'|'); + *extraDetails2++ = 0; + } +struct dyString *extraTbl2Str = dyStringNew(0); +struct slName *detailsTable2Fields = NULL; +if (extraDetails2) + detailsTable2Fields = findFieldsInExtraFile(extraDetails2, col, extraTbl2Str); struct hash *embeddedTblHash = hashNew(0); struct slName *embeddedTblFields = NULL; struct embeddedTbl *embeddedTblList = NULL; getExtraTableFields(tdb, &embeddedTblFields, &embeddedTblList, embeddedTblHash); // iterate over fields, print as table rows int count = 0; int printCount = 0; for (;col != NULL && count < fieldCount;col=col->next) { if (start > 0) // skip past already known fields { start--; continue; @@ -1789,30 +1821,44 @@ // don't print this field if we are gonna print it later in a custom table if (detailsTableFields && slNameInList(detailsTableFields, fieldName)) { int fieldLen = strlen(fieldName); char *replaceField = needMem(fieldLen+4); replaceField[0] = '$'; replaceField[1] = '{'; strcpy(replaceField+2, fieldName); replaceField[fieldLen+2] = '}'; replaceField[fieldLen+3] = 0; extraTblStr = dyStringSub(extraTblStr->string, replaceField, fields[ix]); continue; } + // don't print this field if we are gonna print it later in a custom table + if (detailsTable2Fields && slNameInList(detailsTable2Fields, fieldName)) + { + int fieldLen = strlen(fieldName); + char *replaceField = needMem(fieldLen+4); + replaceField[0] = '$'; + replaceField[1] = '{'; + strcpy(replaceField+2, fieldName); + replaceField[fieldLen+2] = '}'; + replaceField[fieldLen+3] = 0; + extraTbl2Str = dyStringSub(extraTbl2Str->string, replaceField, fields[ix]); + continue; + } + // similar to above, if the field contains an embedded table skip it here // and print it later if (embeddedTblFields) { struct embeddedTbl *new = hashFindVal(embeddedTblHash, fieldName); if (new) { new->encodedTbl = fields[ix]; continue; } } // do not print a row if the fieldName from the .as file is in the "skipFields" list // or if a field name starts with _. This makes bigBed extra fields consistent with // external extra fields in that _ field names have some meaning and are not shown @@ -1869,30 +1915,34 @@ { printEmbeddedTable(tdb, thisTbl, tableLabelsDy); } } jsInline(dyStringCannibalize(&tableLabelsDy)); } if (printCount > 0) printf("\n"); if (detailsTableFields) { printExtraDetailsTable(tdb->track, extraDetailsTableName, extraDetails, extraTblStr); } +if (detailsTable2Fields) + { + printExtraDetailsTable(tdb->track, extraDetails2TableName, extraDetails2, extraTbl2Str); + } return printCount; } int extraFieldsPrint(struct trackDb *tdb,struct sqlResult *sr,char **fields,int fieldCount) // Any extra bed or bigBed fields (defined in as and occurring after N in bed N + types. // sr may be null for bigBeds. // Returns number of extra fields actually printed. { struct asObject *as = asForDb(tdb, database); if (as == NULL) return 0; int ret = extraFieldsPrintAs(tdb, sr, fields,fieldCount, as); //asObjectFree(&as);