Skip to content

Commit 82064f2

Browse files
Initial steps for internal pedigree samples
1 parent 865acb6 commit 82064f2

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

algorithms.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1011,10 +1011,12 @@ def initialise(self, ts):
10111011
root_segments_tail[root] = seg
10121012
self.S[self.L] = -1
10131013

1014+
# FIXME should determine start_time from the youngest roots. See the C code.
1015+
start_time = 0
10141016
# Insert the segment chains into the algorithm state.
10151017
for node in range(ts.num_nodes):
10161018
lineage = root_lineages[node]
1017-
if lineage is not None:
1019+
if lineage is not None and ts.nodes_time[node] == start_time:
10181020
seg = lineage.head
10191021
left_end = seg.left
10201022
while seg is not None:
@@ -1617,6 +1619,7 @@ def process_pedigree_common_ancestors(self, ind, ploid):
16171619
material among its parent ploids.
16181620
"""
16191621
common_ancestors = ind.common_ancestors[ploid]
1622+
node = ind.nodes[ploid]
16201623
if len(common_ancestors) == 0:
16211624
# No ancestral material inherited on this ploid of this individual
16221625
return
@@ -1632,7 +1635,6 @@ def process_pedigree_common_ancestors(self, ind, ploid):
16321635
# monoploid genome for this ploid of this individual.
16331636
# If any coalescences occur, they use the corresponding node ID.
16341637
# FIXME update the population/label here
1635-
node = ind.nodes[ploid]
16361638
genome = self.merge_ancestors(common_ancestors, 0, 0, node)
16371639
if ind.parents[ploid] == tskit.NULL:
16381640
# If this individual is a founder we need to make sure that all

tests/test_algorithms.py

+17
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,23 @@ def test_pedigree_trio(self, r):
423423
input_tables.nodes.assert_equals(output_tables.nodes[: len(input_tables.nodes)])
424424
assert len(output_tables.edges) >= 2
425425

426+
@pytest.mark.parametrize("r", [0, 0.1, 1])
427+
def test_pedigree_internal_sample(self, r):
428+
input_tables = simulate_pedigree(num_founders=4, num_generations=4)
429+
flags = input_tables.nodes.flags
430+
flags[8:12] = tskit.NODE_IS_SAMPLE # Make inds 4 and 5 samples
431+
input_tables.nodes.flags = flags
432+
print(input_tables)
433+
with tempfile.TemporaryDirectory() as tmpdir:
434+
# ts_path = pathlib.Path(tmpdir) / "pedigree.trees"
435+
ts_path = "pedigree.trees"
436+
input_tables.dump(ts_path)
437+
ts = self.run_script(f"0 --from-ts {ts_path} -r {r} --model=fixed_pedigree")
438+
output_tables = ts.dump_tables()
439+
input_tables.individuals.assert_equals(output_tables.individuals)
440+
input_tables.nodes.assert_equals(output_tables.nodes[: len(input_tables.nodes)])
441+
assert len(output_tables.edges) >= 2
442+
426443
@pytest.mark.parametrize("num_founders", [1, 2, 20])
427444
def test_one_gen_pedigree(self, num_founders):
428445
tables = simulate_pedigree(num_founders=num_founders, num_generations=1)

0 commit comments

Comments
 (0)