TreeNode.
shuffle
(k=None, names=None, shuffle_f=<built-in method shuffle of mtrand.RandomState object>, n=1)[source]¶Yield trees with shuffled tip names
State: Experimental as of 0.4.0.
Parameters: | k : int, optional
names : list, optional
shuffle_f : func
n : int, optional
|
---|---|
Raises: | ValueError
ValueError
MissingNodeError
|
Notes
Tip names are shuffled inplace. If neither k nor names are provided, all tips are shuffled.
Examples
Alternate the names on two of the tips, ‘a’, and ‘b’, and do this 5 times.
>>> from skbio import TreeNode
>>> tree = TreeNode.read(["((a,b),(c,d));"])
>>> rev = lambda items: items.reverse()
>>> shuffler = tree.shuffle(names=['a', 'b'], shuffle_f=rev, n=5)
>>> for shuffled_tree in shuffler:
... print(shuffled_tree)
((b,a),(c,d));
((a,b),(c,d));
((b,a),(c,d));
((a,b),(c,d));
((b,a),(c,d));