예제 #1
0
def _get_weighted_choices(rng, sub_rate, indel_rate):
    choices_by_nt = {}
    for src_nt in "ACGT":
        choices = "ACGTID"
        probs = [sub_rate / 4] * 4     # ACGT
        probs += [indel_rate / 2] * 2  # ID
        probs[choices.index(src_nt)] = 1 - sum(probs) + sub_rate / 4
        choices_by_nt[src_nt] = weighted_sampling(choices, probs, rng)
    return choices_by_nt
예제 #2
0
def _get_weighted_choices(rng, sub_rate, indel_rate):
    choices_by_nt = {}
    for src_nt in "ACGT":
        choices = "ACGTID"
        probs = [sub_rate / 4] * 4     # ACGT
        probs += [indel_rate / 2] * 2  # ID
        probs[choices.index(src_nt)] = 1 - sum(probs) + sub_rate / 4
        choices_by_nt[src_nt] = weighted_sampling(choices, probs, rng)
    return choices_by_nt
예제 #3
0
def test_weighted_sampling__non_numerical_weight_raises_type_error():
    choices = range(3)
    weights = [1, "foo", 3]
    iterator = sampling.weighted_sampling(choices, weights)
    assert_raises(TypeError, iterator.next)
예제 #4
0
def test_weighted_sampling__zero_weight_raises_value_error():
    choices = range(3)
    weights = [1, 0, 3]
    iterator = sampling.weighted_sampling(choices, weights)
    assert_raises(ValueError, iterator.next)
예제 #5
0
 def _do_different_length_input_raises(choices, weights):
     iterator = sampling.weighted_sampling(choices, weights)
     assert_raises(ValueError, iterator.next)
예제 #6
0
 def _do_empty_input_raises(choices, weights):
     iterator = sampling.weighted_sampling(choices, weights)
     assert_raises(ValueError, iterator.next)
예제 #7
0
 def _do_select_by_weight(value, expectation):
     choices = "abc"
     weights = (1, 2, 3)
     rng = flexmock(random=lambda: value)
     iterator = sampling.weighted_sampling(choices, weights, rng)
     assert_equal(iterator.next(), expectation)
예제 #8
0
def test_weighted_sampling__non_numerical_weight_raises_type_error():
    choices = range(3)
    weights = [1, "foo", 3]
    iterator = sampling.weighted_sampling(choices, weights)
    assert_raises(TypeError, iterator.next)
예제 #9
0
def test_weighted_sampling__zero_weight_raises_value_error():
    choices = range(3)
    weights = [1, 0, 3]
    iterator = sampling.weighted_sampling(choices, weights)
    assert_raises(ValueError, iterator.next)
예제 #10
0
 def _do_different_length_input_raises(choices, weights):
     iterator = sampling.weighted_sampling(choices, weights)
     assert_raises(ValueError, iterator.next)
예제 #11
0
 def _do_empty_input_raises(choices, weights):
     iterator = sampling.weighted_sampling(choices, weights)
     assert_raises(ValueError, iterator.next)
예제 #12
0
 def _do_select_by_weight(value, expectation):
     choices = "abc"
     weights = (1, 2, 3)
     rng = flexmock(random = lambda: value)
     iterator = sampling.weighted_sampling(choices, weights, rng)
     assert_equal(iterator.next(), expectation)