Loaders
Premade Loaders¶
Multiple well known formats are ready for import out of the box:
-
csv with the format: id, time, z, y, x, id, pred_id, lin_id
-
Astec data
- Multiple C. Elegans formats (add citations here)
- MaMut xml files
- Mastodon files ( Either the .mastodon file or the 2 CSV files extracted using the User interface)
- TGMM data
The user may also decide to import their custom format. The bare minimum inormation needed to create a Lineage tree is the hierarchy of the nodes, which is a Python dictionary of the successors or the predecessors shown in the example:
successor/predecessor : {unique_node_id (int) : [next_unique_node_ids (int)]}
lT = Lineagetree(successor= successor)
###or###
LineageTree(predecessor= predecessor)
Other attributes that can be used to initiate a lineageTree file apart from the hierarchy dictionary are:
-
time: A dictionary that has this format {unique_node_id: time (int)}
-
starting_time: If the time dictionary is not given, the algorithm sets the starting point of all roots to the value of this parameter. The default value is set to 0.
-
pos: The positions of all the nodes in 3D space. The format is {unique_id: position}.
-
**kwargs: Any other dictionary provided during imaging can be loaded into lineageTree. The format is {unique_id: value}
Custom Loaders¶
from pathlib import Path
from LineageTree import lineageTree
def template_load(path, name=None):
"""
Load lineage data from a file and convert it into a LineageTree object.
Parameters:
- path (str or Path): Path to the data file.
- name (str, optional): Name of the tree. Defaults to the filename stem.
Returns:
- lineageTree object
"""
# Step 1: Load and parse data from the file
data = extract_info_from_file(path) # <-- Implement this function
# Step 2: Build the relationship dictionary
relations = {}
for unique_id in data:
related_ids = data.get_descendantsr(unique_id) # <- Implement this function or change the block according to format
if related_ids:
relations[unique_id] = related_ids
# Step 3: Extract optional positional information
pos = {
uid: [data.x_of_id(uid), data.y_of_id(uid), data.z_of_id(uid)]
for uid in data
}
time = {uid: data.time_of_id(uid) for uid in data}
# Optional properties, like labels or others
properties = {}
labels = {uid: data.label_of_id(uid) for uid in data}
if labels:
properties["_label"] = labels
for attr in data.get_additional_attributes(): # You can define how this works
properties[attr] = {uid: data.info_of_id(uid, attr) for uid in data}
# Step 4: Default name from filename
if not name:
name = Path(path).stem
# If the relationship dictionary is successors
return lineageTree(successor=relations, time=time, pos=pos, name=name, **properties
)
# If the relationship dictionary is predecessors
return lineageTree(predecessor=relations, time=time, pos=pos, name=name, **properties
)
API reference for existing loaders¶
lineagetree
¶
Functions:
| Name | Description |
|---|---|
read_from_ASTEC |
Read an |
read_from_binary |
Reads a binary LineageTree file name. |
read_from_bmf |
Read a lineage tree from a bmf file. |
read_from_csv |
Read a lineage tree from a csv file with the following format: |
read_from_mamut_xml |
Read a lineage tree from a MaMuT xml. |
read_from_mastodon |
Read a maston lineage tree. |
read_from_mastodon_csv |
Read a lineage tree from a mastodon csv. |
read_from_tgmm_xml |
Reads a lineage tree from TGMM xml output. |
read_from_txt_for_celegans |
Read a C. elegans lineage tree |
read_from_txt_for_celegans_BAO |
Read a C. elegans Bao file from http://digital-development.org |
read_from_txt_for_celegans_CAO |
Read a C. elegans lineage tree from Cao et al. |
read_from_ASTEC
¶
Read an xml or pkl file produced by the ASTEC algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
path to an output generated by ASTEC |
required |
|
bool
|
whether or not to read the eigen values, default False |
False
|
|
None or str
|
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. |
None
|
Returns:
| Type | Description |
|---|---|
LineageTree
|
lineage tree |
Source code in src/lineagetree/_io/_loaders.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
read_from_binary
¶
Reads a binary LineageTree file name. Format description: see LineageTree.to_binary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
string
|
path to the binary file |
required |
|
None or str
|
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. |
None
|
Returns:
| Type | Description |
|---|---|
LineageTree
|
lineage tree |
Source code in src/lineagetree/_io/_loaders.py
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | |
read_from_bmf
¶
read_from_bmf(
file_path: str,
store_meshes: bool = True,
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.
Returns:
| Type | Description |
|---|---|
LineageTree
|
lineage tree |
Source code in src/lineagetree/_io/_loaders.py
read_from_csv
¶
read_from_csv(
file_path: str,
z_mult: float = 1,
link: int = 1,
delim: str = ",",
name: None | str = None,
) -> LineageTree
Read a lineage tree from a csv file with the following format: id, time, z, y, x, id, pred_id, lin_id
Returns:
| Type | Description |
|---|---|
LineageTree
|
lineage tree |
Source code in src/lineagetree/_io/_loaders.py
read_from_mamut_xml
¶
read_from_mamut_xml(
path: str,
xml_attributes: list[str] | None = None,
name: None | str = None,
) -> LineageTree
Read a lineage tree from a MaMuT xml.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
path to the MaMut xml |
required |
|
None or str
|
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. |
None
|
Returns:
| Type | Description |
|---|---|
LineageTree
|
lineage tree |
Source code in src/lineagetree/_io/_loaders.py
966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 | |
read_from_mastodon
¶
read_from_mastodon(
path: str,
tag_set: str | None = None,
name: str | None = None,
) -> LineageTree
Read a maston lineage tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
path to the mastodon file |
required |
|
str
|
If specified, |
None
|
|
str
|
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. |
None
|
Returns:
| Type | Description |
|---|---|
LineageTree
|
lineage tree |
Source code in src/lineagetree/_io/_loaders.py
read_from_mastodon_csv
¶
Read a lineage tree from a mastodon csv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list of strings
|
list of paths to the csv files |
required |
|
None or str
|
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. |
None
|
Returns:
| Type | Description |
|---|---|
LineageTree
|
lineage tree |
Source code in src/lineagetree/_io/_loaders.py
read_from_tgmm_xml
¶
read_from_tgmm_xml(
file_format: str,
tb: int,
te: int,
z_mult: float = 1.0,
name: None | str = None,
) -> LineageTree
Reads a lineage tree from TGMM xml output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
path to the xmls location. it should be written as follow: path/to/xml/standard_name_t{t:06d}.xml where (as an example) {t:06d} means a series of 6 digits representing the time and if the time values is smaller that 6 digits, the missing digits are filed with 0s |
required |
|
int
|
first time point to read |
required |
|
int
|
last time point to read |
required |
|
float
|
aspect ratio |
1.0
|
|
str
|
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. |
None
|
Returns:
| Type | Description |
|---|---|
LineageTree
|
lineage tree |
Source code in src/lineagetree/_io/_loaders.py
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 | |
read_from_txt_for_celegans
¶
Read a C. elegans lineage tree
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Path to the file to read |
required |
|
None or str
|
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. |
None
|
Returns:
| Type | Description |
|---|---|
LineageTree
|
lineage tree |
Source code in src/lineagetree/_io/_loaders.py
read_from_txt_for_celegans_BAO
¶
Read a C. elegans Bao file from http://digital-development.org
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Path to the file to read |
required |
|
str
|
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. |
None
|
Returns:
| Type | Description |
|---|---|
LineageTree
|
lineage tree |
Source code in src/lineagetree/_io/_loaders.py
read_from_txt_for_celegans_CAO
¶
read_from_txt_for_celegans_CAO(
file: str,
reorder: bool = False,
raw_size: ndarray | None = None,
shape: float | None = None,
name: str | None = None,
) -> LineageTree
Read a C. elegans lineage tree from Cao et al.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Path to the file to read |
required |
|
None or str
|
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. |
None
|
Returns:
| Type | Description |
|---|---|
LineageTree
|
lineage tree |
Source code in src/lineagetree/_io/_loaders.py
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 | |