TreeNode.
shuffle
(k=None, names=None, shuffle_f=<built-in method shuffle of numpy.random.mtrand.RandomState object>, n=1)[source]¶Yield trees with shuffled tip names
State: Experimental as of 0.4.0.
Parameters: |
|
---|
Notes
Tip names are shuffled inplace. If neither k nor names are provided, all tips are shuffled.
Yields: | TreeNode – Tree with shuffled tip names. |
---|---|
Raises: |
|
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));
<BLANKLINE>
((a,b),(c,d));
<BLANKLINE>
((b,a),(c,d));
<BLANKLINE>
((a,b),(c,d));
<BLANKLINE>
((b,a),(c,d));
<BLANKLINE>