src/hg/bedItemOverlapCount/bedItemOverlapCount.c 1.13

1.13 2009/04/23 00:31:12 larrym
modify code to support the normal two column chromSize file format
Index: src/hg/bedItemOverlapCount/bedItemOverlapCount.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/bedItemOverlapCount/bedItemOverlapCount.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -b -B -U 4 -r1.12 -r1.13
--- src/hg/bedItemOverlapCount/bedItemOverlapCount.c	21 Apr 2009 23:02:25 -0000	1.12
+++ src/hg/bedItemOverlapCount/bedItemOverlapCount.c	23 Apr 2009 00:31:12 -0000	1.13
@@ -50,13 +50,13 @@
   "   -chromSize=sizefile\tRead chrom sizes from file instead of database\n"
   "   -host=hostname\tmysql host used to get chrom sizes\n"
   "   -user=username\tmysql user\n"
   "   -password=password\tmysql password\n\n"
-  "\tchromSize file is three white space separated fields per line: chrom name, size, and dummy value\n"
+  "\tchromSize file contains two white space separated fields per line: chrom name and size\n"
   "\tYou will want to separate your + and - strand\n"
   "\titems before sending into this program as it only looks at\n"
   "\tthe chrom, start and end columns of the bed file.\n"
-  "\tIt requires a <database> connection to lookup chrom sizes for a sanity\n"
+  "\tProgram requires a <database> connection to lookup chrom sizes for a sanity\n"
   "\tcheck of the incoming data (unless you use -chromSize argument).\n\n"
   "The bed file must be sorted at least by chrom since the processing is\n"
   "\tgoing to be chrom by chrom with no going back.\n"
   " *** AND *** this is only for simple bed files without multiple blocks. ***"
@@ -157,17 +157,19 @@
 
 if (chromSizes != NULL)
     {
     chromHash = newHash(0);
-    // unfortunately, chromInfoLoadAll requires that the file have three fields (I don't know why),
-    // so that's why we require a dummy third column in the chromInfo file.
-    struct chromInfo *el = chromInfoLoadAll(chromSizes);
-    for(;el != NULL;el=el->next)
-        {
-        if (el->size > maxChromSize) maxChromSize = el->size;
-        verbose(4, "Add hash %s value %u (%#lx)\n", el->chrom, el->size, (unsigned long)&el->size);
-        hashAdd(chromHash, el->chrom, (void *)(& el->size));
+    struct lineFile *lf = lineFileOpen(chromSizes, TRUE);
+    char *row[2];
+    while (lineFileRow(lf, row))
+        {
+        unsigned *ptr;
+        AllocVar(ptr);
+        *ptr = sqlUnsigned(row[1]);
+        maxChromSize = max(*ptr, maxChromSize);
+        hashAdd(chromHash, row[0], ptr);
         }
+    lineFileClose(&lf);
     }
 else
     {
     chromHash = loadAllChromInfo(database, &maxChromSize);