0ae26a1ef8d06bccf28f3e823220c64099eaeda9 ceisenhart Mon Sep 15 12:35:16 2014 -0700 Fixed comments and memory leak diff --git src/utils/bigWigCluster/bigWigCluster.c src/utils/bigWigCluster/bigWigCluster.c index f585fd8..7cad967 100644 --- src/utils/bigWigCluster/bigWigCluster.c +++ src/utils/bigWigCluster/bigWigCluster.c @@ -3,38 +3,46 @@ #include "common.h" #include "linefile.h" #include "hash.h" #include "options.h" #include "hacTree.h" #include "rainbow.h" void usage() /* Explain usage and exit. */ { errAbort( "bigWigCluster - Cluster bigWigs using a hactree\n" "usage:\n" " bigWigCluster input.list chrom.sizes output.json\n" "options:\n" + " -threads = int Sets the thread count for the multiThreads option, default is 10 \n" + " -hacTree = Dictates how the tree is generated; multiThreads or costlyMerges or fromItems. fromItems is default \n" ); } /* Command line validation table. */ static struct optionSpec options[] = { {NULL, 0}, + {"threads", OPTION_INT}, + {"hacTree", OPTION_STRING}, }; + + double longest = 0; +char* clHacTree = "fromItems"; +int clThreads = 10; // The number of threads to run with the multiThreads option int nameCount = 0; struct bigWig { struct bigWig *next; //next item in series char *name; //name of the bigWig filei struct rgbColor color; //for coloring }; struct bigWig *getBigWigs(char* input) // get the bigWig files { struct bigWig **list; AllocVar(list); @@ -168,31 +176,31 @@ { verbose(1,"Merging...\n"); ++ nameCount; struct bigWig *result; AllocVar(result); const struct bigWig *kid1 = (const struct bigWig *)item1; const struct bigWig *kid2 = (const struct bigWig *)item2; char cmd1[1024]; char cmd2[1024]; safef(cmd1, 1024, "bigWigMerge %s %s output -verbose=0", kid1->name, kid2->name); char name[1024]; safef(name,1024, "%i", nameCount); safef(cmd2, 1024, "bedGraphToBigWig output chrom.sizes %s", name); mustSystem(cmd1); mustSystem(cmd2); -result->name = name; +result->name = cloneString(name); return (struct slList *)result; } void colorLeaves(struct slRef *leafList) /* Assign colors of rainbow to leaves. */ { /* Loop through list once to figure out total, since we need to * normalize */ double total = 0; double purplePos = 0.80; struct slRef *el, *nextEl; for (el = leafList; el != NULL; el = nextEl) { nextEl = el->next; @@ -220,43 +228,59 @@ double normalized = soFar/total; bio2->color = saturatedRainbowAtPos(normalized * purplePos); } /* Set first color to correspond to 0, since not set in above loop */ struct bigWig *bio = leafList->val; bio->color = saturatedRainbowAtPos(0); } void bigWigCluster(char *inputList, char* chromSizes, char* output) /* bigWigCluster - Cluster bigWigs using a hactree. */ { struct bigWig *list = getBigWigs(inputList); FILE *f = mustOpen(output,"w"); struct lm *localMem = lmInit(0); -//struct hacTree *clusters = hacTreeFromItems((struct slList *)list, localMem, -// slBigWigDistance, slBigWigMerge,NULL, NULL); -//struct hacTree *clusters = hacTreeForCostlyMerges((struct slList *)list, localMem, -// slBigWigDistance, slBigWigMerge, NULL); -struct hacTree *clusters = hacTreeMultiThread(10 ,(struct slList *)list, localMem, +struct hacTree *clusters = NULL; +if (sameString(clHacTree, "multiThreads")) + { + clusters = hacTreeMultiThread(clThreads, (struct slList *)list, localMem, + slBigWigDistance, slBigWigMerge, NULL, NULL); + } +else if (sameString(clHacTree, "costlyMerges")) + { + clusters = hacTreeForCostlyMerges((struct slList *)list, localMem, slBigWigDistance, slBigWigMerge, NULL); + } +else if (sameString(clHacTree, "fromItems")) + { + clusters = hacTreeFromItems((struct slList *)list, localMem, + slBigWigDistance, slBigWigMerge, NULL, NULL); + } +else + { + uglyAbort("Unrecognized input option: %s", clHacTree); + } struct slRef *orderedList = getOrderedLeafList(clusters); colorLeaves(orderedList); printHierarchicalJson(f, clusters, 20, 20); // some cleanup int i; for (i = 0 ; i <= nameCount; ++i) { char name[1024]; safef(name,1024, "%i", i); remove(name); } } int main(int argc, char *argv[]) /* Process command line. */ { +clThreads = optionInt("threads", clThreads); +clHacTree = optionVal("hacTree", clHacTree); optionInit(&argc, argv, options); if (argc != 4) usage(); bigWigCluster(argv[1], argv[2], argv[3]); return 0; }