Пример #1
0
 def test_unweighted_add(self):
     number_comparisons = 0
     values_a = [-10, -1, 0, 1, 3, 5, 7, 9, 15, 50, 100, 1000]
     values_b = [-50, -5, 0, 0.1, 11, 22, 33, 44, 55, 1000000]
     for a in values_a:
         for b in values_b:
             sv = StrategyValue(a, 0) + StrategyValue(b, 0)
             self.assertEqual(float(a) + b, float(sv))
             number_comparisons += 1
     self.assertEqual(len(values_a) * len(values_b), number_comparisons)
Пример #2
0
 def test_default_k_0(self):
     number_comparisons = 0
     values = [0, 0.1, 1.0, -1.0, 10.0, 100.0]
     for value in values:
         sv = StrategyValue(value)
         self.assertEquals(value, sv)
         self.assertEquals(0.0, sv.k)
         number_comparisons += 1
     self.assertEqual(len(values), number_comparisons)
Пример #3
0
 def test_k(self):
     number_comparisons = 0
     values = [0.1, 1.0, -1.0, 10.0, 100.0, 0, 0.0]
     weights = [0, 1, 10, 100]
     for value in values:
         for k in weights:
             sv = StrategyValue(value, k)
             self.assertEquals(value, sv)
             self.assertEquals(k, sv.k)
             number_comparisons += 1
     self.assertEqual(len(values) * len(weights), number_comparisons)
Пример #4
0
    def test_weighted_radd(self):
        values_a = [-10, -1, 0, 1, 3, 5, 7, 9, 15, 50, 100, 1000]
        values_b = [-50, -5, 0, 0.1, 11, 22, 33, 44, 55, 1000000]
        weights_b = [1, 2, 9, 15, 50, 1000]

        number_comparisons = 0
        for a in values_a:
            for b in values_b:
                for w_b in weights_b:
                    sv = a + StrategyValue(b, w_b)
                    total_a = a
                    total_b = b * w_b
                    expected = (total_a + total_b) / float(0 + w_b)
                    self.assertEqual(expected, sv)
                    number_comparisons += 1
        self.assertEqual(
            len(values_a) * len(values_b) * len(weights_b), number_comparisons)
Пример #5
0
    def test_weighted_add(self):
        cascade_3 = StrategyValue(82, 180)
        cascade_2 = StrategyValue(70.25, 120)
        cascade_1 = StrategyValue(72.5, 60)
        self.assertEqual(76.5, 0 + cascade_3 + cascade_2 + cascade_1)
        self.assertEqual(76.5, cascade_3 + cascade_2 + cascade_1 + 0)
        self.assertEqual(76.5, 1 + cascade_3 + cascade_2 + cascade_1 + (-1))
        self.assertEqual(
            76.5,
            StrategyValue(1) + cascade_3 + cascade_2 + cascade_1 + (-1))
        self.assertEqual(
            76.5,
            StrategyValue(1) + cascade_3 + cascade_2 + cascade_1 +
            StrategyValue(-1))
        self.assertEqual(76.5,
                         StrategyValue(0) + cascade_3 + cascade_2 + cascade_1)

        values_a = [-10, -1, 0, 1, 3, 5, 7, 9, 15, 50, 100, 1000]
        weights_a = [1, 3, 5, 10, 25, 100]
        values_b = [-50, -5, 0, 0.1, 11, 22, 33, 44, 55, 1000000]
        weights_b = [1, 2, 9, 15, 50, 1000]

        number_comparisons = 0
        for a in values_a:
            for b in values_b:
                for w_a in weights_a:
                    for w_b in weights_b:
                        sv = StrategyValue(a, w_a) + StrategyValue(b, w_b)
                        total_a = a * w_a
                        total_b = b * w_b
                        expected = (total_a + total_b) / float(w_a + w_b)
                        self.assertEqual(expected, sv)
                        number_comparisons += 1
        self.assertEqual(
            len(values_a) * len(values_b) * len(weights_a) * len(weights_b),
            number_comparisons)
