Skip to content

count of ibd segments between all sampled pairs #1241

Answered by jeromekelleher
hancockzb asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Zach! 👋

This is actually not a simple question at all - computing IBD segments efficiently is not easy, and we don't have any public APIs for doing this at the moment. Here's a simple brute-force approach though, that you might be able to adapt for your purposes:

import itertools
import dataclasses
import msprime


@dataclasses.dataclass
class IbdSegment:
    pair: (int, int)
    mrca: int
    left: float = 0
    right: float = -1


ts = msprime.simulate(5, recombination_rate=0.01, length=40, random_seed=42)
print(ts.draw_text())

pairs = list(itertools.combinations(ts.samples(), 2))
tree = ts.first()
mrca_map = {pair: IbdSegment(pair, tree.mrca(*pair)) for pair in pairs}
ibd_segs = []

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by benjeffery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants