phylox.rearrangement.move
Functions
|
Generates all possible valid moves for a given network and move type. |
|
Apply a move to the network, not in place. |
|
Apply a sequence of moves to the network, not in place. |
Classes
|
A move is a rearrangement operation on a phylogenetic network. |
- phylox.rearrangement.move.apply_move(network, move)
Apply a move to the network, not in place. returns True if successful, and False otherwise.
- Parameters:
network – a phylogenetic network (phylox.DiNetwork).
move – a move (phylox.rearrangement.move.Move) to apply to the network.
- Returns:
a new phylogenetic network (phylox.DiNetwork) with the move applied.
- Example:
>>> from phylox import DiNetwork >>> from phylox.rearrangement.move import apply_move, Move >>> network = DiNetwork( ... edges=[(0,1),(1,2),(1,3),(2,3),(2,4),(3,5)], ... ) >>> move = Move( ... move_type=MoveType.HEAD, ... origin=(2,5), ... moving_edge=(1,3), ... target=(2,4), ... ) >>> new_network = apply_move(network, move) >>> edges = set(new_network.edges()) >>> edges == {(0, 1), (1, 2), (1, 3), (2, 3), (3, 4), (2, 5)} True
- phylox.rearrangement.move.apply_move_sequence(network, seq_moves)
Apply a sequence of moves to the network, not in place. returns the resulting network.
- Parameters:
network – a phylogenetic network (phylox.DiNetwork).
seq_moves – a sequence of moves (list of phylox.rearrangement.move.Move) to apply to the network.
- Returns:
a new phylogenetic network (phylox.DiNetwork) with the moves applied.
- Example:
>>> from phylox import DiNetwork >>> from phylox.rearrangement.move import apply_move_sequence, Move >>> network = DiNetwork( ... edges=[(0,1),(1,2),(1,3),(2,4),(2,5),(3,6),(3,7)], ... ) >>> seq_moves = [ ... Move( ... move_type=MoveType.TAIL, ... moving_edge=(3,6), ... target=(0,1), ... origin=(1,7), ... ), ... Move( ... move_type=MoveType.VPLU, ... start_edge=(1,2), ... end_edge=(1,7), ... network=network, ... ), ... ] >>> new_network = apply_move_sequence(network, seq_moves) >>> edges = set(new_network.edges()) >>> edges == {(0, 3), (3, 1), (1, -1), (-1, 2), (1, -2), (-2, 7), (2, 4), (2, 5), (3, 6), (-1, -2)} True
- phylox.rearrangement.move.all_valid_moves(network, move_type=MoveType.ALL)
Generates all possible valid moves for a given network and move type.
- Parameters:
network – a phylogenetic network (phylox.DiNetwork).
move_type – the type of moves to generate (phylox.rearrangement.movetype.MoveType).
- Yield:
a move (phylox.rearrangement.move.Move).
- Example:
>>> from phylox import DiNetwork >>> from phylox.rearrangement.move import all_valid_moves >>> network = DiNetwork( ... edges=[(0,1),(1,2),(1,3)], ... ) >>> moves = list(all_valid_moves(network, MoveType.TAIL)) >>> len(moves) 4 >>> moves[0].is_type(MoveType.TAIL) True >>> moves = list(all_valid_moves(network, MoveType.VERT)) >>> len(moves) 4 >>> moves[0].is_type(MoveType.VPLU) True
- class phylox.rearrangement.move.Move(*args, **kwargs)
Bases:
objectA move is a rearrangement operation on a phylogenetic network.
- Parameters:
move_type – the type of move (phylox.rearrangement.movetype.MoveType).
kwargs – the parameters of the move, depending on the move type.
- is_type(move_type)
Checks if the move is of a given type.
- Parameters:
move_type – the move type to check (phylox.rearrangement.movetype.MoveType).
- Returns:
True if the move is of the given type, False otherwise.
- Example:
>>> from phylox.rearrangement.move import Move >>> move = Move( ... move_type=MoveType.TAIL, ... origin=(2,5), ... moving_edge=(1,3), ... target=(2,4), ... ) >>> move.is_type(MoveType.TAIL) True >>> move.is_type(MoveType.RSPR) True >>> move.is_type(MoveType.HEAD) False >>> move.is_type(MoveType.VERT) False
- rename_nodes(isomorphism)
Renames the nodes in the move using an isomorphism mapping between two networks.
- Parameters:
isomorphism – a dictionary, containing a bijective mapping from nodes of the networks to another set.
- Returns:
a new move with the nodes renamed.
- invert(network=None)
Inverts the move.
- Parameters:
network – a phylogenetic network (phylox.DiNetwork) in which to invert the move. (needed for VMIN moves)
- Returns:
a new move that is the inverse of the current move.
- classmethod random_move(network, available_tree_nodes=None, available_reticulations=None, move_type_probabilities={MoveType.HEAD: 0.4, MoveType.TAIL: 0.4, MoveType.VMIN: 0.1, MoveType.VPLU: 0.1}, seed=None)
Generates a random move for the given network. The move may not be valid.
- Parameters:
network – a phylogenetic network (phylox.DiNetwork).
available_tree_nodes – a list of available tree nodes to use for the move.
available_reticulations – a list of available reticulations to use for the move.
move_type_probabilities – a dictionary of move type probabilities.
- Returns:
a random move (phylox.rearrangement.move.Move).
- Example:
>>> from phylox import DiNetwork >>> from phylox.rearrangement.move import Move >>> network = DiNetwork( ... edges=[(0,1),(1,2),(1,3),(2,3),(2,4),(3,5)], ... ) >>> move = Move.random_move( ... network, ... move_type_probabilities={ ... MoveType.TAIL: 0.5, ... MoveType.HEAD: 0.5, ... }, ... ) >>> move.is_type(MoveType.RSPR) True