4d2f4049ac3d658165ea79d365cc6ed642e1683e angie Tue May 26 12:25:41 2015 -0700 In order to make it more clear that wiggle values are averaged now, print out wiggle's value column as "valueAverage" in the header. refs #14579 note 61 diff --git src/lib/annoFormatTab.c src/lib/annoFormatTab.c index 9df06f0..d80f3a3 100644 --- src/lib/annoFormatTab.c +++ src/lib/annoFormatTab.c @@ -5,30 +5,33 @@ #include "annoFormatTab.h" #include "annoGratorQuery.h" #include "dystring.h" struct annoFormatTab { struct annoFormatter formatter; // External interface char *fileName; // Output file name, can be "stdout" FILE *f; // Output file handle struct hash *columnVis; // Hash of columns that have been explicitly selected // or deselected by user. boolean needHeader; // TRUE if we should print out the header }; +//#*** config options: avg? more stats? list of values? +static boolean doAvg = TRUE; + static void makeFullColumnName(char *fullName, size_t size, char *sourceName, char *colName) /* If sourceName is non-empty, make fullName sourceName.colName, otherwise just colName. */ { if (isNotEmpty(sourceName)) safef(fullName, size, "%s.%s", sourceName, colName); else safecpy(fullName, size, colName); } void annoFormatTabSetColumnVis(struct annoFormatter *vSelf, char *sourceName, char *colName, boolean enabled) /* Explicitly include or exclude column in output. sourceName must be the same * as the corresponding annoStreamer source's name. */ { struct annoFormatTab *self = (struct annoFormatTab *)vSelf; @@ -41,51 +44,64 @@ static boolean columnIsIncluded(struct annoFormatTab *self, char *sourceName, char *colName) // Return TRUE if column has not been explicitly deselected. { if (self->columnVis) { char fullName[PATH_LEN]; makeFullColumnName(fullName, sizeof(fullName), sourceName, colName); int vis = hashIntValDefault(self->columnVis, fullName, 1); if (vis == 0) return FALSE; } return TRUE; } +static boolean isWiggle(struct asColumn *colList) +/* Recognize wiggle/bigWig data by its column signature. */ +{ +return (slCount(colList) == 4 && + sameString(colList->name, "chrom") && + sameString(colList->next->name, "chromStart") && + sameString(colList->next->next->name, "chromEnd") && + sameString(colList->next->next->next->name, "value")); +} + static void printHeaderColumns(struct annoFormatTab *self, struct annoStreamer *source, boolean isFirst) /* Print names of included columns from this source. */ { FILE *f = self->f; char *sourceName = source->name; +boolean isAvg = isWiggle(source->asObj->columnList) && doAvg; struct asColumn *col; int i; for (col = source->asObj->columnList, i = 0; col != NULL; col = col->next, i++) { if (columnIsIncluded(self, sourceName, col->name)) { if (isFirst) { fputc('#', f); isFirst = FALSE; } else fputc('\t', f); char fullName[PATH_LEN]; makeFullColumnName(fullName, sizeof(fullName), sourceName, col->name); + if (isAvg && sameString(col->name, "value")) + safecat(fullName, sizeof(fullName), "Average"); fputs(fullName, f); } } } static void aftInitialize(struct annoFormatter *vSelf, struct annoStreamer *primary, struct annoStreamer *integrators) /* Print header, regardless of whether we get any data after this. */ { struct annoFormatTab *self = (struct annoFormatTab *)vSelf; if (self->needHeader) { char *primaryHeader = primary->getHeader(primary); if (isNotEmpty(primaryHeader)) fprintf(self->f, "# Header from primary input:\n%s", primaryHeader); @@ -149,32 +165,30 @@ } static char **wordsFromRow(struct annoRow *row, struct annoStreamer *source, boolean *retFreeWhenDone) /* If source->rowType is arWords, return its words. Otherwise translate row->data into words. */ { if (row == NULL) return NULL; boolean freeWhenDone = FALSE; char **words = NULL; if (source->rowType == arWords) words = row->data; else if (source->rowType == arWig) { freeWhenDone = TRUE; - //#*** config options: avg? more stats? list of values? - boolean doAvg = TRUE; if (doAvg) words = wordsFromWigRowAvg(row); else words = wordsFromWigRowVals(row); } else errAbort("annoFormatTab: unrecognized row type %d from source %s", source->rowType, source->name); if (retFreeWhenDone != NULL) *retFreeWhenDone = freeWhenDone; return words; } static void printColumns(struct annoFormatTab *self, struct annoStreamer *streamer, struct annoRow *row, boolean isFirst)