Skip to content

Commit 726f717

Browse files
Fixup tests
1 parent 5876424 commit 726f717

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

sc2ts/inference.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ class Sample:
347347
mutations: List = dataclasses.field(default_factory=list)
348348
alignment_qc: Dict = dataclasses.field(default_factory=dict)
349349
masked_sites: List = dataclasses.field(default_factory=list)
350+
# FIXME need a better name for this, as it's a different thing
351+
# the original alignment. Haplotype is probably good, as it's
352+
# what it would be in the tskit/tsinfer world.
350353
alignment: List = None
351354

352355
# def __repr__(self):

tests/test_inference.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,9 @@ def test_two_samples_one_mutation_one_filtered(self, tmp_path):
175175

176176

177177
class TestMatchTsinfer:
178-
def match_tsinfer(self, samples, ts, haplotypes, **kwargs):
179-
assert len(samples) == len(haplotypes)
180-
G = np.array(haplotypes).T
178+
def match_tsinfer(self, samples, ts, **kwargs):
181179
sc2ts.inference.match_tsinfer(
182-
samples=samples, ts=ts, genotypes=G, num_mismatches=1000, **kwargs
180+
samples=samples, ts=ts, num_mismatches=1000, **kwargs
183181
)
184182

185183
@pytest.mark.parametrize("mirror", [False, True])
@@ -189,10 +187,11 @@ def test_match_reference(self, mirror):
189187
tables.sites.truncate(20)
190188
ts = tables.tree_sequence()
191189
samples = util.get_samples(ts, [[(0, ts.sequence_length, 1)]])
192-
samples[0].alignment = sc2ts.core.get_reference_sequence()
193-
ma = sc2ts.alignments.encode_and_mask(samples[0].alignment)
190+
alignment = sc2ts.core.get_reference_sequence()
191+
ma = sc2ts.alignments.encode_and_mask(alignment)
194192
h = ma.alignment[ts.sites_position.astype(int)]
195-
self.match_tsinfer(samples, ts, [h], mirror_coordinates=mirror)
193+
samples[0].alignment = h
194+
self.match_tsinfer(samples, ts, mirror_coordinates=mirror)
196195
assert samples[0].breakpoints == [0, ts.sequence_length]
197196
assert samples[0].parents == [ts.num_nodes - 1]
198197
assert len(samples[0].mutations) == 0
@@ -205,12 +204,13 @@ def test_match_reference_one_mutation(self, mirror, site_id):
205204
tables.sites.truncate(20)
206205
ts = tables.tree_sequence()
207206
samples = util.get_samples(ts, [[(0, ts.sequence_length, 1)]])
208-
samples[0].alignment = sc2ts.core.get_reference_sequence()
209-
ma = sc2ts.alignments.encode_and_mask(samples[0].alignment)
207+
alignment = sc2ts.core.get_reference_sequence()
208+
ma = sc2ts.alignments.encode_and_mask(alignment)
210209
h = ma.alignment[ts.sites_position.astype(int)]
211210
# Mutate to gap
212211
h[site_id] = sc2ts.core.ALLELES.index("-")
213-
self.match_tsinfer(samples, ts, [h], mirror_coordinates=mirror)
212+
samples[0].alignment = h
213+
self.match_tsinfer(samples, ts, mirror_coordinates=mirror)
214214
assert samples[0].breakpoints == [0, ts.sequence_length]
215215
assert samples[0].parents == [ts.num_nodes - 1]
216216
assert len(samples[0].mutations) == 1
@@ -230,11 +230,12 @@ def test_match_reference_all_same(self, mirror, allele):
230230
tables.sites.truncate(20)
231231
ts = tables.tree_sequence()
232232
samples = util.get_samples(ts, [[(0, ts.sequence_length, 1)]])
233-
samples[0].alignment = sc2ts.core.get_reference_sequence()
234-
ma = sc2ts.alignments.encode_and_mask(samples[0].alignment)
233+
alignment = sc2ts.core.get_reference_sequence()
234+
ma = sc2ts.alignments.encode_and_mask(alignment)
235235
ref = ma.alignment[ts.sites_position.astype(int)]
236236
h = np.zeros_like(ref) + allele
237-
self.match_tsinfer(samples, ts, [h], mirror_coordinates=mirror)
237+
samples[0].alignment = h
238+
self.match_tsinfer(samples, ts, mirror_coordinates=mirror)
238239
assert samples[0].breakpoints == [0, ts.sequence_length]
239240
assert samples[0].parents == [ts.num_nodes - 1]
240241
muts = samples[0].mutations

0 commit comments

Comments
 (0)