src/hg/encode/validateFiles/validateFiles.c 1.36

1.36 2010/03/21 18:03:25 braney
add support for validating bigWig
Index: src/hg/encode/validateFiles/validateFiles.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/encode/validateFiles/validateFiles.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -b -B -U 4 -r1.35 -r1.36
--- src/hg/encode/validateFiles/validateFiles.c	19 Mar 2010 23:16:37 -0000	1.35
+++ src/hg/encode/validateFiles/validateFiles.c	21 Mar 2010 18:03:25 -0000	1.36
@@ -6,8 +6,10 @@
 #include "jksql.h"
 #include "twoBit.h"
 #include "dnaseq.h"
 #include "bamFile.h"
+#include "bbiFile.h"
+#include "bigWig.h"
 
 static char const rcsid[] = "$Id$";
 static char *version = "$Revision$";
 
@@ -67,8 +69,10 @@
   "         csqual    : Colorspace quality (see link below)\n"
   "                     (see http://marketing.appliedbiosystems.com/mk/submit/SOLID_KNOWLEDGE_RD?_JS=T&rd=dm)\n"
   "         BAM       : Binary Alignment/Map\n"
   "                     (see http://samtools.sourceforge.net/SAM1.pdf)\n"
+  "         bigWig    : Big Wig\n"
+  "                     (see http://genome.ucsc.edu/goldenPath/help/bigWig.html\n"
   "\n"
   "   -chromDb=db                  Specify DB containing chromInfo table to validate chrom names\n"
   "                                  and sizes\n"
   "   -chromInfo=file.txt          Specify chromInfo file to validate chrom names and sizes\n"
@@ -1060,8 +1064,56 @@
 {
 return 0;
 }
 
+int validateBigWig(struct lineFile *lf, char *file)
+{
+if (chrHash == NULL)
+    errAbort("BAM validation requires the -chromInfo or -chromDb option\n");
+
+int errs = 0;
+struct bbiFile *bbiFile;
+bbiFile = bigWigFileOpen(file);
+
+if (bbiFile == NULL)
+    errAbort("Aborting... Cannot open bigWig file: %s\n", file);
+
+
+struct bbiChromInfo *bbiChroms = bbiChromList(bbiFile);
+
+if (bbiChroms == NULL)
+    errAbort("Aborting... cannot get bigWig chromosome list in file: %s\n", file);
+
+struct bbiChromInfo *chroms = bbiChroms;
+for(; chroms; chroms = chroms->next)
+    {
+    unsigned *size;
+
+    if ( (size = hashFindVal(chrHash, chroms->name)) == NULL)
+	{
+	printf("bigWig contains invalid chromosome name: %s\n", 
+	    chroms->name);
+	errs++;
+	}
+    else
+	{
+	if (*size != chroms->size)
+	    {
+	    printf("bigWig contains chromosome with wrong length: %s should be %d bases, not %d bases\n", 
+		chroms->name,
+		*size, chroms->size);
+	    errs++;
+	    }
+	}
+    }
+
+
+if (errs)
+    errAbort("Aborting... %d errors found in bigWig file\n", errs);
+
+return errs;
+}
+
 int validateBAM(struct lineFile *lf, char *file)
 {
 if (chrHash == NULL)
     errAbort("BAM validation requires the -chromInfo or -chromDb option\n");
@@ -1216,8 +1268,9 @@
 hashAdd(funcs, "narrowPeak",     &validateNarrowPeak);
 hashAdd(funcs, "gappedPeak",     &validateGappedPeak);
 hashAdd(funcs, "bedGraph",       &validateBedGraph);
 hashAdd(funcs, "BAM",            &validateBAM);
+hashAdd(funcs, "bigWig",         &validateBigWig);
 //hashAdd(funcs, "test", &testFunc);
 if (!(func = hashFindVal(funcs, type)))
     errAbort("Cannot validate %s type files\n", type);
 validateFiles(func, argc, argv);