Skip to content

Missing genotypes in variants and genotype_matrix - #272

Merged
jeromekelleher merged 9 commits into
tskit-dev:masterfrom
jeromekelleher:missing-genotypes
Aug 6, 2019
Merged

jeromekelleher merged 9 commits into
tskit-dev:masterfrom
jeromekelleher:missing-genotypes

Conversation

@jeromekelleher

Copy link
Copy Markdown
Member

Here's the basic proposal:

  • Add a flag isolated_samples_missing (or something) to variants/genotype_matrix.
  • When this is true, for each site after we have generated all the genotypes in the usual way, update them to mark any samples that are 'isolated' as missing data (-1). An isolated sample is defined as a root that has no children, which I think covers all the cases where we would actually want to consider a sample as missing. (Note to self: there is a complication here when we are generating genotypes for non-sample nodes, in that we'll need to check if the root in question is one of the input list of nodes as well.)
  • If we find at least one isolated root, we add a value to the end of the list of alleles to indicate this. In python this will be None and an C it'll be NULL. This will allow users to quickly check if there's any missing data, without needing to look at the genotypes.

There's some work to be done here, but I thought I'd share the basic idea first to see what people think before going any further with it. Pinging @hyanwong and @petrelharp for input.

Closes #270

@codecov

codecov Bot commented Jul 26, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #272 into master will increase coverage by 0.02%.
The diff coverage is 93.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #272      +/-   ##
==========================================
+ Coverage   85.82%   85.85%   +0.02%     
==========================================
  Files          19       19              
  Lines       14093    14162      +69     
  Branches     2742     2758      +16     
==========================================
+ Hits        12096    12159      +63     
- Misses       1043     1048       +5     
- Partials      954      955       +1
Flag Coverage Δ
#c_tests 86.78% <93.75%> (+0.02%) ⬆️
#python_c_tests 89.94% <94.11%> (-0.01%) ⬇️
#python_tests 99.17% <100%> (?)
Impacted Files Coverage Δ
c/tskit/core.c 81.32% <0%> (-1.29%) ⬇️
c/tskit/genotypes.c 89.03% <100%> (+1.53%) ⬆️
python/tskit/trees.py 98.58% <100%> (ø) ⬆️
python/_tskitmodule.c 83.38% <92%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cb7a45c...5cb42f1. Read the comment docs.

@hyanwong

Copy link
Copy Markdown
Member

This seems like a reasonable way to deal with the issue to me. The only down side is that this way, the missingness criterion (i.e. the value to use for isolated_samples_missing) is not encoded in the tree sequence itself, but has to be recorded elsewhere. So e.g. when round-tripping data from a SampleData file, through tsinfer, and back to a variant matrix, I will have to remember whether the file contained missing data (and if so, ensure that isolated_samples_missing=True for all potential variants).

@jeromekelleher

Copy link
Copy Markdown
Member Author

I think this is OK - for tsinfer derived tree sequences where we expect to deal with missing data we always set isolated_samples_missing=True. If there is no missing data, then there'll be no missing data in the output genotypes.

If client code doesn't know how to deal with missing data, by default any missing states are imputed as the ancestral state (which, I guess, is reasonable).

So, the missingness criteria is encoded in the tree sequence (samples with no edges), but how you deal with that missingness is determined by the user. If the user wants to know explicitly that the sites are missing when generating genotypes, they set isolated_samples_missing=True. Otherwise, by default, we impute missing sites for samples marked as missing data to be the ancestral state.

There's a different conversation to be had about how we deal with short regions of missing data within tsinfer (should we break edges and output them as missing, or should we impute the states using LS?), but that's something to discuss in the context of inference rather than tskit.

@jeromekelleher

Copy link
Copy Markdown
Member Author

Or, we could make this the default behaviour and add a flag impute_missing to fill in the missing data as ancestral state. I don't think it'll affect anyone to change the default behaviour here as this is pretty esoteric to people not developing on tsinfer. On reflection, this is probably the right thing to do - users should have to make a conscious decision to impute the missing data.

@petrelharp, any thoughts on this? I actually need this for something I'm working on now, so I'd like to push it through ASAP.

@jeromekelleher
jeromekelleher force-pushed the missing-genotypes branch 3 times, most recently from 830adae to afff9f7 Compare August 1, 2019 01:04
@jeromekelleher

Copy link
Copy Markdown
Member Author

... and of course this has implications for the stats. Currently most site based tests are broken as the default behaviour of genotype_matrix has changed.

@petrelharp

Copy link
Copy Markdown
Contributor

I think that making "isolated nodes = missing" is probably the right thing to do. I can think of all sorts of potential questions (what if there are two sister nodes in their own tree? why are they not missing?) but not questions that are likely to come up in practice. The case of ancestral nodes that aren't specified in the current tree is much more important, and these should obviously be missing.

(Note: the more obvious method of just sticking a "missing" mutation above the relevant samples should also work - because just because someone's genotype is unknown at a site doesn't mean we don't have a good guess at their location in the genealogy... but this we already have, right?)

@hyanwong

hyanwong commented Aug 1, 2019

Copy link
Copy Markdown
Member

I agree that having isolated nodes as missing seems the most sensible default, FWIW

@jeromekelleher
jeromekelleher force-pushed the missing-genotypes branch 4 times, most recently from 032a650 to b78490c Compare August 2, 2019 21:06
Jerome Kelleher added 6 commits August 2, 2019 22:06
The haplotype generator will now fail if missing data is detected and
impute missing is not set.
Also fixed up tests that depended on the missing data imputation
property of haplotypes and genotypes.
@jeromekelleher

Copy link
Copy Markdown
Member Author

Notes to self, TODO

  • Add some specific tests for behaviour in the new module, i.e. haplotypes should raise exceptions in specific cases
  • document changes to haplotypes, variants, genotype_matrix
  • Add a section in the documentation laying out the rationale and how it works.

Also port test cases for genotypes into new file, test_genotypes.
@jeromekelleher

Copy link
Copy Markdown
Member Author

I think this is ready to merge - final reviews anyone?

Comment thread docs/data-model.rst Resolved
@petrelharp

Copy link
Copy Markdown
Contributor

Looks good to me! I got confused for a bit about why we can't also denote missingness by setting the derived state of a mutation to "missing", but after thinking about it more, I like this approach.

@jeromekelleher

Copy link
Copy Markdown
Member Author

OK, merging.

@jeromekelleher
jeromekelleher merged commit ec2fac3 into tskit-dev:master Aug 6, 2019
@jeromekelleher
jeromekelleher deleted the missing-genotypes branch August 6, 2019 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ancestral states when sample data is missing

3 participants