d24f68e60112fbd009085ec5f7a7d59b05160cec tdreszer Tue Nov 1 10:10:40 2011 -0700 Added extraFields support for bigBeds in hgc. diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c index ba77bf9..e08362e 100644 --- src/hg/hgc/hgc.c +++ src/hg/hgc/hgc.c @@ -1386,91 +1386,70 @@ safef(dbOnly, sizeof(dbOnly), "%s", comp1->src); chopPrefix(dbOnly); printf("%-20s %d\n",hOrganism(dbOnly), diff); } printf("
"); } } } } int extraFieldsPrint(struct trackDb *tdb,struct sqlResult *sr,char **row) // Any extra fields defined in trackDb. Retruns number of extra fields actually printed { // Additional fields requested in trackDb? -char *fields = trackDbSetting(tdb, "extraFields"); // showFileds pValue=P_Value qValue=qValue -if (fields == NULL) +struct extraField *extras = extraFieldsGet(tdb); +if (extras == NULL) return 0; -char *historicalRecord = fields; int count = 0; -char *field = cloneNextWord(&fields); // fields not harmed but pointer advanced -while(field != NULL) +struct extraField *extra = extras; +for(;extra != NULL;extra=extra->next) { - // parse field as "pValue=[f]P_Value" inot field="pValue" and label="[f]P_Value" - char *label = field; - char *equal = strchr(field,'='); - if (equal != NULL) + int ix = sqlFieldColumn(sr, extra->name); // Name must match sql columnn name! + if (ix == -1) // so extraField really just provides a label { - *equal = '\0'; - label = equal + 1; - assert(*label!='\0'); + char *setting = trackDbSetting(tdb, "extraFields"); // showFileds pValue=P_Value qValue=qValue + warn("trackDb setting [extraFields %s] could not find %s in %s.\n", setting, extra->name,tdb->table); } - - // We have a field requested but is it in the table? - int ix = sqlFieldColumn(sr, field); - if (ix == -1) - warn("trackDb setting [extraFields %s] could not find %s in %s.\n", historicalRecord, field,tdb->table); else { - // parse label "[f]P_Value" into label="P Value" and type=float - char *type = "string"; - if (*label == '[') - { - if (startsWith("[i",label)) - type = "integer"; - else if (startsWith("[f",label)) - type = "float"; - label = strchr(label,']'); - assert(label != NULL); - label += 1; - } - // Print as table rows if(count == 0) printf("
"); - printf("", strSwapChar(label,'_',' ')); // No '_' in label - if (sameString(type,"integer")) + count++; + printf("", extra->label); + switch (extra->type) { - long long val = sqlLongLong(row[ix]); - printf("\n", val); + case ftInteger: { + long long valInt = sqlLongLong(row[ix]); + printf("\n", valInt); } - else if (sameString(type,"float")) - { - double val = sqlDouble(row[ix]); - printf("\n", val); + break; + case ftFloat: { + double valDouble = sqlDouble(row[ix]); + printf("\n", valDouble); } - else + break; + default: printf("\n", row[ix]); - count++; + break; + } } - - // free mem and move to next field - freeMem(field); - field = cloneNextWord(&fields); // around we go } +extraFieldsFree(&extras); if(count > 0) printf("
%s:
%s:%lld
%lld
%g
%g
%s
\n"); return count; } void genericBedClick(struct sqlConnection *conn, struct trackDb *tdb, char *item, int start, int bedSize) /* Handle click in generic BED track. */ { char table[64]; boolean hasBin; struct bed *bed; char query[512]; struct sqlResult *sr;