Skip to content

Tree num lineages - #2422

Merged
mergify[bot] merged 2 commits into
tskit-dev:mainfrom
jeromekelleher:tree-num-lineages
Jul 22, 2022
Merged

mergify[bot] merged 2 commits into
tskit-dev:mainfrom
jeromekelleher:tree-num-lineages

Conversation

@jeromekelleher

Copy link
Copy Markdown
Member

Adds the Tree.num_lineages(t) method as discussed in #386 and elsewhere.

The definition is slightly tricky because we're not just counting the edges that intersect with a given time/space coordinate, but we're also counting the number of roots. It seems logical that the number of lineages in a tree for any time greater than the root time should be 1 (assuming a single root) rather than 0.

I didn't bother adding the vector form (where t can be a sorted list of values) because it's a lot more work, and we can add it later if we want. This will be efficient enough for most purposes I think.

@savitakartik, @a-ignatieva - we should now be able to define the Relate statistic p-value easily in terms of this, right?

@codecov

codecov Bot commented Jul 19, 2022 •

Copy link
Copy Markdown

Codecov Report

Merging #2422 (2e029b6) into main (c12c160) will increase coverage by 0.01%.
The diff coverage is 95.65%.

❗ Current head 2e029b6 differs from pull request most recent head 757029a. Consider uploading reports for the commit 757029a to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2422      +/-   ##
==========================================
+ Coverage   93.34%   93.36%   +0.01%     
==========================================
  Files          28       28              
  Lines       27006    27052      +46     
  Branches     1253     1253              
==========================================
+ Hits        25209    25256      +47     
+ Misses       1763     1762       -1     
  Partials       34       34              
Flag Coverage Δ
c-tests 92.26% <92.85%> (+<0.01%) ⬆️
lwt-tests 89.05% <ø> (ø)
python-c-tests 70.96% <94.44%> (+0.05%) ⬆️
python-tests 98.93% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
c/tskit/trees.c 94.97% <92.85%> (-0.02%) ⬇️
python/_tskitmodule.c 90.73% <100.00%> (+0.06%) ⬆️
python/tskit/trees.py 98.66% <100.00%> (+<0.01%) ⬆️

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 c12c160...757029a. Read the comment docs.

@a-ignatieva

a-ignatieva commented Jul 19, 2022 •

Copy link
Copy Markdown

Looks good @jeromekelleher! And yes then for the test we do k = 1 + t.num_lineages(t.time(m.node)) or something (the number of lineages just below the node carrying the mutation, but we shouldn't count all of the lineages if there is a polytomy - so take number of lineages just above + 1).

@jeromekelleher

Copy link
Copy Markdown
Member Author

@petrelharp - are you happy with this definition?

Comment thread python/tskit/trees.py Resolved
Comment thread python/tskit/trees.py Resolved
Comment thread c/tskit/trees.c Resolved
@petrelharp

Copy link
Copy Markdown
Contributor

Looks good to me. I could imagine not wanting the roots included, but we have zero use cases for this in the many-disconnected-trees case, so no need to complexify this. (that could be an option added later if necessary)

One question: will this skip missing samples? (i.e., if a sample is missing it's not included in the roots, right?)

@jeromekelleher

Copy link
Copy Markdown
Member Author

One question: will this skip missing samples? (i.e., if a sample is missing it's not included in the roots, right?)

Ah, hmm, great point. Actually no, it'll consider these are roots in the same way (see the test I just added in 8228392), so you'll count missing a node representing missing data as a lineage.

On reflection, that probably seems right? The lineage/missing sample does exist, we just don't know anything about it.

@petrelharp

Copy link
Copy Markdown
Contributor

I don't think that's right - we don't know anything about it, so it might coalesce into the existing trees more recently than t. (So, computing the statistics correctly would require knowing how many non-missing samples there are here.)

@jeromekelleher

Copy link
Copy Markdown
Member Author

Hmm - so should we just count the number of edges intersecting with time t then? This gives the same answer most of the time, except defines num_lineages = 0 when t >= time of the root. (So, in a binary singly rooted tree, we'd go from 2 lineages just before the root to 0 at and older than the root).

@petrelharp

Copy link
Copy Markdown
Contributor

That seems okay to me, yes?

@jeromekelleher

Copy link
Copy Markdown
Member Author

OK, I'll update. Better to have a simpler definition!

Modify the definition to be the number of edges intersecting with t.
@jeromekelleher

Copy link
Copy Markdown
Member Author

@petrelharp - updated to simpler definition.

@petrelharp petrelharp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mergify
mergify Bot merged commit fe2576d into tskit-dev:main Jul 22, 2022

@hyanwong hyanwong left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I completely agree with the missing-data rationale for not counting lineages above roots. I'm wondering about rephrasing the docstring, though, as if I were a newcomer I think I would find it a little hard to grok. If so, I'll make a minor PR.

@jeromekelleher
jeromekelleher deleted the tree-num-lineages branch July 27, 2022 13:03
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.

4 participants