Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Replicating Tehrani & Collard 2002
# paste from http://www.ceacb.ucl.ac.uk/ceacb_files/misc/Tehrani_Collard_2002.pdf
# edit to get each textile design on one line
raw_input <-
c("Ersari 1 0 1 0 1 1 0 1 0 1 1 0 1 1 100000011010000001011001111101011000011111100110111011011011011011110000000 0
Saryk 1 0 1 0 1 1 1 1 1 1 1 0 1 0 100000011010111101010100001111100000010101010110011011100000001011100000000 0
Salor 1 0 1 1 0 1 0 1 0 1 0 1 0 0 011110110101000001011000001011110111010101000100111101111101001101100000101 0
PSDP Tekke 1 1 0 0 0 1 0 1 1 0 1 0 0 0 011000011111111111011010001010100000010101101101000000000000000000001101000 0
SDP Tekke 1 1 0 0 0 1 0 1 1 0 0 1 0 0 000011111001110011111010000000000010100001100000000000001100101010001011111 1
Yomut 0 0 0 0 0 1 0 1 1 0 0 0 1 1 000000000000101100000001100000011000010100000000000000000000000000000000000 0")
library(tidyverse)
v1 <- unlist(str_split(raw_input, "\n"))
textile_design_names <-
map_chr(v1, ~str_remove_all(.x, "[[0-9]]") %>% str_trim) %>%
str_replace_all(" ", "_")
textile_design_chr_states <-
map_chr(v1, ~str_remove_all(.x, "[[:alpha:]]| ") %>% str_trim)
x <- str_split(textile_design_chr_states, "")
names(x) <- textile_design_names
ape::write.nexus.data(x,
file = "Tehrani_Collard_2002.nex",
format = "standard")
x_in <- ape::read.nexus.data("Tehrani_Collard_2002.nex")
library(phangorn) # load library phangorn 'Phylogenetic analysis in R'
b.pd <- phyDat(x, type="USER", levels=c(0:1)) # convert nex to phyDat format
b.pd #check what went in.
pratchet_out <- pratchet(b.pd)
plot(pratchet_out)
library(phytools)
b.pd.e <- exhaustiveMP(b.pd, method="exhaustive")
# consistency index
CI(b.pd.e[[1]], b.pd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment