使用R从CSV文件分配树提示标签

时间:2018-12-06 20:53:13

标签: r bioinformatics phylogeny

我正在尝试创建一个系统发育树,为此,我使用MUSCLE确定了比对序列(135个序列)并将其转换为dnaBIN对象。我还为物种名称创建了一个单独的文件,需要将其用作树梢标签,因为我创建的树没有物种名称,它只有序列数。

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.

下面,我试图创建一棵树,其中提示标签遵循所创建的CSV文件中物种名称的顺序。

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)]

但是,当我尝试执行此操作时,出现以下错误:

Error in base::match(x, table, nomatch = nomatch, incomparables = incomparables,  : 
  argument "table" is missing, with no default

当我输入tree时,理想的输出应该是:

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.

0 个答案:

没有答案