Read New Hampshire eXtended format for trees

read_nhx(fn, txt)

Arguments

fn

Full path to the tree file.

txt

If no file is specified, trees can also be passed as a character scalar (see examples).

Value

A list with the following elements:

  • tree An object of class ape

  • edge Edge annotations (length and other annotations)

  • nhx A list of annotations NHX

References

"NHX - New Hampshire eXtended [version 2.0]", https://en.wikipedia.org/wiki/Newick_format#New_Hampshire_X_format

See also

Other reading: panther-tree, read_pli()

Examples

# Example directly extracted from
# https://sites.google.com/site/cmzmasek/home/software/forester/nhx
read_nhx(
  txt = "(((ADH2:0.1[&&NHX:S=human], ADH1:0.11[&&NHX:S=human]):0.05[&&NHX:S=primates:D=Y:B=100],
    ADHY:0.1[&&NHX:S=nematode],ADHX:0.12[&&NHX:S=insect]):0.1[&&NHX:S=metazoa:D=N],
    (ADH4:0.09[&&NHX:S=yeast],ADH3:0.13[&&NHX:S=yeast], ADH2:0.12[&&NHX:S=yeast],
    ADH1:0.11[&&NHX:S=yeast]):0.1 [&&NHX:S=Fungi])[&&NHX:D=N];"
    )
#> $tree
#> 
#> Phylogenetic tree with 8 tips and 4 internal nodes.
#> 
#> Tip labels:
#>   ADH2, ADH1, 
#> ADHY, ADHX, ADH4, ADH3, ...
#> Node labels:
#>   , unnamed0002, unnamed0001, unnamed0003
#> 
#> Rooted; includes branch lengths.
#> 
#> $edge
#>       [,1]          [,2]   
#>  [1,] "ADH2"        ":0.1" 
#>  [2,] "ADH1"        ":0.11"
#>  [3,] "unnamed0001" ":0.05"
#>  [4,] "ADHY"        ":0.1" 
#>  [5,] "ADHX"        ":0.12"
#>  [6,] "unnamed0002" ":0.1" 
#>  [7,] "ADH4"        ":0.09"
#>  [8,] "ADH3"        ":0.13"
#>  [9,] "ADH2"        ":0.12"
#> [10,] "ADH1"        ":0.11"
#> [11,] "unnamed0003" ":0.1" 
#> 
#> $nhx
#> $nhx[[1]]
#>       S 
#> "human" 
#> 
#> $nhx[[2]]
#>       S 
#> "human" 
#> 
#> $nhx[[3]]
#>          S          D          B 
#> "primates"        "Y"      "100" 
#> 
#> $nhx[[4]]
#>          S 
#> "nematode" 
#> 
#> $nhx[[5]]
#>        S 
#> "insect" 
#> 
#> $nhx[[6]]
#>         S         D 
#> "metazoa"       "N" 
#> 
#> $nhx[[7]]
#>       S 
#> "yeast" 
#> 
#> $nhx[[8]]
#>       S 
#> "yeast" 
#> 
#> $nhx[[9]]
#>       S 
#> "yeast" 
#> 
#> $nhx[[10]]
#>       S 
#> "yeast" 
#> 
#> $nhx[[11]]
#>       S 
#> "Fungi" 
#> 
#>