コード例 #1
0
ファイル: synthesize_reads.py プロジェクト: CarlesV/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
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
ファイル: sampling_tests.py プロジェクト: health1987/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)
コード例 #4
0
ファイル: sampling_tests.py プロジェクト: health1987/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)
コード例 #5
0
ファイル: sampling_tests.py プロジェクト: health1987/paleomix
 def _do_different_length_input_raises(choices, weights):
     iterator = sampling.weighted_sampling(choices, weights)
     assert_raises(ValueError, iterator.next)
コード例 #6
0
ファイル: sampling_tests.py プロジェクト: health1987/paleomix
 def _do_empty_input_raises(choices, weights):
     iterator = sampling.weighted_sampling(choices, weights)
     assert_raises(ValueError, iterator.next)
コード例 #7
0
ファイル: sampling_tests.py プロジェクト: health1987/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)
コード例 #8
0
ファイル: sampling_tests.py プロジェクト: CarlesV/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)
コード例 #9
0
ファイル: sampling_tests.py プロジェクト: CarlesV/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)
コード例 #10
0
ファイル: sampling_tests.py プロジェクト: CarlesV/paleomix
 def _do_different_length_input_raises(choices, weights):
     iterator = sampling.weighted_sampling(choices, weights)
     assert_raises(ValueError, iterator.next)
コード例 #11
0
ファイル: sampling_tests.py プロジェクト: CarlesV/paleomix
 def _do_empty_input_raises(choices, weights):
     iterator = sampling.weighted_sampling(choices, weights)
     assert_raises(ValueError, iterator.next)
コード例 #12
0
ファイル: sampling_tests.py プロジェクト: CarlesV/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)