コード例 #1
0
ファイル: synthesize_reads.py プロジェクト: jelber2/paleomix
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
ファイル: synthesize_reads.py プロジェクト: muslih14/paleomix
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__different_length_input_raises_value_error(
        choices, weights):
    iterator = sampling.weighted_sampling(choices, weights)
    with pytest.raises(ValueError):
        iterator.__next__()
コード例 #4
0
def test_weighted_sampling__(choices, weights):
    iterator = sampling.weighted_sampling(choices, weights)
    with pytest.raises(ValueError):
        iterator.__next__()
コード例 #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
コード例 #6
0
ファイル: sampling_tests.py プロジェクト: muslih14/paleomix
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)
コード例 #7
0
ファイル: sampling_tests.py プロジェクト: muslih14/paleomix
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)
コード例 #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)
コード例 #9
0
ファイル: sampling_tests.py プロジェクト: muslih14/paleomix
 def _do_empty_input_raises(choices, weights):
     iterator = sampling.weighted_sampling(choices, weights)
     assert_raises(ValueError, iterator.next)
コード例 #10
0
ファイル: sampling_tests.py プロジェクト: muslih14/paleomix
 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)
コード例 #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)
コード例 #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)
コード例 #13
0
 def _do_different_length_input_raises(choices, weights):
     iterator = sampling.weighted_sampling(choices, weights)
     assert_raises(ValueError, iterator.next)
コード例 #14
0
 def _do_empty_input_raises(choices, weights):
     iterator = sampling.weighted_sampling(choices, weights)
     assert_raises(ValueError, iterator.next)
コード例 #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__()
コード例 #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__()
コード例 #17
0
ファイル: sampling_tests.py プロジェクト: muslih14/paleomix
 def _do_different_length_input_raises(choices, weights):
     iterator = sampling.weighted_sampling(choices, weights)
     assert_raises(ValueError, iterator.next)