talgalili / dendextend

Extending R's Dendrogram Functionality
152 stars 28 forks source link

Getting all member names under a particular node #98

Closed Jayesh-Kumar-Sundaram closed 4 years ago

Jayesh-Kumar-Sundaram commented 4 years ago

Do we have any attribute in the get_node_attr() function where we can get all the member names under a particular node?

talgalili commented 4 years ago

When you say names you mean the labels in the leaves or something else?

On Thu, Apr 2, 2020, 21:16 Jayesh-Kumar-Sundaram notifications@github.com wrote:

Do we have any attribute in the get_node_attr() function where we can get all the member names under a particular node?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/talgalili/dendextend/issues/98, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHOJBVPDLEXWPOZPQT3Q7LRKTI7DANCNFSM4L2YHMMQ .

Jayesh-Kumar-Sundaram commented 4 years ago

Yes, labels in the leaves

Jayesh-Kumar-Sundaram commented 4 years ago

I wrote a small code to find all leave labels under a given node:

dend = hclust(as.dist(x), method = "average")

Getting leaf labels under a given node

node_data = (dend$merge)

node_member_length = c() member_list = list()

for(n in seq(from=1, to=dim(node_data)[1], by=1)) { members = c() members = append(members, node_data[n,1], after=length(members)) members = append(members, node_data[n,2], after=length(members)) i = 1 while(i <= length(members)) { if(as.numeric(members[i]) > 0) { members = append(members, node_data[members[i],1], after=length(members)) members = append(members, node_data[members[i],2], after=length(members)) } i = i + 1 } members_index = which(members < 0) members = -1*(members[members_index]) node_member_length = append(node_member_length, length(members), after=length(node_member_length)) member_list = append(member_list, list(dend$labels[members]), after=length(member_list)) }

talgalili commented 4 years ago

Just to be sure - why do you need it? I think labels would get it back if you give it the node. The question is how to get to a node you're interested in. And that depends on your context.

On Thu, Apr 2, 2020, 21:23 Jayesh-Kumar-Sundaram notifications@github.com wrote:

Yes, labels in the leaves

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/talgalili/dendextend/issues/98#issuecomment-608026344, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHOJBQDWIIRN2W2QMQQZODRKTJ2BANCNFSM4L2YHMMQ .

talgalili commented 4 years ago

Thanks. What's the use case?

On Thu, Apr 2, 2020, 22:00 Jayesh-Kumar-Sundaram notifications@github.com wrote:

I wrote a small code to find all leave labels under a given node:

dend = hclust(as.dist(x), method = "average") Getting leaf labels under a given node

node_data = (dend$merge)

node_member_length = c() member_list = list()

for(n in seq(from=1, to=dim(node_data)[1], by=1)) { members = c() members = append(members, node_data[n,1], after=length(members)) members = append(members, node_data[n,2], after=length(members)) i = 1 while(i <= length(members)) { if(as.numeric(members[i]) > 1) { members = append(members, node_data[members[i],1], after=length(members)) members = append(members, node_data[members[i],2], after=length(members)) } i = i + 1 } members_index = which(members < 1) members = -1*(members[members_index]) node_member_length = append(node_member_length, length(members), after=length(node_member_length)) member_list = append(member_list, list(dend$labels[members]), after=length(member_list)) }

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/talgalili/dendextend/issues/98#issuecomment-608045530, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHOJBUJKE2ZBOHOYHCMQ7DRKTOF7ANCNFSM4L2YHMMQ .

Jayesh-Kumar-Sundaram commented 4 years ago

I constructed a tree based on gene expression data. I wanted to check whether a particular GO term is enriched in all sub-trees connected by a node. So, for all nodes i want to know all the genes under it to perform enrichment analysis.

talgalili commented 4 years ago

Just to verify, you closed the issue since you found a solution? (if so, could you please write it also here?)

On Fri, Aug 28, 2020 at 7:22 AM Jayesh-Kumar-Sundaram < notifications@github.com> wrote:

Closed #98 https://github.com/talgalili/dendextend/issues/98.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/talgalili/dendextend/issues/98#event-3702290911, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHOJBRGYAE6WWFJHXRT62TSC4WG3ANCNFSM4L2YHMMQ .

Jayesh-Kumar-Sundaram commented 3 years ago

I didn't find the solution using the "dendextend" package but I used the code I have written in my previous comment to get all member names under a particular node. If you wish to keep the issue open, we can re-open it. Thanks