aa76ee6119d9baf92a033231d898cc31967846b5
tdreszer
Tue Feb 1 17:32:37 2011 -0800
Support for extraFields trackDb setting for bed items
diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c
index e6d51c4..62b2091 100644
--- src/hg/hgc/hgc.c
+++ src/hg/hgc/hgc.c
@@ -756,30 +756,31 @@
char *label = "Item", *tdbLabel = NULL;
if (tdb && ((tdbLabel = trackDbSetting(tdb, "bedNameLabel")) != NULL))
label = tdbLabel;
printf("%s: %s
\n", label, bed->name);
}
if (bedSize >= 5)
{
if (!tdb || !trackDbSetting(tdb, "noScoreFilter"))
printf("Score: %d
\n", bed->score);
}
if (bedSize >= 6)
{
strand = bed->strand;
}
printPos(bed->chrom, bed->chromStart, bed->chromEnd, strand, TRUE, bed->name);
+
}
void interactionPrintPos( struct bed *bed, int bedSize, struct trackDb *tdb)
/* Print first bedSize fields of a bed type structure in
* standard format. */
{
if (bed->blockCount == 2)
{
printf("Intrachromosomal interaction:
\n");
printf("Positions:
");
printf("",
hgTracksPathAndSettings(), database, bed->chrom,
bed->chromStarts[0]+bed->chromStart,
bed->chromStarts[0]+bed->chromStart + bed->blockSizes[0]);
@@ -1373,30 +1374,101 @@
char dbOnly[4096];
diff = comp2->start - (comp1->start + comp1->size);
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)
+ return 0;
+
+char *historicalRecord = fields;
+int count = 0;
+char *field = cloneNextWord(&fields); // fields not harmed but pointer advanced
+while(field != NULL)
+ {
+ // 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)
+ {
+ *equal = '\0';
+ label = equal + 1;
+ assert(*label!='\0');
+ }
+
+ // 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("
%s: | ", strSwapChar(label,'_',' ')); // No '_' in label + if (sameString(type,"integer")) + { + long long val = sqlLongLong(row[ix]); + printf("%lld | %g | \n", val); + } + else + printf("%s | \n", row[ix]); + count++; + } + + // free mem and move to next field + freeMem(field); + field = cloneNextWord(&fields); // around we go + } +if(count > 0) + printf("