emmanuelparadis / ape

analysis of phylogenetics and evolution
http://ape-package.ird.fr/
GNU General Public License v2.0
52 stars 11 forks source link

fix issue of read.nexus to solve the labels of translation contains space #29

Closed xiangpin closed 3 years ago

xiangpin commented 3 years ago

If the labels in Translation contain space, the original read.nexus will generate an error.

The related issue

> library(magrittr)
> readLines("./problem.tree.txt") %>% writeLines()
#NEXUS

Begin trees;
        Translate
                   1 "Tip 1",
                   2 "Tip 2",
                   3 "Tip 3 c"
;
tree TREE1 = ((1[&height=0.3]:1,2[&height=0.3]:1)[&height=0.3]:1,3[&height=0.3])[&height=0.3]:1;
End;

This issue was fixed following the steps.

First, the space and tab before the string was removed Second, The , and ; symbols were also removed Last, split the label string with the first space (start from left)

> library(ape)
> read.nexus("./problem.tree.txt")

Phylogenetic tree with 3 tips and 2 internal nodes.

Tip labels:
  Tip 1, Tip 2, Tip 3 c

Rooted; includes branch lengths.
emmanuelparadis commented 3 years ago

Thanks a lot.