Repository navigation
Parsimony algorithm. - #125
Conversation
Codecov Report
@@ Coverage Diff @@
## master #125 +/- ##
==========================================
- Coverage 86.47% 85.64% -0.84%
==========================================
Files 18 19 +1
Lines 9812 13735 +3923
Branches 1777 2665 +888
==========================================
+ Hits 8485 11763 +3278
- Misses 788 1022 +234
- Partials 539 950 +411
Continue to review full report at Codecov.
|
|
I think this is ready for merging, so it would be good to get some review. The documentation on the new I'm not entirely sure the interface is right (is "reconstruct" the right word?), so any thoughts on this would be appreciated. The implementation is fast: finding a parsimonious explanation for an arbitrary set of genotypes for a tree with 100K samples takes < 0.01 seconds. Pinging @hyanwong and @petrelharp for thoughts/review. |
|
TODO: this needs to handle missing data. |
Wow. That's seriously impressive. I will try to look through this, but may have more questions than answers. |
|
Just thought of an issue here with not having a consistent mapping of genotype value to base pair. It doesn't matter for Fitch, but for Sankoff we need a transition matrix where we need a consistent mapping from 0 -> "A", 1 -> "C" etc for the matrix to make sense. Options are:
|
|
Presumably most sites will have SNP-type variants, but some will be indels etc, which could be accounted for by having different cost matrices. I assume by 2. you mean having a list of matrices, with each site containing an index into the list? In other words, it's a bit like an additional tskit table, the "cost" table, which gives both the allele encoding and the cost of transition. |
Yes, exactly; it would be nice to have this generality.
Yes, that's a good way of looking at it. |
|
I may not be totally following here, but: you are wondering what about when the entries in the genotype matrix aren't consistently coded? This seems overly accomodating, and easy to deal with on the user's side. If all mutations are ACGT, then it is not hard to readjust the genotype matrix to be consistent, if this has not been done already. In fact, this seems easier than trying to wrangle the list of per-site cost matrices. If the user has more than one type of mutation, they could separate out the genotype sub-matrices corresponding to different cost matrices and pass those in. |
"Reconstruct" makes me think you're reconstructing the tree maybe. I think the more usual terminology for this is "mapping" the mutations on the tree? Maybe the method should be called |
|
For the future: it would be natural to make this a method of a tree sequence, and give also a vector of positions, so that this happens for each site on the tree for its site. |
|
Thanks @petrelharp, I like |
|
This is ready to go I think. Review would be appreciated here @petrelharp and @hyanwong! |
|
I'd like to get this one squared away soon, if possible. @hyanwong, would you mind taking a look through please and see if you agree with the high-level API and docs? This will be very useful in tsinfer, as we can get rid of the slow and crappy code for dealing with non-inference sites. Also, it has the first steps for dealing with missing data (missing genotype is -1, and genotypes are now signed). |
|
Right - will make this a priority today & tomorrow. Have to go for 2 hrs now but will be on this when I return. |
|
alert @bhaller vargen will be changing: |
Thanks for the heads-up. Whenever things are in a state where it makes sense to pull over the new code from tskit into SLiM, I can coordinate with you on that; up to you. (Well, until August 5th or so, and then I'll be busy until mid-September.) |
|
Looks great! |
|
Thanks @petrelharp! Quick question: after discussing this with Yan, I think it's better if we change the API to def map_mutations(self, genotypes, alleles):
# do stuff
return ancestral_state, mutationsWhere alleles is a list of strings, and we now return the ancestral state as a string and return a list actual mutation objects rather than An advantage of this is that the alleles = ["A", "T"]
costs = {("A", "T"): 0.1, ("T", "A"): 0.2)}
# or
costs = [
[0, 0.1],
[0.2, 0]]This would be nice and general I think, and should be reasonably intuitive in either direction. Any objections? |
|
That sounds much nicer! I'm not sure that specifying a dictionary mapping of pairs is actually useful, though, unless you're thinking of cases where some transitions are not possible. |
Great, I'll do that and merge. The advantage of the dictionary mapping pairs that the encoding 0->"A", 1->"C" etc can change from site to site (as it does with tskit's output). So, we can specify a single cost mapping for all sites without having to worry about permuting the numpy matrix each site. Anyway, we don't have to worry about that for now - the door is open to both approaches. |
This is a big advantage, in my book. |
This is a BREAKING CHANGE for C code. Should not affect Python code other than changing the dtype of the array silently. Closes tskit-dev#144.
Closes #99
WIP.