Skip to main content

PhyloSlicer

tests CodeQL build DOI

Temporal slicing of phylogenies and cumulative-diversity rate analysis for macroecology in Python.

Version 0.1.1 · BSD-3-Clause · Python ≥ 3.10

Repository: https://github.com/ZengZichao/PhyloSlicer


Overview

PhyloSlicer is an independent, vectorised Python implementation of the "slice phylogenies to infer phylogenetic patterns over evolutionary time" paradigm introduced by treesliceR (Araujo et al. 2025, Ecography 2025, e07364, https://doi.org/10.1111/ecog.07364), extended with posterior-tree uncertainty quantification, robust fitting diagnostics, spatial workflow helpers and a command-line interface.

Speed is a structural consequence, not a marketing word: slicing is a single E × k interval-intersection contribution matrix instead of the k complete tree copies the reference design materialises. The one array still grows with k, but the k whole-tree copies do not. Python-side peaks are measured (benchmarks/benchmark_memory.py → benchmarks/results_memory_py.csv): at 2000 tips the single (E, k) array peaks at 1.93 / 3.49 / 6.69 MB for k = 25 / 50 / 100, against 2.81 / 5.62 / 11.23 MB for k array-level tree copies — a 1.45× to 1.68× saving that widens with k. Because this package's own matrix also grows with k, the honest claim is about object count and copy structure, not about a memory ratio that diverges; the R-side peak of treesliceR is not measured, and the documentation keeps to the same qualification.

Key features

  1. Array-based slicing — slicing is expressed as an interval-intersection contribution matrix (C[e, j] = max(0, min(d_e, t_j) − max(b_e, t_{j−1}))), so no tree is ever copied.
  2. Sparse-matrix indices — per-site, per-slice PD/PE/PB(+RW) via a single sparse product A @ C.
  3. Robust rate fitting — bounded multi-start optimisation with converged, r_squared, residuals and an explicit reason for every failure.
  4. Posterior-tree uncertainty — posterior_rate / posterior_origin credible intervals and bootstrap_sites stability analysis.
  5. Spatial workflow — rook/queen/knn/radius adjacency builders and rate maps that accept GeoDataFrames (geopandas optional).
  6. CLI — phyloslicer slice | rates | posterior | validate with JSON run summaries.

Documentation

The English document in each pair is the version of record and the Chinese one is its translation, maintained to the same section list; tests/test_release_hygiene.py fails when the two heading structures drift apart, so the pair cannot quietly become a partial translation.

Installation

pip install -e .            # core (numpy, scipy, pandas, matplotlib)
pip install -e ".[io]"      # + dendropy/biopython adapters
pip install -e ".[spatial]" # + geopandas
pip install -e ".[accel]"   # + numba batched kernels
pip install -e ".[dev]"     # + pytest, ruff, mypy, pre-commit

Quick start

Run the bundled example first — it needs no data, no download and no setup, and it is the workflow the user guide walks through:

python examples/quickstart.py

The snippet below is the same workflow on your own files:

import phyloslicer as ps

tree = ps.TreeArray.from_newick("birds.tre")
mat = ps.io.presence_matrix(long_table, site_col="grid", species_col="species")
adj = ps.spatial.adjacency_from_coords(x, y, method="knn", k=8)

rates = ps.cpd_rate(tree, mat, n_slices=100)      # CpD, PD, pDO + diagnostics
post = ps.posterior_rate("posterior_trees/", mat, n_slices=100)
beta = ps.cpb_rate(tree, mat, adj, component="sorensen")

Command line:

phyloslicer rates input.tre sites.csv --rate cpd --n-slices 100 --out rates.csv
phyloslicer slice input.tre --rootward 5.0 --out crown.tre

Testing and validation

python -m pytest tests/                     # unit + regression tests
python validation/compare.py                # Python vs treesliceR equivalence

The comparison set is {PD, PE, CpD, CpE} plus the beta families (CpB, CpB_RW, r_phylo(index = "PB")) — 11 of the 14 beta component-by-approach families are cross-checked numerically against treesliceR 1.1.0. See validation/NOTES.md for the full gap list and tolerance rationale.

Benchmarks

benchmarks/ holds four independent protocols and the archived tables they produced. Read benchmarks/README.md before quoting a number from them: two column names mean different things in different files, and only the fixed-k scaling tables are cross-language. python benchmarks/recompute_ratios.py recomputes every documented speed-up range from the CSVs and is run by CI.

Citation

If you use PhyloSlicer, please cite both this package and the methodological source. The package citation is in CITATION.cff; the version-agnostic Zenodo concept DOI for all releases is 10.5281/zenodo.23057620.

Araujo, M.L., Ferreira, L.G.S.S., Nakamura, G., Coelho, M.T.P., Rangel, T.F. (2025) 'treesliceR': a package for slicing phylogenies and inferring phylogenetic patterns over evolutionary time. Ecography 2025, e07364. https://doi.org/10.1111/ecog.07364

License

Code: BSD-3-Clause (see LICENSE). Documentation: CC-BY 4.0. Third-party attribution, including the origin of the treesliceR reference values: NOTICE.md · Chinese: NOTICE_CN.md.

Why BSD-3-Clause

The Ecography Software Notes page recommends "fully open licenses (e.g., MIT)" and states that copyleft licences (e.g., GPL) are also accepted. BSD-3-Clause is neither exemplar, but it is squarely inside the recommendation: it is OSI-approved and permissive, carries no copyleft condition, and a BSD-3-Clause work can be combined into MIT- or GPL-licensed projects without re-licensing trouble. It is also the licence of the scientific stack this package extends — numpy, scipy and pandas are all BSD-3-Clause — while the reference implementation it cross-validates against, treesliceR, is MIT, likewise permissive and likewise compatible. The only substantive difference from MIT is the third clause, which asks users not to use the copyright holders' names to endorse derived products; that is a deliberate choice, not an obstacle, and it is why some venues prefer MIT. Nothing here restricts reuse: the package is free and open-source, and the shipped LICENSE is the BSD-3-Clause text verbatim.

Open access

Ecography is fully open access: every article is published under a Creative Commons licence, all authors grant the Nordic Society Oikos a licence to publish, and an Article Publication Charge (APC) applies. This repository makes no claim about the amount or about anyone's eligibility — the corresponding author checks the current fee and any institutional agreement at acceptance, when the Wiley Author Licence is signed. Waivers and discounts do exist (Wiley's Research4Life programme for eligible countries, and NSO-funded waivers), so a group without a publication budget should ask the editorial office rather than assume the charge is unavoidable. Note the split: the Creative Commons licence covers the article once published; the software stays BSD-3-Clause, and the prose in this repository stays CC-BY 4.0 (see NOTICE.md).

