src/hg/utils/gapToLift/gapToLift.c 1.7

1.7 2009/03/09 16:43:40 hiram
Fixup counting of parts to be more accurate and a uniform %02d output
Index: src/hg/utils/gapToLift/gapToLift.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/utils/gapToLift/gapToLift.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -b -B -U 4 -r1.6 -r1.7
--- src/hg/utils/gapToLift/gapToLift.c	8 Nov 2007 20:03:59 -0000	1.6
+++ src/hg/utils/gapToLift/gapToLift.c	9 Mar 2009 16:43:40 -0000	1.7
@@ -157,18 +157,20 @@
 verbose(2,"#\tfound %d gaps\n", gapCount);
 return (gapList);
 }
 
-static void liftOutLine(FILE *out, char *chr, int start, int end,
+static int liftOutLine(FILE *out, char *chr, int start, int end,
     int count, int chrSize)
 {
 if ((end-start) > 0)
     {
-    fprintf(out, "%d\t%s.%d\t%d\t%s\t%d\n", start, chr,
+    fprintf(out, "%d\t%s.%02d\t%d\t%s\t%d\n", start, chr,
 	count, end-start, chr, chrSize);
     if (bedFile)
-	fprintf(bedFile, "%s\t%d\t%d\t%s.%d\n", chr, start, end, chr, count);
+	fprintf(bedFile, "%s\t%d\t%d\t%s.%02d\n", chr, start, end, chr, count);
+    count += 1;
     }
+return count;
 }
 
 static void gapToLift(char *db, char *outFile)
 /* gapToLift - create lift file from gap table(s). */
@@ -200,9 +202,9 @@
 		 *	or gap at end of chrom */
 	if (sameWord("no",gap->bridge) || (gap->chromEnd == chrSize))
 	    {
 	    end = gap->chromStart;
-	    liftOutLine(out, gap->chrom, start, end, liftCount++, chrSize);
+	    liftCount = liftOutLine(out, gap->chrom, start, end, liftCount, chrSize);
 	    start = gap->chromEnd;
 	    end = start;
 	    }
 	else
@@ -212,19 +214,20 @@
 	{ /* output last segment of previous chrom when necessary */
 	if (prevChr && differentWord(prevChr, gap->chrom))
 	    {
 	    if (end < chrSize)
-		liftOutLine(out, prevChr, start, chrSize, liftCount++, chrSize);
+		liftCount = liftOutLine(out, prevChr, start, chrSize, liftCount, chrSize);
 	    }
+	liftCount = 0;
 	chrSize = hashIntVal(cInfoHash, gap->chrom);
 	if (gap->chromStart > 0)
 	    {	/* starting first segment at position 0 */
 	    start = 0;
 	    end = gap->chromStart;
 	    /* does the first gap break it ?  Or gap goes to end of chrom. */
 	    if (sameWord("no",gap->bridge) || (gap->chromEnd == chrSize))
 		{
-		liftOutLine(out, gap->chrom, start, end, liftCount++, chrSize);
+		liftCount = liftOutLine(out, gap->chrom, start, end, liftCount, chrSize);
 		start = gap->chromEnd;
 		end = start;
 		}
 	    }
@@ -237,9 +240,9 @@
     prevChr = gap->chrom;	/* remember prev chrom to detect next chrom */
     }
 /* potentially a last one */
 if (end < chrSize)
-    liftOutLine(out, prevChr, start, chrSize, liftCount++, chrSize);
+    liftCount = liftOutLine(out, prevChr, start, chrSize, liftCount, chrSize);
 carefulClose(&out);
 sqlDisconnect(&conn);
 }