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; 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; }
static struct bed *bedTable2(struct sqlConnection *conn, struct region *region, char *table2) /* get a bed list, possibly complement, for table2 */ { /* This use of bedTable rather than a bitmap is not really working. The * rest of the table browser does intersection at the exon level, while * the wig code, which this is part of, does it at the gene level. I * noticed it while working on the corresponding routines for bigWig, * which I'm building to work with bitmaps at the exon level. I'm not * sure it's worth fixing this code since nobody has complained, and we're * probably going to be doing mostly bigWig rather than wig in the future. * -JK */ boolean invTable2 = cartCgiUsualBoolean(cart, hgtaInvertTable2, FALSE); char *op = cartString(cart, hgtaIntersectOp); struct bed *bedList = NULL; struct lm *lm1 = lmInit(64*1024); /* fetch table 2 as a bed list */ bedList = getFilteredBeds(conn, table2, region, lm1, NULL); /* If table 2 bed list needs to be complemented (!table2), then do so */ if (invTable2 || sameString("none", op)) { unsigned chromStart = 0; /* start == end == 0 */ unsigned chromEnd = 0; /* means do full chrom */ unsigned chromSize = hChromSize(database, region->chrom); struct lm *lm2 = lmInit(64*1024); struct bed *inverseBedList = NULL; /* new list */ if ((region->start != 0) || (region->end != 0)) { chromStart = region->start; chromEnd = region->end; } if ((struct bed *)NULL == bedList) { if (0 == region->end) chromEnd = chromSize; addBedElement(&inverseBedList, region->chrom, chromStart, chromEnd, 1, lm2); } else inverseBedList=invertBedList(bedList, lm2, region->chrom, chromStart, chromEnd, chromSize); lmCleanup(&lm1); /* == bedFreeList(&bedList) */ return inverseBedList; } else return bedList; }
static struct bed *getIntersectedBeds(struct sqlConnection *conn, char *table, struct region *region, struct lm *lm, int *retFieldCount) /* Get list of beds in region that pass intersection * (and filtering) */ { struct bed *bedList = getFilteredBeds(conn, table, region, lm, retFieldCount); /* wiggle tracks have already done the intersection if there was one */ if (!isWiggle(database, table) && anyIntersection()) { struct bed *iBedList = intersectOnRegion(conn, region, table, bedList, lm, retFieldCount); return iBedList; } else return bedList; }
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); if (!isBpWise) expandZeroSize(bedList2, hti2->hasBlocks, chromSize); bedOrBits(bits2, chromSize, bedList2, hti2->hasBlocks, 0); if (invTable2) bitNot(bits2, chromSize); lmCleanup(&lm2); return bits2; }