phylox.cherrypicking.base
Functions
|
Adds a pair to the network, using the construction from a cherry-picking sequence :param x: first element of the pair :param y: second element of the pair :param height: height of the pair :param inplace: if true, the network is modified in place, otherwise a copy is returned :param nodes_by_label: if true, the nodes are indexed by their label, otherwise by their index :return: the network with the pair added |
|
Modifies a cherry-picking sequence so that it represents a network with exactly one root. |
|
Checks whether the pair (x,y) is a reducible pair in the network. |
|
Returns the height of (x,y) if it is a cherry: |
|
Finds all reducible pairs (cherries and reticulated cherries) in the network. |
|
Finds a set of cherries in the network N with leaf x as first element of the pair. |
Finds a list of reducible pairs (cherries and reticulated cherries) in the network N with leaf x as first element of the pair. |
|
Finds a list of reducible pairs (cherries and reticulated cherries) in the network N with leaf x as second element of the pair. |
|
Finds a list of reticulated cherries in the network N with leaf x as first element of the pair. |
|
|
Checks which pairs of a sequence actually reduce a given network for a given cherry-picking sequence `sequence' reduces a given tree `tree' input: sequence: a list of pairs of leaves network: a network output: if the network is reduced by the sequence, returns the list of all indices of pairs that reduce the network otherwise returns False |
|
Checks whether the pair (x,y) forms a cherry in the network |
|
|
|
Reduces the reducible pair (x,y) in the network. |
Classes
|
|
- class phylox.cherrypicking.base.CHERRYTYPE(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
- phylox.cherrypicking.base.find_all_reducible_pairs(network)
Finds all reducible pairs (cherries and reticulated cherries) in the network.
- Parameters:
network – a phylogenetic network.
- Returns:
a set of reducible pairs (cherries and reticulated cherries) in the network.
- Example:
>>> from phylox import DiNetwork >>> from phylox.cherrypicking.base import find_all_reducible_pairs >>> network = DiNetwork( ... edges=[(-1,0),(0,1),(1,2),(1,3),(2,3),(2,4),(3,5),(0,6),(6,7),(6,8)], ... ) >>> reducible_pairs = find_all_reducible_pairs(network) >>> reducible_pairs == {(7,8),(8,7),(5,4)} True
- phylox.cherrypicking.base.find_reducible_pairs_with_second(N, x)
Finds a list of reducible pairs (cherries and reticulated cherries) in the network N with leaf x as second element of the pair.
- Parameters:
N – a phylogenetic network.
x – a leaf of the network N.
- Returns:
a list of reducible pairs (cherries and reticulated cherries) in the network N with leaf x as second element of the pair.
- Example:
>>> from phylox import DiNetwork >>> from phylox.cherrypicking.base import find_reducible_pairs_with_second >>> network = DiNetwork( ... edges=[(-1,0), (0,1), (0,2), (1,2), (1,3), (2,4)], ... ) >>> find_reducible_pairs_with_second(network, 3) [(4, 3)]
- phylox.cherrypicking.base.find_reducible_pairs_with_first(N, x)
Finds a list of reducible pairs (cherries and reticulated cherries) in the network N with leaf x as first element of the pair.
- Parameters:
N – a phylogenetic network.
x – a leaf of the network N.
- Returns:
a list of reducible pairs (cherries and reticulated cherries) in the network N with leaf x as first element of the pair.
- Example:
>>> from phylox import DiNetwork >>> from phylox.cherrypicking.base import find_reducible_pairs_with_first >>> network = DiNetwork( ... edges=[(-1,0), (0,1), (0,2), (1,2), (1,3), (2,4)], ... ) >>> find_reducible_pairs_with_first(network, 4) [(4, 3)]
- phylox.cherrypicking.base.find_reticulated_cherry_with_first(N, x)
Finds a list of reticulated cherries in the network N with leaf x as first element of the pair.
- Parameters:
N (phylox.DiNetwork) – The network to find reticulated cherries in.
x (str or int) – The leaf to find reticulated cherries with.
- Returns:
A list of reticulated cherries in the network with leaf x as first element of the pair.
- Return type:
list
- phylox.cherrypicking.base.find_cherries_with_first(network, x)
Finds a set of cherries in the network N with leaf x as first element of the pair.
- Parameters:
network (phylox.DiNetwork) – The network to find cherries in.
x (str or int) – The leaf to find cherries with.
- Returns:
A set of cherries in the network with leaf x as first element of the pair.
- Return type:
set
- phylox.cherrypicking.base.reduce_pair(network, x, y, inplace=False, nodes_by_label=False)
Reduces the reducible pair (x,y) in the network. Note: Cache of network properties is not updated.
- Parameters:
network (phylox.DiNetwork) – The network to reduce the reducible pair in.
x (str or int) – The first element of the reducible pair.
y (str or int) – The second element of the reducible pair.
inplace (bool) – If True, the network is modified in place.
nodes_by_label (bool) – If True, the nodes x and y are interpreted as labels.
- Returns:
phylox.DiNetwork – The network with the reducible pair reduced.
CHERRYTYPE – The type of the reducible pair.
- Raises:
ValueError – If x or y are not in the network.
Examples
>>> from phylox import DiNetwork >>> from phylox.cherrypicking.base import reduce_pair, CHERRYTYPE >>> network = DiNetwork( ... edges=[(-1,0), (0,1), (0,2), (1,2), (1,3), (2,4)], ... ) >>> network, cherry_type = reduce_pair(network, 4, 3) >>> cherry_type == CHERRYTYPE.RETICULATEDCHERRY True >>> set(network.edges) == {(-1, 0), (0, 3), (0, 4)} True
- phylox.cherrypicking.base.check_reducible_pair(network, x, y)
Checks whether the pair (x,y) is a reducible pair in the network.
- Parameters:
network – a phylogenetic network.
x – a leaf of the network.
y – a leaf of the network.
- Returns:
the type of reducible pair (x,y) in the network.
- Example:
>>> from phylox import DiNetwork >>> from phylox.cherrypicking.base import check_reducible_pair, CHERRYTYPE >>> network = DiNetwork( ... edges=[(-1,0), (0,1), (0,2), (1,2), (1,3), (2,4)], ... ) >>> check_reducible_pair(network, 4, 3) == CHERRYTYPE.RETICULATEDCHERRY True
- phylox.cherrypicking.base.add_pair(network, x, y, height=[1, 1], inplace=False, nodes_by_label=False)
Adds a pair to the network, using the construction from a cherry-picking sequence :param x: first element of the pair :param y: second element of the pair :param height: height of the pair :param inplace: if true, the network is modified in place, otherwise a copy is returned :param nodes_by_label: if true, the nodes are indexed by their label, otherwise by their index :return: the network with the pair added
- phylox.cherrypicking.base.get_indices_of_reducing_pairs(sequence, network)
Checks which pairs of a sequence actually reduce a given network for a given cherry-picking sequence `sequence’ reduces a given tree `tree’ input:
sequence: a list of pairs of leaves network: a network
- output:
if the network is reduced by the sequence, returns the list of all indices of pairs that reduce the network otherwise returns False
- phylox.cherrypicking.base.add_roots_to_sequence(sequence, reduced_trees_per_pair)
Modifies a cherry-picking sequence so that it represents a network with exactly one root. A sequence may be such that reconstructing a network from the sequence results in multiple roots This function adds some pairs to the sequence so that the network has a single root. :param sequence: the sequence to modify :param reduced_trees_per_pair: the sets of trees reduced by each pair in the sequence
- Returns:
the new sequence, and also the sets of trees reduced by each pair in the sequence, modified so that the new pairs are also represented (they reduce no trees)
- phylox.cherrypicking.base.has_cherry(network, x, y)
Checks whether the pair (x,y) forms a cherry in the network
- Parameters:
network (phylox.DiNetwork) – The network in which we want to check whether (x,y) is a cherry
x (string) – The first element of the pair
y (string) – The second element of the pair
- Returns:
True if (x,y) is a cherry in the network, False otherwise
- Return type:
bool
- phylox.cherrypicking.base.cherry_height(network, x, y)
- Returns the height of (x,y) if it is a cherry:
i.e.: length(p,x)+length(p,y)/2
Returns false otherwise
- Parameters:
network (phylox.DiNetwork) – The network in which we want to check the height of cherry (x,y)
x (string) – The first element of the pair
y (string) – The second element of the pair
- Returns:
The height of the cherry (x,y) if it is a cherry, False otherwise
- Return type:
float