API Reference
Library usage not recommended
I recommend using TACT mainly via its console commands for stability and best results. To get started, see the Tutorial.
While TACT can be used as a Python library, its internal interface is subject to change at any time, even for minor or patch versions. This API documentation is provided merely for the sake of completeness.
Numerical functions
Functions in tact/lib.py.
Functions to handle various numerical operations, including optimization.
crown_capture_probability(n: int, k: int) -> float
Calculate probability of observing the crown node in an incomplete sample.
Probability that a random sample of k taxa from a clade of n total taxa
includes the crown (root) node, under a Yule process.
Reference: Sanderson (1996), Systematic Biology 45:168-173.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Total number of taxa in the clade. |
required |
k
|
int
|
Number of sampled taxa. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Probability of crown node inclusion. |
Raises:
| Type | Description |
|---|---|
Exception
|
If |
Source code in tact/lib.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
get_bd(r: float, a: float) -> tuple[float, float]
Convert turnover and relative extinction to birth and death rates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
float
|
Turnover rate (net diversification, birth - death). |
required |
a
|
float
|
Relative extinction rate (death / birth). |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (birth rate, death rate). |
Source code in tact/lib.py
17 18 19 20 21 22 23 24 25 26 27 | |
get_new_times(ages: list[float], birth: float, death: float, missing: int, told: float | None = None, tyoung: float | None = None) -> list[float]
Simulate new speciation event times in an incomplete phylogeny.
Simulates missing speciation events under a constant-rate birth-death process.
Adapted from TreeSim::corsim by Tanja Stadler. Reference: Cusimano et al.
(2012), Systematic Biology 61(5):785-792.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ages
|
list[float]
|
List of existing waiting times (will be sorted in place). |
required |
birth
|
float
|
Birth rate. |
required |
death
|
float
|
Death rate. |
required |
missing
|
int
|
Number of missing taxa to simulate. |
required |
told
|
float | None
|
Maximum simulated age. Defaults to |
None
|
tyoung
|
float | None
|
Minimum simulated age. Defaults to 0. |
None
|
Returns:
| Type | Description |
|---|---|
list[float]
|
List of simulated waiting times, sorted in descending order. |
Raises:
| Type | Description |
|---|---|
Exception
|
If zero or negative branch lengths are detected. |
Source code in tact/lib.py
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 | |
get_ra(b: float, d: float) -> tuple[float, float]
Convert birth and death rates to turnover and relative extinction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b
|
float
|
Birth rate. |
required |
d
|
float
|
Death rate. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (turnover rate, relative extinction rate). |
Source code in tact/lib.py
30 31 32 33 34 35 36 37 38 39 40 | |
intp1(t: float, l: float, m: float) -> float
Compute integration constant for sampling missing speciation event times.
This is a portion of the cdf used to perform inverse-transform sampling of missing speciation event times
under a constant-rate birth-death model. It is the c_2 term from equation A.2 in Cusimano et al. (2012),
Systematic Biology 61(5):785-792. Originally implemented as TreeSim:::intp1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Time before present. |
required |
l
|
float
|
Birth rate (lambda). |
required |
m
|
float
|
Death rate (mu). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Integration constant value. |
Source code in tact/lib.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
intp1_exact(t: float, l: float, m: float) -> D
Compute intp1 using exact Decimal arithmetic.
Used as fallback when floating-point arithmetic fails due to overflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Time before present. |
required |
l
|
float
|
Birth rate (lambda). |
required |
m
|
float
|
Death rate (mu). |
required |
Returns:
| Type | Description |
|---|---|
Decimal
|
Integration constant as a Decimal. |
Source code in tact/lib.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
lik_constant(vec: tuple[float, float], rho: float, t: list[float], root: int = 1, survival: int = 1, p1: Callable[[float, float, float, float], float] = p1) -> float
Calculate likelihood of a constant-rate birth-death process.
Likelihood conditioned on waiting times and incomplete sampling. Based on
TreePar::LikConstant by Tanja Stadler. Reference: Stadler (2009), Journal
of Theoretical Biology 261:58-66.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vec
|
tuple[float, float]
|
Tuple of (birth rate, death rate). |
required |
rho
|
float
|
Sampling fraction. |
required |
t
|
list[float]
|
List of waiting times (will be sorted in place). |
required |
root
|
int
|
Include root contribution (1) or not (0). Default: 1. |
1
|
survival
|
int
|
Assume process survival (1) or not (0). Default: 1. |
1
|
p1
|
Callable[[float, float, float, float], float]
|
Function to compute p1 probability (default: |
p1
|
Returns:
| Type | Description |
|---|---|
float
|
Negative log-likelihood value. |
Source code in tact/lib.py
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 | |
optim_bd(ages: list[float], sampling: float, min_bound: float = 1e-09) -> tuple[float, float]
Optimize birth and death rates from node ages under a birth-death model.
Uses maximum likelihood estimation with the Magallon-Sanderson crown estimator for initial values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ages
|
list[float]
|
List of node ages (splitting times). |
required |
sampling
|
float
|
Sampling fraction in (0, 1]. |
required |
min_bound
|
float
|
Minimum allowed birth rate (default: 1e-9). |
1e-09
|
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (optimized birth rate, optimized death rate). |
Source code in tact/lib.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
optim_yule(ages: list[float], sampling: float, min_bound: float = 1e-09) -> tuple[float, float]
Optimize birth rate under a Yule (pure birth) model.
Assumes zero extinction rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ages
|
list[float]
|
List of node ages (splitting times). |
required |
sampling
|
float
|
Sampling fraction in (0, 1]. |
required |
min_bound
|
float
|
Minimum allowed birth rate (default: 1e-9). |
1e-09
|
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (optimized birth rate, 0.0). |
Raises:
| Type | Description |
|---|---|
Exception
|
If optimization fails. |
Source code in tact/lib.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
p0(t: float, l: float, m: float, rho: float) -> float
Compute the probability of no sampled descendants.
Probability that an individual alive at time t before present has no sampled
descendants (extant or extinct), assuming no past sampling. Falls back to
exact Decimal arithmetic if floating-point overflow occurs.
Reference: Stadler (2010), Journal of Theoretical Biology 267(3):396-404,
remark 3.2. Originally implemented as TreePar:::p0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Time before present. |
required |
l
|
float
|
Birth rate (lambda). |
required |
m
|
float
|
Death rate (mu). |
required |
rho
|
float
|
Sampling fraction. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Probability of no sampled descendants. |
Source code in tact/lib.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
p0_exact(t: float, l: float, m: float, rho: float) -> D
Compute p0 using exact Decimal arithmetic.
Used as fallback when floating-point arithmetic fails due to overflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Time before present. |
required |
l
|
float
|
Birth rate (lambda). |
required |
m
|
float
|
Death rate (mu). |
required |
rho
|
float
|
Sampling fraction. |
required |
Returns:
| Type | Description |
|---|---|
Decimal
|
Probability of no sampled descendants as a Decimal. |
Source code in tact/lib.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
p1(t: float, l: float, m: float, rho: float) -> float
Compute the probability of exactly one sampled descendant.
Probability that an individual alive at time t before present has precisely
one sampled extant descendant and no sampled extinct descendants, assuming
no past sampling. Optimized version using common subexpression elimination.
Reference: Stadler (2010), Journal of Theoretical Biology 267(3):396-404,
remark 3.2. Originally implemented as TreePar:::p1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Time before present. |
required |
l
|
float
|
Birth rate (lambda). |
required |
m
|
float
|
Death rate (mu). |
required |
rho
|
float
|
Sampling fraction. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Probability of exactly one sampled descendant. |
Source code in tact/lib.py
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 | |
p1_exact(t: float, l: float, m: float, rho: float) -> D
Compute p1 using exact Decimal arithmetic.
Used as fallback when floating-point arithmetic fails due to overflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Time before present. |
required |
l
|
float
|
Birth rate (lambda). |
required |
m
|
float
|
Death rate (mu). |
required |
rho
|
float
|
Sampling fraction. |
required |
Returns:
| Type | Description |
|---|---|
Decimal
|
Probability of exactly one sampled descendant as a Decimal. |
Source code in tact/lib.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
p1_orig(t: float, l: float, m: float, rho: float) -> float
Original implementation of p1 for testing and comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Time before present. |
required |
l
|
float
|
Birth rate (lambda). |
required |
m
|
float
|
Death rate (mu). |
required |
rho
|
float
|
Sampling fraction. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Probability of exactly one sampled descendant. |
Source code in tact/lib.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
two_step_optim(func: Callable[..., float], x0: tuple[float, ...], bounds: tuple[tuple[float, float], ...], args: tuple[Any, ...]) -> list[float]
Optimize a function using a two-step approach.
First attempts L-BFGS-B (fast gradient-based method), then falls back to simulated annealing if L-BFGS-B fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., float]
|
Objective function to minimize. |
required |
x0
|
tuple[float, ...]
|
Initial parameter values. |
required |
bounds
|
tuple[tuple[float, float], ...]
|
Parameter bounds as tuples of (min, max) for each parameter. |
required |
args
|
tuple[Any, ...]
|
Additional arguments to pass to the objective function. |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
Optimized parameter values as a list. |
Raises:
| Type | Description |
|---|---|
Exception
|
If both optimization methods fail. |
Source code in tact/lib.py
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 | |
wrapped_lik_constant(x: tuple[float, float], sampling: float, ages: list[float]) -> float
Wrapper for birth-death likelihood function for optimization.
Converts turnover and relative extinction parameters to birth/death rates before computing the likelihood.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
tuple[float, float]
|
Tuple of (turnover, relative extinction). |
required |
sampling
|
float
|
Sampling fraction in (0, 1]. |
required |
ages
|
list[float]
|
List of node ages. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Negative log-likelihood value. |
Source code in tact/lib.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
wrapped_lik_constant_yule(x: float, sampling: float, ages: list[float]) -> float
Wrapper for Yule model likelihood function for optimization.
Assumes zero extinction (pure birth process).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Birth rate. |
required |
sampling
|
float
|
Sampling fraction in (0, 1]. |
required |
ages
|
list[float]
|
List of node ages. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Negative log-likelihood value. |
Source code in tact/lib.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
Tree functions
Functions in tact/tree_util.py.
Functions specifically to handle DendroPy tree objects.
compute_node_depths(tree: dendropy.Tree) -> dict[str, int]
Compute node depths for all labeled nodes.
Depth is defined as the number of labeled ancestor nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
Tree
|
DendroPy tree object. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
Dictionary mapping tip labels to their node depths. |
Source code in tact/tree_util.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
count_locked(node: dendropy.Node) -> int
Count the number of locked edges in a subtree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
Node representing the root of the subtree. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of edges marked as locked. |
Source code in tact/tree_util.py
309 310 311 312 313 314 315 316 317 318 | |
edge_iter(node: dendropy.Node, filter_fn: Callable[[dendropy.Edge], bool] | None = None) -> dendropy.Edge
Iterate over edges in a subtree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
DendroPy node representing the root of the subtree. |
required |
filter_fn
|
Callable[[Edge], bool] | None
|
Optional function to filter edges. Default: None. |
None
|
Yields:
| Type | Description |
|---|---|
Edge
|
DendroPy edge objects in the subtree. |
Source code in tact/tree_util.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
get_age_intervals(node: dendropy.Node) -> portion.Interval
Get the age interval for possible grafts in a clade.
Computes the union of all age intervals from unlocked edges, which represents all possible ages where a graft could be placed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
Node representing the root of the clade. |
required |
Returns:
| Type | Description |
|---|---|
Interval
|
Portion interval (possibly disjoint) representing valid graft ages. |
Source code in tact/tree_util.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
get_ages(node: dendropy.Node, include_root: bool = False) -> list[float]
Get list of node ages in a subtree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
DendroPy node representing the root of the subtree. |
required |
include_root
|
bool
|
If True, include the root node's age. Default: False. |
False
|
Returns:
| Type | Description |
|---|---|
list[float]
|
List of node ages, sorted in descending order. |
Source code in tact/tree_util.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
get_birth_death_rates(node: dendropy.Node, sampfrac: float, yule: bool = False, include_root: bool = False) -> tuple[float, float]
Estimate birth-death rates from a subtree.
Computes maximum likelihood birth and death rates for the subtree descending from the given node, optionally using a Yule (pure birth) model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
DendroPy node representing the root of the subtree. |
required |
sampfrac
|
float
|
Sampling fraction in (0, 1]. |
required |
yule
|
bool
|
If True, use Yule model (zero extinction). Default: False. |
False
|
include_root
|
bool
|
If True, include root node age in calculations. Default: False. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (birth rate, death rate). |
Source code in tact/tree_util.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
get_min_age(node: dendropy.Node) -> float
Get the minimum possible age for a graft in a clade.
Computes the minimum age that could be generated by grafting into the clade, considering only unlocked edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
Node representing the root of the clade. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Minimum possible age (0.0 if interval is empty). |
Raises:
| Type | Description |
|---|---|
DisjointConstraintError
|
If the age interval is not atomic (disjoint). |
Source code in tact/tree_util.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
get_monophyletic_node(tree: dendropy.Tree, species: set[str]) -> dendropy.Node | None
Get the MRCA node if it forms a monophyletic group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
Tree
|
DendroPy tree object. |
required |
species
|
set[str]
|
Set of taxon labels to check for monophyly. |
required |
Returns:
| Type | Description |
|---|---|
Node | None
|
MRCA node if all its descendants are in the species set, None otherwise. |
Source code in tact/tree_util.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
get_short_branches(node: dendropy.Node) -> dendropy.Edge
Get edges with very short branch lengths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
DendroPy node representing the root of the subtree. |
required |
Yields:
| Type | Description |
|---|---|
Edge
|
DendroPy edge objects with length <= 0.001. |
Source code in tact/tree_util.py
176 177 178 179 180 181 182 183 184 185 186 187 | |
get_tip_labels(tree_or_node: dendropy.Tree | dendropy.Node) -> set[str]
Get set of tip labels for a tree or node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree_or_node
|
Tree | Node
|
DendroPy tree or node object. |
required |
Returns:
| Type | Description |
|---|---|
set[str]
|
Set of taxon labels for all tips. |
Source code in tact/tree_util.py
70 71 72 73 74 75 76 77 78 79 80 81 82 | |
get_tree(path: str, namespace: dendropy.TaxonNamespace | None = None) -> dendropy.Tree
Load a DendroPy tree from a file path.
Loads a Newick-format tree and precalculates node ages and bipartition bitmasks for efficient operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
File path to the tree file. |
required |
namespace
|
TaxonNamespace | None
|
Optional taxon namespace to use. Default: None. |
None
|
Returns:
| Type | Description |
|---|---|
Tree
|
DendroPy tree object with ages and bipartitions calculated. |
Source code in tact/tree_util.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
graft_node(graft_recipient: dendropy.Node, graft: dendropy.Node, stem: bool = False) -> dendropy.Node
Graft a node randomly into a subtree.
Grafts a node into the subtree below the recipient node, randomly selecting an eligible edge. The graft node's age must be set. Edge lengths are adjusted to maintain ultrametricity.
The eligible edge (above which the graft is placed) must satisfy: 1. Not be the crown node 2. Head node younger than graft node 3. Tail node older than graft node 4. Not be locked
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graft_recipient
|
Node
|
Node representing the clade to graft into. |
required |
graft
|
Node
|
Node to graft (must have age attribute set). |
required |
stem
|
bool
|
If True, allow grafting on the stem edge. Default: False. |
False
|
Returns:
| Type | Description |
|---|---|
Node
|
The crown node of the clade (may be the graft if it becomes the new crown). |
Raises:
| Type | Description |
|---|---|
Exception
|
If no eligible edge is found or negative branch lengths result. |
Source code in tact/tree_util.py
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 | |
is_binary(node: dendropy.Node) -> bool
Check if a subtree is fully bifurcating.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
DendroPy node representing the root of the subtree. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if all internal nodes have exactly two children, False otherwise. |
Source code in tact/tree_util.py
138 139 140 141 142 143 144 145 146 147 148 149 150 | |
is_fully_locked(node: dendropy.Node) -> bool
Check if all edges in a subtree are locked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
Node representing the root of the subtree. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if all edges are locked, False otherwise. |
Source code in tact/tree_util.py
321 322 323 324 325 326 327 328 329 330 | |
is_ultrametric(tree: dendropy.Tree, tolerance: float = 1e-06) -> tuple[bool, tuple[tuple[str, float], tuple[str, float]]]
Check if a tree is ultrametric within a specified tolerance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
Tree
|
DendroPy tree object to check. |
required |
tolerance
|
float
|
Relative tolerance for ultrametricity check. Default: 1e-6. |
1e-06
|
Returns:
| Type | Description |
|---|---|
bool
|
Tuple of (is_ultrametric, (min_tip, max_tip)) where min_tip and max_tip |
tuple[tuple[str, float], tuple[str, float]]
|
are tuples of (label, root_distance) for the tips with minimum and |
tuple[bool, tuple[tuple[str, float], tuple[str, float]]]
|
maximum root-to-tip distances. |
Source code in tact/tree_util.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
lock_clade(node: dendropy.Node, stem: bool = False) -> None
Lock a clade to prevent future grafts.
Marks all edges in the subtree as locked, preventing new grafts from being placed on them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
Node representing the root of the clade to lock. |
required |
stem
|
bool
|
If True, also lock the stem edge. Default: False. |
False
|
Source code in tact/tree_util.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
unlock_clade(node: dendropy.Node, stem: bool = False) -> None
Unlock a clade to allow future grafts.
Removes the locked label from all edges in the subtree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
Node representing the root of the clade to unlock. |
required |
stem
|
bool
|
If True, also unlock the stem edge. Default: False. |
False
|
Source code in tact/tree_util.py
294 295 296 297 298 299 300 301 302 303 304 305 306 | |
update_tree_view(tree: dendropy.Tree) -> set[str]
Update a tree with node ages and bipartition bitmasks.
Performs in-place updates to calculate node ages and bipartition bitmasks, correcting for minor ultrametricity errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
Tree
|
DendroPy tree object to update. |
required |
Returns:
| Type | Description |
|---|---|
set[str]
|
Set of tip labels in the tree. |
Source code in tact/tree_util.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
FastMRCA
Functions in tact/fastmrca.py.
Singleton object that helps speed up MRCA lookups.
tree: dendropy.Tree | None = None
module-attribute
bitmask(labels: list[str]) -> int
Get a bitmask for the specified taxa labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
list[str]
|
List of taxon labels. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Bitmask representing the taxa. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If fastmrca has not been initialized. |
Source code in tact/fastmrca.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
fastmrca_getter(tn: dendropy.TaxonNamespace, x: list[str]) -> int
Helper function to compute bitmask for parallel processing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tn
|
TaxonNamespace
|
Taxon namespace object. |
required |
x
|
list[str]
|
List of taxon labels. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Bitmask representing the taxa. |
Source code in tact/fastmrca.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
get(labels: list[str]) -> dendropy.Node | None
Get the MRCA node for the specified taxa.
Returns the most recent common ancestor node if all descendants of that node are included in the label set, otherwise returns None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
list[str]
|
List of taxon labels to find MRCA for. |
required |
Returns:
| Type | Description |
|---|---|
Node | None
|
MRCA node if it forms a monophyletic group, None otherwise. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If fastmrca has not been initialized. |
Source code in tact/fastmrca.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
initialize(phy: dendropy.Tree) -> None
Initialize the fastmrca singleton with a tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phy
|
Tree
|
DendroPy tree object to use for MRCA lookups. |
required |
Source code in tact/fastmrca.py
13 14 15 16 17 18 19 20 | |
Validation
Functions in tact/validation.py.
Various validation functions for click classes and parameters.
BackboneCommand
Bases: Command
Helper class to validate a Click Command that contains a backbone tree.
At a minimum, the Command must contain a backbone parameter, which is validated by validate_newick
and checked to ensure it is a binary tree.
If the command also contains a taxonomy parameter, representing a taxonomic phylogeny,
this is also validated to ensure that the DendroPy TaxonNamespace is non-strict superset
of the taxa contained in backbone. An optional outgroups parameter may add
other taxa not in the taxonomy.
If the command also contains an ultrametricity_precision parameter, the
ultrametricity of the backbone is also checked.
Source code in tact/validation.py
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 | |
make_context(*args, **kwargs)
Set up the proper Click context for a command handler.
Source code in tact/validation.py
102 103 104 105 106 | |
validate_backbone_variables(ctx, params)
Validates variables related to the backbone and taxonomy files.
Source code in tact/validation.py
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 | |
validate_newick(ctx, param, value, **kwargs)
Validates a Newick tree, using appropriate defaults.
Source code in tact/validation.py
23 24 25 | |
validate_outgroups(ctx, param, value)
Validates an outgroups parameter, by splitting on commas and transforming underscores to spaces.
Source code in tact/validation.py
11 12 13 14 15 16 17 18 19 20 | |
validate_taxonomy_tree(ctx, param, value)
Validates a taxonomy tree.
Source code in tact/validation.py
42 43 44 45 | |
validate_tree_node_depths(ctx, param, value)
Validates a DendroPy tree, ensuring that the node depth is equal for all tips.
Source code in tact/validation.py
28 29 30 31 32 33 34 35 36 37 38 39 | |
Exceptions
Functions in tact/exceptions.py.
Exceptions used by TACT.
DisjointConstraintError
Bases: TactError
Exception raised when a set of constraints lead to a disjoint implied age interval.
Source code in tact/exceptions.py
8 9 | |
TactError
Bases: Exception
Base class for errors raised by TACT.
Source code in tact/exceptions.py
4 5 | |