treeevolve¶
Simulation of species and gene trees.
species
¶
Simulation of dated species trees.
species_tree_n(n: int, model: str = 'yule', innovation: bool = False, planted: bool = True, remove_extinct: bool = False, birth_rate: float | None = None, death_rate: float | None = None, episodes: list[EpisodeType] | None = None, contraction_probability: float = 0.0, contraction_proportion: float = 0.0, contraction_bias: str | None = None, bias_strength: float = 1.0, **kwargs: object) -> Tree
¶
Simulates a species tree S with n leaves.
The tree is sampled under the Yule, BDP, or EBDP model conditioned on the number n of surviving species [1, 2, 3].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of leaves in the resulting tree that correspond to extant species. |
required |
model
|
str
|
Simulation model to be applied, the default is 'yule', see [1]. Other available models are birth-death process ('BDP', [2]), and episodic birth-death process ('EBDP', [3]). |
'yule'
|
innovation
|
bool
|
If True, use the innovation model, see [4], to sample a lineage for the next speciation event. Only available for the Yule model. The default is False, in which case the lineage is chosen uniformly at random among the currently existing lineages. The innovation model is not available for the BDP and EBDP models. |
False
|
planted
|
bool
|
Add a planted root that has the canonical root as its single neighbor. |
True
|
remove_extinct
|
bool
|
Remove all branches that lead to extinctions, only relevant for some models. |
False
|
birth_rate
|
float | None
|
The birth rate for models such as 'yule' and 'BDP'. The default is None, in which case the birth rate is set to 1.0 unless episodes are specified. |
None
|
death_rate
|
float | None
|
The death rate for models such as 'BDP'. The default is None, in which case the death rate is set to 0.0 unless episodes are specified. |
None
|
episodes
|
list[EpisodeType] | None
|
The episodes for the model 'EBDP'. |
None
|
contraction_probability
|
float
|
Probability that an inner edge is contracted. The default is 0.0, in which case the tree is binary. Only one of this parameter and 'contraction_proportion' may be non-zero. |
0.0
|
contraction_proportion
|
float
|
The proportion of inner edges to be contracted. The default is 0.0, in which case the tree is binary. Only one of this parameter and 'contraction_probability' may be non-zero. |
0.0
|
contraction_bias
|
str | None
|
Specifies whether shorter edges, i.e., with a smaller difference t of the time stamps, have a higher probability to be contracted. Only relevant if 'contraction_proportion' > 0.0. The default is None, in which case all edges have the same probability to be contracted. The options 'inverse' and 'exponential' mean that an edge is sampled weighted by 1/t or e^(-t), respectively. |
None
|
bias_strength
|
float
|
Intensity factor for preferring shorter edges to be contracted. The default is 1.0. |
1.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If unknown or invalid parameter values are passed. |
ValueError
|
If the innovation model is selected for a model that does not support it. |
Returns:
| Type | Description |
|---|---|
Tree
|
The simulated species tree. |
References
- G. U. Yule. A mathematical theory of evolution, based on the conclusions of Dr. J. C. Willis, F. R. S. In: Phil. Trans. R. Soc. Lond. B, 1924, 213, 21-87. doi:10.1098/rstb.1925.0002.
- D. G. Kendall. On the Generalized "Birth-and-Death" Process. In: Ann. Math. Statist. 1948, 19, 1-15. doi:10.1214/aoms/1177730285.
- T. Stadler. Simulating trees with a fixed number of extant species. In: Syst. Biol. 2011, 60, 676-684. doi:10.1093/sysbio/syr029.
- S. Keller-Schmidt, K. Klemm. A model of macroevolution as a branching process based on innovations. In: Adv. Complex Syst.,2012, 15, 1250043. doi:10.1142/S0219525912500439.
Source code in asymmetree/treeevolve/species.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 | |
species_tree_age(age: float, model: str = 'yule', innovation: bool = False, birth_rate: float | None = None, death_rate: float | None = None, episodes: list[EpisodeType] | None = None, contraction_probability: float = 0.0, contraction_proportion: float = 0.0, contraction_bias: str | None = None, bias_strength: float = 1.0, **kwargs: object) -> Tree
¶
Simulates a (planted) species tree S of the specified age.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
age
|
float
|
Simulation time, i.e., the time span from the root of the tree to the leaves that correspond to extant species. |
required |
model
|
str
|
Simulation model to be applied, the default is 'yule', see [1]. Other available models are birth-death process ('BDP', [2]), and episodic birth-death process ('EBDP', [3]). |
'yule'
|
innovation
|
bool
|
If True, use the innovation model, see [4], to sample a lineage for the next speciation event. The default is False, in which case the lineage is chosen uniformly at random among the currently existing lineages. |
False
|
birth_rate
|
float | None
|
The birth rate for models such as 'yule' and 'BDP'. The default is None, in which case the birth rate is set to 1.0 unless episodes are specified. |
None
|
death_rate
|
float | None
|
The death rate for models such as 'BDP'. The default is None, in which case the death rate is set to 0.0 unless episodes are specified. |
None
|
episodes
|
list[EpisodeType] | None
|
The episodes for the model 'EBDP'. |
None
|
contraction_probability
|
float
|
Probability that an inner edge is contracted. The default is 0.0, in which case the tree is binary. Only one of this parameter and 'contraction_proportion' may be non-zero. |
0.0
|
contraction_proportion
|
float
|
The proportion of inner edges to be contracted. The default is 0.0, in which case the tree is binary. Only one of this parameter and 'contraction_probability' may be non-zero. |
0.0
|
contraction_bias
|
str | None
|
Specifies whether shorter edges, i.e., with a smaller difference t of the time stamps, have a higher probability to be contracted. Only relevant if 'contraction_proportion' > 0.0. The default is None, in which case all edges have the same probability to be contracted. The options 'inverse' and 'exponential' mean that an edge is sampled weighted by 1/(a * t) or e^(-a * t), respectively, where a is a user-defined factor. |
None
|
bias_strength
|
float
|
Intensity factor for preferring shorter edges to be contracted. The default is 1.0. |
1.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If unknown or invalid parameter values are passed. |
Returns:
| Type | Description |
|---|---|
Tree
|
The simulated species tree. |
References
- G. U. Yule. A mathematical theory of evolution, based on the conclusions of Dr. J. C. Willis, F. R. S. In: Phil. Trans. R. Soc. Lond. B, 1924, 213, 21-87. doi:10.1098/rstb.1925.0002.
- D. G. Kendall. On the Generalized "Birth-and-Death" Process. In: Ann. Math. Statist. 1948, 19, 1-15. doi:10.1214/aoms/1177730285.
- T. Stadler. Simulating trees with a fixed number of extant species. In: Syst. Biol. 2011, 60, 676-684. doi:10.1093/sysbio/syr029.
- S. Keller-Schmidt, K. Klemm. A model of macroevolution as a branching process based on innovations. In: Adv. Complex Syst.,2012, 15, 1250043. doi:10.1142/S0219525912500439.
Source code in asymmetree/treeevolve/species.py
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 | |
species_tree_n_age(n: int, age: float, model: str = 'yule', innovation: bool = False, birth_rate: float | None = None, death_rate: float | None = None, contraction_probability: float = 0.0, contraction_proportion: float = 0.0, contraction_bias: str | None = None, bias_strength: float = 1.0, **kwargs: object) -> Tree
¶
Simulate a (planted) species tree S with n leaves and of the specified age.
The tree is sampled under the Yule or BDP model conditioned on the number n of surviving species and with a given age [1]. The resulting tree does not contain loss leaves even if the specified death rate is > 0 as a consequence of the tree sampling method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of leaves in the resulting tree that correspond to extant species. |
required |
age
|
float
|
Simulation time, i.e., the time span from the root of the tree to the leaves that correspond to extant species. |
required |
model
|
str
|
Simulation model to be applied, the default is 'yule', see [2]. Alternatively the birth-death process ('BDP', [3]) is available. |
'yule'
|
innovation
|
bool
|
If True, use the innovation model, see [4], to sample a lineage for the next speciation event. The default is False, in which case the lineage is chosen uniformly at random among the currently existing lineages. |
False
|
birth_rate
|
float | None
|
The birth rate for models such as 'yule' and 'BDP'. The default is None, in which case the birth rate is set to 1.0 unless episodes are specified. |
None
|
death_rate
|
float | None
|
The death rate for models such as 'BDP'. The default is None, in which case the death rate is set to 0.0 unless episodes are specified. |
None
|
contraction_probability
|
float
|
Probability that an inner edge is contracted. The default is 0.0, in which case the tree is binary. Only one of this parameter and 'contraction_proportion' may be non-zero. |
0.0
|
contraction_proportion
|
float
|
The proportion of inner edges to be contracted. The default is 0.0, in which case the tree is binary. Only one of this parameter and 'contraction_probability' may be non-zero. |
0.0
|
contraction_bias
|
str | None
|
Specifies whether shorter edges, i.e., with a smaller difference t of the time stamps, have a higher probability to be contracted. Only relevant if 'contraction_proportion' > 0.0. The default is None, in which case all edges have the same probability to be contracted. The options 'inverse' and 'exponential' mean that an edge is sampled weighted by 1/(a * t) or e^(-a * t), respectively, where a is a user-defined factor. |
None
|
bias_strength
|
float
|
Intensity factor for preferring shorter edges to be contracted. The default is 1.0. |
1.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If unknown or invalid parameter values are passed. |
Returns:
| Type | Description |
|---|---|
Tree
|
The simulated species tree. |
References
- G. U. Yule. A mathematical theory of evolution, based on the conclusions of Dr. J. C. Willis, F. R. S. In: Phil. Trans. R. Soc. Lond. B, 1924, 213, 21-87. doi:10.1098/rstb.1925.0002.
- D. G. Kendall. On the Generalized "Birth-and-Death" Process. In: Ann. Math. Statist. 1948, 19, 1-15. doi:10.1214/aoms/1177730285.
- T. Stadler. Simulating trees with a fixed number of extant species. In: Syst. Biol. 2011, 60, 676-684. doi:10.1093/sysbio/syr029.
- S. Keller-Schmidt, K. Klemm. A model of macroevolution as a branching process based on innovations. In: Adv. Complex Syst.,2012, 15, 1250043. doi:10.1142/S0219525912500439.
Source code in asymmetree/treeevolve/species.py
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 | |
nonbinary(tree: Tree, contraction_probability: float = 0.0, contraction_proportion: float = 0.0, contraction_bias: str | None = None, bias_strength: float = 1.0, inplace: bool = False) -> Tree
¶
Introduce multifurcation into a tree by contraction of inner edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
Tree
|
The tree whose edges shall be contracted. |
required |
contraction_probability
|
float
|
Probability that an inner edge is contracted; results in non-binary tree; default is 0.0. Only one of this parameter and 'contraction_proportion' may be non-zero. |
0.0
|
contraction_proportion
|
float
|
The proportion of inner edges to be contracted; results in non-binary tree; default is 0.0. Only one of this parameter and 'contraction_probability' may be non-zero. |
0.0
|
contraction_bias
|
str | None
|
Specifies whether shorter edges, i.e., with a smaller difference t of the time stamps, have a higher probability to be contracted. Only relevant if 'contraction_proportion' > 0.0. The default is None, in which case all edges have the same probability to be contracted. The options 'inverse' and 'exponential' mean that an edge is sampled weighted by 1/(a * t) or e^(-a * t), respectively, where a is a user-defined factor. |
None
|
bias_strength
|
float
|
Intensity factor for preferring shorter edges to be contracted. |
1.0
|
inplace
|
bool
|
If True, the edges are contracted in the original tree instance; otherwise a copy of the tree in which edges are contracted is returned. |
False
|
Returns:
| Type | Description |
|---|---|
Tree
|
The tree whose edges have been contracted according to the parameters. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both contraction_probability and contraction_proportion are non-zero or do not lie in the interval [0, 1]. |
Source code in asymmetree/treeevolve/species.py
rescale(tree: Tree, height: float, inplace: bool = True) -> Tree
¶
Rescale the time stamps of a tree.
The time stamps of all vertices are multiplied by a scaling factor such that the height of the tree is equal to the specified height. The height of the tree is defined as the time stamp of the root vertex.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
Tree
|
The tree whose time stamps shall be rescaled. |
required |
height
|
float
|
The new height of the tree. |
required |
inplace
|
bool
|
If True, the time stamps are rescaled in the original tree instance; otherwise a copy of the tree with rescaled time stamps is returned. |
True
|
Returns:
| Type | Description |
|---|---|
Tree
|
The tree with rescaled time stamps. |
Source code in asymmetree/treeevolve/species.py
assign_losses(tree: Tree, proportion: float) -> None
¶
Randomly assigns a specified proportion of leaves as losses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
Tree
|
The tree whose leaves shall be assigned as losses. |
required |
proportion
|
float
|
The proportion of leaves to be assigned as losses. |
required |
Source code in asymmetree/treeevolve/species.py
genes
¶
Simulation of dated gene trees.
This module contains the class GeneTreeSimulator for simulating dated gene trees along a given dated species tree. The simulation is based on a birth-death process with speciations as additional branching events, and allows for the simulation of gene duplications, losses, horizontal gene transfers, and gene conversions. A pruning function is provided to remove all branches that lead to losses only, and to suppress superfluous vertices.
GeneTreeSimulator
¶
Class for simulating dated gene trees along a given dated species tree.
Source code in asymmetree/treeevolve/genes.py
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 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 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 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 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 | |
__init__(S: Tree) -> None
¶
Initialize the gene tree simulator with a given dated species tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
S
|
Tree
|
A dated species tree with a non-empty root. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If S is not a non-empty tree of type 'Tree'. |
Source code in asymmetree/treeevolve/genes.py
simulate(dupl_rate: float = 0.0, loss_rate: float = 0.0, hgt_rate: float = 0.0, gc_rate: float = 0.0, dupl_polytomy: float = 0.0, prohibit_extinction: str | bool = 'per_species', replace_prob: float = 0.0, additive_transfer_distance_bias: str | None = None, replacing_transfer_distance_bias: str | None = None, transfer_distance_bias: str | None = None, transfer_distance_bias_strength: float = 1.0, gc_distance_bias: str | None = None, gc_distance_bias_strength: float = 1.0, **kwargs) -> Tree
¶
Simulate a gene tree along the specified species tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dupl_rate
|
float
|
Duplication rate, default is 0.0. |
0.0
|
loss_rate
|
float
|
Loss rate, default is 0.0. |
0.0
|
hgt_rate
|
float
|
Horizontal gene transfer rate, default is 0.0. |
0.0
|
gc_rate
|
float
|
Gene conversion rate, default is 0.0. |
0.0
|
dupl_polytomy
|
float
|
Allows non-binary duplication events by specifying the lambda parameter for a poisson distribution (copy number = drawn number + 2); default is 0.0. |
0.0
|
prohibit_extinction
|
str | bool
|
Avoid the extinction of all members in any species ('per_species'), of the complete gene family ('per_family'), or no constraints (False); default is 'per_species'. |
'per_species'
|
replace_prob
|
float
|
Enables replacing HGT events, probability by which one random homolog in the receiving branch of the receiving branch gets lost immediately after the transfer. The default is 0.0, in which case all HGT events are additive. |
0.0
|
additive_transfer_distance_bias
|
str | None
|
Specifies whether closer related species have a higher probability to be the recipient species in an additive HGT event. The default is None, in which case the recipient species is chosen at random among the co-existing species. The options 'inverse' and 'exponential' mean that a species branch is sampled weighted by 1/(a * t) or e^(-(a * t)), resp., where t is the elapsed time between the last common ancestor of the two species branches and the time of the event, see [1], and a is a user-defined factor. |
None
|
replacing_transfer_distance_bias
|
str | None
|
Specifies whether closer related gene branches have a higher probability to be replaced in a replacing HGT event. The default is None, in which case the replaced gene is chosen at random among the co-existing gene branches. The options 'inverse' and 'exponential' mean that a gene branch is sampled weighted by 1/(a * t) or e^(-(a * t)), resp., where t is the elapsed time between the last common ancestor of the two gene branches and the time of the event, see [1], and a is a user-defined factor. |
None
|
transfer_distance_bias
|
str | None
|
Set a common bias mode for additive and replacing HGT, see description of parameters 'additive_transfer_distance_bias' and 'replacing_transfer_distance_bias'. This parameter is used if the bias mode shall be the same for both types of HGT and the respective parameters are not set, and overrides the default bias mode for replacing HGT. |
None
|
transfer_distance_bias_strength
|
float
|
Intensity of the transfer distance bias (factor a) for additive and replacing HGT, default is 1.0. |
1.0
|
gc_distance_bias
|
str | None
|
Specifies whether closer related gene branches have a higher probability to be replaced in a gene conversion event. The default is None, in which case the replaced gene is chosen at random among the paralogs in the respective species lineage. The options 'inverse' and 'exponential' mean that a paralog is sampled weighted by 1/(a * t) or e^(-(a * t)), resp., where t is the elapsed time between the last common ancestor of the two gene branches and the time of the event, see [1], and a is a user-defined factor. |
None
|
gc_distance_bias_strength
|
float
|
Intensity of the distance bias (factor a) for gene conversion, default is 1.0. |
1.0
|
Returns:
| Type | Description |
|---|---|
Tree
|
The simulated gene tree. |
References
- S. Kundu, M. S. Bansal. SaGePhy: an improved phylogenetic simulation framework for gene and subgene evolution. In: Bioinformatics, 35(18), 2019, 3496-3498. doi:10.1093/bioinformatics/btz081.
Source code in asymmetree/treeevolve/genes.py
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 | |
dated_gene_tree(S: Tree, **kwargs: object) -> Tree
¶
Simulate a gene tree along the specified species tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
S
|
Tree
|
A dated species tree of type 'Tree' with a non-empty root. |
required |
**kwargs
|
object
|
Keyword arguments passed to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Tree
|
The simulated gene tree. |
Source code in asymmetree/treeevolve/genes.py
prune_losses(tree: Tree) -> Tree
¶
Prune all loss branches.
Returns a copy of the tree with all branches that lead to losses only removed and superfluous vertices suppressed. Additionally, if the root of the tree has only a single child, then this 'planted edge' is also removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
Tree
|
The tree to be pruned. |
required |
Returns:
| Type | Description |
|---|---|
Tree
|
A pruned version of the tree. |
Source code in asymmetree/treeevolve/genes.py
observable_tree(tree: Tree) -> Tree
¶
Prune all loss branches (deprecated).
This method is deprecated. Use prune_losses() instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
Tree
|
The tree to be pruned. |
required |
Returns:
| Type | Description |
|---|---|
Tree
|
A pruned version of the tree. |
Source code in asymmetree/treeevolve/genes.py
rate_heterogeneity
¶
Evolution rate heterogeneity.
This module contains functions to introduce evolution rate asymmetries and autocorrelation. The main function is 'rate_heterogeneity()', which modifies the edge lengths of a gene tree according to three sources of heterogeneity: (i) gene-family-specific heterogeneity, (ii) species-specific heterogeneity, and (iii) paralog-specific heterogeneity. The function 'gene_trees()' can be used to simulate gene trees with rate heterogeneity along a species tree.
gene_trees(S: Tree, n: int = 1, dupl_rate: float | tuple = 0.0, loss_rate: float | tuple = 0.0, hgt_rate: float | tuple = 0.0, base_rate: float | tuple = 1.0, **kwargs: object) -> list[Tree]
¶
Simulates dated gene trees with non-ultrametric edge lengths along a species tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
S
|
Tree
|
The species tree along which the gene trees are simulated. |
required |
n
|
int
|
Number of gene trees to be simulated, default is 1, in which case a tree is returned, otherwise a list is returned. |
1
|
dupl_rate
|
float | tuple
|
The (distribution for the) duplication rate, see documentation for available option. The default is constant 0.0. |
0.0
|
loss_rate
|
float | tuple
|
The (distribution for the) loss rate, see documentation for available option. The default is constant 0.0. |
0.0
|
hgt_rate
|
float | tuple
|
The (distribution for the) HGT rate, see documentation for available option. The default is constant 0.0. |
0.0
|
base_rate
|
float | tuple
|
The (distribution for the) evolution rate at the roots of the gene trees, see documentation for available options. The default is constant 1.0. |
1.0
|
**kwargs
|
object
|
Keyword arguments passed to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
list[Tree]
|
A list of simulated gene tree. |
Source code in asymmetree/treeevolve/rate_heterogeneity.py
rate_heterogeneity(T: Tree, S: Tree, base_rate: float = 1.0, autocorr_factors: dict | None = None, autocorr_variance: float = 0.0, rate_increase: float | tuple = ('gamma', 0.5, 2.2), CSN_weights: tuple = (1, 1, 1), inplace: bool = True, **kwargs) -> Tree
¶
Introduces evolution rate heterogeneity into a gene tree.
The function applies rate multiplier for three sources of evolution rate heterogeneity: (i)
gene-family-specific heterogeneity is modeled through the base_rate parameter; (ii) for
species-specific heterogeneity an autocorrelated relaxed molecular clock model as in [1] is
used; and (iii) for paralog-specific heterogeneity it is chosen between the three modes
conservation, subfunctionalization, and neofunctionalization for the rates of the descendant
lineages of a duplication event. The assigned rates are used to modify the length ('dist'
attribute) of the edges of the (originally ultrametric) dated gene tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Tree
|
The gene tree. |
required |
S
|
Tree
|
The species tree. |
required |
base_rate
|
float
|
Mean of substitution rate for conserved genes. |
1.0
|
autocorr_factors
|
dict | None
|
A dictionary containing autocorrelation rate factors for the edges of S (key = v.label for edge (v.parent, v); value = the rate as a float). The default is None, in which case autocorrelation factors are generated if 'autocorr_variance' > 0.0, or no such modification is applied. See [1] for theoretical background. |
None
|
autocorr_variance
|
float
|
Autocorrelation variance factor for a lognormal distribution, only
considered if |
0.0
|
rate_increase
|
float | tuple
|
Distribution of the (relative) rate increase (w.r.t. the base rate) for divergent genes, i.e. to a factor 1 + x. The default is a Gamma distribution with shape 0.5 and scale 2.2, which was fitted to the data in [2]. |
('gamma', 0.5, 2.2)
|
CSN_weights
|
tuple
|
Weights for choice between conservation, subfunctionalization and neofunctionalization. The default is (1, 1, 1), i.e., all three modes are equally likely to be chosen at each duplication event. |
(1, 1, 1)
|
inplace
|
bool
|
If False, copy the tree before imbalancing. The default is True. |
True
|
Returns:
| Type | Description |
|---|---|
Tree
|
The original instance of the gene tree ( |
References
- H. Kishino, J. L. Thorne, and W. J. Bruno. Performance of a Divergence Time Estimation Method under a Probabilistic Model of Rate Evolution. In: Molecular Biology and Evolution, 18(3):352-361, March 2001. doi: 10.1093/oxfordjournals.molbev.a003811.
- K. P. Byrne and K. H. Wolfe. Consistent Patterns of Rate Asymmetry and Gene Loss Indicate Widespread Neofunctionalization of Yeast Genes After Whole-Genome Duplication. In: Genetics, 175(3):1341-1350, March 2007. doi: 10.1534/genetics.106.066951.
Source code in asymmetree/treeevolve/rate_heterogeneity.py
assign_rates(T: Tree, S: Tree, **kwargs: object) -> Tree
¶
Deprecated alias for rate_heterogeneity().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Tree
|
The gene tree. |
required |
S
|
Tree
|
The species tree. |
required |
**kwargs
|
object
|
Keyword arguments passed to :func: |
{}
|
Returns:
| Type | Description |
|---|---|
Tree
|
The original instance of the gene tree with modified |
Source code in asymmetree/treeevolve/rate_heterogeneity.py
autocorrelation_factors(tree: Tree, variance: float) -> tuple[dict, dict]
¶
Lognormal model to assign rate factors to a species tree.
The parameter variance is a hyperparameter for a log-normal distribution from which offspring
rates are drawn. The overall variance of this distribution is variance * divergence time.
The rates are first computed for the nodes, the rates of the edges are assigned afterwards as
the arithmetic mean of the rates of the two incident nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
Tree
|
The species tree. |
required |
variance
|
float
|
The hyperparameter for a log-normal distribution from which offspring rates are drawn at each node. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A |
dict
|
A |
References
- H. Kishino, J. L. Thorne, and W. J. Bruno. Performance of a Divergence Time Estimation Method under a Probabilistic Model of Rate Evolution. In: Molecular Biology and Evolution, 18(3):352-361, March 2001. doi: 10.1093/oxfordjournals.molbev.a003811.
Source code in asymmetree/treeevolve/rate_heterogeneity.py
distance_noise
¶
Simulation of noisy distance matrices.
Distances derived from (real-life) gene or protein sequences are burdened with noise. Such data can either be modeled by simulating sequences, or by disturbing the distances specified by a given tree directly. This module implements functions for the latter alternative.
noisy_matrix(orig_matrix: np.ndarray, sd: float, metric_repair: str = 'reject') -> np.ndarray
¶
Disturb a distance matrix (which must be a metric) with random noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orig_matrix
|
ndarray
|
The 2-dimensional distance matrix. |
required |
sd
|
float
|
Disturbance parameter. Serves as standard deviation of a normal distrubition with mean 1.0. |
required |
metric_repair
|
str
|
Strategy to ensure that the resulting matrix is still a metric and, in particular, satisfies the triangle inequality. The default is 'reject', see [1]. Other available options are 'general' and 'DOMR', see [2]. |
'reject'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The disturbed distance matrix. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the argument 'metric_repair' is not one of 'reject', 'general', or 'DOMR'. |
References
- P. F. Stadler, M. Geiß, D. Schaller, A. López Sánchez, M. González Laffitte, D. Valdivia, M. Hellmuth, M. Hernández Rosales. From pairs of most similar sequences to phylogenetic best matches. In: Alg. Mol. Biol., 2020, 15, 5. doi: 10.1186/s13015-020-00165-2.
- A. C. Gilbert, L. Jain. If it ain't broke, don't fix it: Sparse metric repair. In: 2017 55th Annual Allerton Conference on Communication, Control, and Computing (Allerton), pages 612-619, Monticello, IL, USA, October 2017. IEEE. ISBN 978-1-5386-3266-6. doi: 10.1109/ALLERTON.2017.8262793.
Source code in asymmetree/treeevolve/distance_noise.py
convex_linear_comb(D1: np.ndarray, D2: np.ndarray, alpha: float = 0.05, first_only: bool = False) -> np.ndarray | tuple[np.ndarray, np.ndarray]
¶
Convex linear combination of distance matrices.
Returns the convex linear combinations of two distance matrices D1' = (1-alpha) * D1 + alpha * D2 D2' = (1-alpha) * D2 + alpha * D1
The motivation for this function is to simulate non-random noise from a wrong topology, which can be used to test the robustness of tree reconstruction methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
D1
|
ndarray
|
The first distance matrix. |
required |
D2
|
ndarray
|
The second distance matrix. |
required |
alpha
|
float
|
Disturbance parameter, the default is 0.05. |
0.05
|
first_only
|
bool
|
If True, only return the disturbed first matrix. |
False
|
Returns:
| Type | Description |
|---|---|
ndarray | tuple[ndarray, ndarray]
|
The disturbed distance matrix or matrices as a convex linear combination of the input
matrices. If |
References
- P. F. Stadler, M. Geiß, D. Schaller, A. López Sánchez, M. González Laffitte, D. Valdivia, M. Hellmuth, M. Hernández Rosales. From pairs of most similar sequences to phylogenetic best matches. In: Alg. Mol. Biol., 2020, 15, 5. doi: 10.1186/s13015-020-00165-2.
Source code in asymmetree/treeevolve/distance_noise.py
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 | |
wrong_topology_matrix(PGT: Tree) -> np.ndarray
¶
Return a wrong topology matrix by rearranging the edges of a binary tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
PGT
|
Tree
|
The input binary tree, which is typically a pruned gene tree (PGT). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The distance matrix of the wrong topology. |
Source code in asymmetree/treeevolve/distance_noise.py
check_metric(matrix: np.ndarray, verbose: bool = False) -> bool
¶
Check whether a given matrix is a metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
ndarray
|
The distance matrix to check. |
required |
verbose
|
bool
|
If True, print the reason for failure if the matrix is not a metric. |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the matrix is a metric, False otherwise. |