5f9691856204ac8ee77795e1b9a89f82f825d2cd angie Fri Jun 1 14:39:34 2012 -0700 Feature #6152 (Variant Annotation Integrator): added getHeader methodto annoStreamer so formatters can include primary source's header in output -- header is a crucial part of some formats e.g. VCF. diff --git src/lib/annoStreamVcf.c src/lib/annoStreamVcf.c index b2e43b7..e0ffee1 100644 --- src/lib/annoStreamVcf.c +++ src/lib/annoStreamVcf.c @@ -18,30 +18,37 @@ //#*** streamer getHeader method?? }; static void asvSetRegion(struct annoStreamer *vSelf, char *chrom, uint regionStart, uint regionEnd) /* Set region -- and free current sqlResult if there is one. */ { annoStreamerSetRegion(vSelf, chrom, regionStart, regionEnd); struct annoStreamVcf *self = (struct annoStreamVcf *)vSelf; if (self->isTabix) lineFileSetTabixRegion(self->vcff->lf, chrom, regionStart, regionEnd); else if (chrom != NULL) errAbort("annoStreamVcf: setRegion not yet implemented for non-tabix VCF."); } +static char *asvGetHeader(struct annoStreamer *vSelf) +/* Return VCF header (e.g. for use by formatter) */ +{ +struct annoStreamVcf *self = (struct annoStreamVcf *)vSelf; +return cloneString(self->vcff->headerString); +} + static char **nextRowUnfiltered(struct annoStreamVcf *self) /* Get the next VCF record and put the row text into autoSql words. * Return pointer to self->asWords if we get a row, otherwise NULL. */ { char *words[self->numFileCols]; int wordCount; if ((wordCount = lineFileChop(self->vcff->lf, words)) <= 0) return NULL; lineFileExpectWords(self->vcff->lf, self->numFileCols, wordCount); int i; // First 8 columns are always in the VCF file: for (i = 0; i < 8; i++) { freeMem(self->asWords[i]); self->asWords[i] = cloneString(words[i]); @@ -110,26 +117,27 @@ int maxErr = -1; // don't errAbort on VCF format warnings/errs struct vcfFile *vcff; if (isTabix) vcff = vcfTabixFileMayOpen(fileOrUrl, NULL, 0, 0, maxErr, maxRecords); else vcff = vcfFileMayOpen(fileOrUrl, maxErr, maxRecords, FALSE); if (vcff == NULL) errAbort("Unable to open VCF: '%s'", fileOrUrl); struct annoStreamVcf *self; AllocVar(self); struct annoStreamer *streamer = &(self->streamer); struct asObject *asObj = vcfAsObj(); annoStreamerInit(streamer, asObj); streamer->rowType = arVcf; streamer->setRegion = asvSetRegion; +streamer->getHeader = asvGetHeader; streamer->nextRow = asvNextRow; streamer->close = asvClose; self->vcff = vcff; self->dyGt = dyStringNew(1024); self->isTabix = isTabix; self->numCols = slCount(asObj->columnList); self->numFileCols = 8; if (vcff->genotypeCount > 0) self->numFileCols = 9 + vcff->genotypeCount; return (struct annoStreamer *)self; }