Skip to main content

LineageTree

PyPI version License: MIT Python 3.10+

A Python library for importing, analyzing, and visualizing cell lineage trees. Built for developmental biology workflows, it supports data from the most common cell-tracking algorithms and provides tools for spatial analysis, tree comparison, and visualization.

Full documentation: guignardlab.github.io/LineageTree


Features

  • Multi-format I/O — read from TGMM, MaMuT/TrackMate, Mastodon, ASTEC, SVF, SWC, BMF, and CSV; export to pickle (.lT), SVG, or Tulip (.tlp)
  • Tree analysis — unordered tree edit distance (UTED), dynamic time warping (DTW), chain extraction, depth computation
  • Spatial analysis — KD-tree indexing, Gabriel graphs, k-nearest neighbours, spatial density
  • Trajectory manipulation — smooth trajectories, stabilise positions across time points
  • Visualization — lineage plots, subtree views, DTW heatmaps, chain histograms

Installation

pip install lineagetree

For the development version:

pip install git+https://github.com/GuignardLab/LineageTree

Or from a local clone:

pip install .

Quick start

Loading a tree

from lineagetree import LineageTree

# From a saved .lT file
lT = LineageTree.load("path/to/file.lT")

# Inspect basic properties
print(lT.nodes)    # frozenset of all node ids
print(lT.roots)    # frozenset of root nodes
print(lT.leaves)   # frozenset of leaf nodes
print(lT.t_b, lT.t_e)  # first and last time points

Reading from tracking software

from lineagetree import (
    read_from_ASTEC,
    read_from_mamut_xml,
    read_from_mastodon,
    read_from_mastodon_csv,
    read_from_tgmm_xml,
    read_from_swc,
)

# ASTEC (Guignard, Fiuza et al. 2020)
lT = read_from_ASTEC("path/to/ASTEC.pkl")

# MaMuT / TrackMate (Wolff et al. 2018 / Tinevez et al. 2017)
lT = read_from_mamut_xml("path/to/MaMuT.xml")

# Mastodon — binary format
lT = read_from_mastodon("path/to/file.mastodon")

# Mastodon — CSV export
lT = read_from_mastodon_csv(["path/to/nodes.csv", "path/to/links.csv"])

# TGMM (Amat et al. 2014) — one XML per time point
lT = read_from_tgmm_xml("path/to/single_time_file{t:04d}.xml", tb=0, te=500)

# SWC morphology files
lT = read_from_swc("path/to/morphology.swc")

Building a tree programmatically

from lineagetree import LineageTree

# From a successor dictionary
lT = LineageTree(
    successor={0: [1, 2], 1: [3], 2: [], 3: []},
    time={0: 0, 1: 1, 2: 1, 3: 2},
    pos={0: [0, 0, 0], 1: [1, 0, 0], 2: [-1, 0, 0], 3: [1, 1, 0]},
    name="example",
)

Tree navigation

# Traverse successors / predecessors
lT.get_successors(node)
lT.get_predecessors(node)

# All nodes in a subtree rooted at `node`
lT.get_subtree_nodes({node})

# Unbroken chains (segments between division events)
lT.all_chains

# Nodes at a specific time point
lT.nodes_at_t(t)

Saving

lT.write("output.lT")          # pickle
lT.write_to_svg("tree.svg")    # SVG visualization
lT.write_to_tlp("tree.tlp")    # Tulip graph format

Tree comparison

# Unordered tree edit distance between two subtrees
dist = lT.unordered_tree_edit_distance(node_a, node_b)

# Dynamic time warping on trajectories
score, path = lT.dtw(node_a, node_b)

Spatial analysis

# KD-tree index at time t
idx = lT.idx3d(t)

# k nearest neighbours of a node
neighbours = lT.k_nearest_neighbours(node, t, k=5)

# Gabriel graph at time t
g = lT.gabriel_graph(t)

# Local cell density
density = lT.spatial_density(t)

Visualization

lT.plot_subtree(root_node)
lT.plot_all_lineages()
lT.draw_tree_graph()

# DTW visualizations
lT.plot_dtw_trajectory(node_a, node_b)
lT.plot_dtw_heatmap(node_a, node_b)

Multi-tree workflows

from lineagetree import LineageTreeManager

manager = LineageTreeManager()
manager.add(lT_1)
manager.add(lT_2)

# Compare subtrees across lineages
manager.cross_lineage_edit_distance(root_of_lT1, name_of_lT1,root_of_lT2, name_of_lT2)

Supported input formats

Format Algorithm / Tool Reference
.xml (TGMM) TGMM Amat et al. 2014
.xml (MaMuT/TrackMate) MaMuT / TrackMate Wolff et al. 2018 / Tinevez et al. 2017
.mastodon Mastodon —
.pkl (ASTEC) ASTEC Guignard, Fiuza et al. 2020
.lT LineageTree native —
.swc SWC morphology —
.bmf Binary mesh format —
.csv Generic / Mastodon CSV —
.txt C. elegans specific Du et al. 2014

Development

pip install -e ".[dev]"
pytest

To build the documentation:

pip install -e ".[doc]"
cd docs && make html

Citation

If you use LineageTree in your research, please cite the relevant tracking algorithm paper for the data you loaded, and consider citing this library directly.


License

MIT — see LICENSE.

Release files for lineagetree 3.3.0

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

Source distribution (sdist)

Source distribution for lineagetree 3.3.0
File Size Uploaded
lineagetree-3.3.0.tar.gz 76.4 kB Details

Built distribution (wheel)

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

Total release size: 153.2 kB

Release files / lineagetree-3.3.0.tar.gz

Download URL lineagetree-3.3.0.tar.gz
Size 76.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ee1737cc3619e4889570e2fab67bdaad96f3fe02d0e1b093a37dd4e242d2bdd4
BLAKE2b-256 checksum
How to use checksums
db7255fbd8ad2142667eb7dc885936981e5efee086dc0bc1a3bfcab3ede72440
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / lineagetree-3.3.0-py3-none-any.whl

Download URL lineagetree-3.3.0-py3-none-any.whl
Size 76.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
50941cf4544b5d262d5fef1c18faa43890b9ad534e5b218b283f468e5877d05e
BLAKE2b-256 checksum
How to use checksums
a950aaedffc4b92afe8c17e0cd4e6a2e322f4e84fe9f7f74237e951dc95daf8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release history Release notifications | RSS feed

3.3.1

2 release files

This release

3.3.0 This release

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.4

2 release files

3.0.3

2 release files

3.0.2

2 release files

2.0.3

2 release files

2.0.1

2 release files

1.8.0

2 release files

1.7.0

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 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