Exemplo n.º 1
0
 def testEmptyCoverageCounts(self):
     """
     When no intervals are added, coverageCounts should return an empty
     Counter.
     """
     ri = ReadIntervals(100)
     self.assertEqual({}, ri.coverageCounts())
Exemplo n.º 2
0
 def testEmptyCoverageCountsOnZeroLengthSequence(self):
     """
     When no intervals are added, coverageCounts should return an empty
     Counter.
     """
     ri = ReadIntervals(0)
     self.assertEqual({}, ri.coverageCounts())
Exemplo n.º 3
0
 def testOneIntervalCoveringAllExtendingLeftCoverage(self):
     """
     If there is a single interval that spans the whole hit, including
     going negative to the left, coverage should return 1.0.
     """
     ri = ReadIntervals(100)
     ri.add(-10, 100)
     self.assertEqual(1.0, ri.coverage())
Exemplo n.º 4
0
 def testOneIntervalCoveringAllExtendingRightCoverage(self):
     """
     If there is a single interval that spans the whole hit, including
     going beyond the hit to the right, coverage should return 1.0.
     """
     ri = ReadIntervals(100)
     ri.add(0, 110)
     self.assertEqual(1.0, ri.coverage())
Exemplo n.º 5
0
 def testOneIntervalExactCovering(self):
     """
     If there is a single interval that spans the whole hit exactly, just
     that one interval should be returned by walk, and it should be full.
     """
     ri = ReadIntervals(100)
     ri.add(0, 100)
     self.assertEqual([(self.FULL, (0, 100))], list(ri.walk()))
Exemplo n.º 6
0
 def testOneIntervalExactCovering(self):
     """
     If there is a single interval that spans the whole hit exactly, just
     that one interval should be returned by walk, and it should be full.
     """
     ri = ReadIntervals(100)
     ri.add(0, 100)
     self.assertEqual([(self.FULL, (0, 100))], list(ri.walk()))
Exemplo n.º 7
0
 def testOneIntervalStartingBeforeZeroCoverage(self):
     """
     If there is a single interval that starts before zero but doesn't
     cover the whole hit, coverage should return the correct value.
     """
     ri = ReadIntervals(100)
     ri.add(-50, 50)
     self.assertEqual(0.5, ri.coverage())
Exemplo n.º 8
0
 def testOneIntervalEndingAfterHitEndCoverage(self):
     """
     If there is a single interval that ends after the end of the hit
     but doesn't start at zero, coverage should return the correct value.
     """
     ri = ReadIntervals(100)
     ri.add(50, 150)
     self.assertEqual(0.5, ri.coverage())
Exemplo n.º 9
0
 def testEmpty(self):
     """
     When no intervals are added, walk should just return one empty
     interval that spans the entire rangoe from 0 to the sequence
     length.
     """
     ri = ReadIntervals(100)
     self.assertEqual([(self.EMPTY, (0, 100))], list(ri.walk()))
Exemplo n.º 10
0
 def testOneIntervalCoveringAllExtendingRightCoverage(self):
     """
     If there is a single interval that spans the whole hit, including
     going beyond the hit to the right, coverage should return 1.0.
     """
     ri = ReadIntervals(100)
     ri.add(0, 110)
     self.assertEqual(1.0, ri.coverage())
Exemplo n.º 11
0
 def testOneIntervalEndingAfterHitEndCoverage(self):
     """
     If there is a single interval that ends after the end of the hit
     but doesn't start at zero, coverage should return the correct value.
     """
     ri = ReadIntervals(100)
     ri.add(50, 150)
     self.assertEqual(0.5, ri.coverage())
Exemplo n.º 12
0
 def testOneIntervalCoveringAllExtendingLeftCoverage(self):
     """
     If there is a single interval that spans the whole hit, including
     going negative to the left, coverage should return 1.0.
     """
     ri = ReadIntervals(100)
     ri.add(-10, 100)
     self.assertEqual(1.0, ri.coverage())
