23deae9a8968d022d59a3cbf0be387616ed68fe7 kent Thu Jan 10 15:15:44 2013 -0800 Changing setMaxAlloc default to 100G, and making an undocumented maxGigs command line option to address bedGraphToBigWigh memory issue in redmine #9935 diff --git src/utils/bedGraphToBigWig/bedGraphToBigWig.c src/utils/bedGraphToBigWig/bedGraphToBigWig.c index 1863586..d9e6c75 100644 --- src/utils/bedGraphToBigWig/bedGraphToBigWig.c +++ src/utils/bedGraphToBigWig/bedGraphToBigWig.c @@ -1,65 +1,69 @@ /* bedGraphToBigWig - Convert a bedGraph program to bigWig.. */ #include "common.h" #include "obscure.h" +#include "memalloc.h" #include "linefile.h" #include "localmem.h" #include "hash.h" #include "options.h" #include "sqlNum.h" #include "dystring.h" #include "cirTree.h" #include "sig.h" #include "zlibFace.h" #include "bPlusTree.h" #include "bbiFile.h" #include "bwgInternal.h" #include "bigWig.h" static int blockSize = 256; static int itemsPerSlot = 1024; static boolean doCompress = FALSE; +static int maxGigs = 100; // Maximum number of gigs to allocate in one block. + // Undocumented on purpose. void usage() /* Explain usage and exit. */ { errAbort( "bedGraphToBigWig v %d - Convert a bedGraph file to bigWig format.\n" "usage:\n" " bedGraphToBigWig in.bedGraph chrom.sizes out.bw\n" "where in.bedGraph is a four column file in the format:\n" " <chrom> <start> <end> <value>\n" "and chrom.sizes is two column: <chromosome name> <size in bases>\n" "and out.bw is the output indexed big wig file.\n" "Use the script: fetchChromSizes to obtain the actual chrom.sizes information\n" "from UCSC, please do not make up a chrom sizes from your own information.\n" "The input bedGraph file must be sorted, use the unix sort command:\n" " sort -k1,1 -k2,2n unsorted.bedGraph > sorted.bedGraph\n" "options:\n" " -blockSize=N - Number of items to bundle in r-tree. Default %d\n" " -itemsPerSlot=N - Number of data points bundled at lowest level. Default %d\n" " -unc - If set, do not use compression." , bbiCurrentVersion, blockSize, itemsPerSlot ); } static struct optionSpec options[] = { {"blockSize", OPTION_INT}, {"itemsPerSlot", OPTION_INT}, {"unc", OPTION_BOOLEAN}, + {"maxGigs", OPTION_INT}, {NULL, 0}, }; struct sectionItem /* An item in a section of a bedGraph. */ { bits32 start, end; /* Position in chromosome, half open. */ float val; /* Single precision value. */ }; void writeSections(struct bbiChromUsage *usageList, struct lineFile *lf, int itemsPerSlot, struct bbiBoundsArray *bounds, int sectionCount, FILE *f, int resTryCount, int resScales[], int resSizes[], boolean doCompress, bits32 *retMaxSectionSize) /* Read through lf, chunking it into sections that get written to f. Save info @@ -537,25 +541,27 @@ fseek(f, totalSummaryOffset, SEEK_SET); bbiSummaryElementWrite(f, &totalSum); /* Write end signature. */ fseek(f, 0L, SEEK_END); writeOne(f, sig); lineFileClose(&lf); carefulClose(&f); } int main(int argc, char *argv[]) /* Process command line. */ { optionInit(&argc, argv, options); +maxGigs = optionInt("maxGigs", maxGigs); +setMaxAlloc(maxGigs*1000000000L); blockSize = optionInt("blockSize", blockSize); itemsPerSlot = optionInt("itemsPerSlot", itemsPerSlot); doCompress = !optionExists("unc"); if (argc != 4) usage(); bedGraphToBigWig(argv[1], argv[2], argv[3]); if (verboseLevel() > 1) printVmPeak(); return 0; }