Skip to content

Change node labelling and add rooting to Nexus. - #1838

Merged
mergify[bot] merged 1 commit into
tskit-dev:mainfrom
jeromekelleher:nexus-cleanup
Nov 4, 2021
Merged

mergify[bot] merged 1 commit into
tskit-dev:mainfrom
jeromekelleher:nexus-cleanup

Conversation

@jeromekelleher

Copy link
Copy Markdown
Member

Batch of improvements for nexus handling.

Closes #1803
Closes #1815

@jeromekelleher
jeromekelleher marked this pull request as draft October 22, 2021 19:17
@codecov

codecov Bot commented Oct 22, 2021 •

Copy link
Copy Markdown

Codecov Report

Merging #1838 (2b11d74) into main (804aabb) will decrease coverage by 0.00%.
The diff coverage is 78.57%.

❗ Current head 2b11d74 differs from pull request most recent head 007e399. Consider uploading reports for the commit 007e399 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1838      +/-   ##
==========================================
- Coverage   93.43%   93.42%   -0.01%     
==========================================
  Files          27       27              
  Lines       24808    24818      +10     
  Branches     1094     1098       +4     
==========================================
+ Hits        23179    23186       +7     
- Misses       1594     1595       +1     
- Partials       35       37       +2     
Flag Coverage Δ
c-tests 92.20% <ø> (ø)
lwt-tests 89.14% <ø> (ø)
python-c-tests 94.52% <78.57%> (-0.02%) ⬇️
python-tests 98.70% <78.57%> (-0.06%) ⬇️

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

Impacted Files Coverage Δ
python/tskit/trees.py 97.66% <78.57%> (-0.18%) ⬇️

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 804aabb...007e399. Read the comment docs.

@jeromekelleher

Copy link
Copy Markdown
Member Author

This is ready for review now I think. I've ended up changing quite a lot here, as there was a lot of technical debt incurred on these code paths. Essentially, the newick output hadn't been touched since the very early days when all I wanted it to do was mimic ms output as efficiently as possible. This is as long-overdue spring clean.

The main changes are to add a new as_newick method to the Tree class, which has a sensible default labelling scheme, and to also add as_nexus which has uses the same conventions. I decided that the to_nexus method was unsalvagable, and since we'd been moving towards using as_ rather than to_ recently it seemed best to dump it. Since it was basically useless I'd be very surprised if anyone was actually using it.

I know there's a lot of code changes here, but I'd really appreciate it if you could take a look the API updates (in trees.py) and the examples in the test cases test_phylo_formats.py @jeetsukumaran.

Does the new spatial coordinate encoding ("tree|{tree.interval.left}^{tree.interval.right|") look OK to you? I don't have any particular attachment to it, it was just the best I could come up with that parsed in dendropy. Happy to consider alternatives.

Note there's also the question of whether we should output the alignments in the nexus output, so I've opened #1840 to track.

@jeetsukumaran

Copy link
Copy Markdown
Contributor

Quick look, and it seems fine.

Only thing to remark is that some programs may not be able to handle the pipe character in the tree labels. But that is speculative. PAUP* (reference standard for me) and DendroPy have no issues. In any case, it's easy to fix downstream if needed, and most programs ignore the labels anyway. OTOH, tree0^2, tree2^10 are just as easy to parse and there is no loss of information, so maybe that would be more robust?

@jeromekelleher

jeromekelleher commented Oct 26, 2021 •

Copy link
Copy Markdown
Member Author

Good point @jeetsukumaran - I've changed to f"t{x}^{y}", so we get output like this with precision=2:

#NEXUS
BEGIN TAXA;
  DIMENSIONS NTAX=3;
  TAXLABELS n0 n1 n2;
END;
BEGIN TREES;
  TREE t0.00^2.00 = [&R] (n0:3.00,(n1:2.00,n2:2.00):1.00);
  TREE t2.00^10.00 = [&R] (n1:2.00,(n0:1.00,n2:1.00):1.00);
END;

On reflection, the "tree" prefix is superfluous, and it's consistent that we use the prefix "t" to denote a tree like we use "n" to denote a node. So, "t{x}^{y}" is the tree defined on interval left=x, right=y and "n{u}" is the node with ID u. This seems logical and consistent.

Do you see any issues @jeetsukumaran?

@jeromekelleher

Copy link
Copy Markdown
Member Author

@Mergifyio rebase

@mergify

mergify Bot commented Nov 2, 2021

Copy link
Copy Markdown
Contributor

rebase

✅ Branch has been successfully rebased

@benjeffery

Copy link
Copy Markdown
Member

@Mergifyio rebase

@mergify

mergify Bot commented Nov 3, 2021

Copy link
Copy Markdown
Contributor

rebase

❌ Base branch update has failed

Details

Git reported the following error:

Rebasing (1/1)
error: could not apply ec4840f... Phylo export methods cleanup
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply ec4840f... Phylo export methods cleanup
Auto-merging python/tskit/trees.py
Auto-merging python/tests/test_highlevel.py
Auto-merging python/CHANGELOG.rst
CONFLICT (content): Merge conflict in python/CHANGELOG.rst

err-code: 75871

@benjeffery benjeffery 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.

Very nice, just one fix. Agree with the naming you've gone for here.

Comment thread python/tskit/trees.py Outdated
buffer_size=buffer_size,
legacy_ms_labels=legacy_ms_labels,
)
return

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.

Looks like an extra return slipped in.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Aha, thanks! Surprising flake8 didn't spot this.

- Remove TreeSequence.to_nexus and add TreeSequence.as_nexus
- Add Tree.as_newick and refactor
- Update C newick generation to cover new defaults
- Refactor newick testing code paths

Closes tskit-dev#1803
Closes tskit-dev#1815
Closes tskit-dev#1671
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.

Nexus trees should be marked with "rooted" indicator Node labels in to_nexus are ambiguous

3 participants