Exemplo n.º 13
0
 def testOneIntervalStartingBeforeZeroCoverage(self):
     """
     If there is a single interval that starts before zero but doesn't
     cover the whole hit, coverage should return the correct value.
     """
     ri = ReadIntervals(100)
     ri.add(-50, 50)
     self.assertEqual(0.5, ri.coverage())
Exemplo n.º 14
0
 def testOneIntervalExactCoveringCoverage(self):
     """
     If there is a single interval that spans the whole hit exactly,
     coverage should return 1.0.
     """
     ri = ReadIntervals(100)
     ri.add(0, 100)
     self.assertEqual(1.0, ri.coverage())
Exemplo n.º 15
0
 def testEmpty(self):
     """
     When no intervals are added, walk should just return one empty
     interval that spans the entire rangoe from 0 to the sequence
     length.
     """
     ri = ReadIntervals(100)
     self.assertEqual([(self.EMPTY, (0, 100))], list(ri.walk()))
Exemplo n.º 16
0
 def testOneIntervalExactCoveringCoverage(self):
     """
     If there is a single interval that spans the whole hit exactly,
     coverage should return 1.0.
     """
     ri = ReadIntervals(100)
     ri.add(0, 100)
     self.assertEqual(1.0, ri.coverage())
Exemplo n.º 17
0
 def testOneIntervalEndingAfterHitEnd(self):
     """
     If there is a single interval that ends after the end of the hit
     but doesn't start at zero, we should get 2 intervals back from walk,
     an empty then a full.
     """
     ri = ReadIntervals(100)
     ri.add(50, 150)
     self.assertEqual([(self.EMPTY, (0, 50)), (self.FULL, (50, 150))], list(ri.walk()))
Exemplo n.º 18
0
 def testOneIntervalInMiddleCoverageCounts(self):
     """
     If there is a single interval in the middle of the hit, coverageCounts
     should return the correct result.
     """
     ri = ReadIntervals(10)
     ri.add(5, 6)
     c = Counter([5])
     self.assertEqual(c, ri.coverageCounts())
Exemplo n.º 19
0
 def testOneIntervalStartingAtZeroCoverageCounts(self):
     """
     If there is a single interval that starts at zero but doesn't
     cover the whole hit, coverageCounts should return the correct result.
     """
     ri = ReadIntervals(10)
     ri.add(0, 5)
     c = Counter([0, 1, 2, 3, 4])
     self.assertEqual(c, ri.coverageCounts())
