/* gcForBed - Calculate g/c percentage and other stats for regions covered by bed. */ #include "common.h" #include "linefile.h" #include "hash.h" #include "options.h" #include "bed.h" #include "dnautil.h" #include "nib.h" void usage() /* Explain usage and exit. */ { errAbort( "gcForBed - Calculate g/c percentage and other stats for regions covered by bed\n" "usage:\n" " gcForBed in.bed nibDir\n" "options:\n" " -xxx=XXX\n" ); } void gcForBed(char *bedName, char *nibDir) /* gcForBed - Calculate g/c percentage and * other stats for regions covered by bed. */ { char nibFile[512]; int wordCount; char *words[32]; struct lineFile *lf = lineFileOpen(bedName, TRUE); static double baseCounts[5], totalBases = 0; dnaUtilOpen(); while ((wordCount = lineFileChop(lf, words)) != 0) { struct bed *bed = bedLoadN(words, wordCount); struct dnaSeq *seq; int i, size; DNA *dna; sprintf(nibFile, "%s/%s.nib", nibDir, bed->chrom); seq = nibLoadPart(nibFile, bed->chromStart, bed->chromEnd - bed->chromStart); if (wordCount >= 6 && bed->strand[0] == '-') reverseComplement(seq->dna, seq->size); totalBases += seq->size; dna = seq->dna; size = seq->size; for (i=0; i