analysis¶
Extraction of evolutionary information from simulated scenarios.
best_matches
¶
Orthology graph, BMG, RBMG.
This module provides classes concerning colored graphs and colored (phylogenetic) trees, including a BMG(Tree)-function, and computation of anLRT from a (not necessarily valid) BMG or from a (pruned) gene tree.
Phylogenetic best matches of a gene x of species X are defined as those genes y of another species Y that share the lowest common ancestor with x in the gene tree among all genes in that species. In contrast, two genes are orthologs if their last common ancestor was a speciation event. Orthology and reciprocal best matches are closely related. The module asymmetree.analysis. BestMatches contains methods for extracting BMGs from trees, least resolved trees of BMG, and orthology graphs from trees.
TwoColoredLRT
¶
Construct the least-resolved tree of a 2-colored best match graph.
Implementation of the efficient algorithm in [1].
References
- D. Schaller, M. Geiß, M. Hellmuth, and P. F. Stadler. Least resolved trees for two-colored best match graphs. In: Journal of Graph Algorithms and Applications, 25(1):397-416, 2021. doi: 10.7155/jgaa.00564.
Source code in asymmetree/analysis/best_matches.py
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 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 | |
__init__(digraph: nx.DiGraph) -> None
¶
Construct the least-resolved tree of a 2-colored best match graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
digraph
|
DiGraph
|
A digraph whose nodes have the 'color' attribute. |
required |
Source code in asymmetree/analysis/best_matches.py
build_tree() -> Tree | None
¶
Construct the least-resolved tree.
Returns:
| Type | Description |
|---|---|
Tree | None
|
The least-resolved tree if the graph was a 2-colored BMG, and None otherwise. |
Source code in asymmetree/analysis/best_matches.py
orthology_from_tree(tree: Tree) -> nx.Graph
¶
Constructs the true orthology graph from an event-labeled tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
Tree
|
A tree with leaves that have the |
required |
Returns:
| Type | Description |
|---|---|
Graph
|
The orthology graph explained by the tree, i.e., a graph on the set of leaf labels and edges between two of them if and only if their last common ancestor was a speciation event. |
Source code in asymmetree/analysis/best_matches.py
bmg_from_tree(tree: Tree, supply_rbmg: bool = False) -> nx.DiGraph | tuple[nx.DiGraph, nx.Graph]
¶
Construct a BMG (and optionally RBMG) from a given tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
Tree
|
A tree with leaves that have the |
required |
supply_rbmg
|
bool
|
If True, also return the symmetric part of the constructed BMG. |
False
|
Returns:
| Type | Description |
|---|---|
DiGraph | tuple[DiGraph, Graph]
|
The constructed BMG and optionally its symmetric part. |
References
- M. Geiß, E. Chávez, M. González Laffitte, A. López Sánchez, B. M. R. Stadler, D. I. Valdivia, M. Hellmuth, M. Hernández Rosales, and P. F.Stadler. Best match graphs. In: Journal of Mathematical Biology, 78:2015-2057, 2019. doi:10.1007/s00285-019-01332-9.
Source code in asymmetree/analysis/best_matches.py
extended_best_hits(leaves: list[TreeNode], D: np.ndarray, epsilon: float = 1e-08, supply_rbmg: bool = False) -> nx.DiGraph | tuple[nx.DiGraph, nx.Graph]
¶
Compute BMG and RBMG from a distances matrix D.
Apporximation of best matches as the genes within a tolerance range from the gene with the smallest distance, see [1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
leaves
|
list[TreeNode]
|
List of TreeNode instances with |
required |
D
|
ndarray
|
The distances of the leaves where the order of the rows/columns corresponds to that in the list. |
required |
epsilon
|
float
|
Relative threshold for the inclusion of suboptimal hits, i.e., (x,y) in BMG if D(x,y) <= (1 + epsilon) * min d(x,y'). |
1e-08
|
supply_rbmg
|
bool
|
If True, also return the symmetric part of the constructed BMG. |
False
|
Returns:
| Type | Description |
|---|---|
DiGraph | tuple[DiGraph, Graph]
|
The constructed BMG and optionally its symmetric part. |
References
- P. F. Stadler, M. Geiß, D. Schaller, A. López Sánchez, M. Gonzalez Laffitte, D. I. Valdivia, M. Hellmuth, and M. Hernández Rosales. From pairs of most similar sequences to phylogenetic best matches. In: Algorithms for Molecular Biology, 15:5, 2020. doi: 10.1186/s13015-020-00165-2.
Source code in asymmetree/analysis/best_matches.py
informative_triples(graph: nx.DiGraph, color_dict: dict | None = None) -> list[tuple]
¶
Compute the informative triples of a colored digraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
DiGraph
|
A digraph whose nodes have the 'color' attribute. |
required |
color_dict
|
dict | None
|
A dict containing the colors that appear in the graph as keys and the list of nodes with the respective color as values. If not provided, this dict is computed internally. |
None
|
Returns:
| Type | Description |
|---|---|
list[tuple]
|
A list where each item is a tuple (a, b1, b2) of three nodes such that a b1 | b2 is an informative triple in the graph, see [1]. |
References
- M. Geiß, E. Chávez, M. González Laffitte, A. López Sánchez, B. M. R. Stadler, D. I. Valdivia, M. Hellmuth, M. Hernández Rosales, and P. F. Stadler. Best match graphs. In: Journal of Mathematical Biology, 78:2015-2057, 2019. doi:10.1007/s00285-019-01332-9.
Source code in asymmetree/analysis/best_matches.py
forbidden_triples(graph: nx.DiGraph, color_dict: dict | None = None) -> list[tuple]
¶
Compute the forbidden triples of a colored digraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
DiGraph
|
A digraph whose nodes have the 'color' attribute. |
required |
color_dict
|
dict | None
|
A dict containing the colors that appear in the graph as keys and the list of nodes with the respective color as values. If not provided, this dict is computed internally. |
None
|
Returns:
| Type | Description |
|---|---|
list[tuple]
|
A list where each item is a tuple (a, b1, b2) of three nodes such that a b1 | b2 is a forbidden triple in the graph, see [1]. |
References
- D. Schaller, P. F. Stadler, and M. Hellmuth. Complexity of modification problems for best match graphs. In: Theoretical Computer Science, 865:63-84, 2021. doi:10.1016/j.tcs.2021.02.037.
Source code in asymmetree/analysis/best_matches.py
informative_forbidden_triples(graph: nx.DiGraph, color_dict: dict | None = None) -> tuple[list[tuple], list[tuple]]
¶
Compute the informative and forbidden triples of a colored digraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
DiGraph
|
A digraph whose nodes have the 'color' attribute. |
required |
color_dict
|
dict | None
|
A dict containing the colors that appear in the graph as keys and the list of nodes with the respective color as values. If not provided, this dict is computed internally. |
None
|
Returns:
| Type | Description |
|---|---|
list[tuple]
|
A list where each item is a tuple (a, b1, b2) of three nodes such that a b1 | b2 is an informative triple in the graph, see [1]. |
list[tuple]
|
A list where each item is a tuple (a, b1, b2) of three nodes such that a b1 | b2 is a forbidden triple in the graph, see [1]. |
References
- D. Schaller, P. F. Stadler, and M. Hellmuth. Complexity of modification problems for best match graphs. In: Theoretical Computer Science, 865:63-84, 2021. doi:10.1016/j.tcs.2021.02.037.
Source code in asymmetree/analysis/best_matches.py
binary_explainable_triples(graph: nx.DiGraph, color_dict: dict | None = None) -> list[tuple]
¶
Extended informative triple set for binary-explainable graphs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
DiGraph
|
A digraph whose nodes have the 'color' attribute. |
required |
color_dict
|
dict | None
|
A dict containing the colors that appear in the graph as keys and the list of nodes with the respective color as values. If not provided, this dict is computed internally. |
None
|
Returns:
| Type | Description |
|---|---|
list[tuple]
|
List of tuples where each item is a tuple (a, b, c) of three nodes such that ab|c is a triple displayed by every binary tree that explains the graph (if existent), see [1]. |
References
- D. Schaller, M. Geiß, M. Hellmuth, and P. F. Stadler. Best match graphs with binary trees. In: C. Martín-Vide, M. A. Vega-Rodríguez, and T. Wheeler, editors, Algorithms for Computational Biology, 8th AlCoB, volume 12715 of Lecture Notes in Computer Science, pages 82-93, 2021. doi: 10.1007/978-3-030-74432-8_6.
Source code in asymmetree/analysis/best_matches.py
lrt_from_tree(T: Tree) -> Tree
¶
Computes the Least Resolved Tree from a tree.
The unique Least Resolved Tree from a (pruned) gene tree is computed by contraction of all redundant edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Tree
|
A tree whose leaf nodes have the 'reconc' attribute. |
required |
Returns:
| Type | Description |
|---|---|
Tree
|
The unique least resolved tree (w.r.t. best matches), see [1]. |
References
- D. Schaller, M. Geiß, P. F. Stadler, and M. Hellmuth. Complete characterization of incorrect orthology assignments in best match graphs. In: Journal of Mathematical Biology, 82:20, 2021. doi: 10.1007/s00285-021-01564-8.
Source code in asymmetree/analysis/best_matches.py
redundant_edges(T: Tree, subtree_reconcs: dict[TreeNode, set], arc_colors: dict[TreeNode, set]) -> list[tuple[TreeNode, TreeNode]]
¶
Compute the redundant edges of a tree.
An inner edge (u,v) is redundant if there is no arc (x,y) in the BMG with lca(x,y) = u and y has a color that is not in the subtree of v, see [1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Tree
|
A tree whose leaf nodes have the 'reconc' attribute. |
required |
subtree_reconcs
|
dict[TreeNode, set]
|
A dict mapping each node to the set of reconciliations of its leaf descendants. |
required |
arc_colors
|
dict[TreeNode, set]
|
A dict mapping each inner vertex to the set of colors s such that there is an arc (x,y) in the BMG with lca(x,y) = v and y has color s. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[TreeNode, TreeNode]]
|
A list of tuples representing the redundant edges of the tree. |
Source code in asymmetree/analysis/best_matches.py
is_bmg(G: nx.DiGraph) -> Tree | None
¶
Determine whether a colored digraph is a BMG.
If the graph is a BMG, then its LRT is returned, see [1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
G
|
DiGraph
|
A digraph whose nodes have the 'color' attribute. |
required |
Returns:
| Type | Description |
|---|---|
Tree | None
|
The least-resolved tree if the graph was a BMG, and None otherwise. |
References
- D. Schaller, M. Geiß, E. Chávez, M. González Laffitte, A. López Sánchez, B. M. R. Stadler, D. I. Valdivia, M. Hellmuth, M. Hernández Rosales, and P. F. Stadler. Corrigendum to 'Best match graphs'. In: Journal of Mathematical Biology, 82:47, 2021. doi: 10.1007/s00285-021-01601-6.
Source code in asymmetree/analysis/best_matches.py
lrt_from_colored_graph(G: nx.DiGraph, mincut: bool = False, weighted_mincut: bool = False) -> Tree | None
¶
Compute the least resolved tree from a colored digraph.
If the graph is a BMG, then the unique least resolved tree is returned. If not, then a heuristic
least resolved tree is returned if mincut is True, and None otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
G
|
DiGraph
|
A digraph whose nodes have the 'color' attribute. |
required |
mincut
|
bool
|
Handle inconsistencies that occur if the supplied graph is not a BMG. |
False
|
weighted_mincut
|
bool
|
If True, apply a weighted mincut heuristic. |
False
|
Returns:
| Type | Description |
|---|---|
Tree | None
|
The least resolved tree if the graph was a BMG, a heuristic least resolved tree if |
Source code in asymmetree/analysis/best_matches.py
correct_bmg(G: nx.DiGraph) -> nx.DiGraph
¶
Build the LRT (using min cut in BUILD algorithm) and return its BMG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
G
|
DiGraph
|
A digraph whose nodes have the 'color' attribute. |
required |
Returns:
| Type | Description |
|---|---|
DiGraph
|
The graph edited to be a BMG. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the mincut heuristic fails to construct a tree. |
Source code in asymmetree/analysis/best_matches.py
lrt_from_2bmg(G: nx.DiGraph) -> Tree | None
¶
Effieciently constructs the LRT for a 2-BMG via the support vertices.
Implementation of the efficient algorithm in [1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
G
|
DiGraph
|
A digraph whose nodes have the 'color' attribute. |
required |
Returns:
| Type | Description |
|---|---|
Tree | None
|
The least-resolved tree if the graph was a 2-colored BMG, and None otherwise. |
References
- D. Schaller, M. Geiß, M. Hellmuth, and P. F. Stadler. Least resolved trees for two-colored best match graphs. In: Journal of Graph Algorithms and Applications, 25(1):397-416, 2021. doi: 10.7155/jgaa.00564.
Source code in asymmetree/analysis/best_matches.py
binary_refinable_tree(G: nx.DiGraph, mincut: bool = False, weighted_mincut: bool = False) -> Tree | None
¶
Compute the binary-refinable tree (BRT) for a graph.
The BRT of a BMG can, if it exists, be refined arbitrarily and such that it still explains the BMG. In particular, all binary explanations are refinements of the BRT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
G
|
DiGraph
|
A digraph whose nodes have the |
required |
mincut
|
bool
|
If True, handle inconsistencies that occur if the supplied graph is not a binary-explainable BMG. |
False
|
weighted_mincut
|
bool
|
If True, apply a weighted mincut heuristic. |
False
|
Returns:
| Type | Description |
|---|---|
Tree | None
|
The unique binary-resolvable tree if the graph is a binary-explainable BMG, see [1], or a
heuristic tree if it is not but |
References
- D. Schaller, M. Geiß, M. Hellmuth, and P. F. Stadler. Best match graphs with binary trees. In: C. Martín-Vide, M. A. Vega-Rodríguez, and T. Wheeler, editors, Algorithms for Computational Biology, 8th AlCoB, volume 12715 of Lecture Notes in Computer Science, pages 82-93, 2021. doi: 10.1007/978-3-030-74432-8_6.
Source code in asymmetree/analysis/best_matches.py
augment_and_label(tree: Tree, inplace: bool = False) -> Tree
¶
Augment tree and add event labeling based on color intersections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
Tree
|
A tree whose nodes have the 'reconc' attribute. |
required |
inplace
|
bool
|
If True, the supplied tree instance is directly manipulated, otherwise the tree is copied first. |
False
|
Returns:
| Type | Description |
|---|---|
Tree
|
The unique augmented and duplication/loss-labeled tree as defined in [1]. |
References
- D. Schaller, M. Geiß, P. F. Stadler, and M. Hellmuth. Complete characterization of incorrect orthology assignments in best match graphs. In: Journal of Mathematical Biology, 82:20, 2021. doi: 10.1007/s00285-021-01564-8.
Source code in asymmetree/analysis/best_matches.py
classify_good_ugly(bmg: nx.DiGraph, rbmg: nx.Graph, fp: nx.Graph) -> nx.Graph
¶
Classify edges in the false-positives graph as middle_in_good, first_in_ugly, first_in_bad.
The false positives in an RBMG (w.r.t. to orthology) can be classified into several categories, including middle edges of good quartets, first edges of ugly quartets, and first edges of bad quartets, see [1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bmg
|
DiGraph
|
The best match graph. |
required |
rbmg
|
Graph
|
The reciprocal best match graph. |
required |
fp
|
Graph
|
The false-positives graph. |
required |
Returns:
| Type | Description |
|---|---|
Graph
|
The updated false-positives graph with edges classified as |
References
- D. Schaller, M. Geiß, P. F. Stadler, and M. Hellmuth. Complete characterization of incorrect orthology assignments in best match graphs. In: Journal of Mathematical Biology, 82:20, 2021. doi: 10.1007/s00285-021-01564-8.
Source code in asymmetree/analysis/best_matches.py
count_good_ugly(bmg: nx.DiGraph, rbmg: nx.Graph, fp: nx.Graph) -> tuple[int, int, int]
¶
Count number of edge types in the false-positives graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bmg
|
DiGraph
|
The best match graph. |
required |
rbmg
|
Graph
|
The reciprocal best match graph. |
required |
fp
|
Graph
|
The false-positives graph. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int, int]
|
A tuple containing the number of edges in the false-positives graph that are middle edges of good quartets, first edges of ugly quartets, and both. |
Source code in asymmetree/analysis/best_matches.py
count_good_ugly_bad(bmg: nx.DiGraph, rbmg: nx.Graph, fp: nx.Graph) -> tuple[int, int, int, int, int, int, int]
¶
Count number of edge types in the false-positives graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bmg
|
DiGraph
|
The best match graph. |
required |
rbmg
|
Graph
|
The reciprocal best match graph. |
required |
fp
|
Graph
|
The false-positives graph. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int, int, int, int, int, int]
|
A tuple containing the number of edges in the false-positives graph that are middle edges of good quartets, first edges of ugly quartets, first edges of bad quartets, and all combinations thereof in in order: (gub, gu, gb, ub, g, u, b). |
Source code in asymmetree/analysis/best_matches.py
list_path(t: int, k: int, path: list, G: nx.Graph, P4_list: list) -> None
¶
List all paths of length k in G.
The paths are stored in P4_list as tuples of the form (v1, v2, v3, v4).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
int
|
The current length of the path. |
required |
k
|
int
|
The desired length of the path. |
required |
path
|
list
|
The current path being explored. |
required |
G
|
Graph
|
The graph in which to find paths. |
required |
P4_list
|
list
|
A list to store the found paths. |
required |
Source code in asymmetree/analysis/best_matches.py
find_all_P4(G: nx.Graph) -> list[tuple]
¶
Find all induced P4 in G.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
G
|
Graph
|
A graph in which to find induced P4. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple]
|
A list of tuples of the form (v1, v2, v3, v4) representing all induced P4 in G. |
Source code in asymmetree/analysis/best_matches.py
is_good_quartet(path: tuple, bmg: nx.Graph) -> bool
¶
Determine whether an induced P4 is a good quartet in the bmg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
tuple
|
A tuple representing the induced P4. |
required |
bmg
|
Graph
|
The best match graph. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the induced P4 is a good quartet, False otherwise. |
Source code in asymmetree/analysis/best_matches.py
remove_all_P4(rbmg: nx.Graph, bmg: nx.Graph, P4_list: list[tuple] = None) -> nx.Graph
¶
Find all good quartets and removes the middle edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rbmg
|
Graph
|
The reciprocal best match graph. |
required |
bmg
|
Graph
|
The best match graph. |
required |
P4_list
|
list[tuple]
|
A list of tuples representing all induced P4 in the rbmg. If not provided, it is computed internally. |
None
|
Returns:
| Type | Description |
|---|---|
Graph
|
The graph obtained from the RBMG by removing the middle edges of all good quartets. |
Source code in asymmetree/analysis/best_matches.py
find_all_C6(G: nx.Graph, P4_list: list[tuple] | None = None) -> list[tuple]
¶
Find induces C6 of the form
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
G
|
Graph
|
A graph in which to find induced C6. |
required |
P4_list
|
list[tuple] | None
|
A list of tuples representing all induced P4 in G. If not provided, it is computed internally. |
None
|
Returns:
| Type | Description |
|---|---|
list[tuple]
|
A list of tuples of the form (x1, y1, z1, x2, y2, z2) representing all induced C6 in G. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a detected C6 does not satisfy the properties of an induced C6 in G. |
Source code in asymmetree/analysis/best_matches.py
graph_type(G: nx.Graph) -> tuple[str, list[tuple], list[tuple]]
¶
Classify the graph as type A, B, or C based on the presence of induced P4 and C6.
A graph is of type A if it contains no induced P4, of type B if it contains an induced P4 but no induced C6, and of type C if it contains an induced C6.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
G
|
Graph
|
A graph in which to classify the structure. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The type of the graph ("A", "B", or "C"). |
list[tuple]
|
A list of all induced P4 in the graph. |
list[tuple]
|
A list of all induced C6 in the graph. |
Source code in asymmetree/analysis/best_matches.py
horizontal_gene_transfer
¶
Horizontal gene transfer (HGT), xenology and Fitch graphs.
This module contains several functions for the analysis of horizontal gene transfer events in the simulated scenarios. In particular, the directed and undirected Fitch graph can be extracted, as well as the pairs of genes that diverged later than the respective species in which they reside, i.e., the later-divergence-time (LDT) graph, see [1]. The latter situation is indicative of the presence of HGT events in the scenario.
References
- D. Schaller, M. Lafond, P.F. Stadler, N. Wieseke, M. Hellmuth. Indirect identification of horizontal gene transfer. In: Journal of Mathematical Biology, 2021, 83(1):10. doi: 10.1007/s00285-021-01631-0.
RsScenarioConstructor
¶
Construct an rs-scenario for a given LDT graph.
Implementation of the algorithm presented in [1].
References
- D. Schaller, M. Lafond, P.F. Stadler, N. Wieseke, M. Hellmuth. Indirect identification of horizontal gene transfer. In: Journal of Mathematical Biology, 2021, 83(1):10. doi: 10.1007/s00285-021-01631-0.
Source code in asymmetree/analysis/horizontal_gene_transfer.py
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 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 | |
__init__(colored_cograph: nx.Graph, color_set: set | None = None) -> None
¶
Construct an instance of the RsScenarioConstructor class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
colored_cograph
|
Graph
|
A cograph whose nodes have the 'color' attribute. |
required |
color_set
|
set | None
|
The set of colors appearing in the graph. The default is None, in which case such a set is created internally. |
None
|
Source code in asymmetree/analysis/horizontal_gene_transfer.py
run() -> tuple[Tree, Tree] | None
¶
Construct an rs-scenario consisting of a species and gene tree.
Returns:
| Type | Description |
|---|---|
tuple[Tree, Tree] | None
|
The species and gene tree, or None if the supplied graph was not an LDT graph. |
Source code in asymmetree/analysis/horizontal_gene_transfer.py
true_transfer_edges(T: Tree) -> set[TreeNode]
¶
Returns a set containing v if (u, v) is labeled as a transfer edge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Tree
|
A tree whose nodes have the |
required |
Returns:
| Type | Description |
|---|---|
set[TreeNode]
|
The subset of |
Source code in asymmetree/analysis/horizontal_gene_transfer.py
rs_transfer_edges(T: Tree, S: Tree, lca_S: LCA = None) -> set[TreeNode]
¶
Transfer edges in T according to the relaxed scenario definition.
An edge (u,v) in T is an (rs-)transfer edge if u and v are mapped to incomparable nodes/edges in the species tree S.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Tree
|
The gene tree. |
required |
S
|
Tree
|
The species tree corresponding to the gene tree. |
required |
lca_S
|
LCA
|
Instance of LCA corresponding to the species tree, default is None in which case a new instance is created and used. |
None
|
Returns:
| Type | Description |
|---|---|
set[TreeNode]
|
The subset of |
Source code in asymmetree/analysis/horizontal_gene_transfer.py
fitch(tree: Tree, transfer_edges: Iterable[TreeNode], supply_undirected: bool = False, lca_T: LCA | None = None) -> nx.DiGraph | tuple[nx.DiGraph, nx.Graph]
¶
Returns the (directed) Fitch graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
Tree
|
The gene tree. |
required |
transfer_edges
|
Iterable[TreeNode]
|
The subset of TreeNode instances in the tree that are transfer edges. |
required |
supply_undirected
|
bool
|
If True, additionally return the undirected Fitch graph. |
False
|
lca_T
|
LCA | None
|
Instance of LCA corresponding to the tree, default is False in which case a new instance is created and used. |
None
|
Returns:
| Type | Description |
|---|---|
DiGraph | tuple[DiGraph, Graph]
|
The directed Fitch graph or a tuple containing the directed Fitch graph ( |
Source code in asymmetree/analysis/horizontal_gene_transfer.py
undirected_fitch(tree: Tree, transfer_edges: Iterable[TreeNode], lca_T: LCA | None = None) -> nx.Graph
¶
Returns the undirected Fitch graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
Tree
|
The gene tree. |
required |
transfer_edges
|
Iterable[TreeNode]
|
The subset of TreeNode instances in the tree that are transfer edges. |
required |
lca_T
|
LCA | None
|
Instance of LCA corresponding to the tree, default is None in which case a new instance is created and used. |
None
|
Returns:
| Type | Description |
|---|---|
Graph
|
The undirected Fitch graph ( |
Source code in asymmetree/analysis/horizontal_gene_transfer.py
is_rs_fitch(G: nx.Graph, color_set: set | None = None) -> bool
¶
Checks whether a given graph is an rs-Fitch graph.
This function checks whether the graph is the Fitch graph of some relaxed scenario (rs), see [1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
G
|
Graph
|
A graph whose nodes have the |
required |
color_set
|
set | None
|
The set of colors appearing in the graph. The default is None, in which case such a set is created internally. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the graph is an rs-Fitch graph as defined in [1]. |
References
- D. Schaller, M. Lafond, P.F. Stadler, N. Wieseke, M. Hellmuth. Indirect identification of horizontal gene transfer. In: Journal of Mathematical Biology, 2021, 83(1):10. doi: 10.1007/s00285-021-01631-0.
Source code in asymmetree/analysis/horizontal_gene_transfer.py
below_equal_above(T: Tree, S: Tree, lca_T: LCA | None = None, lca_S: LCA | None = None) -> tuple[nx.Graph, nx.Graph, nx.Graph]
¶
Determine pairs of genes that diverged later, at the same time, or earlier as their species.
Returns three graphs with the leaves of the gene tree T as vertex set, and edges ab if and only if a and b diverged later, at the same time, or earlier, resp., than the corresponding species A and B in the species tree S.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Tree
|
The gene tree. |
required |
S
|
Tree
|
The corresponding species tree. |
required |
lca_T
|
LCA | None
|
Instance of LCA corresponding to the gene tree, default is None in which case a new instance is created and used. |
None
|
lca_S
|
LCA | None
|
Instance of LCA corresponding to the species tree, default is None in which case a new instance is created and used. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Graph, Graph, Graph]
|
The below, equal, and above relation as described above. |
Source code in asymmetree/analysis/horizontal_gene_transfer.py
ldt_graph(T: Tree, S: Tree, lca_T: LCA | None = None, lca_S: LCA | None = None) -> nx.Graph
¶
Later-divergence-time graph, see [1].
Returns a graph with the leaves of the gene tree T as vertex set, and edges ab if and only if a and b diverged later than the corresponding species A and B in the species tree S.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Tree
|
The gene tree. |
required |
S
|
Tree
|
The corresponding species tree. |
required |
lca_T
|
LCA | None
|
Instance of LCA corresponding to the gene tree, default is None in which case a new instance is created and used. |
None
|
lca_S
|
LCA | None
|
Instance of LCA corresponding to the species tree, default is None in which case a new instance is created and used. |
None
|
References
- D. Schaller, M. Lafond, P.F. Stadler, N. Wieseke, M. Hellmuth. Indirect identification of horizontal gene transfer. In: Journal of Mathematical Biology, 2021, 83(1):10. doi: 10.1007/s00285-021-01631-0.
Source code in asymmetree/analysis/horizontal_gene_transfer.py
is_compatible(T: Tree, partition: list | tuple, lca: LCA | None = None) -> tuple[dict, list] | None
¶
Checks whether a tree and a partition are compatible.
A tree with leaf set L and a partition of L are compatible if there is a subset of tree edges such that the forest obtained by their removal induces the given partition (in terms of membership to the same connected component). In this case, the vertices can be uniquely colored by set A of the partition if they lie on a path connecting two elements from A.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Tree
|
A tree with unique leaf labels. |
required |
partition
|
list | tuple
|
A partition of the labels of the trees' leaves. |
required |
lca
|
LCA | None
|
Precomputed LCA datastructure for the tree. The default is None in which case it is computed internally. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[dict, list] | None
|
Returns None if the tree and the partition are incompatible, and otherwise a tuple of a dict and a list. The dict contains vertices of the tree that lie on a path connecting two elements from the same set of the partition with the index of this set as value. The list contains the last common ancestor in the tree for each set in the partition. |
References
- M. Hellmuth, D. Schaller, P.F. Stadler. Compatibility of partitions with trees, hierarchies, and split systems. In: Discrete Applied Mathematics 314 (2022) 265-283. doi: https://doi.org/10.1016/j.dam.2022.03.014
Source code in asymmetree/analysis/horizontal_gene_transfer.py
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 558 559 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 | |
is_refinement_compatible(T: Tree, partition: list | tuple, lca: LCA | None = None) -> tuple[dict, list] | None
¶
Checks whether a tree and a partition are refinement-compatible.
A tree T with leaf set L and a partition of L are refinement-compatible if there is a refinement T' of T for which a subset of edges of T' exists such that the forest obtained by their removal induces the given partition (in terms of membership to the same connected component). In this case, the edges can be uniquely colored by set A of the partition if they lie on a path connecting two elements from A.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Tree
|
A tree with unique leaf labels. |
required |
partition
|
list | tuple
|
A partition of the labels of the trees' leaves. |
required |
lca
|
LCA | None
|
Precomputed LCA datastructure for the tree. The default is None in which case it is computed internally. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[dict, list] | None
|
Returns None if the tree and the partition are not refinement-compatible, and otherwise a tuple of a dict and a list. The dict contains nodes v of the tree such that the edge (parent(v), v) lies on a path connecting two elements from the same set of the partition with the index of this set as value. The list contains the last common ancestor in the tree for each set in the partition. |
References
- M. Hellmuth, D. Schaller, P.F. Stadler. Compatibility of partitions with trees, hierarchies, and split systems. In: Discrete Applied Mathematics 314 (2022) 265-283. doi: https://doi.org/10.1016/j.dam.2022.03.014
Source code in asymmetree/analysis/horizontal_gene_transfer.py
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 | |
fitch_orientation(T: Tree, partition: list | tuple, lca: LCA | None = None) -> list[list[str]] | None
¶
(Un)ambiguously present or absent edges in the directed Fitch graph.
The ordered pair (x, y) of two leaves x and y is in the Fitch relation if the path from lca(x, y) to y contains a transfer edge. An undirected Fitch relation ((x, y) if (x, y) or (y, x) in the directed relation) can be represented by a partition (the maximal independent sets). In combination with a tree, this partition determines to some extent the directed Fitch relation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Tree
|
A tree with unique leaf labels. |
required |
partition
|
list | tuple
|
A partition of the labels of the trees' leaves. |
required |
lca
|
LCA | None
|
Precomputed LCA datastructure for the tree. The default is None in which case it is computed internally. |
None
|
Returns:
| Type | Description |
|---|---|
list[list[str]] | None
|
Returns None if the tree and the partition are incompatible. Otherwise, returns a 2-dimensional array that stores at indices i and j corresponding to sets A and B, resp., of the partition whether (A, B) is 'essential', 'forbidden', or 'ambiguous'. |
References
- D. Schaller, M. Hellmuth, P. F. Stadler. Orientation of Fitch Graphs and Reconciliation-Free Inference of Horizontal Gene Transfer in Gene Trees. In: SIAM Journal on Discrete Mathematics, 37(3): 2172-2207 (2023). doi: https://doi.org/10.1137/22M150736X
Source code in asymmetree/analysis/horizontal_gene_transfer.py
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 | |
fitch_orientation_for_refinements(T: Tree, partition: list | tuple, lca: LCA | None = None) -> list[list[str]] | None
¶
(Un)ambiguously present/absent edges in the directed Fitch graph of all refinements.
The ordered pair (x, y) of two leaves x and y is in the Fitch relation if the path from lca(x, y) to y contains a transfer edge. An undirected Fitch relation ((x, y) if (x, y) or (y, x) in the directed relation) can be represented by a partition (the maximal independent sets). In combination with a tree, this partition determines to some extent the directed Fitch relation w.r.t. the possible refinements of the tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Tree
|
A tree with unique leaf labels. |
required |
partition
|
list | tuple
|
A partition of the labels of the trees' leaves. |
required |
lca
|
LCA | None
|
Precomputed LCA datastructure for the tree. The default is None in which case it is computed internally. |
None
|
Returns:
| Type | Description |
|---|---|
list[list[str]] | None
|
Returns None if the tree and the partition are not refinement-compatible. Otherwise, returns a 2-dimensional array that stores at indices i and j corresponding to sets A and B, resp., of the partition whether (A, B) is 'essential', 'forbidden', or 'ambiguous' for all refinements of the tree that are compatible with the partition. |
References
- D. Schaller, M. Hellmuth, P. F. Stadler. Orientation of Fitch Graphs and Reconciliation-Free Inference of Horizontal Gene Transfer in Gene Trees. In: SIAM Journal on Discrete Mathematics, 37(3): 2172-2207 (2023). doi: https://doi.org/10.1137/22M150736X
Source code in asymmetree/analysis/horizontal_gene_transfer.py
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 843 844 845 846 847 848 849 850 | |