04b879361227c44e9602945464b83e5346b5dd4f markd Tue Jul 19 22:38:07 2022 -0700 add option to output autoSql style header to bigBedNamedItems diff --git src/utils/bigBedToBed/bigBedToBed.c src/utils/bigBedToBed/bigBedToBed.c index 09edda0..eef6593 100644 --- src/utils/bigBedToBed/bigBedToBed.c +++ src/utils/bigBedToBed/bigBedToBed.c @@ -1,28 +1,29 @@ /* bigBedToBed - Convert from bigBed to ascii bed format.. */ /* Copyright (C) 2014 The Regents of the University of California * See kent/LICENSE or http://genome.ucsc.edu/license/ for licensing information. */ #include "common.h" #include "linefile.h" #include "hash.h" #include "options.h" #include "localmem.h" #include "udc.h" #include "bigBed.h" #include "asParse.h" #include "obscure.h" +#include "bigBedCmdSupport.h" char *clChrom = NULL; int clStart = -1; int clEnd = -1; int maxItems = 0; boolean header = FALSE; void usage() /* Explain usage and exit. */ { errAbort( "bigBedToBed v1 - Convert from bigBed to ascii bed format.\n" "usage:\n" " bigBedToBed input.bb output.bed\n" @@ -35,54 +36,37 @@ " -header - output a autoSql-style header (starts with '#').\n" ); } static struct optionSpec options[] = { {"chrom", OPTION_STRING}, {"start", OPTION_INT}, {"end", OPTION_INT}, {"maxItems", OPTION_INT}, {"udcDir", OPTION_STRING}, {"header", OPTION_BOOLEAN}, {NULL, 0}, }; -void writeHeader(struct bbiFile *bbi, FILE *f) -/* output a header from the autoSql in the file */ -{ -char *asText = bigBedAutoSqlText(bbi); -if (asText == NULL) - errAbort("bigBed files does not contain an autoSql schema"); -struct asObject *asObj = asParseText(asText); -char sep = '#'; -for (struct asColumn *asCol = asObj->columnList; asCol != NULL; asCol = asCol->next) - { - fputc(sep, f); - fputs(asCol->name, f); - sep = '\t'; - } -fputc('\n', f); -} - void bigBedToBed(char *inFile, char *outFile) /* bigBedToBed - Convert from bigBed to ascii bed format.. */ { struct bbiFile *bbi = bigBedFileOpen(inFile); FILE *f = mustOpen(outFile, "w"); if (header) - writeHeader(bbi, f); + bigBedCmdOutputHeader(bbi, f); struct bbiChromInfo *chrom, *chromList = bbiChromList(bbi); int itemCount = 0; for (chrom = chromList; chrom != NULL; chrom = chrom->next) { if (clChrom != NULL && !sameString(clChrom, chrom->name)) continue; char *chromName = chrom->name; int start = 0, end = chrom->size; if (clStart > 0) start = clStart; if (clEnd > 0) end = clEnd; int itemsLeft = 0; // Zero actually means no limit.... if (maxItems != 0) {