Skip to main content

FastPhylo-py

Molecular sequence analysis for Python — fast pairwise distances and neighbour-joining trees for DNA, RNA, and protein sequences.

import fastphylo

aln  = fastphylo.read("sequences.fasta")          # FASTA, Stockholm, or Phylip
dm   = fastphylo.distance_matrix(aln)             # k2p for DNA, WAG for protein
tree = fastphylo.fnj(dm)
print(tree.to_newick())

Features

  • Reads FASTA, Stockholm, and Phylip files; format auto-detected from extension and content
  • DNA/RNA distances: Hamming, Jukes-Cantor, Kimura 2-parameter (default), Tamura-Nei 93 — computed by a fast C++ backend with SIMD (SSE2 / NEON)
  • Protein distances: maximum-likelihood estimation under WAG (default), LG, JTT, Dayhoff, BLOSUM62, VT, cpREV, MtREV, RtREV, HIVb, HIVw, DCMUT, JTT-DCMut, and PMB, using a Brent optimizer written in C++
  • Tree reconstruction: Neighbour-Joining, Fast NJ, and BioNJ (with branch lengths) via the FastPhylo library
  • Branch length estimation: fit_branch_lengths fits branch lengths to any tree topology by L1-minimisation against a distance matrix (requires scipy)
  • Distance matrix access: integer or taxon-name indexing, copy(), zeros() factory, NumPy and Phylip export
  • Multiple alignment: optional FAMSA integration for unaligned input
  • Pure-Python sequence types with Stockholm annotation support (organism, AC, description); edge-set Tree with to_newick() and merge()

Installation

pip install fastphylo

Optional extras:

pip install fastphylo[align]    # multiple-sequence alignment (pyfamsa)
pip install scipy               # branch length fitting (fit_branch_lengths)

Quick start

Aligned input → tree

import fastphylo

aln  = fastphylo.read("alignment.sto")            # Stockholm, FASTA, or Phylip
dm   = fastphylo.distance_matrix(aln, model="k2p")
tree = fastphylo.fnj(dm)
print(tree.to_newick())

Unaligned input → align → tree

import fastphylo

seqs = fastphylo.read("sequences.fasta")          # unaligned OK
aln  = fastphylo.align(seqs)                      # requires fastphylo[align]
dm   = fastphylo.distance_matrix(aln)
tree = fastphylo.fnj(dm)
print(tree.to_newick())

Protein sequences

import fastphylo

aln  = fastphylo.read("proteins.fasta")
dm   = fastphylo.distance_matrix(aln, model="LG")
tree = fastphylo.bionj(dm)                        # BioNJ with branch lengths
print(tree.to_newick())

Branch length fitting

NJ and FNJ return topology only (branch lengths are not computed). Use fit_branch_lengths to fit branch lengths to any tree topology by minimising the L1 deviation from the distance matrix:

import fastphylo

aln  = fastphylo.read("alignment.fasta")
dm   = fastphylo.distance_matrix(aln)
tree = fastphylo.fnj(dm)                          # fast topology, no lengths

tree = fastphylo.fit_branch_lengths(tree, dm)     # requires scipy
print(tree.to_newick())                           # now includes branch lengths

This solves a linear program: branch lengths are chosen to minimise sum |path_distance(i,j) − dm[i,j]| over all leaf pairs, subject to non-negative branch lengths.

Distance matrix access

dm = fastphylo.distance_matrix(aln)

# Integer or name-based indexing
d = dm[0, 1]
d = dm["human", "mouse"]

# Set elements
dm["human", "mouse"] = 0.15
dm["mouse", "human"] = 0.15

# Build a matrix manually
dm = fastphylo.DistanceMatrix.zeros(["human", "mouse", "rat"])
dm["human", "mouse"] = dm["mouse", "human"] = 0.15
dm["human", "rat"]   = dm["rat",   "human"] = 0.22
dm["mouse", "rat"]   = dm["rat",   "mouse"] = 0.08

# Copy, NumPy array, Phylip string
dm2  = dm.copy()
arr  = dm.to_numpy()
text = dm.to_phylip()

API overview

