ec51eb191d235e9f9fcd5346825aaf0815c69cf6
kent
  Thu Mar 21 11:27:00 2013 -0700
Renaming bedOutputN_Opt into bedOutFlexible and making it a public function.
diff --git src/lib/basicBed.c src/lib/basicBed.c
index a651070..3c23a7a 100644
--- src/lib/basicBed.c
+++ src/lib/basicBed.c
@@ -437,63 +437,77 @@
 struct lineFile *lf = lineFileOpen(fileName, TRUE);
 char *line, *row[bedKnownFields];
 
 while (lineFileNextReal(lf, &line))
     {
     int numFields = chopByWhite(line, row, ArraySize(row));
     if (numFields < 4)
 	errAbort("file %s doesn't appear to be in bed format. At least 4 fields required, got %d", fileName, numFields);
     slAddHead(&list, bedLoadN(row, numFields));
     }
 lineFileClose(&lf);
 slReverse(&list);
 return list;
 }
 
-void bedLoadAllReturnFieldCount(char *fileName, struct bed **retList, int *retFieldCount)
+void bedLoadAllReturnFieldCountAndRgb(char *fileName, struct bed **retList, int *retFieldCount, 
+    boolean *retRgb)
 /* Load bed of unknown size and return number of fields as well as list of bed items.
- * Ensures that all lines in bed file have same field count. */
+ * Ensures that all lines in bed file have same field count.  Also returns whether 
+ * column 9 is being used as RGB or not. */
 {
 struct bed *list = NULL;
 struct lineFile *lf = lineFileOpen(fileName, TRUE);
 char *line, *row[bedKnownFields];
 int fieldCount = 0;
+boolean isRgb = FALSE;
 
 while (lineFileNextReal(lf, &line))
     {
     int numFields = chopByWhite(line, row, ArraySize(row));
     if (numFields < 4)
 	errAbort("file %s doesn't appear to be in bed format. At least 4 fields required, got %d", 
 		fileName, numFields);
     if (fieldCount == 0)
+	{
         fieldCount = numFields;
+	isRgb =  (strchr(row[8], ',') != NULL);
+	}
     else
         if (fieldCount != numFields)
 	    errAbort("Inconsistent number of fields in file. %d on line %d of %s, %d previously.",
 	        numFields, lf->lineIx, lf->fileName, fieldCount);
     slAddHead(&list, bedLoadN(row, fieldCount));
     }
 lineFileClose(&lf);
 slReverse(&list);
 *retList = list;
 *retFieldCount = fieldCount;
+if (retRgb != NULL)
+   *retRgb = isRgb;
+}
+
+void bedLoadAllReturnFieldCount(char *fileName, struct bed **retList, int *retFieldCount)
+/* Load bed of unknown size and return number of fields as well as list of bed items.
+ * Ensures that all lines in bed file have same field count. */
+{
+bedLoadAllReturnFieldCountAndRgb(fileName, retList, retFieldCount, NULL);
 }
 
-static void bedOutputN_Opt(struct bed *el, int wordCount, FILE *f,
+void bedOutFlexible(struct bed *el, int wordCount, FILE *f,
 	char sep, char lastSep, boolean useItemRgb)
-/* Write a bed of wordCount fields, optionally interpreting field nine
-	as R,G,B values. */
+/* Write a bed of wordCount fields, optionally interpreting field nine as R,G,B values. */
 {
 int i;
 if (sep == ',') fputc('"',f);
 fprintf(f, "%s", el->chrom);
 if (sep == ',') fputc('"',f);
 fputc(sep,f);
 fprintf(f, "%u", el->chromStart);
 fputc(sep,f);
 fprintf(f, "%u", el->chromEnd);
 if (wordCount <= 3)
     {
     fputc(lastSep, f);
     return;
     }
 fputc(sep,f);
@@ -607,38 +621,38 @@
 if (sep == ',') fputc('{',f);
 for (i=0; i<el->expCount; ++i)
     {
     fprintf(f, "%g", el->expScores[i]);
     fputc(',', f);
     }
 if (sep == ',') fputc('}',f);
 
 
 fputc(lastSep,f);
 }
 
 void bedOutputN(struct bed *el, int wordCount, FILE *f, char sep, char lastSep)
 /* Write a bed of wordCount fields. */
 {
-bedOutputN_Opt(el, wordCount, f, sep, lastSep, FALSE);
+bedOutFlexible(el, wordCount, f, sep, lastSep, FALSE);
 }
 
 void bedOutputNitemRgb(struct bed *el, int wordCount, FILE *f,
 	char sep, char lastSep)
 /* Write a bed of wordCount fields, interpret column 9 as RGB. */
 {
-bedOutputN_Opt(el, wordCount, f, sep, lastSep, TRUE);
+bedOutFlexible(el, wordCount, f, sep, lastSep, TRUE);
 }
 
 
 int bedTotalBlockSize(struct bed *bed)
 /* Return total size of all blocks. */
 {
 int total = 0;
 int i;
 if (bed->blockCount == 0)
     return bed->chromEnd - bed->chromStart;
 for (i=0; i<bed->blockCount; ++i)
     total += bed->blockSizes[i];
 return total;
 }