LineageTree 1.8.0__py3-none-any.whl → 2.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- LineageTree/__init__.py +27 -2
- LineageTree/legacy/export_csv.py +70 -0
- LineageTree/legacy/to_lineajea.py +30 -0
- LineageTree/legacy/to_motile.py +36 -0
- LineageTree/lineageTree.py +2298 -1471
- LineageTree/lineageTreeManager.py +767 -79
- LineageTree/loaders.py +942 -864
- LineageTree/test/test_lineageTree.py +634 -0
- LineageTree/test/test_uted.py +233 -0
- LineageTree/tree_approximation.py +488 -0
- LineageTree/utils.py +103 -103
- lineagetree-2.0.3.dist-info/METADATA +130 -0
- lineagetree-2.0.3.dist-info/RECORD +16 -0
- {LineageTree-1.8.0.dist-info → lineagetree-2.0.3.dist-info}/WHEEL +1 -1
- LineageTree/tree_styles.py +0 -334
- LineageTree-1.8.0.dist-info/METADATA +0 -156
- LineageTree-1.8.0.dist-info/RECORD +0 -11
- {LineageTree-1.8.0.dist-info → lineagetree-2.0.3.dist-info/licenses}/LICENSE +0 -0
- {LineageTree-1.8.0.dist-info → lineagetree-2.0.3.dist-info}/top_level.txt +0 -0
LineageTree/__init__.py
CHANGED
@@ -1,5 +1,30 @@
|
|
1
|
-
__version__ = "
|
1
|
+
__version__ = "2.0.3"
|
2
2
|
from .lineageTree import lineageTree
|
3
3
|
from .lineageTreeManager import lineageTreeManager
|
4
|
+
from .loaders import (
|
5
|
+
read_from_ASTEC,
|
6
|
+
read_from_binary,
|
7
|
+
read_from_csv,
|
8
|
+
read_from_mamut_xml,
|
9
|
+
read_from_mastodon,
|
10
|
+
read_from_mastodon_csv,
|
11
|
+
read_from_tgmm_xml,
|
12
|
+
read_from_txt_for_celegans,
|
13
|
+
read_from_txt_for_celegans_BAO,
|
14
|
+
read_from_txt_for_celegans_CAO,
|
15
|
+
)
|
4
16
|
|
5
|
-
__all__ = (
|
17
|
+
__all__ = (
|
18
|
+
"lineageTree",
|
19
|
+
"lineageTreeManager",
|
20
|
+
"read_from_tgmm_xml",
|
21
|
+
"read_from_txt_for_celegans_BAO",
|
22
|
+
"read_from_ASTEC",
|
23
|
+
"read_from_binary",
|
24
|
+
"read_from_csv",
|
25
|
+
"read_from_mamut_xml",
|
26
|
+
"read_from_mastodon_csv",
|
27
|
+
"read_from_mastodon",
|
28
|
+
"read_from_txt_for_celegans",
|
29
|
+
"read_from_txt_for_celegans_CAO",
|
30
|
+
)
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import csv
|
2
|
+
|
3
|
+
from lineageTree import lineageTree
|
4
|
+
|
5
|
+
"""Writes a lineage tree into a series of csv files.
|
6
|
+
|
7
|
+
* spots.csv: id; label; timePoint; x; y; z; volume
|
8
|
+
* links.csv: source spot id; target spot id
|
9
|
+
* fates1.csv: tagValue
|
10
|
+
* fate_values1.csv: spot id; tagValue
|
11
|
+
* fates2.csv: tagValue
|
12
|
+
* fate_values2.csv: spot id; tagValue
|
13
|
+
* fates3.csv: tagValue
|
14
|
+
* fate_values3.csv: spot id; tagValue
|
15
|
+
"""
|
16
|
+
|
17
|
+
|
18
|
+
def export_to_csv():
|
19
|
+
tree = lineageTree("Astec-Pm10_properties.pkl", file_type="ASTEC")
|
20
|
+
|
21
|
+
spots = [["id", "label", "timePoint", "x", "y", "z", "volume"]]
|
22
|
+
for node_id in tree.nodes:
|
23
|
+
cell_name = tree["cell_name"].get(node_id, "unknown")
|
24
|
+
spots.append(
|
25
|
+
[
|
26
|
+
node_id,
|
27
|
+
cell_name,
|
28
|
+
tree.time.get(node_id),
|
29
|
+
tree.pos[node_id][0],
|
30
|
+
tree.pos[node_id][1],
|
31
|
+
tree.pos[node_id][2],
|
32
|
+
tree.volume[node_id],
|
33
|
+
]
|
34
|
+
)
|
35
|
+
write("spots.csv", spots)
|
36
|
+
|
37
|
+
links = [["source", "target"]]
|
38
|
+
for edge in tree.edges:
|
39
|
+
links.append([edge[0], edge[1]])
|
40
|
+
write("links.csv", links)
|
41
|
+
|
42
|
+
write_fate(tree.fates, "fates1.csv", tree, "fate_values1.csv")
|
43
|
+
write_fate(tree["cell_fate_2"], "fates2.csv", tree, "fate_values2.csv")
|
44
|
+
write_fate(tree["cell_fate_3"], "fates3.csv", tree, "fate_values3.csv")
|
45
|
+
|
46
|
+
|
47
|
+
def write_fate(fates, fate_name, tree, fate_value_name):
|
48
|
+
all_fates = []
|
49
|
+
for index in fates:
|
50
|
+
all_fates.append(fates[index])
|
51
|
+
unique_fates = set(all_fates)
|
52
|
+
fates_list = [["fate"]]
|
53
|
+
for fate in unique_fates:
|
54
|
+
fates_list.append([fate])
|
55
|
+
write(fate_name, fates_list)
|
56
|
+
|
57
|
+
fate_values = [["id", "value"]]
|
58
|
+
for node_id in tree.nodes:
|
59
|
+
fate_values.append([node_id, tree.fates.get(node_id)])
|
60
|
+
write(fate_value_name, fate_values)
|
61
|
+
|
62
|
+
|
63
|
+
def write(file_path, data):
|
64
|
+
with open(file_path, mode="w", newline="") as file:
|
65
|
+
writer = csv.writer(file)
|
66
|
+
writer.writerows(data)
|
67
|
+
|
68
|
+
|
69
|
+
if __name__ == "__main__":
|
70
|
+
export_to_csv()
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import csv
|
2
|
+
|
3
|
+
|
4
|
+
def write_csv_from_lT_to_lineaja(
|
5
|
+
lT, path_to, start: int = 0, finish: int = 300
|
6
|
+
):
|
7
|
+
csv_dict = {}
|
8
|
+
for time in range(start, finish):
|
9
|
+
for node in lT.time_nodes[time]:
|
10
|
+
csv_dict[node] = {"pos": lT.pos[node], "t": time}
|
11
|
+
with open(path_to, "w", newline="\n") as file:
|
12
|
+
fieldnames = [
|
13
|
+
"time",
|
14
|
+
"positions_x",
|
15
|
+
"positions_y",
|
16
|
+
"positions_z",
|
17
|
+
"id",
|
18
|
+
]
|
19
|
+
writer = csv.DictWriter(file, fieldnames=fieldnames)
|
20
|
+
writer.writeheader()
|
21
|
+
for node in csv_dict:
|
22
|
+
writer.writerow(
|
23
|
+
{
|
24
|
+
"time": csv_dict[node]["t"],
|
25
|
+
"positions_z": csv_dict[node]["pos"][0],
|
26
|
+
"positions_y": csv_dict[node]["pos"][1],
|
27
|
+
"positions_x": csv_dict[node]["pos"][2],
|
28
|
+
"id": node,
|
29
|
+
}
|
30
|
+
)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import warnings
|
2
|
+
|
3
|
+
from ..lineageTree import lineageTree
|
4
|
+
|
5
|
+
try:
|
6
|
+
import motile
|
7
|
+
except ImportError:
|
8
|
+
warnings.warn(
|
9
|
+
"No motile installed therefore you will not be able to produce links with motile.",
|
10
|
+
stacklevel=2,
|
11
|
+
)
|
12
|
+
|
13
|
+
|
14
|
+
def to_motile(
|
15
|
+
lT: lineageTree, crop: int | None = None, max_dist=200, max_skip_frames=1
|
16
|
+
):
|
17
|
+
try:
|
18
|
+
import networkx as nx
|
19
|
+
except ImportError:
|
20
|
+
raise Warning("Please install networkx") # noqa: B904
|
21
|
+
|
22
|
+
fmt = nx.DiGraph()
|
23
|
+
if not crop:
|
24
|
+
crop = lT.t_e
|
25
|
+
for time in range(crop):
|
26
|
+
for time_node in lT.nodes_at_t(time):
|
27
|
+
fmt.add_node(
|
28
|
+
time_node,
|
29
|
+
t=lT.time[time_node],
|
30
|
+
pos=lT.pos[time_node],
|
31
|
+
score=1,
|
32
|
+
)
|
33
|
+
|
34
|
+
motile.add_cand_edges(fmt, max_dist, max_skip_frames=max_skip_frames)
|
35
|
+
|
36
|
+
return fmt
|