コード例 #1
0
 def testEmpty(self):
     """
     If a combined feature list has no landmarks or trig points, its nearest
     method should not generate any features.
     """
     cfl = CombinedFeatureList([], [])
     self.assertEqual([], list(cfl.nearest(0)))
コード例 #2
0
 def testFindOneMinDistance(self):
     """
     If a combined feature list has one of two landmarks and trig points
     inside the minDistance, find one.
     """
     landmark = Landmark('name1', 'L', 0, 1)
     trigPoint = TrigPoint('name2', 'T', 10)
     cfl = CombinedFeatureList([landmark], [trigPoint])
     result = list(cfl.nearest(8, minDistance=5))
     self.assertEqual([landmark], result)
コード例 #3
0
 def testFindNoneMinDistance(self):
     """
     If a combined feature list has no landmarks and trig points beyond the
     minDistance, find none.
     """
     landmark = Landmark('name1', 'L', 0, 1)
     trigPoint = TrigPoint('name2', 'T', 10)
     cfl = CombinedFeatureList([landmark], [trigPoint])
     result = list(cfl.nearest(6, minDistance=10))
     self.assertEqual([], result)
コード例 #4
0
 def testNothingInRange(self):
     """
     If a combined feature list has no landmarks or trig points within range
     of the offset passed to its nearest method, the method should not
     generate any features.
     """
     landmark1 = Landmark('name1', 'L1', 0, 1)
     landmark2 = Landmark('name2', 'L2', 10, 1)
     cfl = CombinedFeatureList([landmark1, landmark2], [])
     self.assertEqual([], list(cfl.nearest(5, maxDistance=2)))
コード例 #5
0
 def testFindOneMinDistanceMaxDistance(self):
     """
     If a combined feature list has three landmarks and trig points, one
     outside the minDistance, one outside the maxDistance, find one.
     """
     trigPoint1 = TrigPoint('name2', 'T', 0)
     landmark = Landmark('name1', 'L', 5, 1)
     trigPoint2 = TrigPoint('name3', 'T', 8)
     cfl = CombinedFeatureList([landmark], [trigPoint1, trigPoint2])
     result = list(cfl.nearest(5, maxDistance=4, minDistance=1))
     self.assertEqual([trigPoint2], result)
コード例 #6
0
 def testFindAllMinDistance(self):
     """
     If a combined feature list has all landmarks and trig points beyond the
     minDistance, find all, with the landmarks first.
     """
     landmark = Landmark('name1', 'L', 0, 1)
     trigPoint1 = TrigPoint('name2', 'T', 10)
     trigPoint2 = TrigPoint('name3', 'T', 11)
     cfl = CombinedFeatureList([landmark], [trigPoint1, trigPoint2])
     result = list(cfl.nearest(6, minDistance=1))
     self.assertEqual([landmark, trigPoint1, trigPoint2], result)
コード例 #7
0
 def testFindTrigPointAndLandmarkMaxDistance(self):
     """
     If a combined feature list has one landmark and one trig point
     with only the trig point within the passed max distance, the nearest
     method should yield just the trig point.
     """
     landmark = Landmark('name1', 'L', 0, 1)
     trigPoint = TrigPoint('name2', 'T', 10)
     cfl = CombinedFeatureList([landmark], [trigPoint])
     result = list(cfl.nearest(6, maxDistance=5))
     self.assertEqual([trigPoint], result)
コード例 #8
0
 def testFindLandmarkAndTrigPoint(self):
     """
     If a combined feature list has one landmark and one trig point within
     range, with the landmark closest to the passed offset, the nearest
     method should yield them both, with the landmark first.
     """
     landmark = Landmark('name1', 'L', 0, 1)
     trigPoint = TrigPoint('name2', 'T', 10)
     cfl = CombinedFeatureList([landmark], [trigPoint])
     result = list(cfl.nearest(4))
     self.assertEqual([landmark, trigPoint], result)
コード例 #9
0
 def testNearestFindsZeroDistanceTrigPoint(self):
     """
     If a combined feature list has one trig point and the offset of that
     trig point is given to its nearest method, that trig point should be
     generated.
     """
     trigPoint = TrigPoint('name', 'T', 10)
     cfl = CombinedFeatureList([], [trigPoint])
     result = list(cfl.nearest(10, maxDistance=0))
     self.assertEqual(1, len(result))
     self.assertIs(trigPoint, result[0])