Exemplo n.º 20
0
 def testOneIntervalExactCoveringCoverageCounts(self):
     """
     If there is a single interval that spans the whole hit exactly,
     coverageCounts should return the correct result.
     """
     ri = ReadIntervals(10)
     ri.add(0, 10)
     c = Counter([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
     self.assertEqual(c, ri.coverageCounts())
Exemplo n.º 21
0
 def testOneIntervalCoveringAllExtendingLeft(self):
     """
     If there is a single interval that spans the whole hit, including
     going negative to the left, that one interval should be returned by
     walk, and it should be full.
     """
     ri = ReadIntervals(100)
     ri.add(-10, 100)
     self.assertEqual([(self.FULL, (-10, 100))], list(ri.walk()))
Exemplo n.º 22
0
 def testOneIntervalCoveringAllExtendingBoth(self):
     """
     If there is a single interval that spans the whole hit, including
     starting before zero and also going beyond the hit to the right, that
     one interval should be returned by walk, and it should be full.
     """
     ri = ReadIntervals(100)
     ri.add(-10, 110)
     self.assertEqual([(self.FULL, (-10, 110))], list(ri.walk()))
Exemplo n.º 23
0
 def testOneIntervalCoveringAllExtendingBothCoverage(self):
     """
     If there is a single interval that spans the whole hit, including
     starting before zero and also going beyond the hit to the right,
     coverage should return 1.0
     """
     ri = ReadIntervals(100)
     ri.add(-10, 110)
     self.assertEqual(1.0, ri.coverage())
Exemplo n.º 24
0
 def testOneIntervalStartingBeforeZero(self):
     """
     If there is a single interval that starts before zero but doesn't
     cover the whole hit, we should get 2 intervals back from walk,
     a full one and then an empty.
     """
     ri = ReadIntervals(100)
     ri.add(-50, 50)
     self.assertEqual([(self.FULL, (-50, 50)), (self.EMPTY, (50, 100))], list(ri.walk()))
Exemplo n.º 25
0
    def testOneIntervalInMiddle(self):
        """
        If there is a single interval in the middle of the hit, we
        should get 3 intervals back from walk: empty, full, empty.

        """
        ri = ReadIntervals(100)
        ri.add(50, 60)
        self.assertEqual([(self.EMPTY, (0, 50)), (self.FULL, (50, 60)), (self.EMPTY, (60, 100))], list(ri.walk()))
Exemplo n.º 26
0
 def testTwoOverlappingIntervalsInMiddle(self):
     """
     If there are two overlapping intervals in the middle of the hit, we
     should get 3 intervals back from walk: empty, full, empty.
     """
     ri = ReadIntervals(100)
     ri.add(50, 60)
     ri.add(55, 70)
     self.assertEqual([(self.EMPTY, (0, 50)), (self.FULL, (50, 70)), (self.EMPTY, (70, 100))], list(ri.walk()))
Exemplo n.º 27
0
    def testOneIntervalInMiddleCoverage(self):
        """
        If there is a single interval in the middle of the hit, coverage
        should return the correct value.

        """
        ri = ReadIntervals(100)
        ri.add(50, 60)
        self.assertEqual(0.1, ri.coverage())
Exemplo n.º 28
0
 def testOneIntervalCoveringAllExtendingBothCoverage(self):
     """
     If there is a single interval that spans the whole hit, including
     starting before zero and also going beyond the hit to the right,
     coverage should return 1.0
     """
     ri = ReadIntervals(100)
     ri.add(-10, 110)
     self.assertEqual(1.0, ri.coverage())
Exemplo n.º 29
0
 def testOneIntervalCoveringAllExtendingBoth(self):
     """
     If there is a single interval that spans the whole hit, including
     starting before zero and also going beyond the hit to the right, that
     one interval should be returned by walk, and it should be full.
     """
     ri = ReadIntervals(100)
     ri.add(-10, 110)
     self.assertEqual([(self.FULL, (-10, 110))], list(ri.walk()))
Exemplo n.º 30
0
 def coverageCounts(self):
     """
     For each location in the title sequence, return a count of how many
     times that location is covered by a read.
     """
     intervals = ReadIntervals(self.subjectLength)
     for hsp in self.hsps():
         intervals.add(hsp.subjectStart, hsp.subjectEnd)
     return intervals.coverageCounts()
Exemplo n.º 31
0
 def coverageCounts(self):
     """
     For each location in the title sequence, return a count of how many
     times that location is covered by a read.
     """
     intervals = ReadIntervals(self.subjectLength)
     for hsp in self.hsps():
         intervals.add(hsp.subjectStart, hsp.subjectEnd)
     return intervals.coverageCounts()
Exemplo n.º 32
0
 def testTwoOverlappingIntervalsInMiddleCoverage(self):
     """
     If there are two overlapping intervals in the middle of the hit,
     coverage should return the correct value.
     """
     ri = ReadIntervals(100)
     ri.add(50, 60)
     ri.add(55, 70)
     self.assertEqual(0.2, ri.coverage())
Exemplo n.º 33
0
    def testOneIntervalInMiddleCoverage(self):
        """
        If there is a single interval in the middle of the hit, coverage
        should return the correct value.

        """
        ri = ReadIntervals(100)
        ri.add(50, 60)
        self.assertEqual(0.1, ri.coverage())
Exemplo n.º 34
0
 def testTwoOverlappingIntervalsInMiddleCoverage(self):
     """
     If there are two overlapping intervals in the middle of the hit,
     coverage should return the correct value.
     """
     ri = ReadIntervals(100)
     ri.add(50, 60)
     ri.add(55, 70)
     self.assertEqual(0.2, ri.coverage())
Exemplo n.º 35
0
 def testOneIntervalCoveringAllExtendingLeft(self):
     """
     If there is a single interval that spans the whole hit, including
     going negative to the left, that one interval should be returned by
     walk, and it should be full.
     """
     ri = ReadIntervals(100)
     ri.add(-10, 100)
     self.assertEqual([(self.FULL, (-10, 100))], list(ri.walk()))
Exemplo n.º 36
0
 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))
