Skip to content

Commit 680f9c5

Browse files
petrelharplkirk
authored andcommitted
make testing more clear
1 parent 2ddf6d0 commit 680f9c5

2 files changed

Lines changed: 73 additions & 53 deletions

File tree

python/tests/test_ld_matrix.py

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,38 +2063,36 @@ def compute_branch_stat(
20632063
ts
20642064
for ts in get_example_tree_sequences()
20652065
if ts.id
2066-
not in {
2067-
"no_samples",
2068-
"empty_ts",
2069-
# We must skip these cases so that tests run in a reasonable
2070-
# amount of time. To get more complete testing, these filters
2071-
# can be commented out. (runtime ~1hr)
2072-
"gap_0",
2073-
"gap_0.1",
2074-
"gap_0.5",
2075-
"gap_0.75",
2076-
"n=2_m=32_rho=0",
2077-
"n=10_m=1_rho=0",
2078-
"n=10_m=1_rho=0.1",
2079-
"n=10_m=2_rho=0",
2080-
"n=10_m=2_rho=0.1",
2081-
"n=10_m=32_rho=0",
2082-
"n=10_m=32_rho=0.1",
2083-
"n=10_m=32_rho=0.5",
2066+
in {
2067+
# We run only these cases so that tests run in a reasonable
2068+
# amount of time. All examples takes ~1hr.
2069+
"decapitate_recomb",
2070+
"gap_at_end",
2071+
"all_nodes_samples",
2072+
"internal_nodes_samples",
2073+
"mixed_internal_leaf_samples",
2074+
"bottleneck_n=3_mutated",
2075+
"bottleneck_n=10_mutated",
2076+
"rev_node_order",
2077+
"empty_tree",
2078+
"n=3_m=2_rho=0.5",
2079+
"n=3_m=32_rho=0",
2080+
"n=3_m=32_rho=0.1",
2081+
"n=2_m=1_rho=0",
2082+
"n=2_m=1_rho=0.1",
2083+
"n=2_m=1_rho=0.5",
2084+
"n=2_m=2_rho=0",
2085+
"n=2_m=2_rho=0.1",
2086+
"n=2_m=2_rho=0.5",
2087+
"n=2_m=32_rho=0.1",
2088+
"n=2_m=32_rho=0.5",
2089+
"n=3_m=1_rho=0",
2090+
"n=3_m=1_rho=0.5",
2091+
"n=3_m=2_rho=0",
2092+
"n=10_m=1_rho=0.5",
2093+
"n=10_m=2_rho=0.5",
20842094
# we keep one n=100 case to ensure bit arrays are working
2085-
"n=100_m=1_rho=0.1",
2086-
"n=100_m=1_rho=0.5",
2087-
"n=100_m=2_rho=0",
2088-
"n=100_m=2_rho=0.1",
2089-
"n=100_m=2_rho=0.5",
2090-
"n=100_m=32_rho=0",
2091-
"n=100_m=32_rho=0.1",
2092-
"n=100_m=32_rho=0.5",
2093-
"all_fields",
2094-
"back_mutations",
2095-
"multichar",
2096-
"multichar_no_metadata",
2097-
"bottleneck_n=100_mutated",
2095+
"n=100_m=1_rho=0",
20982096
}
20992097
],
21002098
)
@@ -2548,9 +2546,13 @@ def D2_ij_unbiased(X, n):
25482546
"ts,stat",
25492547
[
25502548
(
2551-
ts := [
2552-
p for p in get_example_tree_sequences() if p.id == "n=100_m=32_rho=0.5"
2553-
][0].values[0],
2549+
ts := tsutil.get_sim_example(
2550+
sample_size=100,
2551+
sequence_length=32,
2552+
recombination_rate=0.5,
2553+
mutation_rate=0.1,
2554+
seed=123,
2555+
),
25542556
"D",
25552557
),
25562558
(ts, "D2"),
@@ -2575,9 +2577,13 @@ def test_general_two_locus_site_stat(ts, stat):
25752577
"ts,stat",
25762578
[
25772579
(
2578-
ts := [
2579-
p for p in get_example_tree_sequences() if p.id == "n=100_m=32_rho=0.5"
2580-
][0].values[0],
2580+
ts := tsutil.get_sim_example(
2581+
sample_size=100,
2582+
sequence_length=32,
2583+
recombination_rate=0.5,
2584+
mutation_rate=0.1,
2585+
seed=123,
2586+
),
25812587
"r2_ij",
25822588
),
25832589
(ts, "D2_ij"),
@@ -2609,7 +2615,7 @@ def test_general_two_locus_two_way_site_stat(ts, stat):
26092615
],
26102616
)
26112617
def test_general_one_way_two_locus_stat_multiallelic(stat):
2612-
(ts,) = {t.id: t for t in get_example_tree_sequences()}["all_fields"].values
2618+
ts = tsutil.all_fields_ts()
26132619
func = getattr(GeneralStatFuncs, stat)
26142620
if stat == "r2":
26152621
result = ts.two_locus_count_stat(
@@ -2632,7 +2638,7 @@ def test_general_one_way_two_locus_stat_multiallelic(stat):
26322638
],
26332639
)
26342640
def test_general_two_way_two_locus_stat_multiallelic(stat):
2635-
(ts,) = {t.id: t for t in get_example_tree_sequences()}["all_fields"].values
2641+
ts = tsutil.all_fields_ts()
26362642
func = getattr(GeneralStatFuncs, stat)
26372643
if stat == "r2_ij":
26382644

