diff --git a/TODO.txt b/TODO.txt index 234327a..6422bc4 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,7 +1,6 @@ Hold fire on writers Seekable apply_paste -Memory tracking & cleaning of chrom labels -Read strand in BigBed files? +Memory tracking & cleaning of chrom labels for text files Read score in BigBed files? => Handling overlapping iterators with value in unit and filter Read data in VCF file? HMM app? (requires reverse iterators...) diff --git a/src/apply.c b/src/apply.c index 1f11166..43f8f49 100644 --- a/src/apply.c +++ b/src/apply.c @@ -277,9 +277,7 @@ void computeApplyValues(Multiplexer * apply, ApplyMultiplexerData * data, Buffer apply->values[i] = *((double*) (wi->data)); WiggleIterator * tmp = wi; wi = wi->append; - if (tmp->data) - free(tmp->data); - free(tmp); + destroyWiggleIterator(tmp); i++; } } else diff --git a/src/bedReader.c b/src/bedReader.c index e22c6e0..59a0941 100644 --- a/src/bedReader.c +++ b/src/bedReader.c @@ -120,7 +120,7 @@ WiggleIterator * BedReader(char * filename) { fprintf(stderr, "Could not open bed file %s\n", filename); exit(1); } - WiggleIterator * res = newWiggleIterator(data, &BedReaderPop, &BedReaderSeek, 0); + WiggleIterator * res = newWiggleIteratorChromName(data, &BedReaderPop, &BedReaderSeek, 0); res->overlaps = true; return res; } diff --git a/src/samReader.c b/src/samReader.c index d987837..d393481 100644 --- a/src/samReader.c +++ b/src/samReader.c @@ -222,5 +222,5 @@ WiggleIterator * SamReader(char * filename) { } } else data->file = stdin; - return newWiggleIterator(data, &SamReaderPop, &SamReaderSeek, 0); + return newWiggleIteratorChromName(data, &SamReaderPop, &SamReaderSeek, 0); } diff --git a/src/unaryOps.c b/src/unaryOps.c index 9a22714..27d2444 100644 --- a/src/unaryOps.c +++ b/src/unaryOps.c @@ -306,7 +306,7 @@ void CoverageWiggleIteratorPop(WiggleIterator * wi) { CoverageWiggleIteratorData * data = (CoverageWiggleIteratorData *) wi->data; WiggleIterator * iter = data->iter; if (!iter->done) { - if (wi->chrom[0] == '\0') + if (wi->chrom == NULL) wi->value = 0; while (fh_notempty(data->heap) && fh_min(data->heap) == wi->finish) { diff --git a/src/vcfReader.c b/src/vcfReader.c index 23edaa5..963f52a 100644 --- a/src/vcfReader.c +++ b/src/vcfReader.c @@ -95,7 +95,7 @@ WiggleIterator * VcfReader(char * filename) { fprintf(stderr, "Could not open bed file %s\n", filename); exit(1); } - WiggleIterator * res = newWiggleIterator(data, &VcfReaderPop, &VcfReaderSeek, 0); + WiggleIterator * res = newWiggleIteratorChromName(data, &VcfReaderPop, &VcfReaderSeek, 0); res->value = 1; res->overlaps = true; return res; diff --git a/src/wigReader.c b/src/wigReader.c index 6d10ac2..1b9becd 100644 --- a/src/wigReader.c +++ b/src/wigReader.c @@ -245,5 +245,5 @@ WiggleIterator * WiggleReader(char * f) { data->file = stdin; data->readingMode = BED_GRAPH; data->stop = -1; - return CompressionWiggleIterator(newWiggleIterator(data, &WiggleReaderPop, &WiggleReaderSeek, 0)); + return CompressionWiggleIterator(newWiggleIteratorChromName(data, &WiggleReaderPop, &WiggleReaderSeek, 0)); } diff --git a/src/wiggleIterator.c b/src/wiggleIterator.c index 594da75..172f119 100644 --- a/src/wiggleIterator.c +++ b/src/wiggleIterator.c @@ -18,6 +18,22 @@ #include "wiggleIterator.h" WiggleIterator * newWiggleIterator(void * data, void (*popFunction)(WiggleIterator *), void (*seek)(WiggleIterator *, const char *, int, int), double default_value) { + WiggleIterator * new = (WiggleIterator *) calloc(1, sizeof(WiggleIterator)); + new->data = data; + new->pop = popFunction; + new->seek = seek; + new->chrom = NULL; + new->value = 1; // Default value for non-valued bed tracks; + new->strand = 0; // Default value for non-stranded data; + new->valuePtr = NULL; + new->overlaps = false; + new->append = NULL; + new->default_value = default_value; + pop(new); + return new; +} + +WiggleIterator * newWiggleIteratorChromName(void * data, void (*popFunction)(WiggleIterator *), void (*seek)(WiggleIterator *, const char *, int, int), double default_value) { WiggleIterator * new = (WiggleIterator *) calloc(1, sizeof(WiggleIterator)); new->data = data; new->pop = popFunction; @@ -35,7 +51,6 @@ WiggleIterator * newWiggleIterator(void * data, void (*popFunction)(WiggleIterat void destroyWiggleIterator(WiggleIterator * wi) { free(wi->data); - free(wi->chrom); free(wi); } diff --git a/src/wiggleIterator.h b/src/wiggleIterator.h index fcd2c50..0d14f16 100644 --- a/src/wiggleIterator.h +++ b/src/wiggleIterator.h @@ -35,6 +35,7 @@ struct wiggleIterator_st { }; WiggleIterator * newWiggleIterator(void * data, void (*pop)(WiggleIterator *), void (*seek)(WiggleIterator *, const char *, int, int), double default_value); +WiggleIterator * newWiggleIteratorChromName(void * data, void (*popFunction)(WiggleIterator *), void (*seek)(WiggleIterator *, const char *, int, int), double default_value); void pop(WiggleIterator *); WiggleIterator * CompressionWiggleIterator(WiggleIterator *);