liamrevell / phytools

GNU General Public License v3.0
207 stars 56 forks source link

wrong node label in drop.tip.singleton #14

Closed MarioJose closed 4 years ago

MarioJose commented 7 years ago

Dear @liamrevell,

I'm using the function 'drop.tip.singleton' and having some problems with node labels. The final tree has some node labels of excluded nodes. For instance:

# Pool tree of which I want remove some tips
pool <- "((((((((annona_cacans,annona_sylvatica,annona_montana,annona_dioica,annona_coriacea,annona_cornifolia,annona_dolabripetala,annona_neosalicifolia,annona_neosericea,annona_nutans,annona_crotonifolia,annona_crassiflora)annona,(rollinia_sylvatica,rollinia_emarginata,rollinia_mucosa,rollinia_sericea)rollinia),(guatteria_australis,guatteria_nigrescens)guatteria),(duguetia_furfuracea,duguetia_lanceolata)duguetia),(xylopia_sericea,xylopia_brasiliensis,xylopia_aromatica,xylopia_emarginata)xylopia),(porcelia_macrocarpa)porcelia),((unonopsis_lindmanii)unonopsis,(ephedranthus_parviflorus)ephedranthus)),(anaxagorea_phaeocarpa)anaxagorea)annonaceae;"

# Species of my sample of which I want to keep in pool tree.
samp <- c("annona_cacans","annona_coriacea","annona_crassiflora","annona_dolabripetala","annona_neosalicifolia","annona_neosericea","annona_nutans","annona_sylvatica","duguetia_furfuracea","duguetia_lanceolata","xylopia_aromatica")

# Reading pool tree
tpool <- read.newick(text=pool)

# Removing tips of pool tree that is not in my sample
tsamp <- drop.tip.singleton(tpool, tpool$tip.label[!(tpool$tip.label %in% samp)])

# Final tree
write.tree(tsamp)
"((((((((annona_cacans,annona_sylvatica,annona_coriacea,annona_dolabripetala,annona_neosalicifolia,annona_neosericea,annona_nutans,annona_crassiflora)annona)),(duguetia_furfuracea,duguetia_lanceolata)rollinia),(xylopia_aromatica)guatteria))))annonaceae;"

Note that 'rollinia' and 'guetteria' nodes labels must be dropped, but the function changed 'duguetia' and 'xylopia' nodes labels to labels of nodes that was deleted.

Best regards,

Mario

MarioJose commented 7 years ago

Dear @liamrevell,

I wrote the function drop.tip.label that solve the problem. It can remove tips and preserve singletons.

All the best,

Mario

MarioJose commented 7 years ago

Dear @liamrevell,

I just update phytools to 0.6-20 version and the problem persist.

All the best,

Mario

liamrevell commented 4 years ago

ape::drop.tip now has an option (collapse.singles=TRUE) that drops tips from a tree with non-splitting nodes, and that also allows the resulting tree to contain these nodes. I recommend using that function.