f58379c1b0f0ee95e1bd0a6d2d59c8994e25b370 markd Mon Apr 8 19:54:35 2024 -0700 added option -asOut to bigBedInfo to output the autoSql only for reuse diff --git src/utils/bigBedInfo/bigBedInfo.c src/utils/bigBedInfo/bigBedInfo.c index f5f2df6..84e8317 100644 --- src/utils/bigBedInfo/bigBedInfo.c +++ src/utils/bigBedInfo/bigBedInfo.c @@ -14,55 +14,56 @@ #include "hmmstats.h" void usage() /* Explain usage and exit. */ { errAbort( "bigBedInfo - Show information about a bigBed file.\n" "usage:\n" " bigBedInfo file.bb\n" "options:\n" " -udcDir=/dir/to/cache - place to put cache for remote bigBed/bigWigs\n" " -chroms - list all chromosomes and their sizes\n" " -zooms - list all zoom levels and their sizes\n" " -as - get autoSql spec\n" + " -asOut - output only autoSql spec\n" " -extraIndex - list all the extra indexes\n" ); } static struct optionSpec options[] = { {"udcDir", OPTION_STRING}, {"chroms", OPTION_BOOLEAN}, {"zooms", OPTION_BOOLEAN}, {"as", OPTION_BOOLEAN}, + {"asOut", OPTION_BOOLEAN}, {"extraIndex", OPTION_BOOLEAN}, {NULL, 0}, }; void printLabelAndLongNumber(char *label, long long l) /* Print label: 1,234,567 format number */ { printf("%s: ", label); printLongWithCommas(stdout, l); printf("\n"); } -void bigBedInfo(char *fileName) -/* bigBedInfo - Show information about a bigBed file.. */ +static void bigBedInfoStandard(struct bbiFile *bbi) +/* output lots information about a bigBed file, standard output for humans */ { -struct bbiFile *bbi = bigBedFileOpen(fileName); printf("version: %d\n", bbi->version); printf("fieldCount: %d\n", bbi->fieldCount); printf("hasHeaderExtension: %s\n", (bbi->extensionOffset != 0 ? "yes" : "no")); printf("isCompressed: %s\n", (bbi->uncompressBufSize > 0 ? "yes" : "no")); printf("isSwapped: %d\n", bbi->isSwapped); printf("extraIndexCount: %d\n", bbi->extraIndexCount); if (optionExists("extraIndex")) { struct slName *el, *list = bigBedListExtraIndexes(bbi); for (el = list; el != NULL; el = el->next) { int fieldIx = 0; struct bptFile *bpt = bigBedOpenExtraIndex(bbi, el->name, &fieldIx); printf(" %s (field %d) with %lld items\n", el->name, fieldIx, (long long)bpt->itemCount); } @@ -111,27 +112,46 @@ } struct bbiSummaryElement sum = bbiTotalSummary(bbi); printLabelAndLongNumber("basesCovered", sum.validCount); double meanDepth = 0, depthStd = 0; if (sum.validCount > 0) { meanDepth = sum.sumData/sum.validCount; depthStd = calcStdFromSums(sum.sumData, sum.sumSquares, sum.validCount); } printf("meanDepth (of bases covered): %f\n", meanDepth); printf("minDepth: %f\n", sum.minVal); printf("maxDepth: %f\n", sum.maxVal); printf("std of depth: %f\n", depthStd); } +static void bigBedInfoAsOut(struct bbiFile *bbi) +/* print as schema, if it exists */ +{ +char *asText = bigBedAutoSqlText(bbi); +if (asText == NULL) + errAbort("bigBed does not have an autoSql schema"); +printf("%s", asText); +} + +void bigBedInfo(char *fileName) +/* bigBedInfo - Show information about a bigBed file.. */ +{ +struct bbiFile *bbi = bigBedFileOpen(fileName); +if (optionExists("asOut")) + bigBedInfoAsOut(bbi); +else + bigBedInfoStandard(bbi); +} + int main(int argc, char *argv[]) /* Process command line. */ { optionInit(&argc, argv, options); if (argc != 2) usage(); udcSetDefaultDir(optionVal("udcDir", udcDefaultDir())); bigBedInfo(argv[1]); if (verboseLevel() > 1) printVmPeak(); return 0; }