phylox.generators.lgt.base
A module for generating (random) LGT phylogenetic networks.
By Joan Carles Pons, Celine Scornavacca, Gabriel Cardona With their paper: Generation of Level-k LGT Networks PMID: 30703035 DOI: 10.1109/TCBB.2019.2895344
Adapted by RemieJanssen to output networks with a given number of leaves and reticulations
Functions
|
Returns a dictionary, mapping each internal node to its blob, and each leaf to the blob directly adjacent to it. |
Returns a list internal pairs, and a list of external pairs. |
|
|
Returns a list of internal blobs of the network. |
|
Returns a list of leaves of the network. |
|
Adds a 'lateral gene transfer' to the network between leaves leaf1 and leaf2. |
|
Returns a list of reticulation nodes of the network. |
|
Add a new leaf to the network by a 'speciation event' at leaf leaf of the network. |
- phylox.generators.lgt.base.speciate(net, leaf)
Add a new leaf to the network by a ‘speciation event’ at leaf leaf of the network. This is done by adding two outgoing edges to the leaf node.
- Parameters:
net – a phylox DiNetwork
leaf – leaf of the network net
- Returns:
None
- phylox.generators.lgt.base.lgt(net, leaf1, leaf2)
Adds a ‘lateral gene transfer’ to the network between leaves leaf1 and leaf2. This is done by adding an outgoing edge to each of the leaf nodes and adding an edge between these nodes as well.
- Parameters:
net – a phylox DiNetwork
leaf1 – a leaf of the network net
leaf2 – a leaf of the network net
- Returns:
None
- phylox.generators.lgt.base.leaves(net)
Returns a list of leaves of the network.
- Parameters:
net – a phylox DiNetwork
- Returns:
a list of leaf nodes of the network
- phylox.generators.lgt.base.reticulations(net)
Returns a list of reticulation nodes of the network.
- Parameters:
net – a phylox DiNetwork
- Returns:
a list of reticulation nodes of the network
- phylox.generators.lgt.base.internal_blobs(net)
Returns a list of internal blobs of the network. An internal blob is a biconnected component of the underlying undirected graph of the network, after removing the leaves.
- Parameters:
net – a phylox DiNetwork
- Returns:
a list of internal blobs of the network
- phylox.generators.lgt.base.compute_hash(net)
Returns a dictionary, mapping each internal node to its blob, and each leaf to the blob directly adjacent to it.
- Parameters:
net – a phylox DiNetwork
- Returns:
a dictionary mapping each leaf to an internal blob.
- phylox.generators.lgt.base.internal_and_external_pairs(net)
Returns a list internal pairs, and a list of external pairs. A pair of leaves is internal if they are adjacent to the same internal blob, the pair is external otherwise.
- Parameters:
net – a phylox DiNetwork
- Returns:
a list internal pairs, and a list of external pairs
- phylox.generators.lgt.base.random_pair(net, wint, wext, seed=None)
Randomly returns a pair of leaves, weighted by two parameters: a pair has weight wint if it is an internal pair, and wext otherwise.
- Parameters:
net – a phylox DiNetwork
wint – The weight (float) of an internal leaf pair
wext – The weight (float) of an external leaf pair
- Returns:
a pair of leaves of net
- phylox.generators.lgt.base.simulation_1(num_steps, prob_lgt, wint, wext, seed=None)
Generates a random DiNetwork starting with a tree on two leaves, and adding num_steps events (either speciation or lgt). The type of event is chosen independently at random in each step with probability prob_lgt for an lgt event, and probability 1-prob_lgt for a speciation event.
An lgt is added between a pair of leaves, the pair is chosen by weighting a leaf pair with weight wint if it is an internal pair, and weight wext if it is an external pair. A pair of leaves is internal if they are adjacent to the same internal blob, the pair is external otherwise.
- Parameters:
num_steps – the total number of speciation and lgt events
prob_lgt – the probability of a lgt event (a float in [0,1])
wint – The weight (float) of an internal leaf pair
wext – The weight (float) of an external leaf pair
seed – The random seed
- Returns:
a phylox DiNetwork
- phylox.generators.lgt.base.generate_network_lgt(leaves_goal, retics_goal, wint, wext, seed=None)
Generates a random DiNetwork with a given number of leaves and reticulations. The number of leaves and reticulations uniquely determines the number of speciation and lgt events, but not their order. Hence, the order of the events is determined first (at random), and then the events are all applied randomly.
An lgt edge is added between a pair of leaves, the pair is chosen by weighting a leaf pair with weight wint if it is an internal pair, and weight wext if it is an external pair. A pair of leaves is internal if they are adjacent to the same internal blob, the pair is external otherwise.
- Parameters:
leaves_goal – number of leaves in the network
retics_goal – number of reticulations in the network
wint – The weight (float) of an internal leaf pair
wext – The weight (float) of an external leaf pair
- Returns:
a phylox DiNetwork with the given number of leaves and reticulations
- phylox.generators.lgt.base.generate_network_lgt_conditional(n, k, prob_lgt, wint=1, wext=1, max_tries=1000, seed=None)
Generates a random DiNetwork with a given number of leaves and reticulations. The number of leaves and reticulations uniquely determines the number of speciation and lgt events, but not their order. In contrast to simulation_3 the order of the events is not determined beforhand, but generated like in simulation_1 this guarantees a draw according to simulation_1 conditional on the number of leaves and reticulations
An lgt is added between a pair of leaves, the pair is chosen by weighting a leaf pair with weight wint if it is an internal pair, and weight wext if it is an external pair. A pair of leaves is internal if they are adjacent to the same internal blob, the pair is external otherwise.
- Parameters:
n – number of leaves
k – number of reticulations
alpha – parameter for the weight of internal edges
beta – parameter for the weight of external edges
max_tries – maximum number of tries to generate a network
seed – seed for the random number generator
- Returns:
a network with the given number of leaves and reticulations