Exemplo n.º 37
0
 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))
Exemplo n.º 38
0
 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))
Exemplo n.º 39
0
 def testOneIntervalCoveringAllExtendingRightCoverageCounts(self):
     """
     If there is a single interval that spans the whole hit, including
     going beyond the hit to the right, coverageCounts should return the
     correct result.
     """
     ri = ReadIntervals(10)
     ri.add(0, 12)
     c = Counter([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
     self.assertEqual(c, ri.coverageCounts())
Exemplo n.º 40
0
 def testOneIntervalEndingAtHitEndCoverageCounts(self):
     """
     If there is a single interval that ends at the end of the hit
     but doesn't start at zero, coverageCounts should return the correct
     result.
     """
     ri = ReadIntervals(10)
     ri.add(5, 10)
     c = Counter([5, 6, 7, 8, 9])
     self.assertEqual(c, ri.coverageCounts())
Exemplo n.º 41
0
 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))
Exemplo n.º 42
0
 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))
Exemplo n.º 43
0
 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))
Exemplo n.º 44
0
 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))
Exemplo n.º 45
0
 def testTwoOverlappingIntervalsInMiddleCoverageCounts(self):
     """
     If there are two overlapping intervals in the middle of the hit,
     coverageCounts should return the correct result.
     """
     ri = ReadIntervals(10)
     ri.add(5, 7)
     ri.add(6, 8)
     c = Counter([5, 6, 6, 7])
     self.assertEqual(c, ri.coverageCounts())
Exemplo n.º 46
0
    def coverage(self):
        """
        Get the fraction of this title sequence that is matched by its reads.

        @return: The C{float} fraction of the title sequence matched by its
            reads.
        """
        intervals = ReadIntervals(self.subjectLength)
        for hsp in self.hsps():
            intervals.add(hsp.subjectStart, hsp.subjectEnd)
        return intervals.coverage()
Exemplo n.º 47
0
 def testOneIntervalEndingAtHitEnd(self):
     """
     If there is a single interval that ends at the end of the hit
     but doesn't start at zero, we should get 2 intervals back from walk,
     an empty then a full.
     """
     ri = ReadIntervals(100)
     ri.add(50, 100)
     self.assertEqual([
         (self.EMPTY, (0, 50)),
         (self.FULL, (50, 100)),
     ], list(ri.walk()))
Exemplo n.º 48
0
 def testOneIntervalStartingBeforeZero(self):
     """
     If there is a single interval that starts before zero but doesn't
     cover the whole hit, we should get 2 intervals back from walk,
     a full one and then an empty.
     """
     ri = ReadIntervals(100)
     ri.add(-50, 50)
     self.assertEqual([
         (self.FULL, (-50, 50)),
         (self.EMPTY, (50, 100)),
     ], list(ri.walk()))
Exemplo n.º 49
0
 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))
Exemplo n.º 50
0
 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))
Exemplo n.º 51
0
    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)
Exemplo n.º 52
0
 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))