Preserve small Newick branch lengths by joeydufourd · Pull Request #5243 · biopython/biopython · GitHub
Skip to content

Preserve small Newick branch lengths#5243

Merged
peterjc merged 1 commit into
biopython:masterfrom
joeydufourd:fix-newick-branch-length-precision
Jun 22, 2026
Merged

Preserve small Newick branch lengths#5243
peterjc merged 1 commit into
biopython:masterfrom
joeydufourd:fix-newick-branch-length-precision

Conversation

@joeydufourd

@joeydufourd joeydufourd commented Jun 22, 2026

Copy link
Copy Markdown
Contributor
  • I hereby agree to dual licence this and any previous contributions under both
    the Biopython License Agreement AND the BSD 3-Clause License.

  • I have read the CONTRIBUTING.rst file, have run pre-commit
    locally, and understand that continuous integration checks will be used to
    confirm the Biopython unit tests and style checks pass with these changes.

  • I have added my name to the alphabetical contributors listings in the files
    NEWS.rst and CONTRIB.rst as part of this pull request, am listed
    already, or do not wish to be listed. (This acknowledgement is optional.)

Closes #5184

This PR updates the default Newick branch length format from %1.5f to %1.8g.

The previous default could silently round small nonzero branch lengths to 0.00000 when writing Newick trees, which can lose biologically meaningful distance information. Using significant digits preserves small values such as 0.000001 while avoiding unnecessarily long fixed-width decimal output for all branch lengths.

Changes included:

  • Update the default format_branch_length used by the Newick writer.
  • Add regression coverage for small nonzero branch lengths.
  • Update the expected Newick output for zero-length branches under the new default format.

Testing:

cd Tests
python -m pytest test_Phylo.py
python -m pre_commit run --files Bio/Phylo/NewickIO.py Tests/test_Phylo.py

Result:

39 passed, 1 warning
pre-commit passed

@joeydufourd joeydufourd requested a review from etal as a code owner June 22, 2026 13:05
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

@etal

etal commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Thanks for the fix! It looks like the CircleCI+CodeCov failure was due to an auth issue when uploading from the CircleCI pipeline to CodeCov, not any unit test failure. I don't know why CodeCov is reporting a big drop in test coverage; that seems implausible.

Code LGTM. OK to merge?

@peterjc

peterjc commented Jun 22, 2026

Copy link
Copy Markdown
Member

I think any apparent coverage drop is from the missing CircleCI upload. I don't see that we've opened an issue for fixing that...

@peterjc peterjc merged commit 158b2f2 into biopython:master Jun 22, 2026
33 of 34 checks passed
@peterjc

peterjc commented Jun 22, 2026

Copy link
Copy Markdown
Member

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.

Bio.Phylo.write Newick default precision (%1.5f) causes silent data loss for small branch lengths

3 participants