-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from szhan/split_tests_by_algo
Split tests by algorithm
- Loading branch information
Showing
10 changed files
with
501 additions
and
470 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import pytest | ||
|
||
from . import lsbase | ||
import lshmm as ls | ||
import lshmm.core as core | ||
import lshmm.vit_diploid as vd | ||
|
||
|
||
class TestViterbiDiploid(lsbase.ViterbiAlgorithmBase): | ||
def verify(self, ts, scale_mutation_rate, include_ancestors): | ||
for n, m, H_vs, query, e_vs, r, mu in self.get_examples_pars( | ||
ts, | ||
ploidy=2, | ||
scale_mutation_rate=scale_mutation_rate, | ||
include_ancestors=include_ancestors, | ||
include_extreme_rates=True, | ||
): | ||
G_vs = core.convert_haplotypes_to_phased_genotypes(H_vs) | ||
s = core.convert_haplotypes_to_unphased_genotypes(query) | ||
num_alleles = core.get_num_alleles(H_vs, query) | ||
|
||
V_vs, P_vs, ll_vs = vd.forwards_viterbi_dip_low_mem( | ||
n=n, | ||
m=m, | ||
G=G_vs, | ||
s=s, | ||
e=e_vs, | ||
r=r, | ||
) | ||
path_vs = vd.backwards_viterbi_dip(m=m, V_last=V_vs, P=P_vs) | ||
phased_path_vs = vd.get_phased_path(n=n, path=path_vs) | ||
path, ll = ls.viterbi( | ||
reference_panel=G_vs, | ||
query=s, | ||
num_alleles=num_alleles, | ||
prob_recombination=r, | ||
prob_mutation=mu, | ||
scale_mutation_rate=scale_mutation_rate, | ||
) | ||
|
||
self.assertAllClose(ll_vs, ll) | ||
self.assertAllClose(phased_path_vs, path) | ||
|
||
@pytest.mark.parametrize("scale_mutation_rate", [True, False]) | ||
@pytest.mark.parametrize("include_ancestors", [True, False]) | ||
def test_ts_simple_n10_no_recomb(self, scale_mutation_rate, include_ancestors): | ||
ts = self.get_ts_simple_n10_no_recomb() | ||
self.verify( | ||
ts, | ||
scale_mutation_rate=scale_mutation_rate, | ||
include_ancestors=include_ancestors, | ||
) | ||
|
||
@pytest.mark.parametrize("scale_mutation_rate", [True, False]) | ||
@pytest.mark.parametrize("include_ancestors", [True, False]) | ||
def test_ts_simple_n6(self, scale_mutation_rate, include_ancestors): | ||
ts = self.get_ts_simple_n6() | ||
self.verify( | ||
ts, | ||
scale_mutation_rate=scale_mutation_rate, | ||
include_ancestors=include_ancestors, | ||
) | ||
|
||
@pytest.mark.parametrize("scale_mutation_rate", [True, False]) | ||
@pytest.mark.parametrize("include_ancestors", [True, False]) | ||
def test_ts_simple_n8(self, scale_mutation_rate, include_ancestors): | ||
ts = self.get_ts_simple_n8() | ||
self.verify( | ||
ts, | ||
scale_mutation_rate=scale_mutation_rate, | ||
include_ancestors=include_ancestors, | ||
) | ||
|
||
@pytest.mark.parametrize("scale_mutation_rate", [True, False]) | ||
@pytest.mark.parametrize("include_ancestors", [True, False]) | ||
def test_ts_simple_n8_high_recomb(self, scale_mutation_rate, include_ancestors): | ||
ts = self.get_ts_simple_n8_high_recomb() | ||
self.verify( | ||
ts, | ||
scale_mutation_rate=scale_mutation_rate, | ||
include_ancestors=include_ancestors, | ||
) | ||
|
||
@pytest.mark.parametrize("scale_mutation_rate", [True, False]) | ||
@pytest.mark.parametrize("include_ancestors", [True, False]) | ||
def test_ts_simple_n16(self, scale_mutation_rate, include_ancestors): | ||
ts = self.get_ts_simple_n16() | ||
self.verify( | ||
ts, | ||
scale_mutation_rate=scale_mutation_rate, | ||
include_ancestors=include_ancestors, | ||
) | ||
|
||
@pytest.mark.parametrize("scale_mutation_rate", [True, False]) | ||
@pytest.mark.parametrize("include_ancestors", [True, False]) | ||
def test_ts_larger(self, scale_mutation_rate, include_ancestors): | ||
ts = self.get_ts_custom_pars( | ||
ref_panel_size=45, length=1e5, mean_r=1e-5, mean_mu=1e-5 | ||
) | ||
self.verify( | ||
ts, | ||
scale_mutation_rate=scale_mutation_rate, | ||
include_ancestors=include_ancestors, | ||
) |
Oops, something went wrong.