Skip to content

Commit c818a6c

Browse files
szhanmergify[bot]
authored andcommitted
Fix tests for lshmm 0.0.8
1 parent d3c59ba commit c818a6c

File tree

5 files changed

+176
-109
lines changed

5 files changed

+176
-109
lines changed

python/requirements/CI-complete/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ coverage==7.2.7
33
dendropy==4.6.1
44
h5py==3.9.0
55
kastore==0.3.2
6-
lshmm==0.0.5
6+
lshmm==0.0.8
77
msgpack==1.0.5
88
msprime==1.2.0
99
networkx==3.1

python/requirements/CI-tests-pip/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
lshmm==0.0.5
1+
lshmm==0.0.8
22
numpy==1.24.1
33
pytest==7.1.3
44
pytest-cov==4.0.0
@@ -14,4 +14,4 @@ newick==1.3.2
1414
tszip==0.2.2
1515
kastore==0.3.2
1616
lxml==4.9.2
17-
numba<=0.59.1 #Pinned directly as 0.60.0 fails
17+
numba<=0.59.1 #Pinned directly as 0.60.0 fails

python/requirements/development.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ h5py>=2.6.0
1010
jsonschema>=3.0.0
1111
jupyter-book>=0.12.1
1212
kastore
13-
lshmm>=0.0.5
13+
lshmm>=0.0.8
1414
matplotlib
1515
meson>=0.61.0
1616
msgpack>=1.0.0

python/tests/test_genotype_matching.py

Lines changed: 63 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import lshmm as ls
55
import msprime
66
import numpy as np
7+
import pytest
78

89
import tskit
910

@@ -1257,18 +1258,21 @@ def assertAllClose(self, A, B):
12571258

12581259
# Define a bunch of very small tree-sequences for testing a collection of
12591260
# parameters on
1261+
@pytest.mark.skip(reason="No plans to implement diploid LS HMM yet.")
12601262
def test_simple_n_10_no_recombination(self):
12611263
ts = msprime.simulate(
12621264
10, recombination_rate=0, mutation_rate=0.5, random_seed=42
12631265
)
12641266
assert ts.num_sites > 3
12651267
self.verify(ts)
12661268

1269+
@pytest.mark.skip(reason="No plans to implement diploid LS HMM yet.")
12671270
def test_simple_n_6(self):
12681271
ts = msprime.simulate(6, recombination_rate=2, mutation_rate=7, random_seed=42)
12691272
assert ts.num_sites > 5
12701273
self.verify(ts)
12711274

1275+
@pytest.mark.skip(reason="No plans to implement diploid LS HMM yet.")
12721276
def test_simple_n_8_high_recombination(self):
12731277
ts = msprime.simulate(8, recombination_rate=20, mutation_rate=5, random_seed=42)
12741278
assert ts.num_trees > 15
@@ -1326,11 +1330,10 @@ def verify(self, ts):
13261330
ts_check, mapping = ts.simplify(
13271331
range(1, n + 1), filter_sites=False, map_nodes=True
13281332
)
1333+
H_check = ts_check.genotype_matrix()
13291334
G_check = np.zeros((m, n, n))
13301335
for i in range(m):
1331-
G_check[i, :, :] = np.add.outer(
1332-
ts_check.genotype_matrix()[i, :], ts_check.genotype_matrix()[i, :]
1333-
)
1336+
G_check[i, :, :] = np.add.outer(H_check[i, :], H_check[i, :])
13341337

13351338
cm_d = ls_forward_tree(s[0, :], ts_check, r, mu)
13361339
ll_tree = np.sum(np.log10(cm_d.normalisation_factor))
@@ -1345,12 +1348,16 @@ def verify(self, ts):
13451348
self.assertAllClose(ll_tree, ll_mirror_tree_dict)
13461349

13471350
# Ensure that the decoded matrices are the same
1351+
flipped_H_check = np.flip(H_check, axis=0)
1352+
flipped_s = np.flip(s, axis=1)
1353+
13481354
F_mirror_matrix, c, ll = ls.forwards(
1349-
np.flip(G_check, axis=0),
1350-
np.flip(s, axis=1),
1351-
r_flip,
1352-
p_mutation=np.flip(mu),
1353-
scale_mutation_based_on_n_alleles=False,
1355+
flipped_H_check,
1356+
flipped_s,
1357+
ploidy=2,
1358+
prob_recombination=r_flip,
1359+
prob_mutation=np.flip(mu),
1360+
scale_mutation_rate=False,
13541361
)
13551362

13561363
self.assertAllClose(F_mirror_matrix, cm_mirror.decode())
@@ -1367,14 +1374,18 @@ def verify(self, ts):
13671374
ts_check, mapping = ts.simplify(
13681375
range(1, n + 1), filter_sites=False, map_nodes=True
13691376
)
1377+
H_check = ts_check.genotype_matrix()
13701378
G_check = np.zeros((m, n, n))
13711379
for i in range(m):
1372-
G_check[i, :, :] = np.add.outer(
1373-
ts_check.genotype_matrix()[i, :], ts_check.genotype_matrix()[i, :]
1374-
)
1380+
G_check[i, :, :] = np.add.outer(H_check[i, :], H_check[i, :])
13751381

