Relative evolutionary divergence (RED) #90
ryneches
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
Hey Russel,
This looks great. It would be awesome for you to implement some of these
methods. I think `toytree.pcm` is the right place for it. You could create
a new module within there for the phylorank related functions.
Here is a slightly streamlined version of the red function that gets a
distance matrix up front, and uses .up to reference parents, both of which
will increase speed a bit.
```python
def get_relative_evolutionary_divergence(tree):
"""Returns a dict mapping Node idx to relative evolutionary divergence.
"""
# store root to 0, tips to 1
red = {tree.treenode.idx: 0}
red.update({i: 1 for i in range(tree.ntips)})
# get all-by-all node distance matrix
mat = tree.distance.get_node_distance_matrix(topology_only=False)
# preorder (parent then child) excluding root and tips
for node in tree[-2:tree.ntips - 1:-1]:
# get parent's red value (P), and dist to parent (a)
P = red[node.up.idx]
a = mat[node.idx, node.up.idx]
# get avg dist from this node to each of its leaves (b)
b = np.mean([mat[node.idx, leaf.idx] for leaf in
node.iter_leaves()])
# why can the dist from node to parent not be the same as avg to
its leaves?
if a + b == 0:
raise ValueError(f"node {node}: a == b == {a}")
# store this nodes red value
red[node.idx] = P + (a / (a + b)) * (1 - P)
return red
```
Best,
Deren
…On Tue, Jul 30, 2024 at 4:34 AM Russell Neches ***@***.***> wrote:
Hey folks!
I plotted relative evolutionary divergence
<https://www.nature.com/articles/s41564-021-00918-8> in ToyTree. I
thought I'd and share gather critiques of my implementation. Eventually, I
would like to port over some of the features of PhyloRank
<https://github.com/donovan-h-parks/PhyloRank> into ToyTree, so that RED
can be used to place taxon labels onto trees.
What do you think? If I make a PR, should it live in
toytree.pcm.diversification? Start a new subpackage?
t = toytree.tree( 'test.nwk' )toytree.mod.root_on_minimal_ancestor_deviation( t )
RED = {}
for node in t.traverse( strategy='preorder' ) :
if node.is_root() :
RED[ node ] = 0
continue
if node.is_leaf() :
RED[ node ] = 1
continue
parent = node.get_ancestors()[0]
P = RED[ parent ]
a = t.distance.get_node_distance( node, parent )
b = numpy.mean( [ d for node, d in t.distance.iter_descendant_dists( node ) if node.is_leaf() ] )
if a + b == 0 :
raise Exception( 'node {n} : a={a}, b={b}'.format( n=node, a=a, b=b ) )
RED[ node ] = P + ( a / ( a + b ) ) * ( 1 - P )
t.set_node_data( feature='RED', data=RED, inplace=True )
mystyle = {
'layout' : 'd',
'edge_type' : 'p',
'edge_style' : {
'stroke' : toytree.color.COLORS1[1],
'stroke-width' : 2.5,
},
'tip_labels' : False,
'node_labels' : False,
'node_sizes' : 10,
'node_colors' : ( 'RED', 'Reds', 1, 0 )
}
canvas, axes, mark = t.draw( height=600, width=1200, **mystyle )canvas
77-849_species_RED.svg (view on web)
<https://github.com/user-attachments/assets/bd6eb6f0-3134-4fbc-99ec-67e86e63847a>
—
Reply to this email directly, view it on GitHub
<#90>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGEVUG4D4CDIV62TA6325ILZO5FYFAVCNFSM6AAAAABLV3PEGCVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZWHE4TGOBVGQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
Deren Eaton
Associate Professor, Department of E3B
Affiliate Member, Data Science Institute
Committee on Equity and Diversity
Columbia University
https://eaton-lab.org <http://eaton-lab.org>
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey folks!
I plotted relative evolutionary divergence in ToyTree. I thought I'd and share gather critiques of my implementation. Eventually, I would like to port over some of the features of PhyloRank into ToyTree, so that RED can be used to place taxon labels onto trees.
What do you think? If I make a PR, should it live in
toytree.pcm.diversification
? Start a new subpackage?Beta Was this translation helpful? Give feedback.
All reactions