61ba0f65282f7de325bb658bb7862b1338ea9ce1
hiram
  Fri Feb 28 14:21:19 2020 -0800
add tab and score options to allow for space in names and to allow score setting refs #23891

diff --git src/hg/genePredToBed/genePredToBed.c src/hg/genePredToBed/genePredToBed.c
index 7cda352..8d982c0 100644
--- src/hg/genePredToBed/genePredToBed.c
+++ src/hg/genePredToBed/genePredToBed.c
@@ -1,72 +1,86 @@
 /* genePredToBed - Convert from genePred to bed format.. */
 
 /* Copyright (C) 2013 The Regents of the University of California 
  * See README in this or parent directory for licensing information. */
 #include "common.h"
 #include "linefile.h"
 #include "hash.h"
 #include "options.h"
 #include "genePred.h"
 
 void usage()
 /* Explain usage and exit. */
 {
 errAbort(
   "genePredToBed - Convert from genePred to bed format. Does not yet handle genePredExt\n"
   "usage:\n"
   "   genePredToBed in.genePred out.bed\n"
   "options:\n"
-  "   -xxx=XXX\n"
+  "   -tab - genePred fields are separated by tab instead of just white space\n"
+  "   -score=N - set score to N in bed output (default 0)"
   );
 }
 
 /* Command line validation table. */
 static struct optionSpec options[] = {
+   {"tab", OPTION_BOOLEAN},
+   {"score", OPTION_INT},
    {NULL, 0},
 };
 
+boolean tabSep = FALSE;
+int defaultScore = 0;
+
 void convertGenePredToBed(char *inFile, char *outFile)
 /* genePredToBed - Convert from genePred to bed format.. */
 {
-struct genePred *gp, *gpList= genePredLoadAll(inFile);
+struct genePred *gp = NULL;
+struct genePred *gpList = NULL;
+if (tabSep)
+  gpList= genePredLoadAllByChar(inFile, '\t');
+else
+  gpList= genePredLoadAll(inFile);
+
 FILE *f = mustOpen(outFile, "w");
 for (gp = gpList; gp != NULL; gp = gp->next)
     {
     /* Print scalar bed fields. */
     fprintf(f, "%s\t", gp->chrom);
     fprintf(f, "%u\t", gp->txStart);
     fprintf(f, "%u\t", gp->txEnd);
     fprintf(f, "%s\t", gp->name);
-    fprintf(f, "%u\t", 0);
+    fprintf(f, "%u\t", defaultScore);
     fprintf(f, "%s\t", gp->strand);
     fprintf(f, "%u\t", gp->cdsStart);
     fprintf(f, "%u\t", gp->cdsEnd);
     fprintf(f, "%u\t", 0);
     fprintf(f, "%u\t", gp->exonCount);
 
     /* Print exon-by-exon fields. */
     int i;
 
     /* Print exon sizes */
     for (i=0; i<gp->exonCount; ++i)
         fprintf(f, "%u,", gp->exonEnds[i] - gp->exonStarts[i]);
     fprintf(f, "\t");
 
     /* Print exons starts */
     for (i=0; i<gp->exonCount; ++i)
 	fprintf(f, "%u,", gp->exonStarts[i] - gp->txStart);
     fprintf(f, "\n");
     }
 carefulClose(&f);
 }
 
 
 int main(int argc, char *argv[])
 /* Process command line. */
 {
 optionInit(&argc, argv, options);
 if (argc != 3)
     usage();
+tabSep = optionExists("tab");
+defaultScore = optionInt("score", defaultScore);
 convertGenePredToBed(argv[1], argv[2]);
 return 0;
 }