gneiss.sort.gradient_sort¶
-
gneiss.sort.
gradient_sort
(tree, gradient, ascending=True)[source]¶ Sorts tree according to ordering in gradient.
Parameters: - tree (skbio.TreeNode) – Input tree where leafs correspond to features contained in the index in gradient.
- gradient (pd.Series, numeric) – Gradient where the index correspond to feature names. The index in the gradient must be consistent with names of the tips in the tree.
Returns: A tree whose tips are sorted along the gradient.
Return type: skbio.TreeNode
Examples
>>> from skbio import TreeNode >>> import pandas as pd >>> tree = TreeNode.read([u'((a,b)c, ((g,h)e,f)d)r;']) >>> x = pd.Series({'f':3, 'g':1, 'h':2, 'a':4, 'b':5}) >>> print(tree.ascii_art()) /-a /c-------| | \-b -r-------| | /-g | /e-------| \d-------| \-h | \-f >>> res = gradient_sort(tree, x) >>> print(res.ascii_art()) /-g /e-------| /d-------| \-h | | -r-------| \-f | | /-a \c-------| \-b