f7f5b164d6bacfd8da9b8f7772497ef971f2b0f8
galt
  Fri Dec 19 11:37:31 2025 -0800
Add options -chrom -start -end -range -bed -positions -udcDir to bigMafToMaf. Adds -positions to bigBedToBed. Moved parsePosition and parseRange routines into common.c so they could be shared with these and other utilities. -range has one 0-based start on commandline. -positions is a file with a list of 1-based starts. fixes #28109

diff --git src/lib/common.c src/lib/common.c
index 9ce000d7c34..756bf50236b 100644
--- src/lib/common.c
+++ src/lib/common.c
@@ -3951,15 +3951,69 @@
 return cloneString(g15buffer);
 }
 
 struct hash *loadSizes(char *sizesFile)
 /* load a sizes file */
 {
 struct hash *sizes = hashNew(20);
 struct lineFile *lf = lineFileOpen(sizesFile, TRUE);
 char *cols[2];
 
 while (lineFileNextRowTab(lf, cols, ArraySize(cols)))
     hashAddInt(sizes, cols[0], sqlUnsigned(cols[1]));
 lineFileClose(&lf);
 return sizes;
 }
+
+boolean parseRange(char *range, char **retSeq, int *retStart, int *retEnd)
+/* Parse seq:start-end into components. */
+{
+char *s, *e;
+s = strchr(range, ':');
+if (s == NULL)
+    return FALSE;
+*s++ = 0;
+e = strchr(s, '-');
+if (e == NULL)
+    return FALSE;
+*e++ = 0;
+if (!isdigit(s[0]) || !isdigit(e[0]))
+    return FALSE;
+*retSeq = range;
+*retStart = atoi(s);
+*retEnd = atoi(e);
+return TRUE;
+}
+
+void mustParseRange(char *range, char **retSeq, int *retStart, int *retEnd)
+/* Parse seq:start-end or die. */
+{
+if (!parseRange(range, retSeq, retStart, retEnd))
+    errAbort("Malformed range %s", range);
+}
+
+boolean parsePosition(char *position, char **retChrom, uint *retStart, uint *retEnd)
+/* If position is word:number-number (possibly with commas & whitespace),
+ * set retChrom, retStart (subtracting 1) and retEnd, and return TRUE.
+ * Otherwise return FALSE and leave rets unchanged. */
+{
+char *chrom = cloneString(position);
+stripChar(chrom, ',');
+eraseWhiteSpace(chrom);
+char *startStr = strchr(chrom, ':');
+if (startStr == NULL)
+    return FALSE;
+*startStr++ = '\0';
+char *endStr = strchr(startStr, '-');
+if (endStr == NULL)
+    return FALSE;
+*endStr++ = '\0';
+if (!isAllDigits(startStr))
+    return FALSE;
+if (!isAllDigits(endStr))
+    return FALSE;
+*retChrom = chrom;
+*retStart = sqlUnsigned(startStr) - 1;
+*retEnd = sqlUnsigned(endStr);
+return TRUE;
+}
+