src/utils/bigBedSummary/bigBedSummary.c 1.4
1.4 2009/03/15 00:18:23 kent
Adding fields flag.
Index: src/utils/bigBedSummary/bigBedSummary.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/utils/bigBedSummary/bigBedSummary.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -b -B -U 4 -r1.3 -r1.4
--- src/utils/bigBedSummary/bigBedSummary.c 5 Feb 2009 20:49:48 -0000 1.3
+++ src/utils/bigBedSummary/bigBedSummary.c 15 Mar 2009 00:18:23 -0000 1.4
@@ -4,8 +4,9 @@
#include "hash.h"
#include "options.h"
#include "sqlNum.h"
#include "bigBed.h"
+#include "asParse.h"
static char const rcsid[] = "$Id$";
char *summaryType = "coverage";
@@ -24,13 +25,17 @@
" coverage - %% of region that is covered (default)\n"
" mean - average depth of covered regions\n"
" min - minimum depth of covered regions\n"
" max - maximum depth of covered regions\n"
+ " -fields - print out information on fields in file.\n"
+ " If fields option is used, the chrom, start, end, dataPoints\n"
+ " parameters may be omitted\n"
);
}
static struct optionSpec options[] = {
{"type", OPTION_STRING},
+ {"fields", OPTION_BOOLEAN},
{NULL, 0},
};
void bigBedSummary(char *fileName, char *chrom, int start, int end, int dataPoints)
@@ -42,9 +47,10 @@
int i;
for (i=0; i<dataPoints; ++i)
summaryValues[i] = nan0;
-if (bigBedSummaryArray(fileName, chrom, start, end, bbiSummaryTypeFromString(summaryType),
+struct bbiFile *bbi = bigBedFileOpen(fileName);
+if (bigBedSummaryArray(bbi, chrom, start, end, bbiSummaryTypeFromString(summaryType),
dataPoints, summaryValues))
{
for (i=0; i<dataPoints; ++i)
{
@@ -61,16 +67,47 @@
else
{
errAbort("no data in region %s:%d-%d in %s\n", chrom, start, end, fileName);
}
+bbiFileClose(&bbi);
+}
+
+
+void bigBedFields(char *fileName)
+/* Print out info about fields in bed file. */
+{
+struct bbiFile *bbi = bigBedFileOpen(fileName);
+printf("%d bed definition fields, %d total fields\n", bbi->definedFieldCount, bbi->fieldCount);
+struct asObject *as = bigBedAs(bbi);
+if (as != NULL)
+ {
+ struct asColumn *col;
+ for (col = as->columnList; col != NULL; col = col->next)
+ {
+ printf("\t%s\t%s\n", col->name, col->comment);
+ }
+ }
+else
+ {
+ printf("No additional field information included.\n");
+ }
}
int main(int argc, char *argv[])
/* Process command line. */
{
optionInit(&argc, argv, options);
-summaryType = optionVal("type", summaryType);
-if (argc != 6)
+if (optionExists("fields"))
+ {
+ if (argc < 2)
+ usage();
+ bigBedFields(argv[1]);
+ }
+else
+ {
+ summaryType = optionVal("type", summaryType);
+ if (argc != 6)
usage();
-bigBedSummary(argv[1], argv[2], sqlUnsigned(argv[3]), sqlUnsigned(argv[4]), sqlUnsigned(argv[5]));
+ bigBedSummary(argv[1], argv[2], sqlUnsigned(argv[3]), sqlUnsigned(argv[4]), sqlUnsigned(argv[5]));
+ }
return 0;
}