Before you begin, install the package with:

devtools::install_github("graemetlloyd/ProjectWhalehead")
devtools::install_github("graemetlloyd/metatree")
devtools::install_github("graemetlloyd/Claddis")
devtools::install_github("graemetlloyd/hypRspace")

Now, we’ll load libraries and ensure we’re in the right place (getwd should return “ProjectWhalehead”’s location on your machine).

library(Whalehead)
library(metatree)
library(Claddis)
getwd()

To reproduce the paper, you will make sure all the tips have both data and metadata. If they do, you will get ages from PBDB.

Whalehead::build_ages("Data/NEXUS/", "Data/XML/", "Data/Ages")

Then, you will check the datasets to make sure all the tips have names and those names can be synchronized across data sources. Also, disregard any sets with missing tip ages.

We have included the scripts to estimate phylogenetic trees from the data. This is time-intensive and we will not reproduce this analysis in this notebook. We will skip straight to making the stratigraphic congruence output.

make_strat_congruence("Data/RevBayesOutput/", "Data/NEXUS/", "Data/Ages/", "Data/MPTS/", "revbayes_output", "parsimony_out")

Next, we can summarize the data in a few ways. To make table two:

fi <- list.files("Data/StratCongruenceResults/")
sapply(fi, summary_stat)

Or your could summarize all of the files at once:

summarize_medians(user.path = "Data/StratCongruenceResults/")

Or make violin and box plots of them:

files <- list.files(path = user.path, pattern = "*.txt", full.names = TRUE, recursive = FALSE)
dir.create("ViolinPlots")
lapply(files, makeViolins)
dir.create("boxPlots")
lapply(files, makeBoxplot)

Finally, you can make our custom treespace visuals. These are compute intensive, so only one is shown here. The functions to do this are modified from the R package RWTY and depend on RWTY being installed.

library(rwty)
#dir.create("data/TreeSpacePlots/")
trees  <- list.files(path = "Data/CombinedTrees", pattern = "*.nex", full.names = TRUE, recursive = FALSE)
strats  <- list.files(path = "Data/StratCongruenceResults/InputTreeResults", pattern = "*.txt", full.names = TRUE, recursive = FALSE)

for (i in 1:length(trees)){
  print(trees[i])
  print(strats[i])
  custom_plots(CombinedTrees = trees[i], StratFile =  strats[i], ext_columns = c("MIG", "Bayes"))
}

# custom_plots(CombinedTrees = "Data/CombinedTrees/Aguirre-Fernandez_etal_2009a.nex", StratFile =  "Data/StratCongruenceResults/InputTreeResults/Aguirre-Fernandez_etal_2009a.txt", ext_columns = c("MIG", "Bayes"))