1359d9856e982d83be761f3501bd6a87c046dee6 angie Mon Apr 15 15:56:56 2013 -0700 Added determination of data type by asObject comparison instead ofkludges like special annoRowType or checking a few column names. refs #6152 diff --git src/lib/annoRow.c src/lib/annoRow.c index 920e5bc..0dc86ed 100644 --- src/lib/annoRow.c +++ src/lib/annoRow.c @@ -1,70 +1,70 @@ /* annoRow -- basic data interchange unit of annoGratorQuery framework. */ #include "annoRow.h" struct annoRow *annoRowFromStringArray(char *chrom, uint start, uint end, boolean rightJoinFail, char **wordsIn, int numCols, struct lm *lm) /* Allocate & return an annoRow with words cloned from wordsIn. */ { struct annoRow *aRow; lmAllocVar(lm, aRow); aRow->chrom = lmCloneString(lm, chrom); aRow->start = start; aRow->end = end; aRow->rightJoinFail = rightJoinFail; char **words; lmAllocArray(lm, words, numCols); int i; for (i = 0; i < numCols; i++) words[i] = lmCloneString(lm, wordsIn[i]); aRow->data = words; return aRow; } struct annoRow *annoRowWigNew(char *chrom, uint start, uint end, boolean rightJoinFail, float *values, struct lm *lm) /* Allocate & return an annoRowWig, with clone of values; length of values is (end-start). */ { struct annoRow *row; lmAllocVar(lm, row); row->chrom = lmCloneString(lm, chrom); row->start = start; row->end = end; row->data = lmCloneMem(lm, values, (end - start) * sizeof(values[0])); row->rightJoinFail = rightJoinFail; return row; } struct annoRow *annoRowClone(struct annoRow *rowIn, enum annoRowType rowType, int numCols, struct lm *lm) /* Allocate & return a single annoRow cloned from rowIn. If rowIn is NULL, return NULL. * If type is arWig, numCols is ignored. */ { if (rowIn == NULL) return NULL; -if (rowType == arWords || rowType == arVcf) +if (rowType == arWords) return annoRowFromStringArray(rowIn->chrom, rowIn->start, rowIn->end, rowIn->rightJoinFail, rowIn->data, numCols, lm); else if (rowType == arWig) return annoRowWigNew(rowIn->chrom, rowIn->start, rowIn->end, rowIn->rightJoinFail, (float *)rowIn->data, lm); else errAbort("annoRowClone: unrecognized type %d", rowType); return NULL; } int annoRowCmp(const void *va, const void *vb) /* Compare two annoRows' {chrom, start, end}. */ { struct annoRow *rowA = *((struct annoRow **)va); struct annoRow *rowB = *((struct annoRow **)vb); int dif = strcmp(rowA->chrom, rowB->chrom); if (dif == 0) { dif = rowA->start - rowB->start; if (dif == 0) dif = rowA->end - rowB->end; } return dif; }