YuLab-SMU / treeio

:seedling: Base Classes and Functions for Phylogenetic Tree Input and Output
https://yulab-smu.top/treedata-book/
94 stars 24 forks source link

Error in check_edgelist(x) : Cannot find root. network is not a tree! #80

Closed acpaulo closed 1 year ago

acpaulo commented 2 years ago

Describe you issue

Is there a way to subset the nwk file without transform it to a data.frame or to pass a data.fram to a phylo object again ?

Thank you in advance

brj1 commented 2 years ago

You should use the ape library to manipulate phylo objects. It is a dependency of treeio so should already have it installed. ape's keep.tip function subsets tips.

library(ape)
tree.2018.subset <- keep.tip(tree.2018, grep("PT", tree.2018$tip.label))

Note that keep.tip uses tip/node numbers not a boolean filter so you need to use grep instead of grepl.

acpaulo commented 2 years ago

Thank you Brad, it did solve the problem.