从R中的频率矩阵创建一个genet类

时间:2014-10-07 08:53:57

标签: r data-analysis

我尝试使用“freq2genet”方法在R中创建一个包含“adegenet”的“genet”类。但是一旦我用我的数据集调用该方法,其中存储了基因频率,就会出现“类型”(字符)参数不正确的错误。它仍然发生在我使用“as.data.frame”之后。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

传递给freq2genet的对象应该是data.frame,其中行是观察(群体),列是等位基因频率。这是ade4:::chevaine示例中的数据结构。无论与此有何不同,都可能是您出错的原因。

> head(chevaine$tab)
    PGM-2*.090 PGM-2*.098 PGM-2*.100 IDHP-1*.100 IDHP-1*.145 EST-2*.098 EST-2*.100 G3PDH*.085 G3PDH*.100
P01      0.017      0.150      0.833       1.000       0.000      0.300      0.700      0.217      0.783
P02      0.083      0.216      0.701       1.000       0.000      0.300      0.700      0.167      0.833
P03      0.107      0.179      0.714       0.982       0.018      0.250      0.750      0.179      0.821
P04      0.067      0.200      0.733       1.000       0.000      0.467      0.533      0.217      0.783
P05      0.103      0.190      0.707       1.000       0.000      0.362      0.638      0.103      0.897
P06      0.179      0.125      0.696       0.981       0.019      0.250      0.750      0.154      0.846

> str(freq2genet(chevaine$tab))
List of 8
 $ tab       :'data.frame': 27 obs. of  9 variables:
  ..$ L1.1: num [1:27] 0.3 0.3 0.25 0.467 0.362 0.25 0.217 0.308 0.25 0.31 ...
  ..$ L1.2: num [1:27] 0.7 0.7 0.75 0.533 0.638 0.75 0.783 0.692 0.75 0.69 ...
  ..$ L2.1: num [1:27] 0.217 0.167 0.179 0.217 0.103 0.154 0.1 0.038 0.05 0.119 ...
  ..$ L2.2: num [1:27] 0.783 0.833 0.821 0.783 0.897 0.846 0.9 0.962 0.95 0.881 ...
  ..$ L3.1: num [1:27] 1 1 0.982 1 1 0.981 0.983 1 0.975 0.976 ...
  ..$ L3.2: num [1:27] 0 0 0.018 0 0 0.019 0.017 0 0.025 0.024 ...
  ..$ L4.1: num [1:27] 0.017 0.083 0.107 0.067 0.103 0.179 0.216 0.25 0.175 0.282 ...
  ..$ L4.2: num [1:27] 0.15 0.216 0.179 0.2 0.19 0.125 0.2 0.115 0.05 0 ...
  ..$ L4.3: num [1:27] 0.833 0.701 0.714 0.733 0.707 0.696 0.584 0.635 0.775 0.718 ...
 $ center    : Named num [1:9] 0.322 0.678 0.114 0.886 0.901 ...
  ..- attr(*, "names")= chr [1:9] "L1.1" "L1.2" "L2.1" "L2.2" ...
 $ pop.names : Named chr [1:27] "P01" "P02" "P03" "P04" ...
  ..- attr(*, "names")= chr [1:27] "P01" "P02" "P03" "P04" ...
 $ all.names : Named chr [1:9] "EST-2*.098" "EST-2*.100" "G3PDH*.085" "G3PDH*.100" ...
  ..- attr(*, "names")= chr [1:9] "L1.1" "L1.2" "L2.1" "L2.2" ...
 $ loc.blocks: Named num [1:4] 2 2 2 3
  ..- attr(*, "names")= chr [1:4] "L1" "L2" "L3" "L4"
 $ loc.fac   : Factor w/ 4 levels "EST-2*","G3PDH*",..: 1 1 2 2 3 3 4 4 4
 $ loc.names : Named chr [1:4] "EST-2*" "G3PDH*" "IDHP-1*" "PGM-2*"
  ..- attr(*, "names")= chr [1:4] "L1" "L2" "L3" "L4"
 $ all.pop   :'data.frame': 9 obs. of  27 variables:
  ..$ P01: num [1:9] 0.3 0.7 0.217 0.783 1 0 0.017 0.15 0.833
  ..$ P02: num [1:9] 0.3 0.7 0.167 0.833 1 0 0.083 0.216 0.701
  ..$ P03: num [1:9] 0.25 0.75 0.179 0.821 0.982 0.018 0.107 0.179 0.714
  ..$ P04: num [1:9] 0.467 0.533 0.217 0.783 1 0 0.067 0.2 0.733
  ..$ P05: num [1:9] 0.362 0.638 0.103 0.897 1 0 0.103 0.19 0.707
  ..$ P06: num [1:9] 0.25 0.75 0.154 0.846 0.981 0.019 0.179 0.125 0.696
  ..$ P07: num [1:9] 0.217 0.783 0.1 0.9 0.983 0.017 0.216 0.2 0.584
  ..$ P08: num [1:9] 0.308 0.692 0.038 0.962 1 0 0.25 0.115 0.635
  ..$ P09: num [1:9] 0.25 0.75 0.05 0.95 0.975 0.025 0.175 0.05 0.775
  ..$ P10: num [1:9] 0.31 0.69 0.119 0.881 0.976 0.024 0.282 0 0.718
  ..$ P11: num [1:9] 0.308 0.692 0.154 0.846 0.962 0.038 0.154 0.038 0.808
  ..$ P12: num [1:9] 0.354 0.646 0.104 0.896 0.979 0.021 0.125 0.104 0.771
  ..$ P13: num [1:9] 0.317 0.683 0.167 0.833 0.8 0.2 0.033 0.716 0.251
  ..$ P14: num [1:9] 0.3 0.7 0.083 0.917 0.75 0.25 0.033 0.6 0.367
  ..$ P15: num [1:9] 0.46 0.54 0.14 0.86 0.74 0.26 0.04 0.62 0.34
  ..$ P16: num [1:9] 0.369 0.631 0.119 0.881 0.69 0.31 0 0.69 0.31
  ..$ P17: num [1:9] 0.494 0.506 0.104 0.896 0.747 0.253 0.003 0.659 0.338
  ..$ P18: num [1:9] 0.321 0.679 0.036 0.964 0.589 0.411 0 0.536 0.464
  ..$ P19: num [1:9] 0.286 0.714 0.086 0.914 0.871 0.129 0.129 0.343 0.528
  ..$ P20: num [1:9] 0.267 0.733 0.05 0.95 0.95 0.05 0.15 0.133 0.717
  ..$ P21: num [1:9] 0.241 0.759 0.121 0.879 0.966 0.034 0.138 0.103 0.759
  ..$ P22: num [1:9] 0.25 0.75 0.162 0.838 0.941 0.059 0.176 0.059 0.765
  ..$ P23: num [1:9] 0.339 0.661 0.054 0.946 0.893 0.107 0.125 0.089 0.786
  ..$ P24: num [1:9] 0.386 0.614 0.068 0.932 0.886 0.114 0.114 0.136 0.75
  ..$ P25: num [1:9] 0.308 0.692 0.115 0.885 0.823 0.177 0.135 0.01 0.855
  ..$ P26: num [1:9] 0.338 0.662 0.103 0.897 0.912 0.088 0.088 0.103 0.809
  ..$ P27: num [1:9] 0.353 0.647 0.074 0.926 0.941 0.059 0.059 0.118 0.823
 - attr(*, "class")= chr [1:2] "genet" "list"