Author

Zichao Zeng (曾子超) — School of Life Sciences and Biotechnology, Shanghai Jiao Tong University · zengzichao@sjtu.edu.cn · ORCID 0000-0001-6553-970X

Metadata

Release files for phyloslicer 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for phyloslicer 0.1.1
File Size Uploaded Provenance Actions
phyloslicer-0.1.1.tar.gz 699.9 kB With provenance Details for phyloslicer-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for phyloslicer 0.1.1
File Interpreter ABI Platform Actions
phyloslicer-0.1.1-py3-none-any.whl Python 3 none any Details for phyloslicer-0.1.1-py3-none-any.whl

Total release size: 799.2 kB

Release files / phyloslicer-0.1.1.tar.gz

Download URL phyloslicer-0.1.1.tar.gz
Size 699.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e92fee4d92c004111c88e76186e091581b36a638dcb8338f90aaac73c582f0f9
BLAKE2b-256 checksum
How to use checksums
5f616d34747b5ded297f4ecc489d3dc29ad524648eefe5d405f9290a5242ef0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

Release files / phyloslicer-0.1.1-py3-none-any.whl

Download URL phyloslicer-0.1.1-py3-none-any.whl
Size 99.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
062bbd31ce9b08390ff91c8025115dd6da909ef498180da5d772ccdadfc4ad16
BLAKE2b-256 checksum
How to use checksums
c65716b98a10d0cb5e0d8fd32d643562052d7fc6428316bc3c7c9e3ab014e9d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

Security for phyloslicer 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for phyloslicer-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page