treesap package

TreeSAP Tree SAmpling under Phylogenetic models

Module contents

treesap.birthdeath_tree(L, M, end_num_extant=inf, end_time=inf, max_attempts=100)[source]

Sample a birth-death tree with speciation rate L and death rate M. If both an end number of leaves and an end time are specified, the tree sampling will terminate when the first of the two is reached.

Args:

L (float): The speciation rate L

M (float): The death rate M

end_num_extant (int): The final number of extant leaves

end_time (float): The final height of the tree

max_attempts (int): The maximum number of attempts

Returns:
A Tree object storing the sampled birth-death tree. Leaves with label A* (for Alive) are extant, and leaves with label D* (for Dead) are extinct
treesap.coalescent_const_pop_tree(pop_size, num_leaves, continuous=True)[source]

Sample a coalescent tree with a constant population size`. If both an end number of leaves and an end time are specified, the tree sampling will terminate when the first of the two is reached.

Args:

pop_size (float): The population size

num_leaves (int): The final number of leaves

continuous (bool): True to simulate a continuous-time coalescent tree, or False to simulate a discrete-time coalescent tree

Returns:
A Tree object storing the sampled coalescent tree
treesap.dualbirth_tree(La, Lb, end_num_leaves=inf, end_time=inf)[source]

Sample a Dual-Birth tree with activation rate La and birth rate Lb. If both an end number of leaves and an end time are specified, the tree sampling will terminate when the first of the two is reached.

Args:

La (float): The activation rate La

Lb (float): The birth rate Lb

end_num_leaves (int): The final number of leaves

end_time (float): The final height of the tree

Returns:
A Tree object storing the sampled Dual-Birth tree
treesap.nonhomogeneous_yule_tree(L, end_num_leaves=inf, end_time=inf)[source]

Sample a non-homogeneous Yule tree with speciation rate function L(t). If both an end number of leaves and an end time are specified, the tree sampling will terminate when the first of the two is reached.

Args:

L (func): The speciation rate function L(t)

end_num_leaves (int): The final number of leaves

end_time (float): The final height of the tree

Returns:
A Tree object storing the sampled non-homogeneous Yule tree
treesap.transmission_neutral_coalescent_tree(transmission_network, sample_times, rate=1)[source]

Sample a tree under the pure-neutral coalescent model constrained to a given transmission network with given patient sampling times.

Args:

transmission_network (list): The transmission network as a list of (u,v,t) tuples denoting the transmission from u to v at time t. The transmission network must be sorted in ascending order of time

sample_times (dict): The times at which each individual was sampled (i.e., the times of the leaves) as a dict in which keys are individuals from transmission_network and the value associated with an individual u is a list of times at which u was sampled (i.e., the times of the leaves from individual u)

rate (float): The rate of the Poisson process of coalescing two lineages

Returns:
A Tree object storing the sampled pure-neutral tree, where leaves are labeled ID|u|t, where ID is a unique identifier for the leaf, u is the corresponding individual from transmission_network, and t is the sample time (which equals the leaf’s distance from the root). If there are multiple seed individuals (infected beforehand), a tree will be output for each.
treesap.yule_tree(L, end_num_leaves=inf, end_time=inf)[source]

Sample a Yule tree with speciation rate L. If both an end number of leaves and an end time are specified, the tree sampling will terminate when the first of the two is reached.

Args:

L (float): The speciation rate L

end_num_leaves (int): The final number of leaves

end_time (float): The final height of the tree

Returns:
A Tree object storing the sampled Yule tree