def test_allele_expectation_interface(): bgen = read_bgen(example_filepath("haplotypes.bgen"), verbose=False) with pytest.raises(ValueError): allele_expectation(bgen, 1) bgen = read_bgen(example_filepath("complex.23bits.bgen"), verbose=False) e = allele_expectation(bgen, 3) assert_allclose( e, [[1.0, 0.0, 0.0], [2.0, 0.0, 0.0], [1.0, 1.0, 0.0], [0.0, 2.0, 0.0]])
def test_dosage_example_32bits(): filepath = example_filepath("example.32bits.bgen") bgen = read_bgen(filepath, verbose=False) e = allele_expectation(bgen, 5) assert_allclose(e[7], [1.9556273911044997, 0.044372608895500334]) e = allele_expectation(bgen, 0) assert all(isnan(e[0])) e = allele_expectation(bgen, 0) assert_equal(e.shape, (500, 2))
def test_allele_frequency_interface(): filepath = example_filepath("complex.23bits.bgen") with pytest.raises(ValueError): bgen = read_bgen(filepath, verbose=False) allele_expectation(bgen, 1) bgen = read_bgen(filepath, verbose=False) expec = allele_expectation(bgen, 3) freq = allele_frequency(expec) assert_allclose(freq, [1.33333333333, 1.0, 0.0]) freq = allele_frequency([[1.0, 0.0, 0.0], [2.0, 0.0, 0.0], [1.0, 1.0, 0.0], [0.0, 2.0, 0.0]]) assert_allclose(freq, [1.33333333333, 1.0, 0.0]) with pytest.raises(ValueError): allele_frequency([2, 3, 1])
def test_compute_dosage(): with example_files("example.32bits.bgen") as filepath: bgen = read_bgen(filepath, verbose=False) variant_idx = 2 e = allele_expectation(bgen, variant_idx) dosage = compute_dosage(e) assert_allclose( dosage[:5], [ 0.015502935046214363, 0.9938354277968955, 1.9793395833064196, 0.9956054727070978, 1.978790270625332, ], )
def test_dosage_interface(): bgen = read_bgen(example_filepath("complex.23bits.bgen"), verbose=False) e = allele_expectation(bgen, 3) assert_allclose(compute_dosage(e), [0, 0, 0, 0]) assert_allclose(compute_dosage(e, 0), [1.0, 2.0, 1.0, 0.0])