I am trying to create a phylogenetic tree and for that I have aligned sequences (135 sequences) using MUSCLE and converted them to dnaBIN objects. I have also created a separate file for species name that I need to use as the tree tip labels since the tree I create doesn't have species name it only has the number of sequences.
RandomSampleDf <- RandomSample %>%
select(species_name, nucleotides, markercode, bin_uri) %>%
drop_na(bin_uri)
#A dataframe that includes the 3 variables. We are going to use BIN to annotate the tree so we need drop NA in bin_uri which leaves us with 135 sequences (originally would have been 144 if BIN was not needed)
BIN <- RandomSampleDf %>%
select(bin_uri, species_name)
#Creates a dataframe that we will turn into a csv file to annotate our tree.
write.csv(BIN, file = "BIN.csv", row.names = FALSE)
#Create a csv file to annotate the tree that will be created downstream.
RandomSampleDf$nucleotides <- DNAStringSet(RandomSampleDf$nucleotides) Scler.Sequence <- RandomSampleDf$nucleotides class(Scler.Sequence)
#A DNAStringSet is created to be used for MSA.
Scler.MUSCLE <- DNAStringSet(muscle::muscle(Scler.Sequence, maxiters = 2, diags = TRUE))
#Using the MUSCLE algorithm, an MSA is completed.
Below I am trying to create a tree where the tip labels follow the order of the species name in the CSV file created.
dnaBin.Scler <- as.DNAbin(Scler.MUSCLE)
#Converting the sequences for clustering
annot <- read.csv("BIN.csv")
#The file contains BIN numbers which are unique sequence identifiers.
all(annot$bin_uri==rownames(dnaBin.Scler))
table(annot$bin_uri)
sv1 <- setNames(annot[,1], rownames(sv1))
tree <- nj(dist.Scler)
tree <- ladderize(tree)
tree
Phylogenetic tree with 135 tips and 133 internal nodes.
Tip labels:
1, 2, 3, 4, 5, 6, ...
Unrooted; includes branch lengths.
rownames(annot) <- annot$species_name
mydata <- annot[match(tree$tip.label, annot$species_name)]
However, when I try to do this I get the following error:
Error in base::match(x, table, nomatch = nomatch, incomparables = incomparables, :
argument "table" is missing, with no default
The ideal output for when I type in tree
should be:
Phylogenetic tree with 135 tips and 133 internal nodes.
Tip labels:
Acanthastrea echinata, Acanthastrea echinata, Acanthastrea hillae, Acanthastrea hillae, Acanthastrea lordhowensis, Acanthastrea lordhowensis, ...
Unrooted; includes branch lengths.