e2ff040d76c018b4207c9eb819c898b0fde42dbf kent Mon Dec 2 16:17:28 2013 -0800 Removing lineFileNextRealWithSize - it was buggy and hard to fix in general case, and only one module was using it. Replaced it with something local to fastqStatsAndSubsample.c. diff --git src/utils/fastqStatsAndSubsample/fastqStatsAndSubsample.c src/utils/fastqStatsAndSubsample/fastqStatsAndSubsample.c index 7c02a7d..64f5745 100644 --- src/utils/fastqStatsAndSubsample/fastqStatsAndSubsample.c +++ src/utils/fastqStatsAndSubsample/fastqStatsAndSubsample.c @@ -151,49 +151,78 @@ for (i=0; i<aSize; ++i) fprintf(f, "%g,", a[i]/totalAtPos[i]); fprintf(f, "\n"); } void printAveIntArray(FILE *f, char *label, int *a, long long *totalAtPos, int aSize) /* Print a[i]/totalAtPos[i] for all elements in array */ { fprintf(f, "%s ", label); int i; for (i=0; i<aSize; ++i) fprintf(f, "%g,", ((double)a[i])/totalAtPos[i]); fprintf(f, "\n"); } +static boolean isAllSpace(char *s, int size) +/* Return TRUE if all characters in s are whitespace */ +{ +while (--size >= 0) + { + char c = *s++; + if (!isspace(c)) + return FALSE; + } +return TRUE; +} + +boolean lineFileNextRealWithSize(struct lineFile *lf, char **retStart, int *retSize) +/* Fetch next line from file that is not blank and + * does not start with a '#'. Return size of line. + * Not putting this into library because it's hard to get right for both retSize NULL + * and non-NULL. This case only works with retSize non-NULL. */ +{ +while (lineFileNext(lf, retStart, retSize)) + { + if (isAllSpace(*retStart, *retSize)) + continue; + return TRUE; + } +return FALSE; +} + boolean oneFastqRecord(struct lineFile *lf, FILE *f, boolean copy, boolean firstTime) /* Read next fastq record from LF, and optionally copy it to f. Return FALSE at end of file * Do a _little_ error checking on record while we're at it. The format has already been * validated on the client side fairly thoroughly. */ { char *line; int lineSize; /* Treat NULL file same as non-copy, so only have one condition to check on . */ if (f == NULL) copy = FALSE; /* Deal with initial line starting with '@' */ if (!lineFileNextRealWithSize(lf, &line, &lineSize)) return FALSE; if (line[0] != '@') - errAbort("Expecting line starting with '@' got %s line %d of %s", + { + errAbort("Expecting line starting with '@' got %s line %d of %s (ugh!)", line, lf->lineIx, lf->fileName); + } if (copy) mustWrite(f, line, lineSize); /* Deal with line containing sequence. */ if (!lineFileNext(lf, &line, &lineSize)) errAbort("%s truncated in middle of record", lf->fileName); /* Get size and add it to stats */ int seqSize = lineSize-1; if (seqSize > MAX_READ_SIZE) errAbort("Sequence size %d too long line %d of %s. Max is %d", seqSize, lf->lineIx, lf->fileName, MAX_READ_SIZE); if (firstTime) { maxReadBases = minReadBases = seqSize;