Function / class Description
fastphylo.read(path) Read FASTA / Stockholm / Phylip → SequenceCollection or Alignment
fastphylo.align(seqs) Align with FAMSA → Alignment
fastphylo.distance_matrix(aln, model=…) Compute pairwise distances → DistanceMatrix
evolution.nj(dm) / fnj(dm) / bionj(dm) Tree reconstruction → Tree
fastphylo.fit_branch_lengths(tree, dm) L1-optimal branch lengths for a given topology
DistanceMatrix.zeros(names) Create an all-zero matrix with taxon names
DistanceMatrix.copy() Deep copy
DistanceMatrix.to_numpy() Export as NumPy array
DistanceMatrix.to_phylip() Export as Phylip-format string
Tree.to_newick() Newick string
Tree.merge(other) Union of two edge-set trees

Distance models

Sequences Model string Notes
DNA / RNA "hamming" Raw mismatch count
DNA / RNA "jc" Jukes-Cantor
DNA / RNA "k2p" (default) Kimura 2-parameter
DNA / RNA "tn93" Tamura-Nei 93
Protein "WAG" (default) Whelan & Goldman
Protein "LG", "JTT", "Dayhoff", … 14 models total

RNA is handled transparently (U → T at the C++ boundary).

Requirements

  • Python ≥ 3.12
  • NumPy ≥ 1.24
  • A C compiler (for the bundled FastPhylo extension, built automatically by pip)

Optional:

  • pyfamsa ≥ 0.6.0 — multiple-sequence alignment (pip install fastphylo[align])
  • scipy — branch length fitting via fit_branch_lengths (pip install scipy)

License

GPLv3 — see FastPhylo for the upstream C++ library.

Metadata

Release files for fastphylo 1.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 fastphylo 1.1.1
File Size Uploaded
fastphylo-1.1.1.tar.gz 682.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for fastphylo 1.1.1
File
fastphylo-1.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
fastphylo-1.1.1-cp313-cp313-macosx_10_13_universal2.whl CPython 3.13 CPython 3.13 macOS 10.13+ universal2 (ARM64, x86-64) Details
fastphylo-1.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
fastphylo-1.1.1-cp312-cp312-macosx_10_13_universal2.whl CPython 3.12 CPython 3.12 macOS 10.13+ universal2 (ARM64, x86-64) Details

Total release size: 9.1 MB

Release files / fastphylo-1.1.1.tar.gz

Download URL fastphylo-1.1.1.tar.gz
Size 682.0 kB
Tags Source
SHA-256 checksum
How to use checksums
20fbf806da264ebfc63a932321be02c18c7da1cf84f2eeac13e8819ff30cb75a
BLAKE2b-256 checksum
How to use checksums
87d9d6aaa68aacc1458d7d88ddf892f9a5cae7b272a1cd4408da57f8a7c8affa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Aug 12, 2026.

Transparency log

Release files / fastphylo-1.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fastphylo-1.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 3.6 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
7af65e9f84f8320e3e2f8e70f725f3ae33be5b366a7ca0cbae4e8d555d1a2e79
BLAKE2b-256 checksum
How to use checksums
baa88bfe2fbd6a57f42c7109739af2d983800f9afe5b3dad3be9974cf04fbb5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Aug 12, 2026.

Transparency log

Release files / fastphylo-1.1.1-cp313-cp313-macosx_10_13_universal2.whl

Download URL fastphylo-1.1.1-cp313-cp313-macosx_10_13_universal2.whl
Size 601.1 kB
Tags CPython 3.13 macOS 10.13+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
e29551ae9c232e91edbb6bada80aca97d63e48dceda803c163e2ad7b4189543b
BLAKE2b-256 checksum
How to use checksums
a46d049bef1c251a6d8cf64ee34419b5187984747abe4259e8a29f3806335c23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Aug 12, 2026.

Transparency log

Release files / fastphylo-1.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fastphylo-1.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 3.6 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
17c3b518a221a84f9a787216b5ff84f19ef2095f5d589025d07e7849fa66a0cd
BLAKE2b-256 checksum
How to use checksums
36f842f836b7936f81e49a70ebee1a1fbffa477e921fc75670d2b9a3e207add4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Aug 12, 2026.

Transparency log

Release files / fastphylo-1.1.1-cp312-cp312-macosx_10_13_universal2.whl

Download URL fastphylo-1.1.1-cp312-cp312-macosx_10_13_universal2.whl
Size 601.0 kB
Tags CPython 3.12 macOS 10.13+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
81f8bced815d64cc729dcae111b87bf25060a498f0910476f7f555a6047b3adf
BLAKE2b-256 checksum
How to use checksums
5079c272c7bf557aa378ada483475895661b9779f72f138b6e700d742caac67e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Aug 12, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.1 This release

5 release files

1.1.0

3 release files

1.0.0

3 release files

0.2.1

3 release files

0.1.0

3 release files

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