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 LM(float): The death rate Mend_num_extant(int): The final number of extant leavesend_time(float): The final height of the treemax_attempts(int): The maximum number of attempts- Returns:
- A
Treeobject 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 sizenum_leaves(int): The final number of leavescontinuous(bool):Trueto simulate a continuous-time coalescent tree, orFalseto simulate a discrete-time coalescent tree- Returns:
- A
Treeobject 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 LaLb(float): The birth rate Lbend_num_leaves(int): The final number of leavesend_time(float): The final height of the tree- Returns:
- A
Treeobject 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 leavesend_time(float): The final height of the tree- Returns:
- A
Treeobject 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 alistof(u,v,t)tuples denoting the transmission fromutovat timet. The transmission network must be sorted in ascending order of timesample_times(dict): The times at which each individual was sampled (i.e., the times of the leaves) as adictin which keys are individuals fromtransmission_networkand the value associated with an individualuis alistof times at whichuwas sampled (i.e., the times of the leaves from individualu)rate(float): The rate of the Poisson process of coalescing two lineages- Returns:
- A
Treeobject storing the sampled pure-neutral tree, where leaves are labeledID|u|t, whereIDis a unique identifier for the leaf,uis the corresponding individual fromtransmission_network, andtis 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 Lend_num_leaves(int): The final number of leavesend_time(float): The final height of the tree- Returns:
- A
Treeobject storing the sampled Yule tree