Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies = [
"edist",
"svgwrite",
"Micro-Mastodon-Reader",
"binarymeshformat",
]

[project.optional-dependencies]
Expand Down
4 changes: 3 additions & 1 deletion src/lineagetree/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from ._io._loaders import (
read_from_ASTEC,
read_from_binary,
read_from_bmf,
read_from_csv,
read_from_mamut_xml,
read_from_mastodon,
Expand All @@ -21,10 +22,11 @@
"read_from_txt_for_celegans_BAO",
"read_from_ASTEC",
"read_from_binary",
"read_from_bmf",
"read_from_csv",
"read_from_mamut_xml",
"read_from_mastodon_csv",
"read_from_mastodon",
"read_from_txt_for_celegans",
"read_from_txt_for_celegans_CAO",
)
)
79 changes: 79 additions & 0 deletions src/lineagetree/_io/_loaders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import binarymeshformat as bmf
import csv
import os
import pickle as pkl
Expand Down Expand Up @@ -96,6 +97,84 @@
}


def _load_meshdict_from_bmfmesh(bmfmesh, pos_multipliers, translation):

vertices = np.array(bmfmesh.positions).reshape(-1, 3)[:,::-1]
faces = np.array(bmfmesh.triangles).reshape(-1, 3)

pos_multipliers = np.array(pos_multipliers, dtype=float)
translation = np.array(translation, dtype=float)
vertices = vertices * pos_multipliers + translation

return { # could be a class
'vertices': vertices,
'faces': faces
}


def read_from_bmf(
file_path: str,
store_meshes: bool = False,
pos_multipliers: tuple[float, float, float] = (1.0, 1.0, 1.0),
translation: tuple[float, float, float] = (0.0, 0.0, 0.0),
name: None | str = None,
) -> LineageTree:
"""Read a lineage tree from a bmf file.

Parameters
----------
file_path : str
path to the bmf file
store_meshes : bool, default=False
whether to stores the meshes in the LineageTree or not.
pos_multipliers : tuple of float, default=(1.0, 1.0, 1.0)
multipliers for the x, y, z coordinates
translation : tuple of float, default=(0.0, 0.0, 0.0)
translation for the x, y, z coordinates
name : None or str, optional
The name attribute of the LineageTree file. If given a non-empty string, the value of the attribute
will be the name attribute, otherwise the name will be the stem of the file path.

Returns
-------
LineageTree
lineage tree
"""
tracks = bmf.loadMeshTracks(file_path)
predecessor = {}
times = {}
pos = {}
lT_mesh = {}
cell_id = 1
for track in tracks:
pred = None
for t, mesh in track.meshes.items():
mesh = _load_meshdict_from_bmfmesh(mesh, pos_multipliers, translation)
pos[cell_id] = mesh.center_mass

if store_meshes:
lT_mesh[cell_id] = mesh

predecessor[cell_id] = (pred,)
pred = cell_id
times[cell_id] = t

cell_id += 1

kwargs = {"mesh": lT_mesh} if store_meshes else {}

lT = LineageTree(
predecessor=predecessor,
time=times,
pos=pos,
root_leaf_value=[(None,)],
name=name if name else Path(file_path).stem,
**kwargs,
)

return lT


def read_from_csv(
file_path: str,
z_mult: float,
Expand Down
Loading