首页 > 解决方案 > 在 R 中创建 Nexus 文件

问题描述

我有一个用于创建关联文件的矩阵:

mt = matrix(c(rep(1:5,times = 2), NA, 2,5,2,4,1,2,5,3,1), nrow=10)
rownames(mt) <- paste(rep("taxon", 10), 1:10)
colnames(mt) = c("color", "type")
mt
         color type
taxon 1      1   NA
taxon 2      2    2
taxon 3      3    5
taxon 4      4    2
taxon 5      5    4
taxon 6      1    1
taxon 7      2    2
taxon 8      3    5
taxon 9      4    3
taxon 10     5    1

创建一个 ```mt```` 的关系文件(格式标准 - 分类矩阵)我正在使用:

charstate = write.nexus.data(mt, file = "charstate.nex", format ="stand", datablock = T)

这将导致:

#NEXUS
[Data written by write.nexus.data.R, Sun Mar 07 13:19:14 2021]
BEGIN DATA;
  DIMENSIONS NTAX=10 NCHAR=2;
  FORMAT DATATYPE=STANDARD MISSING=? GAP=- INTERLEAVE=NO symbols="0123456789";
  MATRIX
    taxon 1       1NA
    taxon 2       22
    taxon 3       35
    taxon 4       42
    taxon 5       54
    taxon 6       11
    taxon 7       22
    taxon 8       35
    taxon 9       43
    taxon 10      51
  ;
END;

但是,我想在我的 NEXUS 文件中也有 CHARSTATELABELS。例子:


#NEXUS
[Data written by write.nexus.data.R, Sun Mar 07 13:19:14 2021]
BEGIN DATA;
  DIMENSIONS NTAX=10 NCHAR=2;
  FORMAT DATATYPE=STANDARD MISSING=? GAP=- INTERLEAVE=NO symbols="0123456789"
    CHARSTATELABELS 
        1 'color (1 blue, 2 yellow, 3 red, 4 black, 5 white)'
        2'type(1 big, 2 short, 3 medium, 4 big-short, 5 medium-short)'
; 
    MATRIX

此外,您可以看到符号未显示正确的编码状态。右边是符号 =“012345”,而不是最初描述的 0 到 9。如何包含CHARSTATELABELS和正确的 ** 符号**?

标签: rnexusape

解决方案


推荐阅读