src/lib/basicBed.c 1.3
1.3 2010/03/03 07:52:22 markd
allow bedLoadAll to read from pipe by not closing and reopening
Index: src/lib/basicBed.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/basicBed.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -b -B -U 4 -r1.2 -r1.3
--- src/lib/basicBed.c 29 Jun 2009 20:29:44 -0000 1.2
+++ src/lib/basicBed.c 3 Mar 2010 07:52:22 -0000 1.3
@@ -434,28 +434,19 @@
* a tab-separated file. Dispose of this with bedFreeList(). */
{
struct bed *list = NULL;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
-int numFields = 0;
-char *line = NULL;
-/* First peek to see how many columns in the bed file. */
-lineFileNextReal(lf, &line);
-
-/* If there is something in the file then read it. If file
- is empty return NULL. */
-if(line != NULL)
- {
- numFields = chopByWhite(line, NULL, 0);
- lineFileClose(&lf);
- if(numFields < 4) /* Minimum number of fields. */
- errAbort("file %s doesn't appear to be in bed format. At least 4 fields required, got %d",
- fileName, numFields);
- /* Now load them up with that number of fields. */
- list = bedLoadNAll(fileName, numFields);
- }
-else
- lineFileClose(&lf);
+char *line, *row[bedKnownFields];
+while (lineFileNext(lf, &line, NULL))
+ {
+ 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;
}
static void bedOutputN_Opt(struct bed *el, int wordCount, FILE *f,