def testEmpty(self): """ When no intervals are given, the reduction should be for the full hit width. """ adjuster = OffsetAdjuster() self.assertEqual([], adjuster.adjustments()) self.assertEqual(0, adjuster.adjustOffset(0))
def testNoReads(self): """ When no reads are added to an interval, the reduction should be for the full hit width. """ ri = ReadIntervals(64) adjuster = OffsetAdjuster(ri) self.assertEqual([(64, 58)], adjuster.adjustments()) self.assertEqual(6, adjuster.adjustOffset(64))
def testOneReadThatExceedsHitOnBothEnds(self): """ When one read is given that exceeds the hit at both ends, there should be no length reductions. """ ri = ReadIntervals(106) ri.add(-100, 200) adjuster = OffsetAdjuster(ri) self.assertEqual([], adjuster.adjustments()) self.assertEqual(106, adjuster.adjustOffset(106))
def testOneReadThatExactlyCoversHit(self): """ When one read is given that exactly covers the hit, there should be no length reductions. """ ri = ReadIntervals(106) ri.add(0, 106) adjuster = OffsetAdjuster(ri) self.assertEqual([], adjuster.adjustments()) self.assertEqual(106, adjuster.adjustOffset(106))
def testOneReadInMiddle(self): """ When one read is added to the middle of an interval, there should be two reductions. """ ri = ReadIntervals(106) ri.add(32, 42) adjuster = OffsetAdjuster(ri) self.assertEqual([(32, 27), (106, 58)], adjuster.adjustments()) self.assertEqual(106 - 27 - 58, adjuster.adjustOffset(106))
def testOneReadAtEnd(self): """ When one read is added to the end of an interval, there should be one reduction for the empty section before the read. """ ri = ReadIntervals(228) ri.add(128, 228) adjuster = OffsetAdjuster(ri) self.assertEqual([(128, 121)], adjuster.adjustments()) self.assertEqual(107, adjuster.adjustOffset(228))
def testOneReadBeforeStart(self): """ When one read is added to the start of an interval before zero, there should be one reduction for the empty section after the read. """ ri = ReadIntervals(228) ri.add(-10, 100) adjuster = OffsetAdjuster(ri) self.assertEqual([(228, 121)], adjuster.adjustments()) self.assertEqual(107, adjuster.adjustOffset(228))
def testOneReadAtEnd(self): """ When one read is added to the end of an interval, there should be one reduction for the empty section before the read. """ ri = ReadIntervals(228) ri.add(128, 228) adjuster = OffsetAdjuster(ri) self.assertEqual([ (128, 121), ], adjuster.adjustments()) self.assertEqual(107, adjuster.adjustOffset(228))
def testOneReadBeforeStart(self): """ When one read is added to the start of an interval before zero, there should be one reduction for the empty section after the read. """ ri = ReadIntervals(228) ri.add(-10, 100) adjuster = OffsetAdjuster(ri) self.assertEqual([ (228, 121), ], adjuster.adjustments()) self.assertEqual(107, adjuster.adjustOffset(228))
def testTwoReadsInMiddle(self): """ When two reads are added to the middle of an interval, there should be three reductions (after first empty area, after 2nd empty area, after final empty area. """ ri = ReadIntervals(132) ri.add(32, 42) ri.add(58, 68) adjuster = OffsetAdjuster(ri) self.assertEqual([ (32, 27), (58, 12), (132, 58), ], adjuster.adjustments()) self.assertEqual(132 - 27 - 12 - 58, adjuster.adjustOffset(132)) # Test an HSP at the beginning is unchanged. hsp = HSP(10, readEndInSubject=10, readStartInSubject=0, subjectEnd=10, subjectStart=0) adjuster.adjustHSP(hsp) self.assertEqual(10, hsp.readEndInSubject) self.assertEqual(0, hsp.readStartInSubject) self.assertEqual(10, hsp.subjectEnd) self.assertEqual(0, hsp.subjectStart) # Test an HSP in the first read region. hsp = HSP(10, readEndInSubject=42, readStartInSubject=32, subjectEnd=40, subjectStart=35) adjuster.adjustHSP(hsp) self.assertEqual(15, hsp.readEndInSubject) self.assertEqual(5, hsp.readStartInSubject) self.assertEqual(13, hsp.subjectEnd) self.assertEqual(8, hsp.subjectStart) # Test an HSP in the second read region. hsp = HSP(10, readEndInSubject=68, readStartInSubject=58, subjectEnd=66, subjectStart=60) adjuster.adjustHSP(hsp) self.assertEqual(29, hsp.readEndInSubject) self.assertEqual(19, hsp.readStartInSubject) self.assertEqual(27, hsp.subjectEnd) self.assertEqual(21, hsp.subjectStart)
def testOneReadInMiddle(self): """ When one read is added to the middle of an interval, there should be two reductions. """ ri = ReadIntervals(106) ri.add(32, 42) adjuster = OffsetAdjuster(ri) self.assertEqual([ (32, 27), (106, 58), ], adjuster.adjustments()) self.assertEqual(106 - 27 - 58, adjuster.adjustOffset(106))
def testTwoReadsInMiddle(self): """ When two reads are added to the middle of an interval, there should be three reductions (after first empty area, after 2nd empty area, after final empty area. """ ri = ReadIntervals(132) ri.add(32, 42) ri.add(58, 68) adjuster = OffsetAdjuster(ri) self.assertEqual( [ (32, 27), (58, 12), (132, 58), ], adjuster.adjustments()) self.assertEqual(132 - 27 - 12 - 58, adjuster.adjustOffset(132)) # Test an HSP at the beginning is unchanged. hsp = HSP(10, readEndInSubject=10, readStartInSubject=0, subjectEnd=10, subjectStart=0) adjuster.adjustHSP(hsp) self.assertEqual(10, hsp.readEndInSubject) self.assertEqual(0, hsp.readStartInSubject) self.assertEqual(10, hsp.subjectEnd) self.assertEqual(0, hsp.subjectStart) # Test an HSP in the first read region. hsp = HSP(10, readEndInSubject=42, readStartInSubject=32, subjectEnd=40, subjectStart=35) adjuster.adjustHSP(hsp) self.assertEqual(15, hsp.readEndInSubject) self.assertEqual(5, hsp.readStartInSubject) self.assertEqual(13, hsp.subjectEnd) self.assertEqual(8, hsp.subjectStart) # Test an HSP in the second read region. hsp = HSP(10, readEndInSubject=68, readStartInSubject=58, subjectEnd=66, subjectStart=60) adjuster.adjustHSP(hsp) self.assertEqual(29, hsp.readEndInSubject) self.assertEqual(19, hsp.readStartInSubject) self.assertEqual(27, hsp.subjectEnd) self.assertEqual(21, hsp.subjectStart)