Supertrees¶
BUILD Algorithm¶
build_supertree(trees: Iterable[Tree]) -> Tree | None
¶
Supertree construction based on the BUILD algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trees
|
Iterable[Tree]
|
An iterable of Tree instances. |
required |
Returns:
| Type | Description |
|---|---|
Tree | None
|
A supertree for the input trees if existent, None otherwise. |
Source code in tralda/supertree/build.py
tree_profile_to_triples(trees: Iterable[Tree]) -> tuple[set[Any], set[Triple]]
¶
Construct leaf set and representative triples from a profile of trees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trees
|
Iterable[Tree]
|
An iterable of Tree instances. |
required |
Returns The first set contains all leaf labels that appear in the tree profilea, and the second set contains a representative set of triples.
Source code in tralda/supertree/build.py
Build
¶
BUILD algorithm.
References
- A. V. Aho, Y. Sagiv, T. G. Szymanski, and J. D. Ullman. Inferring a tree from lowest common ancestors with an application to the optimization of relational expressions. SIAM Journal on Computing, 10:405-421, 1981. DOI: 10.1137/0210030.
Source code in tralda/supertree/build.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
__init__(R: Iterable[Triple], L: Collection[Any], mincut: bool = False, weighted_mincut: bool = False, triple_weights: dict[Triple, int | float] | None = None)
¶
Constructor for class implementing the BUILD algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
R
|
Iterable[Triple]
|
An iterable of triples. |
required |
L
|
Collection[Any]
|
A collection of leaf labels. |
required |
mincut
|
bool
|
If True, use MinCut to resolve triple inconsistencies. Otherwise, no tree is returned in case of such inconsistencies. |
False
|
weighted_mincut
|
bool
|
If True, weight the edges in the resulting graph accordingto the number of corresponding triples (and their weights). |
False
|
triple_weights
|
dict[Triple, int | float] | None
|
Dictionary with tuples as keys and float values. The weights of the triples. The default is None, in which case every triple has weight one. |
None
|
Source code in tralda/supertree/build.py
build_tree(return_root: bool = False, print_info: bool = False) -> Tree | TreeNode | None
¶
Build a tree displaying all triples in R if possible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
return_root
|
bool
|
If True, return 'TreeNode' instead of 'Tree' instance. |
False
|
print_info
|
bool
|
If True, print information about inconsistencies. |
False
|
Returns The BUILD tree on leaf set L displaying all triples in R if the triple set R is consistent.
Source code in tralda/supertree/build.py
greedy_build(R: Iterable[Triple], L: Collection[Any], triple_weights: dict[Triple, int | float] | None = None, return_root: bool = False) -> Tree | TreeNode
¶
Greedy heuristic for triple consistency.
Add triples one by one and checks consistency via BUILD.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
R
|
Iterable[Triple]
|
An iterable of triples. |
required |
L
|
Collection[Any]
|
A collection of leaf labels. |
required |
triple_weights
|
dict[Triple, int | float] | None
|
Weights for the triples; default is None in which case all triples are uniformly weighted. |
None
|
return_root
|
bool
|
If True, return 'TreeNode' instead of 'Tree' instance. |
False
|
Returns:
| Type | Description |
|---|---|
Tree | TreeNode
|
The constructed tree. |
Source code in tralda/supertree/build.py
best_pair_merge_first(R: Iterable[Triple], L: Collection[Any], triple_weights: dict[Triple, int | float] | None = None, return_root: bool = False) -> Tree | TreeNode
¶
Wu's (2004) Best-Pair-Merge-First (BPMF) heuristic.
Modified version by Byrka et al. (2010) and added weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
R
|
Iterable[Triple]
|
An iterable of triples. |
required |
L
|
Collection[Any]
|
A collection of leaf labels. |
required |
triple_weights
|
dict[Triple, int | float] | None
|
Weights for the triples; default is None in which case all triples are uniformly weighted. |
None
|
return_root
|
bool
|
If True, return 'TreeNode' instead of 'Tree' instance. |
False
|
Returns:
| Type | Description |
|---|---|
Tree | TreeNode
|
The constructed tree. |
Source code in tralda/supertree/build.py
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 | |
BuildST Algorithm¶
build_st(trees: Collection[Tree]) -> Tree | None
¶
Supertree construction based on BuildST algorithm.
NOTE: The graph connecting to trees in the input set whenever they share at least one leaf label must be connected. Otherwise, the implementation returns None, even though a supertree may exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trees
|
Collection[Tree]
|
A collection of Tree instances. |
required |
Return
The constructed supertree if it exists; None otherwise.
References
- Yun Deng and David Fernández-Baca. Fast Compatibility Testing for Rooted Phylogenetic Trees. 27th Annual Symposium on Combinatorial Pattern Matching (CPM 2016). DOI: 10.4230/LIPIcs.CPM.2016.12
Source code in tralda/supertree/build_st.py
BuildST
¶
BuildST algorithm.
NOTE: The graph connecting to trees in the input set whenever they share at least one leaf label must be connected. Otherwise, the implementation returns None, even though a supertree may exist.
References
- Yun Deng and David Fernández-Baca. Fast Compatibility Testing for Rooted Phylogenetic Trees. 27th Annual Symposium on Combinatorial Pattern Matching (CPM 2016). DOI: 10.4230/LIPIcs.CPM.2016.12
Source code in tralda/supertree/build_st.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 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 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
__init__(trees: Collection[Tree]) -> None
¶
Constructor for BuildST algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trees
|
Collection[Tree]
|
A collection of Tree instances. |
required |
Source code in tralda/supertree/build_st.py
run() -> Tree | None
¶
Build the supertree from the given tree list if existent.
Returns:
| Type | Description |
|---|---|
Tree | None
|
The constructed supertree if it exits; None otherwise. |
Source code in tralda/supertree/build_st.py
Common Refinement¶
linear_common_refinement(trees: Collection[Tree]) -> Tree | None
¶
Minimal common refinement for a set of trees with the same leaf set.
All input trees must be phylogenetic and have the same set of leaf labels. In each tree, the leaves' label attributes must be set and unique.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trees
|
Collection[Tree]
|
A collection of of Tree instances. |
required |
Returns:
| Type | Description |
|---|---|
Tree | None
|
A common refinement of the input trees if existent, None otherwise. |
References
- D. Schaller, M. Hellmuth, P.F. Stadler (2021). A simpler linear-time algorithm for the common refinement of rooted phylogenetic trees on a common leaf set. Algorithms Mol Biol. 16(1):23. DOI: 10.1186/s13015-021-00202-8.
Source code in tralda/supertree/common_refinement.py
LinCR
¶
Minimal common refinement for a set of trees with the same leaf set in linear time.
References
- D. Schaller, M. Hellmuth, P.F. Stadler (2021). A simpler linear-time algorithm for the common refinement of rooted phylogenetic trees on a common leaf set. Algorithms Mol Biol. 16(1):23. DOI: 10.1186/s13015-021-00202-8.
Source code in tralda/supertree/common_refinement.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
__init__(trees: Collection[Tree]) -> None
¶
Constructor of the LinCR class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trees
|
Collection[Tree]
|
A collection of of Tree instances. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the trees do not have the same leaf labels. |
Source code in tralda/supertree/common_refinement.py
run() -> Tree | None
¶
Run the the algorithm for constructing the minimal common refinement.
Returns:
| Type | Description |
|---|---|
Tree | None
|
The minimal common refinement if it exits; None otherwise. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the method was already called for this instance. |
Source code in tralda/supertree/common_refinement.py
Consensus Tree¶
loose_consensus_tree(trees: Collection[Tree]) -> Tree | None
¶
Compute the loose consensus tree for trees with the same leaf set.
All input trees must be phylogenetic and have the same set of leaf labels. In each tree, the leaves' label attributes must be set and unique.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trees
|
Collection[Tree]
|
A collection of of Tree instances. |
required |
Returns:
| Type | Description |
|---|---|
Tree | None
|
The loose consensus tree; None if 'trees' is empty. |
References
- J. Jansson, C. Shen, W.-K. Sung. Improved Algorithms for Constructing Consensus Trees. J. ACM 63, 3, Article 28 (June 2016), 24 pages. DOI: 10.1145/2925985.
Source code in tralda/supertree/consensus.py
LooseConsensusTree
¶
Construction of the loose consensus tree.
References
- J. Jansson, C. Shen, W.-K. Sung. Improved Algorithms for Constructing Consensus Trees. J. ACM 63, 3, Article 28 (June 2016), 24 pages. DOI: 10.1145/2925985.
Source code in tralda/supertree/consensus.py
__init__(trees: Collection[Tree]) -> None
¶
summary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trees
|
Collection[Tree]
|
A collection of of Tree instances. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the trees do not have the same leaf labels. |
Source code in tralda/supertree/consensus.py
run() -> Tree | None
¶
Run the construction of the loose consensus tree.
Returns:
| Type | Description |
|---|---|
Tree | None
|
The loose consensus tree; None if the collection of trees is empty. |
Source code in tralda/supertree/consensus.py
merge_all(trees: Collection[Tree]) -> Tree | None
¶
Common refinement for compatible trees with the same leaf set.
All input trees must be phylogenetic and have the same set of leaf labels. In each tree, the leaves' label attributes must be set and unique.
WARNING: The behavior of the function is undefined if the trees are not compatible, i.e., if no common refinement exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trees
|
Collection[Tree]
|
A collection of of Tree instances. |
required |
Returns:
| Type | Description |
|---|---|
Tree | None
|
A common refinement of the input trees; None if 'trees' is empty. |