jgx65 / hierfstat

the hierfstat package
24 stars 14 forks source link

Bug in `getal` #24

Closed alephreish closed 3 years ago

alephreish commented 6 years ago

The following line in misc.R: if (i==1) ind<-dum else ind<-c(ind,dum) causes the following error when one of the populations is called '1' AND it doesn't appear first in sort(unique(data[,1])):

> data
/// GENIND OBJECT /////////

 // 61 individuals; 7 loci; 14 alleles; size: 16.9 Kb

 // Basic content
   @tab:  61 x 14 matrix of allele counts
   @loc.n.all: number of alleles per locus (range: 2-2)
   @loc.fac: locus factor for the 14 columns of @tab
   @all.names: list of allele names for each locus
   @ploidy: ploidy of each individual  (range: 2-2)
   @type:  codom
   @call: df2genind(X = locus, sep = "/", ind.names = sample, pop = pop, ploidy = 2)

 // Optional content
   @pop: population of each individual (group size range: 1-13)
> data$pop
 [1] F F F 1 1 5 1 2 5 4 N 3 D D D D D D D 5 D C C C D C C D D 2 1 4 1 D N F F F
[39] F F F F F F L C C K C C M M M K K C C L F 4 2
Levels: F 1 5 2 4 N 3 D C L K M

> getal(data)
Error in data.frame(pop = rep(data[, 1], 2), ind = ind, al = rbind(firstal,  : 
  arguments imply differing number of rows: 122, 96

The offending line should be fixed to just ind<-c(ind,dum). The obvious workaround for anyone facing the issue is to guarantee that none of the populations is called '1'.

falseflattortuga commented 3 years ago

There might be problems even if no population is labeled "1". It seems that population labels must be ordered to ensure correct results. See Issue #42

jgx65 commented 3 years ago

should be solved, see #42