18d303bb4f14e1edff401c8a85276ff1344f0f37 angie Tue Apr 3 10:18:14 2012 -0700 Feature #6152 (Variant Annotation Tool): Added annoStreamVcf, whichled to yet more significant changes to annoRow: instead of every row declaring its type and annoRow{Free,Clone} taking a numCols argument that is meaningless for wig, now annoRow{Free,Clone} take the row's source annoStreamer as an argument. The annoStreamer now has public members (rowType and numCols) that provide all information needed about the row. annoStreamer constructors need to set rowType. diff --git src/lib/annoRow.c src/lib/annoRow.c index 7cca169..cc26b26 100644 --- src/lib/annoRow.c +++ src/lib/annoRow.c @@ -1,107 +1,105 @@ /* annoRow -- basic data interchange unit of annoGratorQuery framework. */ #include "annoRow.h" +#include "annoStreamer.h" struct annoRow *annoRowFromStringArray(char *chrom, uint start, uint end, boolean rightJoinFail, char **wordsIn, int numCols) /* Allocate & return an annoRow with words cloned from wordsIn. */ { struct annoRow *aRow; AllocVar(aRow); aRow->chrom = cloneString(chrom); aRow->start = start; aRow->end = end; -aRow->type = arWords; aRow->rightJoinFail = rightJoinFail; char **words; AllocArray(words, numCols); int i; for (i = 0; i < numCols; i++) words[i] = cloneString(wordsIn[i]); aRow->data = words; return aRow; } struct annoRow *annoRowWigNew(char *chrom, uint start, uint end, boolean rightJoinFail, float *values) /* Allocate & return an annoRowWig, with clone of values; length of values is (end-start). */ { struct annoRow *row; AllocVar(row); row->chrom = cloneString(chrom); row->start = start; row->end = end; row->data = cloneMem(values, (end - start) * sizeof(values[0])); -row->type = arWig; row->rightJoinFail = rightJoinFail; return row; } -struct annoRow *annoRowClone(struct annoRow *rowIn, int numCols) +struct annoRow *annoRowClone(struct annoRow *rowIn, struct annoStreamer *source) /* Allocate & return a single annoRow cloned from rowIn. */ { if (rowIn == NULL) return NULL; -if (rowIn->type == arWords) +if (source->rowType == arWords || source->rowType == arVcf) return annoRowFromStringArray(rowIn->chrom, rowIn->start, rowIn->end, rowIn->rightJoinFail, - rowIn->data, numCols); -else if (rowIn->type == arWig) + rowIn->data, source->numCols); +else if (source->rowType == arWig) return annoRowWigNew(rowIn->chrom, rowIn->start, rowIn->end, rowIn->rightJoinFail, (float *)rowIn->data); else - errAbort("annoRowClone: unrecognized type %d", rowIn->type); + errAbort("annoRowClone: unrecognized type %d", source->rowType); return NULL; } static void annoRowWordsFree(struct annoRow **pRow, int numCols) /* Free a single annoRow with type arWords. */ { if (pRow == NULL) return; struct annoRow *row = *pRow; freeMem(row->chrom); char **words = row->data; int i; for (i = 0; i < numCols; i++) freeMem(words[i]); freeMem(row->data); freez(pRow); } static void annoRowWigFree(struct annoRow **pRow) /* Free a single annoRow with type arWig. */ { if (pRow == NULL) return; struct annoRow *row = *pRow; freeMem(row->chrom); freeMem(row->data); freez(pRow); } -void annoRowFree(struct annoRow **pRow, int numCols) +void annoRowFree(struct annoRow **pRow, struct annoStreamer *source) /* Free a single annoRow. */ { if (pRow == NULL) return; -struct annoRow *row = *pRow; -if (row->type == arWords) - annoRowWordsFree(pRow, numCols); -else if (row->type == arWig) +if (source->rowType == arWords || source->rowType == arVcf) + annoRowWordsFree(pRow, source->numCols); +else if (source->rowType == arWig) annoRowWigFree(pRow); else - errAbort("annoRowFree: unrecognized type %d", row->type); + errAbort("annoRowFree: unrecognized type %d", source->rowType); } -void annoRowFreeList(struct annoRow **pList, int numCols) +void annoRowFreeList(struct annoRow **pList, struct annoStreamer *source) /* Free a list of annoRows. */ { if (pList == NULL) return; struct annoRow *row, *nextRow; for (row = *pList; row != NULL; row = nextRow) { nextRow = row->next; - annoRowFree(&row, numCols); + annoRowFree(&row, source); } }