jgx65 / hierfstat

the hierfstat package
24 stars 14 forks source link

pop.freq returns vector for one locus rather than a table #12

Closed EricArcher closed 8 years ago

EricArcher commented 8 years ago

When calculating chord distance for each locus, I got an error that I traced to pop.freq returning a vector rather than a table for a particular locus (Ttr11 in the example data below). It's not clear to me what is different about this locus from the others. I tried to do a bit of debugging and got as far as finding that there is something about the two matrices that the freq function in pop.freq returns for the two columns in ndat that causes apply to return a two-dimensional matrix rather than a two-element list of matrices as it does for the other loci. I couldn't work out why that is happening though...

Here is a zip file with the data: test.pop.freq.dat.rdata.zip

Here is some code that demonstrates the problem:

load("test.pop.freq.dat.rdata")
for(i in 4:ncol(dat)) {
  print(pop.freq(dat[, c(1, i)]))
}

And the output: $EV94

x Coastal Offshore.North Offshore.South 229 0.00000000 0.00000000 0.02777778 239 0.00000000 0.02564103 0.00000000 243 0.00000000 0.11538462 0.16666667 245 0.08823529 0.05128205 0.05555556 247 0.00000000 0.03846154 0.00000000 249 0.34558824 0.32051282 0.30555556 251 0.22058824 0.11538462 0.05555556 253 0.00000000 0.06410256 0.05555556 255 0.00000000 0.06410256 0.02777778 259 0.18382353 0.01282051 0.02777778 261 0.16176471 0.03846154 0.05555556 263 0.00000000 0.05128205 0.08333333 265 0.00000000 0.07692308 0.05555556 269 0.00000000 0.01282051 0.05555556 271 0.00000000 0.01282051 0.02777778

[1] 0.00000000 0.30882353 0.00000000 0.00000000 0.43382353 0.24264706 0.01470588 0.00000000 [9] 0.01282051 0.03846154 0.10256410 0.15384615 0.30769231 0.23076923 0.11538462 0.03846154 [17] 0.00000000 0.00000000 0.19444444 0.08333333 0.13888889 0.30555556 0.08333333 0.11111111 [25] 0.05555556 0.02777778 0.11764706 0.07352941 0.08823529 0.10294118 0.10294118 0.04411765 [33] 0.13235294 0.17647059 0.16176471 0.17500000 0.05000000 0.07500000 0.10000000 0.15000000 [41] 0.10000000 0.07500000 0.15000000 0.12500000 0.33333333 0.11111111 0.05555556 0.11111111 [49] 0.05555556 0.05555556 0.11111111 0.05555556 0.11111111 $Ttr34

x Coastal Offshore.North Offshore.South 179 0.00000000 0.00000000 0.02777778 183 0.00000000 0.13750000 0.08333333 185 0.24264706 0.23750000 0.30555556 187 0.13970588 0.11250000 0.11111111 189 0.00000000 0.21250000 0.19444444 191 0.47794118 0.06250000 0.08333333 193 0.05882353 0.10000000 0.08333333 195 0.08088235 0.11250000 0.08333333 199 0.00000000 0.01250000 0.00000000 201 0.00000000 0.01250000 0.02777778

jgx65 commented 8 years ago

Thanks for the report. Working on it, have just pushed a quick fix to pop.freq, but will need to look in more details into it

jgx65 commented 8 years ago

Should be fixed now. Please check, thanks.

EricArcher commented 8 years ago

Looks good now. Thanks Jerome!