phylocomr
is an R client for Phylocom - a C library for Analysis of Phylogenetic Community Structure and Character Evolution.
Phylocom home page is at http://phylodiversity.net/phylocom/. The source code for Phylocom is at https://github.com/phylocom/phylocom/.
Phylocom is usually used either on the command line or through the R package picante
, which has duplicated some of the Phylocom functionality.
Phylocom has been cited nearly 1000 times according to Google Scholar, so is clearly a very widely used piece of software. The goal with this package is to make it even easier to use - and in particular, to incorporate its use into a reproducible workflow entirely in R instead of going to the shell/command line for Phylocom usage. (Yes, some of Phylocom functionality is in picante
, but not all.)
In terms of performance, some functionality will be faster here than in picante
, but the maintainers of picante
have re-written some Phylocom functionality in C/C++, so performance should be similar in those cases.
Install ape
for below examples:
install.packages('ape')
Stable phylocomr
version from CRAN
install.packages("phylocomr")
Or, the development version from Github
devtools::install_github("ropensci/phylocomr")
library("phylocomr")
taxa_file <- system.file("examples/taxa", package = "phylocomr")
phylo_file <- system.file("examples/phylo", package = "phylocomr")
(taxa_str <- readLines(taxa_file))
#> [1] "campanulaceae/lobelia/lobelia_conferta"
#> [2] "cyperaceae/mapania/mapania_africana"
#> [3] "amaryllidaceae/narcissus/narcissus_cuatrecasasii"
(phylo_str <- readLines(phylo_file))
#> [1] "(((((eliea_articulata,homalanthus_populneus)malpighiales,rosa_willmottiae),((macrocentrum_neblinae,qualea_clavata),hibiscus_pohlii)malvids),(((lobelia_conferta,((millotia_depauperata,(layia_chrysanthemoides,layia_pentachaeta)layia),senecio_flanaganii)asteraceae)asterales,schwenkia_americana),tapinanthus_buntingii)),(narcissus_cuatrecasasii,mapania_africana))poales_to_asterales;"
ph_phylomatic(taxa = taxa_str, phylo = phylo_str)
#> [1] "(lobelia_conferta:5.000000,(mapania_africana:1.000000,narcissus_cuatrecasasii:1.000000):1.000000)poales_to_asterales;\n"
#> attr(,"taxa_file")
#> [1] "/var/folders/fc/n7g_vrvn0sx_st0p8lxb3ts40000gn/T//RtmpU8MrR6/taxa_3df8509f4496"
#> attr(,"phylo_file")
#> [1] "/var/folders/fc/n7g_vrvn0sx_st0p8lxb3ts40000gn/T//RtmpU8MrR6/phylo_3df884ffd34"
traits_file <- system.file("examples/traits_aot", package = "phylocomr")
phylo_file <- system.file("examples/phylo_aot", package = "phylocomr")
traitsdf_file <- system.file("examples/traits_aot_df", package = "phylocomr")
traits <- read.table(text = readLines(traitsdf_file), header = TRUE,
stringsAsFactors = FALSE)
phylo_str <- readLines(phylo_file)
ph_aot(traits = traits, phylo = phylo_str)
#> $trait_conservatism
#> # A tibble: 124 x 28
#> trait trait.name node name age ntaxa n.nodes tip.mn tmn.ranklow
#> <int> <chr> <int> <chr> <dbl> <int> <int> <dbl> <int>
#> 1 1 traitA 0 A 5 32 2 1.75 1000
#> 2 1 traitA 1 B 4 16 2 1.75 648
#> 3 1 traitA 2 C 3 8 2 1.75 647
#> 4 1 traitA 3 D 2 4 2 1.5 258
#> 5 1 traitA 4 E 1 2 2 1 58
#> 6 1 traitA 7 F 1 2 2 2 1000
#> 7 1 traitA 10 G 2 4 2 2 1000
#> 8 1 traitA 11 H 1 2 2 2 1000
#> 9 1 traitA 14 I 1 2 2 2 1000
#> 10 1 traitA 17 J 3 8 2 1.75 676
#> # ... with 114 more rows, and 19 more variables: tmn.rankhi <int>,
#> # tip.sd <dbl>, tsd.ranklow <int>, tsd.rankhi <int>, node.mn <dbl>,
#> # nmn.ranklow <int>, nmn.rankhi <int>, nod.sd <dbl>, nsd.ranklow <int>,
#> # nsd.rankhi <int>, sstipsroot <dbl>, sstips <dbl>,
#> # percvaramongnodes <dbl>, percvaratnode <dbl>, contributionindex <dbl>,
#> # sstipvnoderoot <dbl>, sstipvnode <dbl>, ssamongnodes <dbl>,
#> # sswithinnodes <dbl>
#>
#> $independent_contrasts
#> # A tibble: 31 x 17
#> node name age n.nodes contrast1 contrast2 contrast3 contrast4
#> <int> <chr> <dbl> <int> <dbl> <dbl> <dbl> <dbl>
#> 1 0 A 5 2 0 0 0 0.254
#> 2 1 B 4 2 0 1.03 0 0.516
#> 3 2 C 3 2 0.267 0.535 0 0
#> 4 3 D 2 2 0.577 0 1.15 0
#> 5 4 E 1 2 0 0 0.707 0
#> 6 7 F 1 2 0 0 0.707 0
#> 7 10 G 2 2 0 0 1.15 0
#> 8 11 H 1 2 0 0 0.707 0
#> 9 14 I 1 2 0 0 0.707 0
#> 10 17 J 3 2 0.267 0.535 0 0
#> # ... with 21 more rows, and 9 more variables: contrastsd <dbl>,
#> # lowval1 <dbl>, hival1 <dbl>, lowval2 <dbl>, hival2 <dbl>,
#> # lowval3 <dbl>, hival3 <dbl>, lowval4 <dbl>, hival4 <dbl>
#>
#> $phylogenetic_signal
#> # A tibble: 4 x 5
#> trait ntaxa varcontr varcn.ranklow varcn.rankhi
#> <chr> <int> <dbl> <int> <int>
#> 1 traitA 32 0.054 1 1000
#> 2 traitB 32 0.109 1 1000
#> 3 traitC 32 0.622 52 949
#> 4 traitD 32 0.011 1 1000
#>
#> $ind_contrast_corr
#> # A tibble: 3 x 6
#> xtrait ytrait ntaxa picr npos ncont
#> <chr> <chr> <int> <dbl> <dbl> <int>
#> 1 traitA traitB 32 0.248 18.5 31
#> 2 traitA traitC 32 0.485 27.5 31
#> 3 traitA traitD 32 0 16.5 31
ages_file <- system.file("examples/ages", package = "phylocomr")
phylo_file <- system.file("examples/phylo_bladj", package = "phylocomr")
ages_df <- data.frame(
a = c('malpighiales','salicaceae','fabaceae','rosales','oleaceae',
'gentianales','apocynaceae','rubiaceae'),
b = c(81,20,56,76,47,71,18,56)
)
phylo_str <- readLines(phylo_file)
res <- ph_bladj(ages = ages_df, phylo = phylo_str)
if (requireNamespace("ape")) {
library(ape)
plot(read.tree(text = res))
}
plot