Beispiel #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
Beispiel #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
Beispiel #3
0
def test_weighted_sampling__different_length_input_raises_value_error(
        choices, weights):
    iterator = sampling.weighted_sampling(choices, weights)
    with pytest.raises(ValueError):
        iterator.__next__()
Beispiel #4
0
def test_weighted_sampling__(choices, weights):
    iterator = sampling.weighted_sampling(choices, weights)
    with pytest.raises(ValueError):
        iterator.__next__()
Beispiel #5
0
def test_weighted_sampling__select_by_weight(value, expectation):
    choices = "abc"
    weights = (1, 2, 3)
    rng = Mock(random=lambda: value)
    iterator = sampling.weighted_sampling(choices, weights, rng)
    assert next(iterator) == expectation
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
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)
Beispiel #9
0
 def _do_empty_input_raises(choices, weights):
     iterator = sampling.weighted_sampling(choices, weights)
     assert_raises(ValueError, iterator.next)
Beispiel #10
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)
Beispiel #11
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)
Beispiel #12
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)
Beispiel #13
0
 def _do_different_length_input_raises(choices, weights):
     iterator = sampling.weighted_sampling(choices, weights)
     assert_raises(ValueError, iterator.next)
Beispiel #14
0
 def _do_empty_input_raises(choices, weights):
     iterator = sampling.weighted_sampling(choices, weights)
     assert_raises(ValueError, iterator.next)
Beispiel #15
0
def test_weighted_sampling__zero_weight_raises_value_error():
    choices = [0, 1, 2]
    weights = [1, 0, 3]
    iterator = sampling.weighted_sampling(choices, weights)
    with pytest.raises(ValueError):
        iterator.__next__()
Beispiel #16
0
def test_weighted_sampling__non_numerical_weight_raises_type_error():
    choices = [0, 1, 2]
    weights = [1, "foo", 3]
    iterator = sampling.weighted_sampling(choices, weights)
    with pytest.raises(TypeError):
        iterator.__next__()
Beispiel #17
0
 def _do_different_length_input_raises(choices, weights):
     iterator = sampling.weighted_sampling(choices, weights)
     assert_raises(ValueError, iterator.next)