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
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ maintainers = [
]
name = "lineagetree"
description = "Structure for Lineage Trees"
version = "3.1.0"
version = "3.2.0"
license = "MIT"
license-files = [ "LICENSE" ]
readme = {file = "README.md", content-type = "text/markdown"}
Expand Down Expand Up @@ -76,7 +76,7 @@ profile = "black"
line_length = 79

[tool.bumpver]
current_version = "3.1.0"
current_version = "3.2.0"
version_pattern = "MAJOR.MINOR.PATCH[-TAG]"
commit_message = "bump version {old_version} -> {new_version}"
commit = true
Expand Down
4 changes: 3 additions & 1 deletion src/lineagetree/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "3.1.0"
__version__ = "3.2.0"
from .lineage_tree import LineageTree
from ._io._loaders import (
read_from_ASTEC,
Expand All @@ -12,6 +12,7 @@
read_from_txt_for_celegans,
read_from_txt_for_celegans_BAO,
read_from_txt_for_celegans_CAO,
read_from_swc,
LOADERS,
)
from .lineage_tree_manager import LineageTreeManager
Expand All @@ -30,5 +31,6 @@
"read_from_mastodon",
"read_from_txt_for_celegans",
"read_from_txt_for_celegans_CAO",
"read_from_swc",
"LOADERS",
)
7 changes: 7 additions & 0 deletions src/lineagetree/_core/_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,10 @@ def parenting(lT: LineageTree):
lT._tmp_parenting[(i, j)] = _m(lT, i, j)
del lT._tmp_parenting
return lT._parenting


@property
def temporal(lT: LineageTree):
if not hasattr(lT, "_temporal"):
lT._temporal = True
return lT._temporal
36 changes: 36 additions & 0 deletions src/lineagetree/_io/_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,39 @@ def read_from_mamut_xml(
)


def read_from_swc(swc_path: Path | str) -> LineageTree:
"""
Read a neuronal tree from a swc file
"""
with open(swc_path) as f:
lines = f.readlines()

predecessor = {}
pos = {}
properties = {}
properties["radius"] = {}
properties["structure_id"] = {}
for line in lines:
line = line.strip()
if len(line) < 1 or line[0] == "#":
continue
id_, struct_id, x, y, z, rad, parent = [
eval(li) for li in line.split()
]
predecessor[id_] = parent
pos[id_] = np.array([x, y, z])
properties["radius"][id_] = rad
properties["structure_id"][id_] = struct_id

return LineageTree(
predecessor=predecessor,
pos=pos,
root_leaf_value=(-1,),
temporal=False,
**properties,
)


LOADERS = { # put all formats in smaller case
"bmf": {
"BMF loader": read_from_bmf,
Expand Down Expand Up @@ -1091,4 +1124,7 @@ def read_from_mamut_xml(
"C. elegans CAO loader": read_from_txt_for_celegans_CAO,
"C. elegans BAO loader": read_from_txt_for_celegans_BAO,
},
"swc": {
"Neurons format": read_from_swc,
},
}
2 changes: 2 additions & 0 deletions src/lineagetree/_mixins/properties_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
successor,
t_b,
t_e,
temporal,
time,
time_nodes,
time_resolution,
Expand Down Expand Up @@ -39,3 +40,4 @@ class PropertiesMixin(metaclass=AutoMethodizeMeta):
all_chains = all_chains
time_nodes = time_nodes
parenting = parenting
temporal = temporal
6 changes: 6 additions & 0 deletions src/lineagetree/lineage_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def load(clf, fname: str):
lT.time_resolution = 1
if not hasattr(lT, "spatial_resolution"):
lT.spatial_resolution = np.ones(3)
if not hasattr(lT, "_temporal"):
lT._temporal = True

return lT

Expand Down Expand Up @@ -146,6 +148,7 @@ def __init__(
name: str | None = None,
root_leaf_value: Sequence | None = None,
spatial_resolution: Sequence | None = None,
temporal: bool = True,
**kwargs,
):
"""Create a LineageTree object from minimal information, without reading from a file.
Expand All @@ -169,12 +172,15 @@ def __init__(
root_leaf_value : Iterable, optional
Iterable of values of roots' predecessors and leaves' successors in the successor and predecessor dictionaries.
Defaults are `[None, (), [], set()]`.
temporal : boolean, default `True`
Whether the tree structure has time
Comment thread
BadPrograms marked this conversation as resolved.
**kwargs:
Supported keyword arguments are dictionaries assigning nodes to any custom property.
The property must be specified for every node, and named differently from LineageTree's own attributes.
"""
self.__version__ = importlib.metadata.version("lineagetree")
self.name = str(name) if name is not None else None
self._temporal = temporal

self._validator = TreeValidator(self)

Expand Down
Loading
Loading