src/hg/utils/gapToLift/gapToLift.c 1.8

1.8 2009/08/10 20:58:59 hiram
Properly output lift and bed lines for chroms that have no gaps
Index: src/hg/utils/gapToLift/gapToLift.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/utils/gapToLift/gapToLift.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -b -B -U 4 -r1.7 -r1.8
--- src/hg/utils/gapToLift/gapToLift.c	9 Mar 2009 16:43:40 -0000	1.7
+++ src/hg/utils/gapToLift/gapToLift.c	10 Aug 2009 20:58:59 -0000	1.8
@@ -19,9 +19,10 @@
   "       generates lift file segements separated by non-bridged gaps.\n"
   "options:\n"
   "   -chr=chrN - work only on given chrom\n"
   "   -insane - do *not* perform coordinate sanity checks on gaps\n"
-  "   -bedFile=fileName.bed - output segments to fileName.bed"
+  "   -bedFile=fileName.bed - output segments to fileName.bed\n"
+  "   -verbose=N - N > 1 see more information about procedure"
   );
 }
 
 /* options */
@@ -184,8 +185,11 @@
 int end = 0;
 char *prevChr = NULL;
 int liftCount = 0;
 int chrSize = 0;
+static struct hash *chrDone = NULL;
+
+chrDone = newHash(0);
 
 if (isNotEmpty(bedFileName))
     {
     bedFile = mustOpen(bedFileName, "w");
@@ -218,8 +222,9 @@
 		liftCount = liftOutLine(out, prevChr, start, chrSize, liftCount, chrSize);
 	    }
 	liftCount = 0;
 	chrSize = hashIntVal(cInfoHash, gap->chrom);
+	hashAddInt(chrDone, gap->chrom, 1);
 	if (gap->chromStart > 0)
 	    {	/* starting first segment at position 0 */
 	    start = 0;
 	    end = gap->chromStart;
@@ -241,8 +246,20 @@
     }
 /* potentially a last one */
 if (end < chrSize)
     liftCount = liftOutLine(out, prevChr, start, chrSize, liftCount, chrSize);
+/* check that all chroms have been used */
+struct hashCookie cookie = hashFirst(cInfoHash);
+struct hashEl *hel;
+while ((hel = hashNext(&cookie)) != NULL)
+    {
+    if (NULL == hashLookup(chrDone, hel->name))
+	{
+	chrSize = hashIntVal(cInfoHash, hel->name);
+	verbose(2, "#\tno gaps on chrom: %s, size: %d\n", hel->name, chrSize);
+	liftCount = liftOutLine(out, hel->name, 0, chrSize, 0, chrSize);
+	}
+    }
 carefulClose(&out);
 sqlDisconnect(&conn);
 }