Phylogenetics in R: collapsing descendant tips of an internal node -


i have several thousand gene trees trying ready analysis codeml. tree below typical example. want automate collapsing of tips or nodes appear duplicates. instance, descendants of node 56 tips 26, 27, 28 etc way 36. of these other tip 26 appear duplicates. how can collapse them single tip, leaving tips 28 , 1 representative of other tips descendants of node 56?

i know how manually 1 one, trying automate process function can identify tips need collapsed , reduce them single representative tip. far have been looking @ cophenetic function calculates distances between tips. however, not sure how use information collapse tips.

here newick string below tree:

((((11:0.00201426,12:5e-08,(9:1e-08,10:1e-08,8:1e-08)40:0.00403036)41:0.00099978,7:5e-08)42:0.01717066,(3:0.00191517,(4:0.00196859,(5:1e-08,6:1e-08)71:0.00205168)70:0.00112995)69:0.01796015)43:0.042592645,((1:0.00136179,2:0.00267375)44:0.05586907,(((13:0.00093161,14:0.00532243)47:0.01252989,((15:1e-08,16:1e-08)49:0.00123243,(17:0.00272478,(18:0.00085725,19:0.00113572)51:0.01307761)50:0.00847373)48:0.01103656)46:0.00843782,((20:0.0020268,(21:0.00099593,22:1e-08)54:0.00099081)53:0.00297097,(23:0.00200672,(25:1e-08,(36:1e-08,37:1e-08,35:1e-08,34:1e-08,33:1e-08,32:1e-08,31:1e-08,30:1e-08,29:1e-08,28:0.00099682,27:1e-08,26:1e-08)58:0.00200056,24:1e-08)56:0.00100953)55:0.00210137)52:0.01233888)45:0.01906982)73:0.003562205)38; 

enter image description here

one option drop tips have length beneath threshold.

drop_dupes <- function(tree,thres=1e-5){   tips <- which(tree$edge[,2] %in% 1:ntip(tree))   todrop <- tree$edge.length[tips] < thres   drop.tip(tree,tree$tip.label[todrop]) }  plot(drop_dupes(tree)) 

enter image description here


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -