void testIntersect() { SequenceInterval int1("foo", 1, 100); SequenceInterval int2("foo", 80, 1000); SequenceInterval int3(int1); SequenceInterval int4(int2); SequenceInterval int5(int1); SequenceInterval int6("foo", 101, 1000); SequenceInterval int7("foo", 200, 1000); CPPUNIT_ASSERT(int1.intersects(int2)); Interval int12 = int1.intersect(int2); CPPUNIT_ASSERT_EQUAL(80, int12.getStart()); CPPUNIT_ASSERT_EQUAL(100, int12.getEnd()); int3 += int4; CPPUNIT_ASSERT_EQUAL(1, int3.getStart()); CPPUNIT_ASSERT_EQUAL(1000, int3.getEnd()); Interval tint = int3 + int4; CPPUNIT_ASSERT_EQUAL(1, tint.getStart()); CPPUNIT_ASSERT_EQUAL(1000, tint.getEnd()); int5 += int6; CPPUNIT_ASSERT_EQUAL(1, int5.getStart()); CPPUNIT_ASSERT_EQUAL(1000, int5.getEnd()); CPPUNIT_ASSERT(int1.intersects(int7, 100)); }
bool Range::next(string & chrom, Interval & intv){ if(!on_chromosome) return false; chrom = chr; while(!recurse.empty()){ Cargo c = recurse.top(); Interval i = cvector.at(c.root); if(d.getStart() >= i.getSubMax()){ recurse.pop(); }else{ if(!c.goLeft){ //check this one, pop, then put right on top if it exists and start is less than i stop recurse.pop(); if(d.getStop() > i.getStart()){ Capacity root; if(getMidpoint(c.root+1, c.high, root)){ recurse.push(Cargo(c.root+1, c.high, root)); } if(i.overlaps(d)){ intv = i; return true; } }//else this node and right children do not overlap d }else{ recurse.top().goLeft = false; //go left Capacity root; if(getMidpoint(c.low, c.root, root)){ recurse.push(Cargo(c.low, c.root, root)); } } } } return false; }
bool Interval::operator<(const Interval & b) const { if(getStart() == b.getStart()){ return (getStop() < b.getStop()); } return (getStart() < b.getStart()); }
bool Interval::overlaps(const Interval & b, bool strand_specific){ if(getStrand() == b.getStrand() || getStrand() == BOTH || b.getStrand() == BOTH || !strand_specific){ return (getStart() < b.getStop() && b.getStart() < getStop()); } return false; }
bool Interval::intersects(Interval & interval) { return !(_end - 1 < interval.getStart() || interval.getEnd() - 1 < _start); }