コード例 #10
0
 def testNearestFindsZeroDistanceLandmark(self):
     """
     If a combined feature list has one landmark and the offset of that
     landmark is given to its nearest method, that landmark should be
     generated.
     """
     landmark = Landmark('name', 'L', 10, 1)
     cfl = CombinedFeatureList([landmark], [])
     result = list(cfl.nearest(10, maxDistance=0))
     self.assertEqual(1, len(result))
     self.assertIs(landmark, result[0])
コード例 #11
0
 def testFindLandmarkAndTrigPointWithOffsetBiggerThanBoth(self):
     """
     If a combined feature list has one landmark and one trig point and the
     passed offset is larger than both their offsets, the nearest method
     should yield them both (landmarks first, due to landmark priority,
     even though it is further away than the trig point).
     """
     landmark = Landmark('name1', 'L', 0, 1)
     trigPoint = TrigPoint('name2', 'T', 10)
     cfl = CombinedFeatureList([landmark], [trigPoint])
     result = list(cfl.nearest(20))
     self.assertEqual([landmark, trigPoint], result)
コード例 #12
0
    def getPairs(self,
                 limitPerLandmark=None,
                 maxDistance=None,
                 minDistance=None):
        """
        Get pairs of (landmark, trig point) for use in building a search
        dictionary that can be used to identify this read.

        When considering each landmark, other landmarks to the left (with
        smaller offset) of the current landmark are ignored.  This is to
        reduce the redundancy that results if both (landmark1, landmark2)
        and (landmark2, landmark1) pairs are yielded.

        @param limitPerLandmark: An C{int} limit on the number of pairs to
            yield per landmark.
        @param maxDistance: The C{int} maximum distance permitted between
            yielded pairs.
        @param minDistance: The C{int} minimum distance permitted between
            yielded pairs.
        @return: A generator that yields (landmark, trig point) pairs.
        """
        if limitPerLandmark is not None and limitPerLandmark < 1:
            return

        features = CombinedFeatureList(self.landmarks, self.trigPoints)

        for landmark in self.landmarks:
            count = 0
            landmarkOffset = landmark.offset
            nearest = features.nearest(landmarkOffset,
                                       maxDistance=maxDistance,
                                       minDistance=minDistance)

            while limitPerLandmark is None or count < limitPerLandmark:
                try:
                    feature = next(nearest)
                except StopIteration:
                    break
                else:
                    # Yield any landmark or trig point on the right (with
                    # greater offset) of the current landmark, and all trig
                    # points (whether left or right).
                    if (feature.offset > landmarkOffset
                            or isinstance(feature, TrigPoint)):
                        yield landmark, feature
                        count += 1
コード例 #13
0
 def testFindManyMinDistanceMaxDistance(self):
     """
     If a combined feature list has many landmarks and trig points, some
     outside the minDistance, some outside the maxDistance, find the right
     ones.
     """
     landmark1 = Landmark('name1', 'L1', 0, 1)
     landmark2 = Landmark('name2', 'L2', 3, 1)
     landmark3 = Landmark('name3', 'L3', 5, 1)
     landmark4 = Landmark('name4', 'L4', 7, 1)
     trigPoint1 = TrigPoint('name5', 'T1', 9)
     trigPoint2 = TrigPoint('name6', 'T2', 11)
     trigPoint3 = TrigPoint('name7', 'T3', 13)
     cfl = CombinedFeatureList([landmark1, landmark2, landmark3, landmark4],
                               [trigPoint1, trigPoint2, trigPoint3])
     result = list(cfl.nearest(0, maxDistance=10, minDistance=4))
     self.assertEqual([landmark3, landmark4, trigPoint1], result)
コード例 #14
0
 def testFindMany(self):
     """
     If a combined feature list has many landmarks and trig points
     the nearest method should yield them all.
     """
     landmark1 = Landmark('name1', 'L1', 0, 1)
     landmark2 = Landmark('name2', 'L2', 3, 1)
     landmark3 = Landmark('name3', 'L3', 5, 1)
     landmark4 = Landmark('name4', 'L4', 7, 1)
     trigPoint1 = TrigPoint('name5', 'T1', 9)
     trigPoint2 = TrigPoint('name6', 'T2', 11)
     trigPoint3 = TrigPoint('name7', 'T3', 13)
     cfl = CombinedFeatureList([landmark1, landmark2, landmark3, landmark4],
                               [trigPoint1, trigPoint2, trigPoint3])
     result = list(cfl.nearest(0))
     self.assertEqual([
         landmark1, landmark2, landmark3, landmark4, trigPoint1, trigPoint2,
         trigPoint3
     ], result)