13761382
F, c, ll = ls.forwards(
1377-
G_check, s, r, p_mutation=mu, scale_mutation_based_on_n_alleles=False
1383+
reference_panel=H_check,
1384+
query=s,
1385+
ploidy=2,
1386+
prob_recombination=r,
1387+
prob_mutation=mu,
1388+
scale_mutation_rate=False,
13781389
)
13791390
cm_d = ls_forward_tree(s[0, :], ts_check, r, mu)
13801391
self.assertAllClose(cm_d.decode(), F)
@@ -1393,22 +1404,27 @@ def verify(self, ts):
13931404
ts_check, mapping = ts.simplify(
13941405
range(1, n + 1), filter_sites=False, map_nodes=True
13951406
)
1407+
H_check = ts_check.genotype_matrix()
13961408
G_check = np.zeros((m, n, n))
13971409
for i in range(m):
1398-
G_check[i, :, :] = np.add.outer(
1399-
ts_check.genotype_matrix()[i, :], ts_check.genotype_matrix()[i, :]
1400-
)
1410+
G_check[i, :, :] = np.add.outer(H_check[i, :], H_check[i, :])
14011411

14021412
F, c, ll = ls.forwards(
1403-
G_check, s, r, p_mutation=mu, scale_mutation_based_on_n_alleles=False
1413+
reference_panel=H_check,
1414+
query=s,
1415+
ploidy=2,
1416+
prob_recombination=r,
1417+
prob_mutation=mu,
1418+
scale_mutation_rate=False,
14041419
)
14051420
B = ls.backwards(
1406-
G_check,
1407-
s,
1408-
c,
1409-
r,
1410-
p_mutation=mu,
1411-
scale_mutation_based_on_n_alleles=False,
1421+
reference_panel=H_check,
1422+
query=s,
1423+
ploidy=2,
1424+
normalisation_factor_from_forward=c,
1425+
prob_recombination=r,
1426+
prob_mutation=mu,
1427+
scale_mutation_rate=False,
14121428
)
14131429

14141430
# Note, need to remove the first sample from the ts, and ensure that
@@ -1447,22 +1463,28 @@ def verify(self, ts):
14471463
ts_check, mapping = ts.simplify(
14481464
range(1, n + 1), filter_sites=False, map_nodes=True
14491465
)
1466+
H_check = ts_check.genotype_matrix()
14501467
G_check = np.zeros((m, n, n))
14511468
for i in range(m):
1452-
G_check[i, :, :] = np.add.outer(
1453-
ts_check.genotype_matrix()[i, :], ts_check.genotype_matrix()[i, :]
1454-
)
1469+
G_check[i, :, :] = np.add.outer(H_check[i, :], H_check[i, :])
14551470
ts_check = ts.simplify(range(1, n + 1), filter_sites=False)
1471+
14561472
phased_path, ll = ls.viterbi(
1457-
G_check, s, r, p_mutation=mu, scale_mutation_based_on_n_alleles=False
1473+
reference_panel=H_check,
1474+
query=s,
1475+
ploidy=2,
1476+
prob_recombination=r,
1477+
prob_mutation=mu,
1478+
scale_mutation_rate=False,
14581479
)
1459-
path_ll_matrix = ls.path_ll(
1460-
G_check,
1461-
s,
1462-
phased_path,
1463-
r,
1464-
p_mutation=mu,
1465-
scale_mutation_based_on_n_alleles=False,
1480+
path_ll_matrix = ls.path_loglik(
1481+
reference_panel=H_check,
1482+
query=s,
1483+
ploidy=2,
1484+
path=phased_path,
1485+
prob_recombination=r,
1486+
prob_mutation=mu,
1487+
scale_mutation_rate=False,
14661488
)
14671489

14681490
c_v = ls_viterbi_tree(s[0, :], ts_check, r, mu)
@@ -1471,13 +1493,14 @@ def verify(self, ts):
14711493
# Attempt to get the path
14721494
path_tree_dict = c_v.traceback()
14731495
# Work out the likelihood of the proposed path
1474-
path_ll_tree = ls.path_ll(
1475-
G_check,
1476-
s,
1477-
np.transpose(path_tree_dict),
1478-
r,
1479-
p_mutation=mu,
1480-
scale_mutation_based_on_n_alleles=False,
1496+
path_ll_tree = ls.path_loglik(
1497+
reference_panel=H_check,
1498+
query=s,
1499+
ploidy=2,
1500+
path=np.transpose(path_tree_dict),
1501+
prob_recombination=r,
1502+
prob_mutation=mu,
1503+
scale_mutation_rate=False,
14811504
)
14821505

14831506
self.assertAllClose(ll, ll_tree)

0 commit comments

Comments
 (0)