Skip to content

Commit

Permalink
Initial steps for internal pedigree samples
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromekelleher committed Sep 4, 2024
1 parent 865acb6 commit 82064f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,10 +1011,12 @@ def initialise(self, ts):
root_segments_tail[root] = seg
self.S[self.L] = -1

# FIXME should determine start_time from the youngest roots. See the C code.
start_time = 0
# Insert the segment chains into the algorithm state.
for node in range(ts.num_nodes):
lineage = root_lineages[node]
if lineage is not None:
if lineage is not None and ts.nodes_time[node] == start_time:
seg = lineage.head
left_end = seg.left
while seg is not None:
Expand Down Expand Up @@ -1617,6 +1619,7 @@ def process_pedigree_common_ancestors(self, ind, ploid):
material among its parent ploids.
"""
common_ancestors = ind.common_ancestors[ploid]
node = ind.nodes[ploid]
if len(common_ancestors) == 0:
# No ancestral material inherited on this ploid of this individual
return
Expand All @@ -1632,7 +1635,6 @@ def process_pedigree_common_ancestors(self, ind, ploid):
# monoploid genome for this ploid of this individual.
# If any coalescences occur, they use the corresponding node ID.
# FIXME update the population/label here
node = ind.nodes[ploid]
genome = self.merge_ancestors(common_ancestors, 0, 0, node)
if ind.parents[ploid] == tskit.NULL:
# If this individual is a founder we need to make sure that all
Expand Down
17 changes: 17 additions & 0 deletions tests/test_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,23 @@ def test_pedigree_trio(self, r):
input_tables.nodes.assert_equals(output_tables.nodes[: len(input_tables.nodes)])
assert len(output_tables.edges) >= 2

@pytest.mark.parametrize("r", [0, 0.1, 1])
def test_pedigree_internal_sample(self, r):
input_tables = simulate_pedigree(num_founders=4, num_generations=4)
flags = input_tables.nodes.flags
flags[8:12] = tskit.NODE_IS_SAMPLE # Make inds 4 and 5 samples
input_tables.nodes.flags = flags
print(input_tables)
with tempfile.TemporaryDirectory() as tmpdir:
# ts_path = pathlib.Path(tmpdir) / "pedigree.trees"
ts_path = "pedigree.trees"
input_tables.dump(ts_path)
ts = self.run_script(f"0 --from-ts {ts_path} -r {r} --model=fixed_pedigree")
output_tables = ts.dump_tables()
input_tables.individuals.assert_equals(output_tables.individuals)
input_tables.nodes.assert_equals(output_tables.nodes[: len(input_tables.nodes)])
assert len(output_tables.edges) >= 2

@pytest.mark.parametrize("num_founders", [1, 2, 20])
def test_one_gen_pedigree(self, num_founders):
tables = simulate_pedigree(num_founders=num_founders, num_generations=1)
Expand Down

0 comments on commit 82064f2

Please # to comment.