treeio icon indicating copy to clipboard operation
treeio copied to clipboard

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

Open acpaulo opened this issue 3 years ago • 2 comments

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

acpaulo avatar Jul 29 '22 15:07 acpaulo

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.

brj1 avatar Jul 29 '22 16:07 brj1

Thank you Brad, it did solve the problem.

acpaulo avatar Jul 29 '22 18:07 acpaulo