Exemple #1
0
 def testEmptyCoverageCounts(self):
     """
     When no intervals are added, coverageCounts should return an empty
     Counter.
     """
     ri = ReadIntervals(100)
     self.assertEqual({}, ri.coverageCounts())
Exemple #2
0
 def testEmptyCoverageCountsOnZeroLengthSequence(self):
     """
     When no intervals are added, coverageCounts should return an empty
     Counter.
     """
     ri = ReadIntervals(0)
     self.assertEqual({}, ri.coverageCounts())
 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())
 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()))
 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())
 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())
 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())
 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())
 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()))
Exemple #10
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))
Exemple #11
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()))
Exemple #12
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())
Exemple #13
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())
Exemple #14
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())
Exemple #15
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())
Exemple #16
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())
Exemple #17
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()))
Exemple #18
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()
Exemple #19
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())
Exemple #20
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())
Exemple #21
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))
Exemple #22
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))
Exemple #23
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())
Exemple #24
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())
Exemple #25
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()
Exemple #26
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()))
Exemple #27
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()))
Exemple #28
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))
Exemple #29
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))
Exemple #30
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)