Re: [R-sig-phylo] Counting and getting the age of cherries in a tree

2023-01-10 Thread Ivan Magalhaes
This was exactly what I needed -- thanks a lot!!Best,Ivan
--
Dr. Ivan L. F. Magalhaes

Postdoctoral fellow — División AracnologíaMuseo Argentino de Ciencias Naturales 
"Bernardino Rivadavia" 
Av. Ángel Gallardo 470, C1405DJR, Buenos Aires, Argentina+54 11 4982-8370 ext. 
169Website | ResearchGate | Twitter |iNaturalist | Lattes | CV-Ar | ORCID | 
GitHub 

Em segunda-feira, 9 de janeiro de 2023 20:05:53 GMT-3, Liam J. Revell 
 escreveu:  
 
  
Hi Ivan.
 
Try this simple code:
 
## load packages
 library(phytools)
 library(phangorn)
 ## get tips descended from each node
 dd<-Descendants(tree,node=1:tree$Nnode+Ntip(tree),
     type="tips")
 names(dd)<-1:tree$Nnode+Ntip(tree)
 ## get the NUMBER of tips from each node
 nn<-sapply(dd,length)
 ## get corresponding node indices
 nodes<-as.numeric(names(nn[which(nn==2)]))
 ## compute their heights above root
 heights<-setNames(sapply(nodes,nodeheight,
     tree=tree),nodes)
 
 
This scales well up to trees with 1,000 or more tips IME. It gives you the 
heights above the root of each node with two descendants (cherry). If your tree 
is ultrametric, to get the depth you would just subtract this value from the 
total height of the tree.
 
Let me know if it works!!
 
All the best, Liam
 
 Liam J. Revell
 Professor of Biology, University of Massachusetts Boston
 Web: http://faculty.umb.edu/liam.revell/
 
 
  On 1/9/2023 5:37 PM, Ivan Magalhaes wrote:
  
 CAUTION: EXTERNAL SENDER

Hi all,
Perhaps a dumb question, but is there an easy way to count the number of 
cherries in a given tree, and fetch their ages? (i.e. all the nodes with 
exactly two descendants)
Thanks! Best,Ivan
--
Dr. Ivan L. F. Magalhaes

Postdoctoral fellow — División AracnologíaMuseo Argentino de Ciencias Naturales 
"Bernardino Rivadavia" 
Av. Ángel Gallardo 470, C1405DJR, Buenos Aires, Argentina+54 11 4982-8370 ext. 
169Website | ResearchGate | Twitter |iNaturalist | Lattes | CV-Ar | ORCID | 
GitHub
[[alternative HTML version deleted]]

___
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-phylo=05%7C01%7Cliam.revell%40umb.edu%7C58b9f271e0124a5ff56a08daf292212b%7Cb97188711ee94425953c1ace1373eb38%7C0%7C0%7C638089006703316956%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=xpf1hbFEEJFsi%2BGI3in6yfxNbiThSss5ivqEeiuQS%2BY%3D=0
Searchable archive at 
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.mail-archive.com%2Fr-sig-phylo%40r-project.org%2F=05%7C01%7Cliam.revell%40umb.edu%7C58b9f271e0124a5ff56a08daf292212b%7Cb97188711ee94425953c1ace1373eb38%7C0%7C0%7C638089006703316956%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=wcDMnSGFSQotMzfg05l83bCltDgOkk7SL%2F94LSNhiXQ%3D=0
 
   
[[alternative HTML version deleted]]

___
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/


Re: [R-sig-phylo] Counting and getting the age of cherries in a tree

2023-01-09 Thread Liam J. Revell
Hi Ivan.

Try this simple code:

## load packages
library(phytools)
library(phangorn)
## get tips descended from each node
dd<-Descendants(tree,node=1:tree$Nnode+Ntip(tree),
     type="tips")
names(dd)<-1:tree$Nnode+Ntip(tree)
## get the NUMBER of tips from each node
nn<-sapply(dd,length)
## get corresponding node indices
nodes<-as.numeric(names(nn[which(nn==2)]))
## compute their heights above root
heights<-setNames(sapply(nodes,nodeheight,
     tree=tree),nodes)

This scales well up to trees with 1,000 or more tips IME. It gives you 
the /heights/ above the root of each node with two descendants (cherry). 
If your tree is ultrametric, to get the /depth/ you would just subtract 
this value from the total height of the tree.

Let me know if it works!!

All the best, Liam

Liam J. Revell
Professor of Biology, University of Massachusetts Boston
Web: http://faculty.umb.edu/liam.revell/


On 1/9/2023 5:37 PM, Ivan Magalhaes wrote:
> CAUTION: EXTERNAL SENDER
>
> Hi all,
> Perhaps a dumb question, but is there an easy way to count the number of 
> cherries in a given tree, and fetch their ages? (i.e. all the nodes with 
> exactly two descendants)
> Thanks! Best,Ivan
> --
> Dr. Ivan L. F. Magalhaes
>
> Postdoctoral fellow — División AracnologíaMuseo Argentino de Ciencias 
> Naturales "Bernardino Rivadavia"
> Av. Ángel Gallardo 470, C1405DJR, Buenos Aires, Argentina+54 11 4982-8370 
> ext. 169Website | ResearchGate | Twitter |iNaturalist | Lattes | CV-Ar | 
> ORCID | GitHub
>  [[alternative HTML version deleted]]
>
> ___
> R-sig-phylo mailing list -R-sig-phylo@r-project.org
> https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-phylo=05%7C01%7Cliam.revell%40umb.edu%7C58b9f271e0124a5ff56a08daf292212b%7Cb97188711ee94425953c1ace1373eb38%7C0%7C0%7C638089006703316956%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=xpf1hbFEEJFsi%2BGI3in6yfxNbiThSss5ivqEeiuQS%2BY%3D=0
> Searchable archive 
> athttps://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.mail-archive.com%2Fr-sig-phylo%40r-project.org%2F=05%7C01%7Cliam.revell%40umb.edu%7C58b9f271e0124a5ff56a08daf292212b%7Cb97188711ee94425953c1ace1373eb38%7C0%7C0%7C638089006703316956%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=wcDMnSGFSQotMzfg05l83bCltDgOkk7SL%2F94LSNhiXQ%3D=0
[[alternative HTML version deleted]]

___
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/


[R-sig-phylo] Counting and getting the age of cherries in a tree

2023-01-09 Thread Ivan Magalhaes
Hi all,
Perhaps a dumb question, but is there an easy way to count the number of 
cherries in a given tree, and fetch their ages? (i.e. all the nodes with 
exactly two descendants)
Thanks! Best,Ivan
--
Dr. Ivan L. F. Magalhaes

Postdoctoral fellow — División AracnologíaMuseo Argentino de Ciencias Naturales 
"Bernardino Rivadavia" 
Av. Ángel Gallardo 470, C1405DJR, Buenos Aires, Argentina+54 11 4982-8370 ext. 
169Website | ResearchGate | Twitter |iNaturalist | Lattes | CV-Ar | ORCID | 
GitHub
[[alternative HTML version deleted]]

___
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/