56e6b83f725ff84cb71c0ce66aca02a5e1f519c8 kent Sun Mar 20 13:23:34 2011 -0700 Adding utility to calculate average bigWig value for a bed file. diff --git src/utils/bigWigMerge/bigWigMerge.c src/utils/bigWigMerge/bigWigMerge.c index 77e4059..cf6e5f8 100644 --- src/utils/bigWigMerge/bigWigMerge.c +++ src/utils/bigWigMerge/bigWigMerge.c @@ -79,86 +79,30 @@ int doublesTheSame(double *pt, int size) /* Return count of numbers at start that are the same as first number. */ { int sameCount = 1; int i; double x = pt[0]; for (i=1; i<size; ++i) { if (pt[i] != x) break; ++sameCount; } return sameCount; } -#ifdef OLD -void outputRangeAsBedGraph(FILE *f, char *chrom, struct range *range, - int *pBufAlloc, double **pBuf) -/* Output range (who's val is a list of bbiIntervals) to a bedGraph file. */ -{ -struct bbiInterval *iv, *ivList = range->val; -if (ivList->next == NULL) /* Special case of just one. */ - { - fprintf(f, "%s\t%d\t%d\t%g\n", chrom, ivList->start, ivList->end, ivList->val); - } -else if (allStartEndSame(ivList)) - { - double sum = 0; - for (iv = ivList; iv != NULL; iv = iv->next) - sum += ivList->val; - fprintf(f, "%s\t%d\t%d\t%g\n", chrom, ivList->start, ivList->end, sum); - } -else - { - /* Make sure that merge buffer is big enough */ - int start = range->start; - int size = range->end - start; - if (size > *pBufAlloc) - { - int newAlloc = *pBufAlloc * 2; - if (newAlloc < size) - newAlloc = size; - *pBuf = needHugeMemResize(*pBuf, newAlloc); - } - - /* Set bits of merge buffer we'll use to zero. */ - int i; - double *buf = *pBuf; - for (i=0; i<size; ++i) - buf[i] = 0.0; - - /* Loop through ivList folding into mergeBuf. */ - for (iv = ivList; iv != NULL; iv = iv->next) - { - double val = iv->val; - for (i=iv->start; i < iv->end; ++i) - buf[i-start] += val; - } - - /* Output each range of same values as a bedGraph item */ - int sameCount; - for (i=0; i<size; i += sameCount) - { - sameCount = doublesTheSame(buf+i, size-i); - fprintf(f, "%s\t%d\t%d\t%g\n", - chrom, start + i, start + i + sameCount, buf[i]); - } - } -} -#endif /* OLD */ - void bigWigMerge(int inCount, char *inFiles[], char *outFile) /* bigWigMerge - Merge together multiple bigWigs into a single one.. */ { /* Make a list of open bigWig files. */ struct bbiFile *inFile, *inFileList = NULL; int i; for (i=0; i<inCount; ++i) { inFile = bigWigFileOpen(inFiles[i]); slAddTail(&inFileList, inFile); } FILE *f = mustOpen(outFile, "w"); struct slName *chrom, *chromList = getAllChroms(inFileList);