Пример #6
0
def _test_sort_candidates(suite,
                          op,
                          group,
                          track,
                          EXPECTED_RANK,
                          targets=None):
    number_comparisons = 0

    new_g = suite.g._filter(op, group=group, track=track)
    candidates = new_g.candidates
    last_seen = None
    print(candidates)  # Show some evidence the test is working...
    for i, c in enumerate(candidates):
        # Test value matches expecting region value
        suite.assertEqual(
            suite.g.group_counts[group][track][c["id"]],
            suite.EXPECTED_REGIONS[c["chr"]][group][c["ichr"]][track])

        # Test region is actually correct
        total = StrategyValue(0)
        if group != "total":
            if track == "default":
                for ttrack in suite.TRACKS:
                    if ttrack == "default" and len(suite.TRACKS) > 1:
                        continue
                    region = np.zeros(suite.g.LENGTH, np.int8)
                    prepared = suite.g.strategy.prepare(
                        region, suite.sequence_data[group][c["chr"]]
                        [c["pos_start"]:c["pos_end"] + 1], ttrack)
                    total += suite.g.strategy.evaluate(prepared, track=ttrack)
            else:
                region = np.zeros(suite.g.LENGTH, np.int8)
                prepared = suite.g.strategy.prepare(
                    region, suite.sequence_data[group][c["chr"]]
                    [c["pos_start"]:c["pos_end"] + 1], track)
                total += suite.g.strategy.evaluate(prepared, track=track)
        else:
            for sample in suite.sequence_data:
                if track == "default":
                    for ttrack in suite.TRACKS:
                        if ttrack == "default" and len(suite.TRACKS) > 1:
                            continue
                        region = np.zeros(suite.g.LENGTH, np.int8)
                        prepared = suite.g.strategy.prepare(
                            region, suite.sequence_data[sample][c["chr"]]
                            [c["pos_start"]:c["pos_end"] + 1], ttrack)
                        total += suite.g.strategy.evaluate(prepared,
                                                           track=ttrack)
                else:
                    region = np.zeros(suite.g.LENGTH, np.int8)
                    prepared = suite.g.strategy.prepare(
                        region, suite.sequence_data[sample][c["chr"]]
                        [c["pos_start"]:c["pos_end"] + 1], track)
                    total += suite.g.strategy.evaluate(prepared, track=track)

        suite.assertEqual(suite.g.group_counts[group][track][c["id"]], total)

        # Test expected rank
        suite.assertEqual(EXPECTED_RANK[track][i], c["id"])

        # Test values are ordered
        if last_seen is None:
            last_seen = suite.g.group_counts[group][track][c["id"]]

        if op == "max":
            suite.assertTrue(
                suite.g.group_counts[group][track][c["id"]] <= last_seen)
        elif op == "min":
            suite.assertTrue(
                suite.g.group_counts[group][track][c["id"]] >= last_seen)
        elif op == "mean" or op == "median":
            suite.assertEqual(targets[track], new_g.target)
            if targets is None:
                suite.fail("Invalid test on op:mean|median using no target.")
            if track not in targets:
                suite.fail("Invalid test on op:mean|median using no target.")

            delta_target = abs(suite.g.group_counts[group][track][c["id"]] -
                               targets[track])
            last_delta_target = abs(last_seen - targets[track])
            suite.assertTrue(delta_target >= last_delta_target)
        else:
            suite.fail("Invalid op.")
        last_seen = suite.g.group_counts[group][track][c["id"]]

        number_comparisons += 1

    suite.assertEqual(suite.EXPECTED_NUM_REGION, number_comparisons)
Пример #7
0
    def test_weight(self):
        self.assertEqual(-49.9, 1 + StrategyValue(-50, 10))
        self.assertEqual(50, StrategyValue(0, 100) + StrategyValue(100, 100))

        self.assertEqual(2, StrategyValue(1, 0) + StrategyValue(1, 0))
        self.assertEqual(2, 1 + StrategyValue(1, 0))
        self.assertEqual(2, StrategyValue(1, 0) + 1)

        self.assertEqual(1, StrategyValue(0.5, 0) + StrategyValue(0.5, 0))
        self.assertEqual(1, 0.5 + StrategyValue(0.5, 0))
        self.assertEqual(1, StrategyValue(0.5, 0) + 0.5)

        self.assertEqual(2, 1 + StrategyValue(1, 1))
        self.assertEqual(2, StrategyValue(1, 1) + 1)
        self.assertEqual(2, StrategyValue(1, 0) + StrategyValue(1, 1))

        self.assertEqual(1, StrategyValue(1, 1) + StrategyValue(1, 1))
        self.assertEqual(2, StrategyValue(2, 1) + StrategyValue(2, 1))

        self.assertEqual(10.0, StrategyValue(0) + StrategyValue(10, 100))
        self.assertEqual(10.0, 0 + StrategyValue(10, 100))
        self.assertEqual(10.01, 1 + StrategyValue(10, 100))