python/tests/tsutil.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,6 +2463,28 @@ def get_back_mutation_examples():
24632463
yield insert_branch_mutations(ts)
24642464

24652465

2466+
@functools.lru_cache
2467+
def get_sim_example(
2468+
sample_size, sequence_length, recombination_rate, mutation_rate, seed
2469+
):
2470+
recomb_map = msprime.RecombinationMap.uniform_map(
2471+
sequence_length, recombination_rate
2472+
)
2473+
ts = msprime.simulate(
2474+
recombination_map=recomb_map,
2475+
mutation_rate=mutation_rate,
2476+
random_seed=seed,
2477+
population_configurations=[
2478+
msprime.PopulationConfiguration(sample_size),
2479+
msprime.PopulationConfiguration(0),
2480+
],
2481+
migration_matrix=[[0, 1], [1, 0]],
2482+
)
2483+
ts = insert_random_ploidy_individuals(ts, 4, seed=seed)
2484+
ts = add_random_metadata(ts, seed=seed)
2485+
return ts
2486+
2487+
24662488
def make_example_tree_sequences(custom_max=None):
24672489
yield from get_decapitated_examples(custom_max=custom_max)
24682490
yield from get_gap_examples(custom_max=custom_max)
@@ -2475,22 +2497,14 @@ def make_example_tree_sequences(custom_max=None):
24752497
for n in n_list:
24762498
for m in [1, 2, 32]:
24772499
for rho in [0, 0.1, 0.5]:
2478-
recomb_map = msprime.RecombinationMap.uniform_map(m, rho, num_loci=m)
2479-
ts = msprime.simulate(
2480-
recombination_map=recomb_map,
2500+
ts = get_sim_example(
2501+
sample_size=n,
2502+
sequence_length=m,
2503+
recombination_rate=rho,
24812504
mutation_rate=0.1,
2482-
random_seed=seed,
2483-
population_configurations=[
2484-
msprime.PopulationConfiguration(n),
2485-
msprime.PopulationConfiguration(0),
2486-
],
2487-
migration_matrix=[[0, 1], [1, 0]],
2488-
)
2489-
ts = insert_random_ploidy_individuals(ts, 4, seed=seed)
2490-
yield (
2491-
f"n={n}_m={m}_rho={rho}",
2492-
add_random_metadata(ts, seed=seed),
2505+
seed=seed,
24932506
)
2507+
yield (f"n={n}_m={m}_rho={rho}", ts)
24942508
seed += 1
24952509
for name, ts in get_bottleneck_examples(custom_max=custom_max):
24962510
yield (

0 commit comments

Comments
 (0)