treeio
treeio copied to clipboard
Error in check_edgelist(x) : Cannot find root. network is not a tree!
Describe you issue
- [ ] I import a nkw file as read.newick("
.nwk") - [ ] I construct this file with PopPUNK to habe GPSC
- [ ] I don't want to plot the references jusst my query sequences
- [ ] I run tree.df.2018 <- tree.2018 %>% as_tibble() %>% as.data.frame() # to trsaform to data.frame
- [ ] Then I run tree.df2.2018 <- tree.df.2018[grepl("PT",tree.df.2018$label),] #to keep only sequnces starting with PT
- [ ] tree.df2.2018 %>% as.phylo() # gives the error Error in check_edgelist(x) : Cannot find root. network is not a tree!
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
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.
Thank you Brad, it did solve the problem.