43bbf45d9f7b380ea7394b7a8628be0ad3ae1b8e
angie
  Tue Jul 5 16:10:06 2011 -0700
MLQ #4463 (problem w/intersection):enabling intersection for bigWig uncovered a couple new bugs:

1. The secondary-table-fetching code didn't handle the bigWig case.
Fix: added bigWigIntervalsToBed and hooked it up in bitsForIntersectingTable.

2. The code for intersecting w/bigWig primary table had been written
but never tested, and the code for incompletely covered items from the
primary table was incorrect.

diff --git src/hg/hgTables/intersect.c src/hg/hgTables/intersect.c
index 7a935a5..1d36f68 100644
--- src/hg/hgTables/intersect.c
+++ src/hg/hgTables/intersect.c
@@ -499,31 +499,38 @@
 	    bed->blockSizes[0] = bed->chromEnd - bed->chromStart;
 	    }
 	}
 }
 
 Bits *bitsForIntersectingTable(struct sqlConnection *conn, struct region *region, int chromSize,
 	boolean isBpWise)
 /* Get a bitmap that corresponds to the table we are intersecting with.
  * Consult CGI vars to figure out what table it is. */
 {
 boolean invTable2 = cartCgiUsualBoolean(cart, hgtaInvertTable2, FALSE);
 char *table2 = cartString(cart, hgtaIntersectTable);
 struct hTableInfo *hti2 = getHti(database, table2, conn);
 struct lm *lm2 = lmInit(64*1024);
 Bits *bits2 = bitAlloc(chromSize+8);
-struct bed *bedList2 = getFilteredBeds(conn, table2, region, lm2, NULL);
+struct bed *bedList2;
+if (isBigWigTable(table2))
+    bedList2 = bigWigIntervalsToBed(conn, table2, region, lm2);
+else
+    // We should go straight to raw beds here, not through the routines that
+    // do filter & intersections, because the secondary table has no filter
+    // and sure shouldn't be intersected. :)
+    bedList2 = getFilteredBeds(conn, table2, region, lm2, NULL);
 if (!isBpWise)
     expandZeroSize(bedList2, hti2->hasBlocks, chromSize);
 bedOrBits(bits2, chromSize, bedList2, hti2->hasBlocks, 0);
 if (invTable2)
     bitNot(bits2, chromSize);
 lmCleanup(&lm2);
 return bits2;
 }
 
 char *intersectOp()
 /* Get intersect op from CGI var and make sure it's ok. */
 {
 char *op = cartString(cart, hgtaIntersectOp);
 if ((!sameString("any", op)) &&
     (!sameString("none", op)) &&