lineagetree.measure
¶
Modules:
| Name | Description |
|---|---|
dynamic_time_warping |
|
spatial |
|
uted |
|
Functions:
| Name | Description |
|---|---|
calculate_dtw |
Calculate DTW distance between two chains |
clear_comparisons |
Clears the comparisons saved on the LineageTree object. |
compute_k_nearest_neighbours |
Computes the k-nearest neighbors |
compute_spatial_density |
Computes the spatial density of nodes between |
compute_spatial_edges |
Computes the neighbors at a distance |
get_gabriel_graph |
Build the Gabriel graph of the given graph for time point |
labelled_mappings |
Returns the labels or IDs of all the nodes in the subtrees compared. |
plot_tree_distance_graphs |
Plots the subtrees compared and colors them according to the quality of the matching of their subtree. |
unordered_tree_edit_distance |
Compute the unordered tree edit distance from Zhang 1996 between the trees spawned |
unordered_tree_edit_distances_at_time_t |
Compute all the pairwise unordered tree edit distances from Zhang 996 between the trees spawned at time |
calculate_dtw
¶
calculate_dtw(
lT: LineageTree,
nodes1: int,
nodes2: int,
threshold: int = 1000,
regist: bool = True,
start_d: int = 0,
back_d: int = 0,
fast: bool = False,
w: int = 0,
centered_band: bool = True,
cost_mat_p: bool = False,
) -> (
tuple[float, tuple, np.ndarray, np.ndarray, np.ndarray]
| tuple[float, tuple]
)
Calculate DTW distance between two chains
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
LineageTree
|
The LineageTree instance. |
required |
|
int
|
node to compare distance |
required |
|
int
|
node to compare distance |
required |
|
int
|
set a maximum number of points a chain can have |
1000
|
|
bool
|
Rotate and translate trajectories |
True
|
|
int
|
start delay |
0
|
|
int
|
end delay |
0
|
|
bool
|
if |
False
|
|
int
|
window size |
0
|
|
bool
|
when running the fast algorithm, |
True
|
|
bool
|
True if print the not normalized cost matrix |
False
|
Returns:
| Type | Description |
|---|---|
float
|
DTW distance |
tuple of tuples
|
Aligment path |
matrix
|
Cost matrix |
list of lists
|
rotated and translated trajectories positions |
list of lists
|
rotated and translated trajectories positions |
Source code in src/lineagetree/measure/dynamic_time_warping.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 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 | |
clear_comparisons
¶
Clears the comparisons saved on the LineageTree object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
LineageTree
|
The LineageTree object |
required |
compute_k_nearest_neighbours
¶
Computes the k-nearest neighbors
Writes the output in the attribute kn_graph
and returns it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
LineageTree
|
The LineageTree instance. |
required |
|
float
|
number of nearest neighours |
10
|
Returns:
| Type | Description |
|---|---|
dict mapping int to set of int
|
dictionary that maps
a node id to its |
dict mapping int to set of float
|
dictionary that maps
a node id to the distances of its |
Source code in src/lineagetree/measure/spatial.py
compute_spatial_density
¶
compute_spatial_density(
lT: LineageTree,
t_b: int | None = None,
t_e: int | None = None,
th: float = 50,
) -> dict[int, float]
Computes the spatial density of nodes between t_b and t_e.
The results is stored in lT.spatial_density and returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
LineageTree
|
The LineageTree instance. |
required |
|
int
|
starting time to look at, default first time point |
None
|
|
int
|
ending time to look at, default last time point |
None
|
|
float
|
size of the neighbourhood |
50
|
Returns:
| Type | Description |
|---|---|
dict mapping int to float
|
dictionary that maps a node id to its spatial density |
Source code in src/lineagetree/measure/spatial.py
compute_spatial_edges
¶
Computes the neighbors at a distance th
Writes the output in the attribute th_edge
and returns it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
LineageTree
|
The LineageTree instance. |
required |
|
float
|
distance to consider neighbors |
50
|
Returns:
| Type | Description |
|---|---|
dict mapping int to set of int
|
dictionary that maps a node id to its neighbors at a distance |
Source code in src/lineagetree/measure/spatial.py
get_gabriel_graph
¶
get_gabriel_graph(
lT: LineageTree, time: int | Iterable[int] | None = None
) -> dict[int, set[int]]
Build the Gabriel graph of the given graph for time point t.
The Garbiel graph is then stored in lT.Gabriel_graph and returned.
.. warning:: the graph is not recomputed if already computed, even if the point cloud has changed
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
LineageTree
|
The LineageTree instance. |
required |
|
int or Iterable of int
|
time or iterable of times. If not given the gabriel graph will be calculated for all timepoints. |
None
|
Returns:
| Type | Description |
|---|---|
dict of int to set of int
|
A dictionary that maps a node to the set of its neighbors |
Source code in src/lineagetree/measure/spatial.py
labelled_mappings
¶
labelled_mappings(
lT: LineageTree,
n1: int,
n2: int,
end_time: int | None = None,
norm: Literal["max", "sum", None] = "max",
style: (
Literal[
"simple",
"normalized_simple",
"full",
"downsampled",
]
| type[TreeApproximationTemplate]
) = "simple",
downsample: int = 2,
) -> dict[str, list[str]]
Returns the labels or IDs of all the nodes in the subtrees compared.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
LineageTree
|
The LineageTree instance. |
required |
|
int
|
id of the first node to compare |
required |
|
int
|
id of the second node to compare |
required |
|
int
|
The final time point the comparison algorithm will take into account. If None or not provided all nodes will be taken into account. |
None
|
|
('max', 'sum')
|
The normalization method to use, defaults to 'max'. |
"max"
|
|
"simple", "full", "downsampled", "normalized_simple
|
Which tree approximation is going to be used for the comparisons, defaults to 'simple'. |
"simple"
|
|
int
|
The downsample factor for the downsampled tree approximation.
Used only when |
2
|
Returns:
| Type | Description |
|---|---|
dict mapping str to list of str
|
|
Source code in src/lineagetree/measure/uted.py
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 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 | |
plot_tree_distance_graphs
¶
plot_tree_distance_graphs(
lT: LineageTree,
n1: int,
n2: int,
end_time: int | None = None,
norm: Literal["max", "sum", None] = "max",
style: (
Literal[
"simple",
"normalized_simple",
"full",
"downsampled",
]
| type[TreeApproximationTemplate]
) = "simple",
downsample: int = 2,
colormap: str = "cool",
default_color: str = "black",
size: float = 10,
lw: float = 0.3,
ax: list[Axes] | None = None,
vmin=None,
vmax=None,
) -> tuple[plt.figure, plt.Axes]
Plots the subtrees compared and colors them according to the quality of the matching of their subtree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
LineageTree
|
The LineageTree instance. |
required |
|
int
|
id of the first node to compare |
required |
|
int
|
id of the second node to compare |
required |
|
int
|
The final time point the comparison algorithm will take into account. If None all nodes will be taken into account. |
None
|
|
('max', 'sum')
|
The normalization method to use. |
"max"
|
|
"simple", "full", "downsampled", "normalized_simple
|
Which tree approximation is going to be used for the comparisons. |
"simple"
|
|
int
|
The downsample factor for the downsampled tree approximation.
Used only when |
2
|
|
str
|
The colormap used for matched nodes, defaults to "cool" |
"cool"
|
|
str
|
The color of the unmatched nodes, defaults to "black" |
'black'
|
|
float
|
The size of the nodes, defaults to 10 |
10
|
|
float
|
The width of the edges, defaults to 0.3 |
0.3
|
|
ndarray
|
The axes used, if not provided another set of axes is produced, defaults to None |
None
|
|
Values within the range |
None
|
|
|
Values within the range |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The figure of the plot |
Axes
|
The axes of the plot |
Source code in src/lineagetree/measure/uted.py
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 420 421 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 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |
unordered_tree_edit_distance
¶
unordered_tree_edit_distance(
lT: LineageTree,
n1: int,
n2: int,
end_time: int | None = None,
norm: Literal["max", "sum", None] = "max",
style: (
Literal[
"simple",
"normalized_simple",
"full",
"downsampled",
]
| type[TreeApproximationTemplate]
) = "simple",
downsample: int = 2,
return_norms: bool = False,
) -> float | tuple[float, tuple[float, float]]
Compute the unordered tree edit distance from Zhang 1996 between the trees spawned
by two nodes n1 and n2. The topology of the trees are compared and the matching
cost is given by the function delta (see edist doc for more information).
The distance is normed by the function norm that takes the two list of nodes
spawned by the trees n1 and n2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
LineageTree
|
The LineageTree instance. |
required |
|
int
|
id of the first node to compare |
required |
|
int
|
id of the second node to compare |
required |
|
int
|
The final time point the comparison algorithm will take into account. If None or not provided all nodes will be taken into account. |
None
|
|
('max', 'sum')
|
The normalization method to use, defaults to 'max'. |
"max"
|
|
('simple', 'normalized_simple', 'full', 'downsampled')
|
Which tree approximation is going to be used for the comparisons. |
"simple"
|
|
int
|
The downsample factor for the downsampled tree approximation.
Used only when |
2
|
Returns:
| Type | Description |
|---|---|
float
|
The normalized unordered tree edit distance between |
Source code in src/lineagetree/measure/uted.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 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 | |
unordered_tree_edit_distances_at_time_t
¶
unordered_tree_edit_distances_at_time_t(
lT: LineageTree,
t: int,
end_time: int | None = None,
style: (
Literal[
"simple",
"full",
"downsampled",
"normalized_simple",
]
| type[TreeApproximationTemplate]
) = "simple",
downsample: int = 2,
norm: Literal["max", "sum", None] = "max",
recompute: bool = False,
) -> dict[tuple[int, int], float]
Compute all the pairwise unordered tree edit distances from Zhang 996 between the trees spawned at time t
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
LineageTree
|
The LineageTree instance. |
required |
|
int
|
time to look at |
required |
|
int
|
The final time point the comparison algorithm will take into account. If None all nodes will be taken into account. |
None
|
|
('simple', 'full', 'downsampled', 'normalized_simple')
|
Which tree approximation is going to be used for the comparisons. |
"simple"
|
|
int
|
The downsample factor for the downsampled tree approximation.
Used only when |
2
|
|
('max', 'sum')
|
The normalization method to use. |
"max"
|
|
bool
|
If True, forces to recompute the distances |
False
|
Returns:
| Type | Description |
|---|---|
dict mapping a tuple of tuple that contains 2 ints to float
|
a dictionary that maps a pair of node ids at time |