Skip to content

Implement standard compliant Nexus - #1801

Closed
jeetsukumaran wants to merge 11 commits into
tskit-dev:mainfrom
jeetsukumaran:main
Closed

jeetsukumaran wants to merge 11 commits into
tskit-dev:mainfrom
jeetsukumaran:main

Conversation

@jeetsukumaran

@jeetsukumaran jeetsukumaran commented Oct 16, 2021 •

Copy link
Copy Markdown
Contributor

Description

to_nexus() will now implement standard compliant Nexus.

Fixes #1785

PR Checklist:

  • Tests that fully cover new/changed functionality.
  • Documentation including tutorial content if appropriate.
  • Changelogs, if there are API changes.

@codecov

codecov Bot commented Oct 16, 2021 •

Copy link
Copy Markdown

Codecov Report

Merging #1801 (9781378) into main (6b4d127) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1801   +/-   ##
=======================================
  Coverage   93.43%   93.43%           
=======================================
  Files          27       27           
  Lines       24803    24804    +1     
  Branches     1094     1094           
=======================================
+ Hits        23174    23175    +1     
  Misses       1594     1594           
  Partials       35       35           
Flag Coverage Δ
c-tests 92.20% <ø> (ø)
lwt-tests 89.14% <ø> (ø)
python-c-tests 94.53% <100.00%> (+<0.01%) ⬆️
python-tests 98.75% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
python/tskit/trees.py 97.84% <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 6b4d127...9781378. Read the comment docs.

@jeetsukumaran

Copy link
Copy Markdown
Contributor Author

CI is failing due to one new branch in the code (the option to wrap underscores in quotes so they will be interpreted as underscores rather than spaces when parsed by a strict Nexus-compliant program) not being tested.

As things stand, I can do one of the following:

(1) Remove the branch (i.e., the option to wrap in quotes).

(2) Hack in a dummy test that visits that branch but doesn't really do
anything.

(3) Import dendropy into the test code to properly test the branch.

The reason for (2) and (3) is, unfortunately, as far as I can tell,
Bio.Nexus is very rudimentary in its nexus support and I don't think it
understands how to deal with quotes. So there is no way to test the
"quote" branch without some hackery in the test. On the other hand, data
format parsing/writing is the primary raison d'etre of dendropy :), so
bringing it in will provide some clean testing. However, I am reluctant
to introduce a dendropy dependency so early on (though if you all are Ok
with it, I can go ahead).

Right now, I'm leaning toward (1). (2) has a bad code smell to me, and
as I said, I don't want to introduce dendropy as dependency unless you
folks are all for it. (Side effect, of course, is that it will be
trivial to parse/emit rich, flexible, standards-compliant (or not)
Newick, Nexus, Phylip, NeXML, Fasta, etc. if we do).

@jeromekelleher

Copy link
Copy Markdown
Member

I think (1) is the simplest option for now @jeetsukumaran, as we should probably think a bit more about what the default labels should be in the first place (no point in emitting non-compliant/ambiguous labels by default).

I'm perfectly happy to add dendropy to the test requirements, and maybe it would be good to replace the verifications that we currently have using BioPython with dendropy? Or just add an additional step to verify_nexus which just parses with dendropy, as a quick way of verifying the structure is OK?

@jeromekelleher

Copy link
Copy Markdown
Member

I've added #1803 to discuss the node labels @jeetsukumaran - I think it would be better to change them to something non-ambiguous rather than adding quotes.

@jeetsukumaran

Copy link
Copy Markdown
Contributor Author

So the protected vs. unprotected underscores being interpreted one way or another is an OK "wart" to have now. Fact is, that lots of supposedly Nexus-compliant programs sometimes respect it and sometimes don't. However, at least they are internally consistent. So in practice it doesn't matter if an underscore is "meant" by tskit and a (strictly-compliant) program reads the labels as having spaces, as the trees/data all makes sense internally. The only issue arises if there are mixed sources and the labels have to correspond across sources. This can certainly arise, e.g., if data generated by tskit (with labels such as "tsk_2001_1010" is fed into a program that interprets the underscores as spaces and then this outputs something with labels normalized to its internal representation like "tsk 2001 1010". and then this data is used in conjunction with the original tskit data in yet another program. That's where the problems arise. But due to variation in nexus handling, most folks are familiar enough with these gotchas to, e.g., preprocess one or the other data sets to ensure label consistency. Of course, it's not ideal, but folks are used to it, and it is what it :).

Even more unfortunately, the "correct" handling of the underscores is probably in the minority of bioinformatics packages and maybe even in phylogenetics programs, so defaulting to the correct behavior may end up being more annoying (that's what I discovered in dendropy).

Given all this, I agree that in the short run, (1) is the way to go. While not semantically correct, it is syntactically correct, and it will work for 90% of folks, 90% of the time (and the remaining 10%/10% can easily fix it with some pre- or post-processing). So I will revert the quoting changes and submit a new PR.

@benjeffery benjeffery changed the title Updated tests Implement standard compliant Nexus Oct 18, 2021
@jeromekelleher

Copy link
Copy Markdown
Member

Looks good, thanks @jeetsukumaran. I would be nice to test this though - how about I follow up with a PR in which we add dendropy as a test dependency and do some basic round-tripping tests based on that?

Can you squash down the commits please so it's ready to merge?

@jeromekelleher

Copy link
Copy Markdown
Member

Superseded by #1835

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.

to_nexus() does not emit compliant Nexus

2 participants