msprime icon indicating copy to clipboard operation
msprime copied to clipboard

Support internal samples in simulation through pedigree

Open jeromekelleher opened this issue 2 years ago • 16 comments

A simplification made in #1846 was to disallow samples that are internal nodes in the pedigree (i.e., samples cannot have children). It would not be difficult to implement, it just needs some thinking through exactly what the semantics are.

jeromekelleher avatar Oct 05 '21 13:10 jeromekelleher

Ran into the error pointing me to this issue. I am interested in this as well.

apragsdale avatar Nov 03 '21 16:11 apragsdale

I am also interested, as I would like some ground-truth examples of simulations with non-contemporaneous samples and known pedigrees to test tsinfer (see https://github.com/tskit-dev/tsinfer/discussions/602).

hyanwong avatar Nov 09 '21 17:11 hyanwong

I'm thinking about this a bit more. Based on some recent discussion in the msprime Slack channel, I realized that the DTWF model also doesn't allow ancient samples to be direct ancestors of more recent samples, so it's not possible to sample direct (grand)parent-offspring relationships under DTWF. It would be great to be able to do this within the pedigree (e.g. simulate a bunch of trios within a population).

Would there need to be serious reworking of the backend, or is it mostly a matter of testing to make sure labeling ancient individuals as samples within the pedigree is doing what we expect? From #1846, it was hard to tell what the sticking point is here.

apragsdale avatar Nov 24 '21 17:11 apragsdale

There's a note on it here.

In principle it's simple - we just have to replace the existing segment chain for the sample a with a new chain (0, L, a) (so that we have ancestry everywhere for our sample) and insert edges for every segment x in the old chain, like

for (x = existing_segments_for_a_head; x != NULL; x = x->next) {
     if (x.node != a) {
         add_edge(x.left, x.right, a, x.node)
      }
}

(excuse the mixed up pseudocode!)

Hmm, that seems pretty straightforward actually - fancy having a go at it on the Python algoriths.py version @apragsdale ?

jeromekelleher avatar Nov 24 '21 19:11 jeromekelleher

Yes, I’d be happy to!

On 24 Nov 2021, at 13:33, Jerome Kelleher @.***> wrote:



There's a note on it herehttps://github.com/tskit-dev/msprime/blob/7fbaab3b031f7208cd82b79763e924260f412723/lib/msprime.c#L2184.

In principle it's simple - we just have to replace the existing segment chain for the sample a with a new chain (0, L, a) (so that we have ancestry everywhere for our sample) and insert edges for every segment x in the old chain, like

for (x = existing_segments_for_a_head; x != NULL; x = x->next) { add_edge(x.left, x.right, a, x.node) }

(excuse the mixed up pseudocode!)

Hmm, that seems pretty straightforward actually - fancy having a go at it on the Python algoriths.py version @apragsdalehttps://github.com/apragsdale ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/tskit-dev/msprime/issues/1855#issuecomment-978164864, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIBL46XJUA42WBSQOT62GC3UNU4XHANCNFSM5FLX6ERA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

apragsdale avatar Nov 24 '21 19:11 apragsdale

This functionality to sample subjects internal to the pedigree would be very useful to research I am conducting on probabilities of rare variant sharing by related individuals. I hope this is implemented soon in msprime.

abureau avatar May 12 '22 16:05 abureau

Thanks for letting us know you're interested in this feature @abureau. There's no immediate plans to work on it unfortunately, unless anyone wants help out by doing some coding/testing.

jeromekelleher avatar May 13 '22 08:05 jeromekelleher

I would be happy to test the implementation, but I do not master msprime to the point to code a new feature.

abureau avatar May 18 '22 10:05 abureau

Thanks @abureau - we'll definitely call on your help if/when it gets implemented. Unfortunately I can't dedicate any of my own time here, but I'm happy to help if someone else wants to do a bit of model coding.

jeromekelleher avatar May 18 '22 15:05 jeromekelleher